RP2040 (Raspberry Pi Pico)
Board id: rp2040-pico · 6 step channels · PIO-timed STEP/DIR, one state machine per axis · flashed via UF2 (BOOTSEL) or probe-rs.
Status
Implemented, compiles and host-tested; not yet validated on hardware. Flashing, motor movement and pulse timing on a real Pico are unverified until the hardware validation has been carried out.
Architecture
The RP2040 runs the same shared firmware as the STM32F411 and the virtual MCU. What differs is how pulses leave the chip.
- Scheduling (shared). A tick interrupt (
TIMER_IRQ_0, every 200 µs) runs the shared stepper code, which tracks position, checks soft limits and endstops before every step, detects queue underrun and late segments, and handles homing and controlled stop. It callsHal::steponce for each step that became due. - Pulse execution (RP2040-specific).
Hal::steponly records the step in a per-axis buffer (at most 4 direction runs per tick). At the end of the tick,Hal::flush_pulsesturns each buffer into PIO commands that spread those steps evenly over the next 200 µs window. Overdue steps never go out as a burst.
Everything runs on core 0: the tick interrupt and the main loop (USB, frame decoding, status, watchdog). Core 1 is parked. The PIO does the time-critical part, so the CPU only has to produce one command word per axis per 200 µs. If six-axis measurements show the tick interrupt using more than about half its window, moving it to core 1 is the next step.
Pin map
Fixed by the firmware. The resolver checks every profile against it.
| Channel | STEP | DIR | ENABLE (active low) | ENDSTOP | PIO block / SM |
|---|---|---|---|---|---|
| 0 | GP0 | GP1 | GP12 | GP18 | PIO0 / SM0 |
| 1 | GP2 | GP3 | GP13 | GP19 | PIO0 / SM1 |
| 2 | GP4 | GP5 | GP14 | GP20 | PIO0 / SM2 |
| 3 | GP6 | GP7 | GP15 | GP21 | PIO0 / SM3 |
| 4 | GP8 | GP9 | GP16 | GP22 | PIO1 / SM0 |
| 5 | GP10 | GP11 | GP17 | GP26 | PIO1 / SM1 |
| Signal | Pin | Notes |
|---|---|---|
| Safety interlock | GP27 | Input with pull-up; must be pulled to GND for drives to enable |
| Status LED | GP25 | On while any drive is enabled |
| Host link | USB (micro-USB) | CDC-ACM, VID:PID 16c0:27dd, product "MotionCore MCU (rp2040)" |
Electrical
- RP2040 GPIO is 3.3 V and not 5 V tolerant. Use drivers that accept 3.3 V logic (most TMC, DRV8825 and A4988 boards do), or level shifters.
- Pin drive strength defaults to 4 mA. For long cables or opto-isolated driver inputs, add a buffer such as a 74HCT245 powered at 5 V.
- ENABLE needs an external pull-up to the driver's logic supply, so drivers stay disabled during reset, in BOOTSEL mode, during a watchdog reset, and with no firmware. The firmware drives ENABLE high (disabled) before configuring anything else.
- The Pico must never power motors.
Endstops, E-stop and the interlock
- Endstops: normally-open switch between the ENDSTOP pin and GND; pressed = low. In noisy environments add an RC filter (e.g. 1 kΩ / 100 nF), or use normally-closed switches with
invert = true. - E-stop (mandatory): a hardware circuit that removes driver power (contactor or safety relay), independent of all software.
- Interlock monitor (GP27): wire an auxiliary contact of the E-stop circuit — closed when it is safe to run — between GP27 and GND. While GP27 is open, the firmware latches an emergency stop and disables every drive, and refuses both
EnableandResetFault.
An unconnected GP27 counts as open, the safe default. On a bench without an E-stop circuit, use a jumper to GND — and only with motors that cannot cause harm. The interlock only monitors the E-stop; it does not replace it.
Build and flash
motioncore firmware build --board rp2040-pico # reference profile → build/firmware/rp2040-pico/
motioncore firmware build --config my-robot.toml # your profile → build/firmware/<mcu>/The UF2 is generated from the ELF and validated block by block: magic numbers, RP2040 family id 0xe48bff56, block numbering, and every block inside the 2 MiB flash window starting with the boot2 stage at 0x10000000.
Via BOOTSEL (UF2):
motioncore disableand remove driver power.- Hold BOOTSEL while plugging in USB. A drive named
RPI-RP2appears. - Flash:bash
motioncore firmware flash --board rp2040-pico --yes motioncore firmware flash --board rp2040-pico --uf2-volume /media/$USER/RPI-RP2 --yes # if not found - Confirm what is running — only this proves the flash succeeded:bash
motioncore firmware verify --board rp2040-pico --device /dev/ttyACM0 # COMx on Windows
Via SWD (optional): with a debug probe such as a second Pico running debugprobe, probe-rs download --chip RP2040 build/firmware/rp2040-pico/firmware.elf. cargo run inside boards/rp2040 uses the same runner.
Only the Pico's W25Q080 (2 MiB) boot2 is included. Boards with other flash chips need a different boot2.
Configuration example
robot-profiles/six-axis-rp2040-pico.toml is the reference profile: six revolute axes with endstops and homing. One axis:
[mcu.main]
board = "rp2040-pico"
transport = "serial:///dev/ttyACM0"
watchdog_ms = 500
[[axis]]
id = "j2"
name = "Shoulder"
kind = "revolute"
unit = "deg"
mcu = "main"
channel = 1
steps_per_unit = 44.444444
min = -90.0
max = 90.0
max_velocity = 45.0 # 2000 steps/s, below the 50 kHz board limit
max_acceleration = 180.0
[axis.driver]
actuator = "org.motioncore.actuator.step_dir"
step_pin = "GP2" # must match the pin map
dir_pin = "GP3"
enable_pin = "GP13"
[axis.endstop]
pin = "GP19"
[axis.homing]
direction = "negative"
speed = 15.0
position = -90.0
max_travel = 190.0PIO design
Allocation
One state machine per axis: axes 0–3 on PIO0 SM0–3, axes 4–5 on PIO1 SM0–1; PIO1 SM2–3 stay free. The 8-instruction program is loaded at offset 0 in both blocks (16 of 64 instruction slots used). Each state machine drives STEP by side-set and DIR by out pins, so the two pins need not be adjacent.
Program
0 pull block side 0 ; wait for a command
1 out pins, 1 side 0 [S] ; DIR, then setup delay
2 out x, 15 side 0 ; pulse count - 1
3 out isr, 16 side 0 ; low-time loop count L
4 pulse: nop side 1 [H] ; STEP high for H+1 cycles
5 mov y, isr side 0
6 low: jmp y-- low side 0 ; L+1 cycles
7 jmp x-- pulse side 0Command word: bit 0 = DIR level, bits 1–15 = pulses − 1, bits 16–31 = L.
Timing
State-machine clock: 125 MHz / 25 = 5 MHz (200 ns per cycle, integer divider, no fractional jitter).
| Quantity | Cycles | Time | Set by |
|---|---|---|---|
| STEP high | H + 1 = 10 | 2.0 µs | TIMING.high_cycles |
| STEP low (min) | L + 3 ≥ 10 | ≥ 2.0 µs | TIMING.min_low_cycles |
| DIR setup before first STEP edge | S + 3 = 10 | 2.0 µs | TIMING.dir_setup_cycles |
| DIR hold after last STEP edge | L + 4 ≥ 11 | ≥ 2.2 µs | follows from minimum low |
| Fastest period | 20 | 4 µs (250 kHz) | high + min low |
All values live in boards/rp2040/src/board.rs (TIMING). Check them against your driver's datasheet before changing anything.
Windows, buffering and failure behaviour
- Pulses may use 90 % of each 200 µs window; the rest absorbs command overhead and interrupt jitter.
- At this timing, at most 44 steps per axis fit a window (220 kHz). The board advertises a conservative 50 kHz per axis until hardware measurements justify more.
- The TX FIFO is joined (8 words); one window needs at most 4 words per axis.
- Before queuing a new window, the previous one must have been taken by the state machine. Otherwise output is lagging behind the tick and the firmware faults with
StepRateExceeded, rather than letting the lag grow. The same fault is raised if a window's steps don't fit the timing. - A tick gap longer than 10 windows (2 ms) during motion faults with
SegmentLate. - On disable, fault or E-stop: ENABLE goes high first, then the state machine is stopped, STEP forced low, both FIFOs cleared and the program parked at
pull. No queued pulse is emitted afterwards. - Endstops are checked before every step, but the step reaches the pin up to one window (200 µs) later. Worst-case overtravel is one window of steps: 1 step at 5 kHz, 10 steps at 50 kHz.
Synchronisation between axes
The same tick interrupt queues every axis's commands for a window, one after another, so windows of different axes start within a few microseconds of each other. Segment start times are absolute MCU timestamps. This is channel-level synchronisation only; coordinated multi-axis trajectories are a host planner feature that is not yet wired up.
Hardware validation
None of this has been carried out yet. Record results (date, board, driver, firmware build hash) when you do.
Equipment: a logic analyser with ≥ 24 MHz sample rate on 8 channels (or an oscilloscope), a flashed Pico, step/dir drivers without motor power for the timing tests. Use a temporary debug build that toggles a spare GPIO (e.g. GP28) at the start and end of TIMER_IRQ_0 to measure interrupt timing.
| # | Test | Procedure | Pass criterion |
|---|---|---|---|
| 1 | Safe start | Power up with and without firmware, in BOOTSEL, during flashing | All ENABLE lines high throughout |
| 2 | Identity | motioncore firmware verify | Board rp2040-pico, build hash matches |
| 3 | STEP high time | Jog one axis at 1, 10 and 50 kHz | 2.0 µs ± 0.1 µs |
| 4 | STEP low time | Same captures, shortest low phase | ≥ 2.0 µs at every rate |
| 5 | DIR setup / hold | Reversing move: DIR edge to next STEP rise; last STEP fall to DIR edge | ≥ 2.0 µs / ≥ 2.2 µs |
| 6 | Frequency accuracy | Constant-velocity jog; count edges over 1 s | Within 0.1 % of commanded; exact total step count |
| 7 | Jitter | Histogram of STEP periods at constant velocity | Spread ≤ one window-boundary effect; no period below minimum |
| 8 | Max sustainable rate | Raise rate until StepRateExceeded | Record; keep advertised limit ≤ 50 % of it |
| 9 | Six axes at once | All six channels at 50 kHz | No fault; tick ISR (GP28) < 100 µs; inter-axis start skew recorded |
| 10 | Stop latency | estop during motion: USB command to last STEP edge and ENABLE high | ENABLE high and STEP stopped within 1 ms of frame receipt |
| 11 | Watchdog | Unplug USB while enabled | ENABLE high within 500 ms |
| 12 | Hang | Halt core 0 with a debugger (watchdog pause on debug off) | Reset within ~100 ms, ENABLE high |
| 13 | Interlock | Open GP27 while moving | EmergencyStop fault, drives disabled, reset refused until closed |
| 14 | Endstop | Home each axis at low speed | Trigger detected; overtravel ≤ 1 step at homing speed |
Only after tests 1–14 pass: connect motors with low current limits and no load, then jog ±1°, home, stop mid-move and E-stop.
Known limitations
- Not yet run on hardware: flashing, USB enumeration, pulse timing, six-axis CPU budget and stop latency are unverified.
- Step timing resolution is one 200 µs window. Steps are evenly spaced within a window, not placed at their exact ideal times (deviation < 1 window).
- Endstop and fault reaction can trail the commanded position by one window.
- Advertised step rate is a conservative 50 kHz per axis until measured.
- One MCU per robot; no coordinated multi-axis trajectories from the host yet.