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

Bare-metal Cortex-M3

How-to · Level 2: Building real applications

Needs first: Run a talker on an emulated board, What you just built, Get started on mps2-an385 in QEMU (bare-metal)

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

The starter scaffolded a Rust talker for board = "mps2-an385-baremetal", ran it in QEMU over the board’s serial port, and heard it from ROS 2. This page covers what comes after it: moving the image onto the board’s network, what is particular to a board with no operating system, the run plan, and driving cargo yourself.

Use bare-metal for very constrained Cortex-M targets with no scheduler and no threads. If your target has FreeRTOS or another RTOS, the FreeRTOS on mps2-an385 page is the same board with a scheduler under your nodes.

Configure the platform

The whole deployment is the bringup’s system.toml, compiled into the image: the generated entry folds the image’s network identity into the configuration the board applies at boot. There is no configuration file on the device and no .cargo/ to edit. The target triple, linker script, --gc-sections flag, QEMU runner and the [patch.crates-io] rows that resolve nano-ros’s crates all come from the board, and nros build writes them under build/.

The starter’s image reaches the router over the board’s serial port, the first link a real board’s program uses. To reach it over the board’s ethernet instead, on QEMU’s user-mode network, give the image a TCP locator and an address:

[image.baremetal]
board = "mps2-an385-baremetal"
locator = "tcp/10.0.2.2:10500"
os_config = ["board-net.toml"]

and the address, in a board network file beside system.toml in the bringup:

[eth0]
network = "qemu"
host = 10

The board package owns the network device, so the device’s address lives in the board’s own file, which the image names with os_config. 10.0.2.2 is QEMU’s gateway to the host. With this locator, nros run bm_node starts the router on the host’s port 10500 when it boots the image. If a zenoh router of your own already listens on that port, nros run uses it instead and says so; anything else on the port stops the run before it starts, naming --router. Within about 15 seconds of boot the zenoh session opens and the first Publishing: line appears.

Changing board to "mps2-an385-freertos" and building again builds the FreeRTOS image of the same node, with no other edit: the node package’s Cargo.toml names no board crate, RMW backend or panic handler. Those are the generated entry’s dependencies.

Board notes

  • QEMU’s MPS2-AN385, a Cortex-M3. The board crate is nros-board-mps2-an385, with no -freertos suffix: it carries the Cortex-M3 startup, the linker script, the LAN9118 ethernet driver for smoltcp and the idle wait (wfi).
  • One entry shape: direct execution. The generated entry runs your executor in one loop on the reset path. qemu-arm-baremetal is a retired spelling of the same board; use mps2-an385-baremetal.
  • A bounded, guarded main stack. The whole image runs on one stack at the top of RAM, 256 KiB unless the image says otherwise. Below it sits a small region the MPU blocks. A stack that grows past its size hits that region and stops the image with nros: stack overflow: the main stack grew past its stated size. Nothing below the stack is overwritten. Raise the size with memory.app_stack_bytes, in bytes and a whole number of KiB, in the image’s [image.<id>.knobs.memory] or as NROS_MEMORY_APP_STACK_BYTES in its build environment. A size too big for the image’s statics fails the link, naming the same knob. A size below the image’s stack floor, a heuristic estimate of what nano-ros needs, fails the build with the value to set (A11).
  • No alloc by default. The build is no_std with heapless collections. To use alloc, enable the board crate’s alloc feature and supply a #[global_allocator].
  • No preemption and no wake primitive. Callbacks run one at a time in the loop. A callback that runs long holds back every other callback until it returns.
  • The console is semihosting, so QEMU prints the image’s output on your terminal.
  • Nothing is flashed. mps2-an385 is a QEMU machine, and nros setup provisions no probe or flash tooling for it. A real Cortex-M board is a board package of your own; Add a board takes an STM32F4-Discovery through it, and Flash a real board flashes the result.

Read the run plan

From the starter’s workspace, print the plan nros run follows:

nros run bm_node --dry-run --why

The parts that matter, trimmed, for the starter’s serial image:

[runner]
package = "nros_runner_qemu"
name = "qemu"

[target]
emulator = "qemu:mps2-an385"

[console]
kind = "semihosting"

[link]
kind = "serial"
locator = "serial/UART_0#baudrate=115200"
rmw = "zenoh"
host_peer = "zenoh-router"

--why adds where each fact came from. The emulator, the console and the serial port are the board descriptor’s. The runner passes QEMU -nic user,model=lan9118, which wires the guest’s LAN9118 to the user-mode network; a QEMU line of your own that drops it (-nic none, -nodefaults) leaves the guest with no network.

Drive cargo yourself

The first build cross-compiles nano-ros’s dependencies for thumbv7m-none-eabi, about five minutes; later builds take seconds. To use cargo directly from an IDE, a CI step or with --release, print the exact cargo line nros build runs against the generated entry:

nros build --dry-run

nros configure writes the generated entry and its cargo settings without building, before you open the workspace in an IDE. Both are regenerated on every build: never edit them, and never add a .cargo/config.toml of your own to carry board facts. Your own toolchain preferences go where cargo already looks, a parent directory or $CARGO_HOME. See When nros build drives the build.

If it doesn’t work

  • No Publishing: line over the network: another router holds the locator’s port, or a QEMU line of your own dropped the NIC.
  • The talker stalls after you change it: a callback runs long, and nothing preempts it.
  • Everything else: Troubleshoot.

Reference