samples: drivers: IPM fixes

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 <marek.matej@espressif.com>
This commit is contained in:
Marek Matej 2024-09-04 14:31:23 +02:00 committed by Mahesh Mahadevan
commit a8ab8b49f2
13 changed files with 150 additions and 59 deletions

View file

@ -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)

View file

@ -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"

View file

@ -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

View file

@ -1,2 +0,0 @@
CONFIG_HEAP_MEM_POOL_SIZE=256
CONFIG_IPM=y

View file

@ -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)

View file

@ -0,0 +1,3 @@
CONFIG_HEAP_MEM_POOL_SIZE=2048
CONFIG_MAIN_STACK_SIZE=4096
CONFIG_IPM=y

View file

@ -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);
}
@ -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;
}

View file

@ -0,0 +1,3 @@
&ipm0 {
status = "okay";
};

View file

@ -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));
@ -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));
ret = k_sem_take(&sync, K_MSEC(5000));
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;
}

View file

@ -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);

View file

@ -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()