Skip to content

Commit

Permalink
samples/drivers/mbox: Convert to sysbuild and add support for nrf5340…
Browse files Browse the repository at this point in the history
…bsim

Convert this sample application build to sysbuild,
and add support for the nrf5340bsim target.

Signed-off-by: Alberto Escolar Piedras <[email protected]>
  • Loading branch information
aescolar committed Oct 24, 2023
1 parent df9d818 commit 3ed2a5b
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 35 deletions.
28 changes: 6 additions & 22 deletions samples/drivers/mbox/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
12 changes: 12 additions & 0 deletions samples/drivers/mbox/Kconfig.sysbuild
Original file line number Diff line number Diff line change
@@ -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 "mimxrt595_evk_cm33" if $(BOARD) = "nrf5340dk_nrf5340_cpunet"
21 changes: 21 additions & 0 deletions samples/drivers/mbox/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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.
9 changes: 5 additions & 4 deletions samples/drivers/mbox/remote/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
CONFIG_MBOX_NRFX_IPC=y
CONFIG_BUILD_OUTPUT_EXE=n
9 changes: 0 additions & 9 deletions samples/drivers/mbox/remote/sample.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions samples/drivers/mbox/sample.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
30 changes: 30 additions & 0 deletions samples/drivers/mbox/sysbuild.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
# Copyright (c) 2023 Nordic Semiconductor ASA
# SPDX-License-Identifier: Apache-2.0

ExternalZephyrProject_Add(
APPLICATION remote
SOURCE_DIR ${APP_DIR}/remote
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/zephyr/zephyr.elf)
set_property(TARGET mbox APPEND_STRING PROPERTY CONFIG
"CONFIG_NATIVE_SIMULATOR_EXTRA_IMAGE_PATHS=\"${NET_LIBRARY_PATH}\"\n"
)

# Let's build the net core library first
add_dependencies(mbox remote)

# 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}/mbox/zephyr/zephyr.exe
${CMAKE_BINARY_DIR}/zephyr/zephyr.exe
DEPENDS mbox
)
endif()

0 comments on commit 3ed2a5b

Please sign in to comment.