diff --git a/samples/drivers/mbox/CMakeLists.txt b/samples/drivers/mbox/CMakeLists.txt index d94fdffbfb1..e65d44f0048 100644 --- a/samples/drivers/mbox/CMakeLists.txt +++ b/samples/drivers/mbox/CMakeLists.txt @@ -6,35 +6,19 @@ cmake_minimum_required(VERSION 3.20.0) -set(REMOTE_ZEPHYR_DIR ${CMAKE_CURRENT_BINARY_DIR}/mbox_ipc_remote-prefix/src/mbox_ipc_remote-build/zephyr) +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) -if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp") - set(BOARD_REMOTE "nrf5340dk_nrf5340_cpunet") -elseif("${BOARD}" STREQUAL "adp_xc7k_ae350") - set(BOARD_REMOTE "adp_xc7k_ae350") -elseif("${BOARD}" STREQUAL "mimxrt595_evk_cm33") - set(BOARD_REMOTE "nrf5340dk_nrf5340_cpunet") +if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpuapp") OR + ("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") OR + ("${BOARD}" STREQUAL "adp_xc7k_ae350") OR + ("${BOARD}" STREQUAL "mimxrt595_evk_cm33")) + message(STATUS "${BOARD} compile as Main in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") endif() -message(STATUS "${BOARD} compile as Main in this sample") - -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(mbox_ipc) enable_language(C ASM) target_sources(app PRIVATE src/main.c) - -include(ExternalProject) - -ExternalProject_Add( - mbox_ipc_remote - SOURCE_DIR ${APPLICATION_SOURCE_DIR}/remote - INSTALL_COMMAND "" # This particular build system has no install command - CMAKE_CACHE_ARGS -DBOARD:STRING=${BOARD_REMOTE} - BUILD_BYPRODUCTS "${REMOTE_ZEPHYR_DIR}/${KERNEL_BIN_NAME}" - # NB: Do we need to pass on more CMake variables? - BUILD_ALWAYS True -) diff --git a/samples/drivers/mbox/Kconfig.sysbuild b/samples/drivers/mbox/Kconfig.sysbuild new file mode 100644 index 00000000000..46ffe3e12ae --- /dev/null +++ b/samples/drivers/mbox/Kconfig.sysbuild @@ -0,0 +1,12 @@ +# Copyright 2023 Nordic Semiconductor ASA +# +# SPDX-License-Identifier: Apache-2.0 + +source "share/sysbuild/Kconfig" + +config REMOTE_BOARD +string + default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "nrf5340dk_nrf5340_cpuapp" + default "nrf5340bsim_nrf5340_cpunet" if $(BOARD) = "nrf5340bsim_nrf5340_cpuapp" + default "adp_xc7k_ae350" if $(BOARD) = "adp_xc7k_ae350" + default "nrf5340dk_nrf5340_cpunet" if $(BOARD) = "mimxrt595_evk_cm33" diff --git a/samples/drivers/mbox/README.rst b/samples/drivers/mbox/README.rst index 35c421335f9..cee903710f7 100644 --- a/samples/drivers/mbox/README.rst +++ b/samples/drivers/mbox/README.rst @@ -21,6 +21,7 @@ Building the application for nrf5340dk_nrf5340_cpuapp :zephyr-app: samples/drivers/mbox/ :board: nrf5340dk_nrf5340_cpuapp :goals: debug + :west-args: --sysbuild Open a serial terminal (minicom, putty, etc.) and connect the board with the following settings: @@ -58,3 +59,23 @@ core: Pong (on channel 1) Ping (on channel 0) Pong (on channel 1) + + +Building the application for the simulated nrf5340bsim +****************************************************** + +.. zephyr-app-commands:: + :zephyr-app: samples/drivers/mbox/ + :host-os: unix + :board: nrf5340bsim_nrf5340_cpuapp + :goals: build + :west-args: --sysbuild + +Then you can execute your application using: + +.. code-block:: console + + $ ./build/zephyr/zephyr.exe -nosim + # Press Ctrl+C to exit + +You can expect a similar output as in the real HW in the invoking console. diff --git a/samples/drivers/mbox/remote/CMakeLists.txt b/samples/drivers/mbox/remote/CMakeLists.txt index a2efccf2227..3aee2d96482 100644 --- a/samples/drivers/mbox/remote/CMakeLists.txt +++ b/samples/drivers/mbox/remote/CMakeLists.txt @@ -6,15 +6,16 @@ cmake_minimum_required(VERSION 3.20.0) -if("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet") - message(STATUS "${BOARD} compile as remote in this sample") -elseif("${BOARD}" STREQUAL "adp_xc7k_ae350") +find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) + +if(("${BOARD}" STREQUAL "nrf5340dk_nrf5340_cpunet") OR + ("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpunet") OR + ("${BOARD}" STREQUAL "adp_xc7k_ae350")) message(STATUS "${BOARD} compile as remote in this sample") else() message(FATAL_ERROR "${BOARD} is not supported for this sample") endif() -find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE}) project(mbox_ipc_remote) target_sources(app PRIVATE src/main.c) diff --git a/samples/drivers/mbox/remote/boards/nrf5340bsim_nrf5340_cpunet.conf b/samples/drivers/mbox/remote/boards/nrf5340bsim_nrf5340_cpunet.conf new file mode 100644 index 00000000000..665e456f504 --- /dev/null +++ b/samples/drivers/mbox/remote/boards/nrf5340bsim_nrf5340_cpunet.conf @@ -0,0 +1,2 @@ +CONFIG_MBOX_NRFX_IPC=y +CONFIG_BUILD_OUTPUT_EXE=n diff --git a/samples/drivers/mbox/remote/sample.yaml b/samples/drivers/mbox/remote/sample.yaml deleted file mode 100644 index 014ad53a126..00000000000 --- a/samples/drivers/mbox/remote/sample.yaml +++ /dev/null @@ -1,9 +0,0 @@ -sample: - name: MBOX IPC sample (remote) -tests: - sample.drivers.mbox_remote: - platform_allow: nrf5340dk_nrf5340_cpunet adp_xc7k_ae350 - integration_platforms: - - nrf5340dk_nrf5340_cpunet - tags: mbox - harness: remote diff --git a/samples/drivers/mbox/sample.yaml b/samples/drivers/mbox/sample.yaml index eb5e5ac1a5d..01f894832fc 100644 --- a/samples/drivers/mbox/sample.yaml +++ b/samples/drivers/mbox/sample.yaml @@ -1,9 +1,12 @@ sample: name: MBOX IPC sample tests: + common: + sysbuild: true sample.drivers.mbox: platform_allow: - nrf5340dk_nrf5340_cpuapp + - nrf5340bsim_nrf5340_cpuapp - adp_xc7k_ae350 - mimxrt595_evk_cm33 integration_platforms: diff --git a/samples/drivers/mbox/sysbuild.cmake b/samples/drivers/mbox/sysbuild.cmake new file mode 100644 index 00000000000..1bd6a00ae9e --- /dev/null +++ b/samples/drivers/mbox/sysbuild.cmake @@ -0,0 +1,38 @@ +# Copyright (c) 2023 Nordic Semiconductor ASA +# SPDX-License-Identifier: Apache-2.0 + +if("${SB_CONFIG_REMOTE_BOARD}" STREQUAL "") + message(FATAL_ERROR + "Target ${BOARD} not supported for this sample. " + "There is no remote board selected in Kconfig.sysbuild") +endif() + +set(REMOTE_APP remote) + +ExternalZephyrProject_Add( + APPLICATION ${REMOTE_APP} + SOURCE_DIR ${APP_DIR}/${REMOTE_APP} + BOARD ${SB_CONFIG_REMOTE_BOARD} +) + +if("${BOARD}" STREQUAL "nrf5340bsim_nrf5340_cpuapp") + # For the simulated board, the application core build will produce the final executable + # for that, we give it the path to the netcore image + set(NET_LIBRARY_PATH ${CMAKE_BINARY_DIR}/${REMOTE_APP}/zephyr/zephyr.elf) + set_property(TARGET ${DEFAULT_IMAGE} APPEND_STRING PROPERTY CONFIG + "CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n" + ) + + # Let's build the net core library first + add_dependencies(${DEFAULT_IMAGE} ${REMOTE_APP}) + + # Let's meet users expectations of finding the final executable in zephyr/zephyr.exe + add_custom_target(final_executable + ALL + COMMAND + ${CMAKE_COMMAND} -E copy + ${CMAKE_BINARY_DIR}/${DEFAULT_IMAGE}/zephyr/zephyr.exe + ${CMAKE_BINARY_DIR}/zephyr/zephyr.exe + DEPENDS ${DEFAULT_IMAGE} + ) +endif()