Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Get started on mps2-an385 in QEMU (Zephyr)

How-to · Level 1: First contact

Needs first: Install

Status: Verified in emulator (daily). From the board support registry: nros-board-mps2-an385-zephyr; Board Support Levels explains the words.

This starter puts a talker on Zephyr 3.7, on an emulated Arm Cortex-M3 board, and shows its messages arriving in ROS 2. The board is Arm’s MPS2-AN385 in QEMU, the board this book teaches nano-ros on: it costs nothing and behaves like a real microcontroller. Zephyr runs the talker with its own IP stack on the board’s emulated SMSC911x ethernet. 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 host with the install done, so nros is on your PATH.
  • 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 board talks to, and the message definitions the build generates the talker’s code from.
  • Zephyr’s host tools: west and the build tools Zephyr’s Getting Started lists. nros setup installs 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: QEMU’s user-mode network carries the board’s ethernet to your machine. WiFi is deferred to the Zephyr 4.4 line, so no starter opens over WiFi yet.

Provision

Provision the board:

nros setup mps2-an385-zephyr --rmw zenoh
export ZEPHYR_SDK_INSTALL_DIR="$(nros locate tool zephyr-sdk)"

That fetches the Zephyr SDK, whose QEMU boots the board, and the zenoh-pico 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 the board builds with (import: true would fetch every vendor’s HAL), plus Zephyr’s Rust support:

mkdir -p zephyr_ws/manifest && cd zephyr_ws
manifest/west.yml
manifest:
  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]
    # Zephyr's Rust support. Pinned to the revision nano-ros builds with on
    # 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, and the board’s Rust target:

nros setup board mps2-an385-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
. "$HOME/.cargo/env"
nros new zm_ws --board mps2-an385-zephyr --template talker --lang rust
cd zm_ws
nros setup --sudo

A Rust application on Zephyr needs three things a C one does not: the Rust target the board implies (thumbv7m-none-eabi), 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.

nros new zm_ws --board mps2-an385-zephyr --template talker --lang c
cd zm_ws
nros new zm_ws --board mps2-an385-zephyr --template talker --lang cpp
cd zm_ws

That wrote a workspace with two packages: src/zm_node/, the talker, a library with no main() that names no board, and src/zm_node_bringup/, which says what the talker runs on. The Zephyr application itself is generated under build/ when you build, so you write no CMakeLists.txt and no prj.conf.

Run it in QEMU

The board’s own configuration puts the image on QEMU’s user-mode network, at 10.0.2.15, and points it at the router on 10.0.2.2:7447, which is your host. nros run reads that address from the image’s build and starts the router on your host’s port 7447 itself, or reuses a zenoh router already listening there.

In the workspace, source ROS 2 and build the firmware first. The build writes the image’s network configuration, which nros run reads to start the router, so build before the first run. It goes through west, and the first build takes several minutes; later ones take seconds:

source /opt/ros/humble/setup.bash
nros build

Then run the talker:

nros run zm_node
Publishing: 'Hello World: 1'
Publishing: 'Hello World: 2'

nros run rebuilds the firmware if a source changed, then boots it in the QEMU that the Zephyr SDK ships. What it prints is the board’s console: Zephyr’s boot banner, then the talker. 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

  • nros run refuses the image and names clang, clippy or the Rust target: run nros setup --sudo in the workspace again, or the install command it prints.
  • No Publishing: line within 30 seconds of boot: the board did not reach the router. QEMU’s boot and Zephyr’s start take about 15 seconds. Check what nros run said about the router: it starts one on port 7447, reuses a zenoh router already there, and refuses to run when something else holds the port.
  • A build that names zephyr-lang-rust: the west workspace has no modules/lang/rust. Add the zephyr-lang-rust project to west.yml and run west update again.
  • Everything else: Troubleshooting - First 10 Minutes.

Next