Skip to content

Commit 6c5c082

Browse files
samples: zbus: add ZBus multidomain IPC forwarder sample
Add sample application demonstrating ZBus multidomain communication over IPC between CPU cores. Shows practical usage of shadow channels and proxy agents for inter-core message forwarding. The sample consists of two applications: - CPUAPP: Acts as request publisher with master request_channel - CPURAD: Acts as request listener/responder with shadow request_channel CPUAPP publishes periodic requests which are automatically forwarded via IPC to CPURAD. CPURAD processes requests and sends responses back through the response_channel, demonstrating bidirectional multidomain zbus communication. Key features demonstrated: - ZBUS_MULTIDOMAIN_CHAN_DEFINE for shared conditional channel definitions - ZBUS_PROXY_AGENT_DEFINE for IPC backend configuration - Shadow vs master channel behavior across CPU cores - Automatic message forwarding via proxy agents - Sysbuild configuration for multi-core applications Supports nRF5340DK and nRF54H20DK platforms with appropriate device tree overlays for IPC configuration. Signed-off-by: Trond F. Christiansen <[email protected]>
1 parent 6fa1f9e commit 6c5c082

21 files changed

+615
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
cmake_minimum_required(VERSION 3.20.0)
8+
9+
find_package(Zephyr REQUIRED HINTS $ENV{ZEPHYR_BASE})
10+
project(zbus_ipc_forwarder)
11+
12+
zephyr_library_include_directories(
13+
src
14+
common
15+
)
16+
17+
# Define which device this is
18+
zephyr_compile_definitions(ZBUS_DEVICE_A=1)
19+
20+
target_sources(app PRIVATE src/main.c)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
source "Kconfig.zephyr"
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
source "share/sysbuild/Kconfig"
8+
9+
choice
10+
prompt "Remote board target"
11+
default REMOTE_BOARD_NRF54H20_CPURAD if BOARD = "nrf54h20dk"
12+
default REMOTE_BOARD_NRF5340_CPUNET if BOARD = "nrf5340dk"
13+
14+
config REMOTE_BOARD_NRF54H20_CPURAD
15+
bool "nrf54h20dk/nrf54h20/cpurad"
16+
17+
config REMOTE_BOARD_NRF54H20_CPUPPR
18+
bool "nrf54h20dk/nrf54h20/cpuppr"
19+
20+
config REMOTE_BOARD_NRF54H20_CPUPPR_XIP
21+
bool "nrf54h20dk/nrf54h20/cpuppr/xip"
22+
23+
## Do not fit on nRF54H20_CPUFLPR without XIP
24+
25+
config REMOTE_BOARD_NRF54H20_CPUFLPR_XIP
26+
bool "nrf54h20dk/nrf54h20/cpuflpr/xip"
27+
28+
config REMOTE_BOARD_NRF5340_CPUNET
29+
bool "nrf5340dk/nrf5340/cpunet"
30+
31+
endchoice
32+
33+
config REMOTE_BOARD
34+
string "The board used for remote target"
35+
default "nrf54h20dk/nrf54h20/cpurad" if REMOTE_BOARD_NRF54H20_CPURAD
36+
default "nrf54h20dk/nrf54h20/cpuppr" if REMOTE_BOARD_NRF54H20_CPUPPR
37+
default "nrf54h20dk/nrf54h20/cpuppr/xip" if REMOTE_BOARD_NRF54H20_CPUPPR_XIP
38+
default "nrf54h20dk/nrf54h20/cpuflpr/xip" if REMOTE_BOARD_NRF54H20_CPUFLPR_XIP
39+
default "nrf5340dk/nrf5340/cpunet" if REMOTE_BOARD_NRF5340_CPUNET
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
CONFIG_SOC_NRF53_CPUNET_ENABLE=y
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
&cpuapp_bellboard {
8+
status = "okay";
9+
};
10+
11+
/ {
12+
chosen {
13+
/delete-property/ zephyr,bt-hci;
14+
};
15+
};
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Setup for cpuapp_cpuflpr_ipc */
8+
&cpuapp_bellboard {
9+
status = "okay";
10+
};
11+
12+
/delete-node/ &cpuapp_cpurad_ipc;
13+
14+
ipc0: &cpuapp_cpuflpr_ipc {
15+
status = "okay";
16+
};
17+
18+
&cpuflpr_vevif {
19+
status = "okay";
20+
};
21+
22+
/ {
23+
chosen {
24+
/delete-property/ zephyr,bt-hci;
25+
};
26+
};
27+
28+
/* Necessary for the cpuflpr_xip to work */
29+
&cpuflpr_vpr {
30+
status = "okay";
31+
execution-memory = <&cpuflpr_code_partition>;
32+
/delete-property/ source-memory;
33+
};
34+
35+
&uart120 {
36+
status = "reserved";
37+
interrupt-parent = <&cpuflpr_clic>;
38+
};
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Setup for cpuapp_cpuppr_ipc */
8+
&cpuapp_bellboard {
9+
status = "okay";
10+
};
11+
12+
/delete-node/ &cpuapp_cpurad_ipc;
13+
14+
ipc0: &cpuapp_cpuppr_ipc {
15+
status = "okay";
16+
};
17+
18+
&cpuppr_vevif {
19+
status = "okay";
20+
};
21+
22+
/ {
23+
chosen {
24+
/delete-property/ zephyr,bt-hci;
25+
};
26+
};
27+
28+
/* Necessary for the cpuppr to work */
29+
&cpuppr_vpr {
30+
status = "okay";
31+
};
32+
33+
&cpuppr_ram3x_region {
34+
status = "okay";
35+
};
36+
37+
&uart135 {
38+
status = "reserved";
39+
};
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
/* Setup for cpuapp_cpuppr_ipc */
8+
&cpuapp_bellboard {
9+
status = "okay";
10+
};
11+
12+
/delete-node/ &cpuapp_cpurad_ipc;
13+
14+
ipc0: &cpuapp_cpuppr_ipc {
15+
status = "okay";
16+
};
17+
18+
&cpuppr_vevif {
19+
status = "okay";
20+
};
21+
22+
/ {
23+
chosen {
24+
/delete-property/ zephyr,bt-hci;
25+
};
26+
};
27+
28+
/* Necessary for the cpuppr_xip to work */
29+
&cpuppr_vpr {
30+
status = "okay";
31+
execution-memory = <&cpuppr_code_partition>;
32+
/delete-property/ source-memory;
33+
};
34+
35+
&cpuppr_ram3x_region {
36+
status = "okay";
37+
};
38+
39+
&uart135 {
40+
status = "reserved";
41+
};
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (c) 2025 Nordic Semiconductor ASA
3+
*
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
#ifndef COMMON_H
8+
#define COMMON_H
9+
10+
#include <zephyr/zbus/zbus.h>
11+
12+
/* Sample data structures for request and response */
13+
struct request_data {
14+
int request_id;
15+
int min_value;
16+
int max_value;
17+
};
18+
19+
struct response_data {
20+
int response_id;
21+
int value;
22+
};
23+
24+
/* Conditional compilation for device-specific code, needed if channels should be included on a
25+
* subset of applications devices
26+
*/
27+
#if defined(ZBUS_DEVICE_A) || defined(ZBUS_DEVICE_B)
28+
#define include_on_device_a_b 1
29+
#else
30+
#define include_on_device_a_b 0
31+
#endif
32+
33+
/* Define shared channels for request and response
34+
* request_channel is master on device A and shadow on device B
35+
* response_channel is shadow on device A and master on device B
36+
*/
37+
ZBUS_MULTIDOMAIN_CHAN_DEFINE(request_channel, struct request_data, NULL, NULL, ZBUS_OBSERVERS_EMPTY,
38+
ZBUS_MSG_INIT(0), IS_ENABLED(ZBUS_DEVICE_A), include_on_device_a_b);
39+
40+
ZBUS_MULTIDOMAIN_CHAN_DEFINE(response_channel, struct response_data, NULL, NULL,
41+
ZBUS_OBSERVERS_EMPTY, ZBUS_MSG_INIT(0), IS_ENABLED(ZBUS_DEVICE_B),
42+
include_on_device_a_b);
43+
44+
#endif /* COMMON_H */
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#
2+
# Copyright (c) 2025 Nordic Semiconductor ASA
3+
#
4+
# SPDX-License-Identifier: Apache-2.0
5+
#
6+
7+
CONFIG_LOG=y
8+
# CONFIG_LOG_MODE_MINIMAL=y
9+
CONFIG_LOG_DBG_COLOR_BLUE=y
10+
11+
CONFIG_HEAP_MEM_POOL_SIZE=4096
12+
13+
CONFIG_ZBUS=y
14+
15+
CONFIG_MBOX=y
16+
CONFIG_IPC_SERVICE=y
17+
18+
CONFIG_ZBUS_MULTIDOMAIN=y
19+
CONFIG_ZBUS_MULTIDOMAIN_IPC=y
20+
CONFIG_ZBUS_MULTIDOMAIN_LOG_LEVEL_INF=y
21+
22+
# Increase the size of the receive buffer to accommodate larger messages
23+
CONFIG_PBUF_RX_READ_BUF_SIZE=384

0 commit comments

Comments
 (0)