Get started on NuttX in QEMU (RISC-V)
Needs first: Install
Status: Verified in emulator (daily). From the board support registry:
nros-board-nuttx-qemu; Board Support Levels explains the words.
This starter puts a talker on Apache NuttX, on QEMU’s 32-bit RISC-V virt
machine (rv32imac), and shows its messages arriving in ROS 2. NuttX is a
POSIX-style RTOS, so the talker runs as an ordinary NuttX task, with NuttX’s
own network stack on a virtio-net device. You need no NuttX checkout of your
own: nros setup fetches the kernel and its apps tree, and nros run links
your node into a bootable kernel. 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
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 board talks to, and the message definitions the build generates the talker’s code from. - Two host packages the NuttX kernel build uses: the kconfig-frontends
tools, which configure the kernel, and
unzip. The provision step installs them for you when you allow it. - A
qemu-system-riscv32from your distribution. The QEMU in nano-ros’s store is built for Arm and 64-bit RISC-V only, so this board takes yours. On Debian or Ubuntu it is inqemu-system-misc.
No board, no cable: QEMU’s user-mode network carries the guest’s ethernet to your machine, with no TAP device to create. WiFi is deferred to the Zephyr 4.4 line, so no starter opens over WiFi yet.
Provision
nros setup rv-virt-nuttx --rmw zenoh --sudo
sudo apt-get install -y qemu-system-misc
The first line fetches the RISC-V cross-compiler and the NuttX kernel and apps
sources into a shared store under ~/.nros. Before it downloads anything it
names the host packages that are missing, and --sudo lets it run the one
install command it composed for your package manager
(sudo apt-get install -y kconfig-frontends-nox unzip on Debian or Ubuntu).
Leave --sudo off and it only prints that command. The second line installs the emulator. Neither
installs a router: the router is ROS’s rmw_zenohd.
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
QEMU_SYSTEM_RISCV32 names the emulator nros run boots the board with, so
set it in the shell you build and run from:
export QEMU_SYSTEM_RISCV32="$(command -v qemu-system-riscv32)"
nros new nx_ws --board rv-virt-nuttx --template talker --lang rust
cd nx_ws
export QEMU_SYSTEM_RISCV32="$(command -v qemu-system-riscv32)"
nros new nx_ws --board rv-virt-nuttx --template talker --lang c
cd nx_ws
export QEMU_SYSTEM_RISCV32="$(command -v qemu-system-riscv32)"
nros new nx_ws --board rv-virt-nuttx --template talker --lang cpp
cd nx_ws
That wrote a workspace with two packages: src/nx_node/, the talker, a
library with no main() that names no board, and src/nx_node_bringup/,
which says what the talker runs on. The NuttX task that runs your node is
generated from the bringup when you build. A Rust talker builds for the
board’s riscv32imac-unknown-nuttx-elf target, which the build compiles the
Rust standard library for itself.
Run it in QEMU
The image dials a zenoh router on your host through QEMU’s user-mode
network: the guest reaches your host as 10.0.2.2, on port 7447. nros run
starts that router itself, listening on every interface so the guest’s
connection arrives, and stops it when the run ends. If a router already runs
on that port, nros run --router auto uses it instead.
In the workspace, source ROS 2 and build and run the talker. This first run records the ROS 2 prefix in the workspace, so later runs of it need no sourced shell:
source /opt/ros/humble/setup.bash
nros run nx_node
Publishing: 'Hello World: 1'
Publishing: 'Hello World: 2'
nros run builds the kernel with your node linked in (the first build
configures NuttX from the board’s defconfig and takes several minutes; later
builds take seconds), then boots it with the qemu-system-riscv32 that
QEMU_SYSTEM_RISCV32 names. The image starts its application itself, so what
you see is the talker on the NuttX console. It keeps running until you press
Ctrl-C.
See it in ROS 2
Leave nros run going; its router stays up while it runs. 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 runasksnros locate tool qemu-system-riscv32, or names no emulator: this shell has noQEMU_SYSTEM_RISCV32. Run theexportline again, after installingqemu-system-misc.- No
Publishing:line within a minute of boot: the talker did not reach the router. If you run your own router with--router auto, check that it listens on0.0.0.0:7447: one on127.0.0.1is out of the guest’s reach. nros setupstops and nameskconfig-frontends-noxorunzip: you left--sudooff. Run the command it printed.- Everything else: Troubleshooting - First 10 Minutes.
Next
- The image’s configuration, a NuttX tree of your own, and real hardware: NuttX Arm and RISC-V.
- The same NuttX on Arm: NuttX in QEMU (Arm).
- The project, grown: the Tutorial.