Get started on Zephyr native_sim
Needs first: Install
Status: Verified on host (daily). From the board support registry:
nros-board-zephyr; Board Support Levels explains the words.
This starter puts a talker on Zephyr 3.7’s native_sim board, which builds a
Zephyr application as an ordinary program for your Linux machine, and shows
its messages arriving in ROS 2. There is no emulator: the Zephyr kernel runs
inside one host process, and its sockets are your host’s, so the talker
reaches a router on this machine with no network setup. nano-ros is a Zephyr
module here: nros run writes the Zephyr application for your image and
builds it with Zephyr’s west. You write the talker in Rust, C or C++; pick a
tab and every tab on the page follows.
What you need
- A Linux x86_64 host with the install done, so
nrosis on yourPATH. - ROS 2 with
ros-<distro>-rmw-zenoh-cpp: Humble on Ubuntu 22.04, Jazzy on 24.04 (which edition). ROS 2 provides the zenoh router the talker talks to, and the message definitions the build generates the talker’s code from. - Zephyr’s host tools:
westand the build tools Zephyr’s Getting Started lists.nros setupinstalls no system packages, so install them yourself. On Debian or Ubuntu:
sudo apt-get install -y --no-install-recommends git cmake ninja-build gperf \
device-tree-compiler python3-pip python3-venv xz-utils file wget clang
pip3 install --user west
export PATH="$HOME/.local/bin:$PATH"
No board, no cable and no root access: the board’s own configuration routes the application’s sockets to the host’s, so no TAP interface is created.
Provision
Provision the board:
nros setup zephyr --rmw zenoh
export ZEPHYR_SDK_INSTALL_DIR="$(nros locate tool zephyr-sdk)"
That fetches the Zephyr SDK and the zenoh-pico and mbedtls sources into a
shared store under ~/.nros. It installs no router: the router is ROS’s
rmw_zenohd.
Zephyr’s sources live in a west workspace of your own. This one pins Zephyr
3.7 and fetches only the modules nano-ros’s boards build with (import: true
would fetch every vendor’s HAL, about 2.5 GB more), plus Zephyr’s Rust
support, which only a Rust talker builds with:
mkdir -p my_zephyr_ws/manifest && cd my_zephyr_ws
manifest/west.ymlmanifest:
remotes:
- name: zephyrproject-rtos
url-base: https://github.com/zephyrproject-rtos
projects:
- name: zephyr
remote: zephyrproject-rtos
revision: v3.7.2
import:
name-allowlist: [cmsis, picolibc, mbedtls, tinycrypt, mcuboot, net-tools]
# Rust support: only a Rust app builds with it. Pinned to the revision
# nano-ros's own west.yml pins for the 3.7 line (it has no release tags).
- name: zephyr-lang-rust
remote: zephyrproject-rtos
revision: 404fcefdbab0f2711cd342a1fab9d2eda52a1ba9
path: modules/lang/rust
self:
path: manifest
west init -l manifest
west update --narrow -o=--depth=1
pip3 install --user -r zephyr/scripts/requirements-base.txt
export ZEPHYR_BASE="$PWD/zephyr"
Last, give the west workspace the patches nano-ros carries for Zephyr 3.7, among them the one that passes the board’s settings to a Rust app’s cargo build:
nros setup board zephyr --zephyr-workspace "$PWD"
Scaffold the project
Source ROS 2 first, in the shell you scaffold from. nros new writes
the ROS 2 edition the project speaks, and it takes it from the sourced
ROS 2; with none sourced, it writes Humble. On Jazzy, source
/opt/ros/jazzy/setup.bash instead:
source /opt/ros/humble/setup.bash
Scaffold the workspace beside the west workspace, and tell nros where the
west workspace is with NROS_ZEPHYR_WORKSPACE:
. "$HOME/.cargo/env"
export NROS_ZEPHYR_WORKSPACE="$PWD"
cd ..
nros new zs_ws --board zephyr --template talker --lang rust --rmw zenoh
cd zs_ws
nros setup --sudo
A Rust application on Zephyr needs three things a C one does not: the Rust
target the board implies (x86_64-unknown-none for native_sim/64 on an
x86_64 host), rustup’s clippy (Zephyr’s Rust support lints every Rust app
as it builds), and clang with libclang, for the bindings it generates from
Zephyr’s headers. nros setup in the workspace installs the target and
clippy, and with --sudo the two packages. Without --sudo it prints the
install command instead.
export NROS_ZEPHYR_WORKSPACE="$PWD"
cd ..
nros new zs_ws --board zephyr --template talker --lang c --rmw zenoh
cd zs_ws
export NROS_ZEPHYR_WORKSPACE="$PWD"
cd ..
nros new zs_ws --board zephyr --template talker --lang cpp --rmw zenoh
cd zs_ws
That wrote a workspace with two packages: src/zs_node/, the talker, a
library with no main() that names no board, and src/zs_node_bringup/,
whose system.toml holds one image, [image.zephyr], with
board = "zephyr": Zephyr’s native_sim/native/64. The Zephyr application
itself is generated under build/ when you build, so you write no
CMakeLists.txt and no prj.conf.
Run it on this machine
Source ROS 2, then build and run. This first run records the ROS 2 prefix in the workspace, so later runs of it need no sourced shell (the router still comes from ROS 2):
source /opt/ros/humble/setup.bash
nros run zs_node
Publishing: 'Hello World: 1'
Publishing: 'Hello World: 2'
The image dials a router on this machine’s port 7447, so nros run starts
that router, ROS’s rmw_zenohd, then builds the application through west
(the first build takes several minutes; later ones take seconds) and runs
zephyr.exe. Don’t start a router of your own on the same port. It keeps
running until you press Ctrl-C.
See it in ROS 2
Leave nros run going. In a second terminal:
source /opt/ros/humble/setup.bash
export RMW_IMPLEMENTATION=rmw_zenoh_cpp
ros2 topic echo /chatter std_msgs/msg/String --qos-reliability best_effort
data: 'Hello World: …'
The talker’s publisher is reliable, as ros2 topic info -v /chatter shows.
Asking for best-effort receives from a publisher of either kind, so the
command works whatever QoS a publisher offers.
If it doesn’t work
eth_posix: Cannot create zethon the console: the application tried to create a TAP interface instead of using the host’s sockets. The board’s configuration prevents that; an application you configured yourself needs nano-ros’snros-nsossnippet.nros runrefuses a Rust image and namesclang,clippyor the Rust target: runnros setup --sudoin the workspace again, or the install command it prints.nros runstops at once and names the router: it could not findrmw_zenohd, or another router already holds port 7447.- Everything else: Troubleshooting - First 10 Minutes.
Next
- Each Zephyr piece, the image’s configuration, and other boards: Zephyr native_sim.
- A Zephyr application you build with west yourself: A Zephyr app you build with west.
- The same Zephyr on an emulated microcontroller: mps2-an385 in QEMU (Zephyr).