Skip to content

Commit

Permalink
samples: drivers: IPM fixes
Browse files Browse the repository at this point in the history
Updates and fixes to support IPM sample on ESP32:

- fix IPM sample code for APPCPU and PROCPU
- align with memory layout, add flash awarenes
- shell commands to stop/start APPCPU
- reorganize overlays

Signed-off-by: Marek Matej <[email protected]>
  • Loading branch information
Marek Matej committed Nov 5, 2024
1 parent e24f57c commit c8c9a15
Show file tree
Hide file tree
Showing 10 changed files with 99 additions and 43 deletions.
30 changes: 4 additions & 26 deletions samples/drivers/ipm/ipm_esp32/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,11 @@

cmake_minimum_required(VERSION 3.20.0)

set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/ipm_esp32_appcpu-prefix/src/ipm_esp32_appcpu-build/zephyr)

if("${BOARD}" STREQUAL "esp32_devkitc_wrover/esp32/procpu")
set(BOARD_REMOTE "esp32_devkitc_wrover/esp32/appcpu")
elseif("${BOARD}" STREQUAL "esp32_devkitc_wroom/esp32/procpu")
set(BOARD_REMOTE "esp32_devkitc_wroom/esp32/appcpu")
elseif("${BOARD}" STREQUAL "esp32s3_devkitm/esp32s3/procpu")
set(BOARD_REMOTE "esp32s3_devkitm/esp32s3/appcpu")
else()
message(FATAL_ERROR "${BOARD} was not supported for this sample")
endif()
set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/../ipm_esp32_remote/zephyr)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ipm_esp32)

set_source_files_properties(${REMOTE_ZEPHYR_DIR}/esp32_appcpu_firmware.c PROPERTIES GENERATED TRUE)
target_sources(app PRIVATE src/main.c ${REMOTE_ZEPHYR_DIR}/esp32_appcpu_firmware.c)

include(ExternalProject)

ExternalProject_Add(
ipm_esp32_appcpu
SOURCE_DIR ${APPLICATION_SOURCE_DIR}/ipm_esp_appcpu
INSTALL_COMMAND ""
CMAKE_CACHE_ARGS -DBOARD:STRING=${BOARD_REMOTE}
BUILD_BYPRODUCTS "${REMOTE_ZEPHYR_DIR}/${KERNEL_BIN_NAME}"
BUILD_ALWAYS True
)
message(STATUS "${BOARD} compile as Master in this sample")
project(ipm_esp32)

add_dependencies(app ipm_esp32_appcpu)
target_sources(app PRIVATE src/main.c src/procpu_shell.c)
2 changes: 0 additions & 2 deletions samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/prj.conf

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
cmake_minimum_required(VERSION 3.20.0)

find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
project(ipm_esp32_appcpu)

message(STATUS "${BOARD} compiles as remote in this sample")
project(ipm_esp32_remote)

target_sources(app PRIVATE src/main.c)
3 changes: 3 additions & 0 deletions samples/drivers/ipm/ipm_esp32/remote/prj.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_IPM=y
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdio.h>
#include <zephyr/kernel.h>
#include <zephyr/device.h>
#include <zephyr/sys/printk.h>
#include <zephyr/drivers/ipm.h>
#include <zephyr/device.h>

static const struct device *ipm_dev;
static const char fake_resp[] = {"APP_CPU: This is a response"};
static char resp[64];
struct k_sem sync;

static void ipm_receive_callback(const struct device *ipmdev, void *user_data,
uint32_t id, volatile void *data)
static void ipm_receive_callback(const struct device *ipmdev, void *user_data, uint32_t id,
volatile void *data)
{
k_sem_give(&sync);
}
Expand All @@ -33,7 +34,9 @@ int main(void)

while (1) {
k_sem_take(&sync, K_FOREVER);
ipm_send(ipm_dev, -1, sizeof(fake_resp), &fake_resp, sizeof(fake_resp));
snprintf(resp, sizeof(resp), "APP_CPU uptime ticks %lli\n", k_uptime_ticks());
ipm_send(ipm_dev, -1, sizeof(resp), &resp, sizeof(resp));
}

