diff --git a/boards/arm/mps2_an521/Kconfig.defconfig b/boards/arm/mps2_an521/Kconfig.defconfig index ce85a4e387d4..9f1df66905f4 100644 --- a/boards/arm/mps2_an521/Kconfig.defconfig +++ b/boards/arm/mps2_an521/Kconfig.defconfig @@ -44,4 +44,11 @@ config I2C_SBCON default y depends on I2C +if IPM + +config IPM_MHU + default y + +endif # IPM + endif diff --git a/boards/arm/v2m_musca/Kconfig.defconfig b/boards/arm/v2m_musca/Kconfig.defconfig index e4f2132493b9..eca4ffc89d8f 100644 --- a/boards/arm/v2m_musca/Kconfig.defconfig +++ b/boards/arm/v2m_musca/Kconfig.defconfig @@ -43,4 +43,11 @@ config TIMER_DTMR_CMSDK_APB endif # COUNTER +if IPM + +config IPM_MHU + default y + +endif # IPM + endif diff --git a/boards/arm/v2m_musca_b1/Kconfig.defconfig b/boards/arm/v2m_musca_b1/Kconfig.defconfig index e91edfa415ad..af0f2ce8a550 100644 --- a/boards/arm/v2m_musca_b1/Kconfig.defconfig +++ b/boards/arm/v2m_musca_b1/Kconfig.defconfig @@ -33,4 +33,11 @@ config UART_PL011_PORT1 endif # SERIAL +if IPM + +config IPM_MHU + default y + +endif # IPM + endif diff --git a/samples/subsys/ipc/openamp/CMakeLists.txt b/samples/subsys/ipc/openamp/CMakeLists.txt index 95e866dfb276..b9d1d0ee9d9b 100644 --- a/samples/subsys/ipc/openamp/CMakeLists.txt +++ b/samples/subsys/ipc/openamp/CMakeLists.txt @@ -1,17 +1,30 @@ cmake_minimum_required(VERSION 3.13.1) # Copyright (c) 2018 Nordic Semiconductor ASA +# Copyright (c) 2019 Linaro Limited # # SPDX-License-Identifier: Apache-2.0 # -set(BOARD lpcxpresso54114_m4) -include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) -project(openamp) +set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/openamp_remote-prefix/src/openamp_remote-build/zephyr) -if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m4")) - message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m4") +if("${BOARD}" STREQUAL "lpcxpresso54114_m4") + set(BOARD_REMOTE "lpcxpresso54114_m0") +elseif("${BOARD}" STREQUAL "mps2_an521") + set(QEMU_EXTRA_FLAGS "-device;loader,file=${REMOTE_ZEPHYR_DIR}/zephyr.elf") + set(BOARD_REMOTE "mps2_an521_nonsecure") +elseif("${BOARD}" STREQUAL "v2m_musca") + set(BOARD_REMOTE "v2m_musca_nonsecure") +elseif("${BOARD}" STREQUAL "v2m_musca_b1") + set(BOARD_REMOTE "v2m_musca_b1_nonsecure") +else() + message(FATAL_ERROR "${BOARD} was not supported for this sample") endif() +message(INFO " ${BOARD} compile as Master in this sample") + +include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) +project(openamp) + enable_language(C ASM) target_sources(app PRIVATE src/main.c) @@ -22,10 +35,15 @@ ExternalProject_Add( openamp_remote SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote INSTALL_COMMAND "" # This particular build system has no install command - BUILD_BYPRODUCTS "${CMAKE_CURRENT_BINARY_DIR}/openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin" + CMAKE_CACHE_ARGS -DBOARD:string=${BOARD_REMOTE} + CMAKE_CACHE_ARGS -DDTC_OVERLAY_FILE:string=${DTC_OVERLAY_FILE} + BUILD_BYPRODUCTS "${REMOTE_ZEPHYR_DIR}/zephyr.bin" # NB: Do we need to pass on more CMake variables? BUILD_ALWAYS True ) -add_dependencies(core_m0_inc_target openamp_remote) + +if(("${BOARD}" STREQUAL "lpcxpresso54114_m4")) + add_dependencies(core_m0_inc_target openamp_remote) +endif() target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/samples/subsys/ipc/openamp/Kconfig b/samples/subsys/ipc/openamp/Kconfig new file mode 100644 index 000000000000..39bbc199d0bb --- /dev/null +++ b/samples/subsys/ipc/openamp/Kconfig @@ -0,0 +1,30 @@ +# Private config options for openamp sample app + +# Copyright (c) 2020 Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +# Workaround for not being able to have commas in macro arguments +DT_CHOSEN_Z_IPC_SHM := zephyr,ipc_shm +DT_CHOSEN_Z_IPC := zephyr,ipc + +config OPENAMP_IPC_SHM_BASE_ADDRESS + hex + default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies base address of the memory region to + be used for the OpenAMP IPC shared memory + +config OPENAMP_IPC_SHM_SIZE + hex + default "$(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies size of the memory region to be used + for the OpenAMP IPC shared memory + +config OPENAMP_IPC_DEV_NAME + string + default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC))" + help + This option specifies the device name for the IPC device to be used + +source "Kconfig.zephyr" diff --git a/samples/subsys/ipc/openamp/README.rst b/samples/subsys/ipc/openamp/README.rst index bd71856ce031..701dbae09ad0 100644 --- a/samples/subsys/ipc/openamp/README.rst +++ b/samples/subsys/ipc/openamp/README.rst @@ -8,16 +8,40 @@ Overview This application demonstrates how to use OpenAMP with Zephyr. It is designed to demonstrate how to integrate OpenAMP with Zephyr both from a build perspective -and code. Currently this integration is specific to the LPC54114 SoC. +and code. -Building the application -************************* +Building the application for lpcxpresso54114_m4 +*********************************************** .. zephyr-app-commands:: :zephyr-app: samples/subsys/ipc/openamp :board: lpcxpresso54114_m4 :goals: debug +Building the application for mps2_an521 +*************************************** + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/ipc/openamp + :board: mps2_an521 + :goals: debug + +Building the application for v2m_musca +************************************** + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/ipc/openamp + :board: v2m_musca + :goals: debug + +Building the application for v2m_musca_b1 +***************************************** + +.. zephyr-app-commands:: + :zephyr-app: samples/subsys/ipc/openamp + :board: v2m_musca_b1 + :goals: debug + Open a serial terminal (minicom, putty, etc.) and connect the board with the following settings: @@ -27,17 +51,31 @@ following settings: - Stop bits: 1 Reset the board and the following message will appear on the corresponding -serial port: +serial port, one is master another is remote: + +.. code-block:: console + + **** Booting Zephyr OS build zephyr-v1.14.0-2064-g888fc98fddaa **** + Starting application thread! + + OpenAMP[master] demo started + Master core received a message: 1 + Master core received a message: 3 + Master core received a message: 5 + ... + Master core received a message: 99 + OpenAMP demo ended. + .. code-block:: console - ***** Booting Zephyr OS v1.11.0-1377-g580b9add47 ***** + **** Booting Zephyr OS build zephyr-v1.14.0-2064-g888fc98fddaa **** Starting application thread! - OpenAMP demo started - Primary core received a message: 1 - Primary core received a message: 3 - Primary core received a message: 5 + OpenAMP[remote] demo started + Remote core received a message: 0 + Remote core received a message: 2 + Remote core received a message: 4 ... - Primary core received a message: 101 + Remote core received a message: 98 OpenAMP demo ended. diff --git a/samples/subsys/ipc/openamp/boards/lpcxpresso54114_m4.conf b/samples/subsys/ipc/openamp/boards/lpcxpresso54114_m4.conf new file mode 100644 index 000000000000..b5432c4c56e0 --- /dev/null +++ b/samples/subsys/ipc/openamp/boards/lpcxpresso54114_m4.conf @@ -0,0 +1,3 @@ +CONFIG_IPM_MCUX=y +CONFIG_SLAVE_CORE_MCUX=y +CONFIG_SLAVE_IMAGE_MCUX="${ZEPHYR_BINARY_DIR}/../openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin" diff --git a/samples/subsys/ipc/openamp/common.h b/samples/subsys/ipc/openamp/common.h index 27ceaf094d00..2386eb8715d8 100644 --- a/samples/subsys/ipc/openamp/common.h +++ b/samples/subsys/ipc/openamp/common.h @@ -1,6 +1,6 @@ /* * Copyright (c) 2018 Nordic Semiconductor ASA - * Copyright (c) 2018 Linaro Limited + * Copyright (c) 2018-2019 Linaro Limited * * SPDX-License-Identifier: Apache-2.0 */ @@ -8,16 +8,21 @@ #ifndef COMMON_H__ #define COMMON_H__ -#define SHM_START_ADDR 0x04000400 -#define SHM_SIZE 0x7c00 +#define VDEV_START_ADDR CONFIG_OPENAMP_IPC_SHM_BASE_ADDRESS +#define VDEV_SIZE CONFIG_OPENAMP_IPC_SHM_SIZE + +#define VDEV_STATUS_ADDR VDEV_START_ADDR +#define VDEV_STATUS_SIZE 0x400 + +#define SHM_START_ADDR (VDEV_START_ADDR + VDEV_STATUS_SIZE) +#define SHM_SIZE (VDEV_SIZE - VDEV_STATUS_SIZE) #define SHM_DEVICE_NAME "sramx.shm" #define VRING_COUNT 2 -#define VRING_RX_ADDRESS 0x04007800 -#define VRING_TX_ADDRESS 0x04007C00 +#define VRING_RX_ADDRESS (VDEV_START_ADDR + SHM_SIZE - VDEV_STATUS_SIZE) +#define VRING_TX_ADDRESS (VDEV_START_ADDR + SHM_SIZE) #define VRING_ALIGNMENT 4 #define VRING_SIZE 16 -#define VDEV_STATUS_ADDR 0x04000000 #endif diff --git a/samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay b/samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay new file mode 100644 index 000000000000..61e3476ecb4f --- /dev/null +++ b/samples/subsys/ipc/openamp/lpcxpresso54114_m4.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* + * shared memory reserved for the inter-processor communication + */ + zephyr,ipc_shm = &sramx1; + zephyr,ipc = &mailbox0; + }; + + sramx1:memory@4000000{ + compatible = "mmio-sram"; + reg = <0x4000000 0x8000>; + }; +}; diff --git a/samples/subsys/ipc/openamp/mps2_an521.overlay b/samples/subsys/ipc/openamp/mps2_an521.overlay new file mode 100644 index 000000000000..aff3c460cbc0 --- /dev/null +++ b/samples/subsys/ipc/openamp/mps2_an521.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* + * shared memory reserved for the inter-processor communication + */ + zephyr,ipc_shm = &sramx; + zephyr,ipc = &mhu0; + }; + + sramx: memory@28180000 { + compatible = "mmio-sram"; + reg = <0x28180000 0x8000>; + }; +}; diff --git a/samples/subsys/ipc/openamp/prj.conf b/samples/subsys/ipc/openamp/prj.conf index a9b5cad7d290..d9b869b60337 100644 --- a/samples/subsys/ipc/openamp/prj.conf +++ b/samples/subsys/ipc/openamp/prj.conf @@ -1,8 +1,5 @@ CONFIG_PRINTK=y CONFIG_IPM=y -CONFIG_IPM_MCUX=y -CONFIG_SLAVE_CORE_MCUX=y -CONFIG_SLAVE_IMAGE_MCUX="${ZEPHYR_BINARY_DIR}/../openamp_remote-prefix/src/openamp_remote-build/zephyr/zephyr.bin" CONFIG_TIMESLICE_SIZE=1 CONFIG_MAIN_STACK_SIZE=2048 CONFIG_HEAP_MEM_POOL_SIZE=4096 diff --git a/samples/subsys/ipc/openamp/remote/CMakeLists.txt b/samples/subsys/ipc/openamp/remote/CMakeLists.txt index a6cc307808de..74a2fd71d9ff 100644 --- a/samples/subsys/ipc/openamp/remote/CMakeLists.txt +++ b/samples/subsys/ipc/openamp/remote/CMakeLists.txt @@ -1,16 +1,21 @@ cmake_minimum_required(VERSION 3.13.1) # Copyright (c) 2018 Nordic Semiconductor ASA +# Copyright (c) 2019 Linaro Limited # # SPDX-License-Identifier: Apache-2.0 # -set(BOARD lpcxpresso54114_m0) + +if(("${BOARD}" STREQUAL "lpcxpresso54114_m0") + OR "${BOARD}" STREQUAL "mps2_an521_nonsecure" + OR "${BOARD}" STREQUAL "v2m_musca_nonsecure" + OR "${BOARD}" STREQUAL "v2m_musca_b1_nonsecure") + message(INFO " ${BOARD} compile as slave in this sample") +else() + message(FATAL_ERROR "${BOARD} was not supported for this sample") +endif() include($ENV{ZEPHYR_BASE}/cmake/app/boilerplate.cmake NO_POLICY_SCOPE) project(openamp_remote) -if(NOT ("${BOARD}" STREQUAL "lpcxpresso54114_m0")) - message(FATAL_ERROR "${BOARD} was specified, but this sample only supports lpcxpresso54114_m0") -endif() - target_sources(app PRIVATE src/main.c) target_include_directories(app PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/..) diff --git a/samples/subsys/ipc/openamp/remote/Kconfig b/samples/subsys/ipc/openamp/remote/Kconfig new file mode 100644 index 000000000000..39bbc199d0bb --- /dev/null +++ b/samples/subsys/ipc/openamp/remote/Kconfig @@ -0,0 +1,30 @@ +# Private config options for openamp sample app + +# Copyright (c) 2020 Linaro Limited +# SPDX-License-Identifier: Apache-2.0 + +# Workaround for not being able to have commas in macro arguments +DT_CHOSEN_Z_IPC_SHM := zephyr,ipc_shm +DT_CHOSEN_Z_IPC := zephyr,ipc + +config OPENAMP_IPC_SHM_BASE_ADDRESS + hex + default "$(dt_chosen_reg_addr_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies base address of the memory region to + be used for the OpenAMP IPC shared memory + +config OPENAMP_IPC_SHM_SIZE + hex + default "$(dt_chosen_reg_size_hex,$(DT_CHOSEN_Z_IPC_SHM))" + help + This option specifies size of the memory region to be used + for the OpenAMP IPC shared memory + +config OPENAMP_IPC_DEV_NAME + string + default "$(dt_chosen_label,$(DT_CHOSEN_Z_IPC))" + help + This option specifies the device name for the IPC device to be used + +source "Kconfig.zephyr" diff --git a/samples/subsys/ipc/openamp/remote/boards/lpcxpresso54114_m0.conf b/samples/subsys/ipc/openamp/remote/boards/lpcxpresso54114_m0.conf new file mode 100644 index 000000000000..2360fff8e423 --- /dev/null +++ b/samples/subsys/ipc/openamp/remote/boards/lpcxpresso54114_m0.conf @@ -0,0 +1 @@ +CONFIG_IPM_MCUX=y diff --git a/samples/subsys/ipc/openamp/remote/prj.conf b/samples/subsys/ipc/openamp/remote/prj.conf index 7a08439febe6..9b8ceae532f2 100644 --- a/samples/subsys/ipc/openamp/remote/prj.conf +++ b/samples/subsys/ipc/openamp/remote/prj.conf @@ -1,7 +1,6 @@ CONFIG_STDOUT_CONSOLE=n CONFIG_PRINTK=n CONFIG_IPM=y -CONFIG_IPM_MCUX=y CONFIG_PLATFORM_SPECIFIC_INIT=n CONFIG_HEAP_MEM_POOL_SIZE=4096 CONFIG_OPENAMP=y diff --git a/samples/subsys/ipc/openamp/remote/src/main.c b/samples/subsys/ipc/openamp/remote/src/main.c index 0f24b3f0a460..86d44d5da233 100644 --- a/samples/subsys/ipc/openamp/remote/src/main.c +++ b/samples/subsys/ipc/openamp/remote/src/main.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018, NXP * Copyright (c) 2018, Nordic Semiconductor ASA - * Copyright (c) 2018, Linaro Limited + * Copyright (c) 2018-2019, Linaro Limited * * SPDX-License-Identifier: Apache-2.0 */ @@ -73,9 +73,17 @@ static u32_t virtio_get_features(struct virtio_device *vdev) static void virtio_notify(struct virtqueue *vq) { +#if defined(CONFIG_SOC_MPS2_AN521) || \ + defined(CONFIG_SOC_V2M_MUSCA_A) || \ + defined(CONFIG_SOC_V2M_MUSCA_B1) + u32_t current_core = sse_200_platform_get_cpu_id(); + + ipm_send(ipm_handle, 0, current_core ? 0 : 1, 0, 1); +#else u32_t dummy_data = 0x00110011; /* Some data must be provided */ ipm_send(ipm_handle, 0, 0, &dummy_data, sizeof(dummy_data)); +#endif /* #if defined(CONFIG_SOC_MPS2_AN521) */ } struct virtio_dispatch dispatch = { @@ -168,7 +176,7 @@ void app_task(void *arg1, void *arg2, void *arg3) } /* setup IPM */ - ipm_handle = device_get_binding("MAILBOX_0"); + ipm_handle = device_get_binding(CONFIG_OPENAMP_IPC_DEV_NAME); if (ipm_handle == NULL) { printk("device_get_binding failed to find device\n"); return; diff --git a/samples/subsys/ipc/openamp/sample.yaml b/samples/subsys/ipc/openamp/sample.yaml index 4f6d5b97f57e..e17964e6c571 100644 --- a/samples/subsys/ipc/openamp/sample.yaml +++ b/samples/subsys/ipc/openamp/sample.yaml @@ -4,7 +4,7 @@ sample: name: OpenAMP example integration tests: sample.ipc.openamp: - platform_whitelist: lpcxpresso54114_m4 + platform_whitelist: lpcxpresso54114_m4 mps2_an521 v2m_musca v2m_musca_b1 tags: ipm harness: console harness_config: diff --git a/samples/subsys/ipc/openamp/src/main.c b/samples/subsys/ipc/openamp/src/main.c index ef4699d63c63..08c24f92c903 100644 --- a/samples/subsys/ipc/openamp/src/main.c +++ b/samples/subsys/ipc/openamp/src/main.c @@ -1,7 +1,7 @@ /* * Copyright (c) 2018, NXP * Copyright (c) 2018, Nordic Semiconductor ASA - * Copyright (c) 2018, Linaro Limited + * Copyright (c) 2018-2019, Linaro Limited * * SPDX-License-Identifier: Apache-2.0 */ @@ -84,9 +84,17 @@ static void virtio_set_features(struct virtio_device *vdev, static void virtio_notify(struct virtqueue *vq) { +#if defined(CONFIG_SOC_MPS2_AN521) || \ + defined(CONFIG_SOC_V2M_MUSCA_A) || \ + defined(CONFIG_SOC_V2M_MUSCA_B1) + u32_t current_core = sse_200_platform_get_cpu_id(); + + ipm_send(ipm_handle, 0, current_core ? 0 : 1, 0, 1); +#else u32_t dummy_data = 0x55005500; /* Some data must be provided */ ipm_send(ipm_handle, 0, 0, &dummy_data, sizeof(dummy_data)); +#endif /* #if defined(CONFIG_SOC_MPS2_AN521) */ } struct virtio_dispatch dispatch = { @@ -192,7 +200,7 @@ void app_task(void *arg1, void *arg2, void *arg3) } /* setup IPM */ - ipm_handle = device_get_binding("MAILBOX_0"); + ipm_handle = device_get_binding(CONFIG_OPENAMP_IPC_DEV_NAME); if (ipm_handle == NULL) { printk("device_get_binding failed to find device\n"); return; @@ -279,6 +287,13 @@ void main(void) k_thread_create(&thread_data, thread_stack, APP_TASK_STACK_SIZE, (k_thread_entry_t)app_task, NULL, NULL, NULL, K_PRIO_COOP(7), 0, K_NO_WAIT); + +#if defined(CONFIG_SOC_MPS2_AN521) || \ + defined(CONFIG_SOC_V2M_MUSCA_A) || \ + defined(CONFIG_SOC_V2M_MUSCA_B1) + wakeup_cpu1(); + k_sleep(500); +#endif /* #if defined(CONFIG_SOC_MPS2_AN521) */ } /* Make sure we clear out the status flag very early (before we bringup the diff --git a/samples/subsys/ipc/openamp/v2m_musca.overlay b/samples/subsys/ipc/openamp/v2m_musca.overlay new file mode 100644 index 000000000000..a713dd604693 --- /dev/null +++ b/samples/subsys/ipc/openamp/v2m_musca.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* + * shared memory reserved for the inter-processor communication + */ + zephyr,ipc_shm = &sramx; + zephyr,ipc = &mhu0; + }; + + sramx: memory@20018000 { + compatible = "mmio-sram"; + reg = <0x20018000 0x8000>; + }; +}; diff --git a/samples/subsys/ipc/openamp/v2m_musca_b1.overlay b/samples/subsys/ipc/openamp/v2m_musca_b1.overlay new file mode 100644 index 000000000000..a2473c4cc09b --- /dev/null +++ b/samples/subsys/ipc/openamp/v2m_musca_b1.overlay @@ -0,0 +1,20 @@ +/* + * Copyright (c) 2019 Linaro Limited + * + * SPDX-License-Identifier: Apache-2.0 + */ + +/ { + chosen { + /* + * shared memory reserved for the inter-processor communication + */ + zephyr,ipc_shm = &sramx; + zephyr,ipc = &mhu0; + }; + + sramx: memory@20060000 { + compatible = "mmio-sram"; + reg = <0x20060000 0x8000>; + }; +};