Zephyr native_sim
Needs first: Run a talker on an emulated board, What you just built, Get started on Zephyr native_sim
Status:
nros-board-zephyr(ZephyrNativeSim): Verified on host (daily). From the board support registry; Board Support Levels explains the words.
The starter made a west workspace
pinned to Zephyr 3.7, scaffolded a talker for board = "zephyr", and ran it
on native_sim, Zephyr’s host build, where the image is a Linux executable.
This page covers what comes after it: where an image’s nano-ros and Zephyr
settings each go, the Zephyr lines nano-ros builds against, what is particular
to native_sim, and how nros build hands the build to west. The
configuration here applies to every Zephyr board; the
mps2-an385 and Nucleo-F767ZI pages add
only their board notes.
Configure the platform
An image’s nano-ros configuration lives in one place, the bringup’s
system.toml. Zephyr’s own settings (networking, POSIX, stacks, heaps) live
in Zephyr’s prj.conf fragments, which the image names with os_config:
[system]
name = "zs_node"
rmw = "zenoh"
domain_id = 0
[image.zephyr]
# a nano-ros board id; west gets native_sim/native/64
board = "zephyr"
locator = "tcp/127.0.0.1:7447"
os_config = ["prj-zenoh.conf"] # Zephyr settings only
[image.zephyr.knobs.zenoh]
max_publishers = 4
nano-ros’s Zephyr module renders the image into a Kconfig fragment and
merges it last, after every conf file. So a prj*.conf file holds Zephyr’s
settings only, and never a CONFIG_NROS_* line: one there is either
overridden or a second source that can disagree with the first.
You write in system.toml | The build gets |
|---|---|
rmw = "xrce" | CONFIG_NROS_RMW_XRCE=y |
| (the node package’s language) | CONFIG_NROS_{C,CPP,RUST}_API=y |
locator = "tcp/…" (zenoh) | CONFIG_NROS_LOCATOR |
locator = "udp/<host>:<port>" (XRCE) | CONFIG_NROS_XRCE_AGENT_ADDR and _PORT |
domain_id = 7 | CONFIG_NROS_DOMAIN_ID |
[image.<id>.knobs.zenoh] max_queryables = 12 | CONFIG_NROS_MAX_QUERYABLES=12 |
env = { NROS_ZEPHYR_TASK_STACK_BYTES = "16384" } | CONFIG_NROS_ZEPHYR_TASK_STACK_BYTES=16384 |
os_config = ["prj-xrce.conf"] | that fragment, ahead of your own EXTRA_CONF_FILE |
A key whose value does not fit its Kconfig symbol, or that exists only under
another RMW, is refused when the build configures, naming the
system.toml line. Configure an image
lists the knobs.
One image per RMW
A bringup built for several backends states one image per RMW and picks one
at build time. The copy-out C talker,
examples/zephyr/c/talker/src/nros_zephyr_talker_c_bringup/system.toml,
does this:
[system]
name = "nros_zephyr_talker_c"
rmw = "zenoh"
domain_id = 0
default_images = ["zephyr_zenoh"]
[image.zephyr_zenoh]
board = "zephyr"
rmw = "zenoh"
os_config = ["prj-zenoh.conf", "prj-zenoh-native-sim.conf"]
[image.zephyr_xrce]
board = "zephyr"
rmw = "xrce"
os_config = ["prj-xrce.conf"]
locator = "udp/127.0.0.1:2018"
nros build builds the default_images, and nros build zephyr_xrce
builds the other. Each image has its own build directory,
build/<platform>-<rmw>/<package>__<image>_west, so switching never reuses
another image’s cache.
What each backend needs from Zephyr goes in its fragment:
- zenoh: TCP and POSIX threads, with pthread pools big enough for
zenoh-pico (
CONFIG_MAX_PTHREAD_MUTEX_COUNT=64,CONFIG_MAX_PTHREAD_COND_COUNT=16). - XRCE-DDS:
CONFIG_NET_TCP=y, on the BSD sockets every image enables. - Cyclone DDS:
CONFIG_CPP=y(its source is C++, even for a Rust node),CONFIG_MAIN_STACK_SIZE=524288, andCONFIG_NET_IPV4_IGMP=yfor discovery. Raise its heap with[image.<id>.knobs.memory] heap_bytes, not in the conf.
The Zephyr lines
nano-ros builds as a module against whichever Zephyr your west workspace pins: the 3.7 LTS line (the starters’ pin) or the 4.x line. The two differ in two places:
- Python. 3.7 needs Python 3.10 or later; 4.x needs 3.12 or later. On a
host with an older Python, make a 3.12 virtual environment and run
westfrom it. - An app with no
system.toml. On 4.x, nano-ros’swestsnippets pick the RMW on the build line,west build -S nros-cyclonedds …. With asystem.toml, the image’srmwdecides on both lines, and a snippet that names a different RMW is refused.
Board notes
board = "zephyr"isnative_sim/native/64. The board’s descriptor states the idwest build -breceives, so an image never names it.- Sockets are the host’s. The board applies nano-ros’s
nros-nsossnippet, which routes the image’s sockets through Zephyr’s NSOS offload to the host kernel. The image reaches a router on loopback with no TAP interface and no root access. Without the snippet,native_simtries to create one and fails witheth_posix: Cannot create zeth. - nano-ros patches Zephyr’s NSOS driver (
recvmsg, IPv4 multicast).nros setup zephyrapplies the patches to your workspace, checked by hash. After awest updateresets the tree, run the same command again to reapply them. - The console is standard output, and the image runs until you stop it.
Read the run plan
From the starter’s workspace, print the plan nros run follows:
nros run zs_node --dry-run --why
The target is a host process: nros run runs the built zephyr.exe, and the
console is its standard output. A zenoh image’s link is the image’s
locator, and nros run starts the router the link needs.
Drive west yourself
On Zephyr, nros build writes a Zephyr application for the image under
build/, then runs west build on it from your west workspace with the
image’s overlays applied (EXTRA_CONF_FILE, EXTRA_DTC_OVERLAY_FILE,
APPLICATION_CONFIG_DIR). Print that west build line without running it:
nros build --dry-run
Copy the line to run west yourself. Anything after -- on the
nros build line goes to west, to its option zone or its CMake zone by
west’s own flag list, so nros build -- -p always -DMY_OPT=1 reaches both.
Two flags are refused, because the image decides them: -b, which comes
from the image’s board, and --sysbuild, which comes from a
sysbuild.conf beside the application.
nros build finds your Zephyr through --zephyr-workspace <dir>,
$ZEPHYR_BASE or $NROS_ZEPHYR_WORKSPACE (the starter exported the last),
in that order. Next it looks for the west workspace your project sits in:
the nearest .west/ at or above the workspace, as west finds it, counts
when its manifest names a zephyr project that is checked out. That tree
carries your own manifest’s pins and patches, so it comes before the store’s
workspace (~/.nros/workspaces/zephyr/<line>), and the build prints one line
naming it:
nros build: Zephyr tree /work/robot/zephyr (the west workspace /work/robot this project is in, not the store's /home/me/.nros/workspaces/zephyr/3.7/zephyr; --zephyr-workspace or ZEPHYR_BASE names another)
When it finds none it stops and prints the west build line and where to run
it, rather than guess. nano-ros never writes into the west workspace.
When a change needs the application’s own CMakeLists.txt or prj.conf,
take the application over with nros materialize zephyr. That writes it to
src/zephyr_entry/, and nros build builds your copy from then on. Delete
the directory to return to the generated one. An application that owns its
west build and has no bringup at all is
A Zephyr app you build with west.
If it doesn’t work
<err> … executor open failed: Transport(ConnectionFailed): the image found no router. Both sides default totcp/127.0.0.1:7447; alocatorchanged on one side must change on the other.Could NOT find Python3 … required is at least "3.12": a 4.x workspace on an older Python. Runwestfrom a 3.12 environment.undefined symbol ETH_NATIVE_POSIX: 4.x renamed itETH_NATIVE_TAP; the board’s NSOS fragment handles it, so a conf file of your own should not set it.- Everything else: Troubleshoot.
Reference
- The
native_simboard’s support evidence. - The module’s Kconfig, every
CONFIG_NROS*symbol:zephyr/Kconfig. - Copy-out talkers:
examples/zephyr/, one per language. The other roles are thezephyr_*image rows of the language workspaces,examples/workspaces/{rust,c,cpp}.