return 0;
}
3 changes: 3 additions & 0 deletions samples/drivers/ipm/ipm_esp32/socs/esp32s3_procpu.overlay
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
&ipm0 {
status = "okay";
};
28 changes: 19 additions & 9 deletions samples/drivers/ipm/ipm_esp32/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,26 @@
#include <zephyr/device.h>
#include <string.h>

static const char fake_request[] = {"PRO_CPU: Fake request to APP_CPU"};
static const char request[] = {"PRO_CPU: request to APP_CPU"};

static const struct device *ipm_dev;
static char received_string[64];
static struct k_sem sync;

static void ipm_receive_callback(const struct device *ipmdev, void *user_data,
uint32_t id, volatile void *data)
static void ipm_receive_callback(const struct device *ipmdev, void *user_data, uint32_t id,
volatile void *data)
{
ARG_UNUSED(ipmdev);
ARG_UNUSED(user_data);

strcpy(received_string, (const char *)data);
strncpy(received_string, (const char *)data, sizeof(received_string));
k_sem_give(&sync);
}

int main(void)
{
int ret;

k_sem_init(&sync, 0, 1);

ipm_dev = DEVICE_DT_GET(DT_NODELABEL(ipm0));
Expand All @@ -38,15 +40,23 @@ int main(void)

ipm_register_callback(ipm_dev, ipm_receive_callback, NULL);

/* Workaround to catch up with APPCPU */
k_sleep(K_MSEC(50));

while (1) {
printk("PRO_CPU is sending a fake request, waiting remote response...\n\r");
printk("PRO_CPU is sending a request, waiting remote response...\n\r");

ipm_send(ipm_dev, -1, sizeof(request), &request, sizeof(request));

ipm_send(ipm_dev, -1, sizeof(fake_request), &fake_request, sizeof(fake_request));
k_sem_take(&sync, K_FOREVER);
ret = k_sem_take(&sync, K_MSEC(5000));

printk("PRO_CPU received a message from APP_CPU : %s\n\r", received_string);
if (ret) {
printk("No response from APP_CPU - trying again.\r\n");
} else {
printk("PRO_CPU received a message from APP_CPU : %s\n\r", received_string);
}

k_sleep(K_MSEC(200));
k_sleep(K_MSEC(1000));
}
return 0;
}
59 changes: 59 additions & 0 deletions samples/drivers/ipm/ipm_esp32/src/procpu_shell.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd.
*
* SPDX-License-Identifier: Apache-2.0
*/

#include <stdlib.h>

#include <zephyr/device.h>
#include <zephyr/drivers/gpio.h>
#include <zephyr/drivers/regulator.h>
#include <zephyr/drivers/watchdog.h>
#include <zephyr/dt-bindings/gpio/nordic-npm6001-gpio.h>
#include <zephyr/dt-bindings/regulator/npm6001.h>
#include <zephyr/posix/unistd.h>
#include <zephyr/shell/shell.h>
#include <zephyr/sys/printk.h>

/* Command usage info. */
#define START_HELP ("<cmd>\n\nStart the APPCPU")
#define STOP_HELP ("<cmd>\n\nStop the APPCPU")

void esp_appcpu_image_start(unsigned int hdr_offset);
void esp_appcpu_image_stop(void);

static int cmd_appcpu_start(const struct shell *sh, size_t argc, char *argv[])
{
ARG_UNUSED(sh);
ARG_UNUSED(argc);
ARG_UNUSED(argv);

printk("start appcpu\n");

esp_appcpu_image_start(0x20);

return 0;
}

static int cmd_appcpu_stop(const struct shell *sh, size_t argc, char *argv[])
{
ARG_UNUSED(sh);
ARG_UNUSED(argc);
ARG_UNUSED(argv);

printk("stop appcpu\n");

esp_appcpu_image_stop();

return 0;
}

SHELL_STATIC_SUBCMD_SET_CREATE(sub_amp,
/* Alphabetically sorted to ensure correct Tab autocompletion. */
SHELL_CMD_ARG(appstart, NULL, START_HELP, cmd_appcpu_start, 1, 0),
SHELL_CMD_ARG(appstop, NULL, STOP_HELP, cmd_appcpu_stop, 1, 0),
SHELL_SUBCMD_SET_END /* Array terminated. */
);

SHELL_CMD_REGISTER(amp, &sub_amp, "AMP debug commands.", NULL);

0 comments on commit c8c9a15

Please sign in to comment.