diff --git a/samples/drivers/ipm/ipm_esp32/CMakeLists.txt b/samples/drivers/ipm/ipm_esp32/CMakeLists.txt index c4399df8a92..f343fa37b01 100644 --- a/samples/drivers/ipm/ipm_esp32/CMakeLists.txt +++ b/samples/drivers/ipm/ipm_esp32/CMakeLists.txt @@ -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}) + +message(STATUS "${BOARD} compile as Master in this sample") 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 -) - -add_dependencies(app ipm_esp32_appcpu) +target_sources(app PRIVATE src/main.c src/procpu_shell.c) diff --git a/samples/drivers/ipm/ipm_esp32/Kconfig.sysbuild b/samples/drivers/ipm/ipm_esp32/Kconfig.sysbuild new file mode 100644 index 00000000000..143c6c08eb5 --- /dev/null +++ b/samples/drivers/ipm/ipm_esp32/Kconfig.sysbuild @@ -0,0 +1,11 @@ +# Copyright 2022 NXP +# +# SPDX-License-Identifier: Apache-2.0 + +source "share/sysbuild/Kconfig" + +config IPM_REMOTE_BOARD + string + default "esp32_devkitc_wrover/esp32/appcpu" if $(BOARD) = "esp32_devkitc_wroom" + default "esp32_devkitc_wroom/esp32/appcpu" if $(BOARD) = "esp32_devkitc_wroom" + default "esp32s3_devkitm/esp32s3/appcpu" if $(BOARD) = "esp32s3_devkitm" diff --git a/samples/drivers/ipm/ipm_esp32/README.rst b/samples/drivers/ipm/ipm_esp32/README.rst index 5deb498b2f9..9f17389cc62 100644 --- a/samples/drivers/ipm/ipm_esp32/README.rst +++ b/samples/drivers/ipm/ipm_esp32/README.rst @@ -26,7 +26,8 @@ Build the ESP32 IPM sample code as follows: .. zephyr-app-commands:: :zephyr-app: samples/drivers/ipm/ipm_esp32 - :board: esp32_devkitc_wroom/esp32/procpu + :board: esp32s3_devkitm/esp32s3/procpu + :west-args: --sysbuild :goals: build :compact: @@ -38,18 +39,20 @@ console program (e.g., minicom, putty, screen, etc). .. code-block:: console - *** Booting Zephyr OS build v3.3.0-rc3-38-gc9225e4365b9 *** - PRO_CPU is sending a fake request, waiting remote response... - PRO_CPU received a message from APP_CPU : APP_CPU: This is a response - PRO_CPU is sending a fake request, waiting remote response... - PRO_CPU received a message from APP_CPU : APP_CPU: This is a response - PRO_CPU is sending a fake request, waiting remote response... - PRO_CPU received a message from APP_CPU : APP_CPU: This is a response - PRO_CPU is sending a fake request, waiting remote response... - PRO_CPU received a message from APP_CPU : APP_CPU: This is a response - PRO_CPU is sending a fake request, waiting remote response... - PRO_CPU received a message from APP_CPU : APP_CPU: This is a response - PRO_CPU is sending a fake request, waiting remote response... - PRO_CPU received a message from APP_CPU : APP_CPU: This is a response - PRO_CPU is sending a fake request, waiting remote response... - PRO_CPU received a message from APP_CPU : APP_CPU: This is a response + *** Booting Zephyr OS build v4.0.0-rc2-61-ga24efebe15e2 *** + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 502 + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 10502 + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 20503 + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 30504 + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 40505 + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 50506 + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 60507 + PRO_CPU is sending a request, waiting remote response... + PRO_CPU received a message from APP_CPU : APP_CPU uptime ticks 70508 diff --git a/samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/prj.conf b/samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/prj.conf deleted file mode 100644 index 05a3de09ec1..00000000000 --- a/samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/prj.conf +++ /dev/null @@ -1,2 +0,0 @@ -CONFIG_HEAP_MEM_POOL_SIZE=256 -CONFIG_IPM=y diff --git a/samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/CMakeLists.txt b/samples/drivers/ipm/ipm_esp32/remote/CMakeLists.txt similarity index 66% rename from samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/CMakeLists.txt rename to samples/drivers/ipm/ipm_esp32/remote/CMakeLists.txt index 44114da8450..51ba683f4f6 100644 --- a/samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/CMakeLists.txt +++ b/samples/drivers/ipm/ipm_esp32/remote/CMakeLists.txt @@ -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) diff --git a/samples/drivers/ipm/ipm_esp32/remote/prj.conf b/samples/drivers/ipm/ipm_esp32/remote/prj.conf new file mode 100644 index 00000000000..c56177a4306 --- /dev/null +++ b/samples/drivers/ipm/ipm_esp32/remote/prj.conf @@ -0,0 +1,3 @@ +CONFIG_HEAP_MEM_POOL_SIZE=2048 +CONFIG_MAIN_STACK_SIZE=4096 +CONFIG_IPM=y diff --git a/samples/drivers/ipm/ipm_esp32/boards/esp32_devkitc_wroom_procpu.overlay b/samples/drivers/ipm/ipm_esp32/remote/socs/esp32s3_appcpu.overlay similarity index 100% rename from samples/drivers/ipm/ipm_esp32/boards/esp32_devkitc_wroom_procpu.overlay rename to samples/drivers/ipm/ipm_esp32/remote/socs/esp32s3_appcpu.overlay diff --git a/samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/src/main.c b/samples/drivers/ipm/ipm_esp32/remote/src/main.c similarity index 73% rename from samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/src/main.c rename to samples/drivers/ipm/ipm_esp32/remote/src/main.c index afb7921fc64..9e7abde4cb5 100644 --- a/samples/drivers/ipm/ipm_esp32/ipm_esp_appcpu/src/main.c +++ b/samples/drivers/ipm/ipm_esp32/remote/src/main.c @@ -4,17 +4,18 @@ * SPDX-License-Identifier: Apache-2.0 */ +#include #include +#include #include #include -#include 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); } @@ -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; } diff --git a/samples/drivers/ipm/ipm_esp32/boards/esp32_devkitc_wrover_procpu.overlay b/samples/drivers/ipm/ipm_esp32/socs/esp32_procpu.overlay similarity index 100% rename from samples/drivers/ipm/ipm_esp32/boards/esp32_devkitc_wrover_procpu.overlay rename to samples/drivers/ipm/ipm_esp32/socs/esp32_procpu.overlay diff --git a/samples/drivers/ipm/ipm_esp32/socs/esp32s3_procpu.overlay b/samples/drivers/ipm/ipm_esp32/socs/esp32s3_procpu.overlay new file mode 100644 index 00000000000..ab1795abad7 --- /dev/null +++ b/samples/drivers/ipm/ipm_esp32/socs/esp32s3_procpu.overlay @@ -0,0 +1,3 @@ +&ipm0 { + status = "okay"; +}; diff --git a/samples/drivers/ipm/ipm_esp32/src/main.c b/samples/drivers/ipm/ipm_esp32/src/main.c index 5bb06f9cf98..4a884281e36 100644 --- a/samples/drivers/ipm/ipm_esp32/src/main.c +++ b/samples/drivers/ipm/ipm_esp32/src/main.c @@ -10,24 +10,26 @@ #include #include -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)); @@ -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(fake_request), &fake_request, sizeof(fake_request)); - k_sem_take(&sync, K_FOREVER); + ipm_send(ipm_dev, -1, sizeof(request), &request, sizeof(request)); - printk("PRO_CPU received a message from APP_CPU : %s\n\r", received_string); + ret = k_sem_take(&sync, K_MSEC(5000)); - k_sleep(K_MSEC(200)); + 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(1000)); } return 0; } diff --git a/samples/drivers/ipm/ipm_esp32/src/procpu_shell.c b/samples/drivers/ipm/ipm_esp32/src/procpu_shell.c new file mode 100644 index 00000000000..e3889efa4ba --- /dev/null +++ b/samples/drivers/ipm/ipm_esp32/src/procpu_shell.c @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2024 Espressif Systems (Shanghai) Co., Ltd. + * + * SPDX-License-Identifier: Apache-2.0 + */ + +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +/* Command usage info. */ +#define START_HELP ("\n\nStart the APPCPU") +#define STOP_HELP ("\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); diff --git a/samples/drivers/ipm/ipm_esp32/sysbuild.cmake b/samples/drivers/ipm/ipm_esp32/sysbuild.cmake new file mode 100644 index 00000000000..1ec5cf9c3e4 --- /dev/null +++ b/samples/drivers/ipm/ipm_esp32/sysbuild.cmake @@ -0,0 +1,21 @@ +# SPDX-License-Identifier: Apache-2.0 +# +# Copyright 2024 Espressif + +# Add external project +ExternalZephyrProject_Add( + APPLICATION ipm_esp32_remote + SOURCE_DIR ${APP_DIR}/remote + BOARD ${SB_CONFIG_IPM_REMOTE_BOARD} + ) + +# Add dependencies so that the remote sample will be built first +# This is required because some primary cores need information from the +# remote core's build, such as the output image's LMA +add_dependencies(ipm_esp32 ipm_esp32_remote) +sysbuild_add_dependencies(CONFIGURE ipm_esp32 ipm_esp32_remote) + +if(SB_CONFIG_BOOTLOADER_MCUBOOT) + # Make sure MCUboot is flashed first + sysbuild_add_dependencies(FLASH ipm_esp32_remote mcuboot) +endif()