I successfully loaded and ran my C program on rpi Pico using Pico SDK and OpenOCD. Now I have ported the program to Rust (a challenging first Rust project!). Must I build a PicoProbe to run it, or is there a way to load it directly ala Pico SDK?
no, you don't have to, you can use your existing probe with openocd just fine. if you want to use probe-rs
, it supports any probe as long as it implements the CMSIS-DAP interface.
the rust toolchain outputs elf files, you can use any tool that can load the elf file to the board. for example, suppose your binary crate name is blinky
, cargo build --target thumbv6m-none-eabi
will generate the output elf file at the path target/thumbv6m-none-eabi/debug/blinky
.
if you just need to load and run the program without debugging it, you can convert the elf file into uf2 and use the onchip uf2 bootloader. any tools can do, like the official picotool, if you already have it. it should be installed with the pico-sdk
.
however, I recommend the elf2uf2-rs tool, which can convert the binary to uf2 format and load it to the board in a single step. you can build it from source or install it with cargo install elf2uf2-rs
from crates.io
alternatively, you can use openocd too, for example:
$ openocd -f target/rp2040.cfg -c "program target/thumbv6m-none-eabi/debug/blinky verify reset exit"
you can also set it as the cargo "runner", so you can use it with the cargo run
command.
cargo
will pass the path to the elf output to the runner as argument. for tools like elf2uf2-rs
, you can set it as the runner directly. for openocd, you can use a wrapper script to convert the command line argument into the openocd script:
# .cargo/config.toml
[target.thumbv6m-none-eabi]
runner = "elf2uf2-rs"
# or
#runner = "openocd-wrapper"
example openocd-wrapper
script:
#!/bin/sh
BINARY="$1"
openocd -f target/rp2040.cfg -c "program $BINARY verify reset exit"
I combine elf2uf2-rs
with a cargo alias to reduce my typing burden:
# .cargo/config.toml
[alias]
build-fw = "run --release --package my-fw-project --target thumbv6m-none-eabi"
[target.thumbv6m-none-eabi]
runner = "elf2uf2-rs -d"
Running cargo build-fw
does all the work.
Nice tip, thanks Parasyte!
Thank you very much Nerditation! I don't have any probe now and was hoping for alternatives. Now I have a few!
if you have multiple pico boards or compatible boards, you can turn one of them into a CMSIS-DAP compatible probe.
I recommend the the rust-probe firmware, remember to change the pin configurations to suit your hardware. it works perfectly for me, both openocd and probe-rs can recognize the CMSIS-DAP interface without any problem.
I heard the official pico-probe firmware can also be modified to run on a pico, but I didn't try it myself.