Raspberry PI Pico with Rust (Embassy)

After I failed to do HTTP requests in Micropython as described in a previous post, I felt like it is time to try Rust on the Raspberry PI Pico. Installing code on the Pico with Rust can be done using UF2 as with Micropython. But because there is no REPL there is no way to see the outputs of the program this way. So using a Debugprobe as described in the Embassy getting started is a good plan.

We need to prepare a second Pico as Debugprobe. The UF2 needed for this can be build as described in Appendix A of the Getting started with Raspberry Pi Pico. But building the UF2 is not neccessary because there is already a version available that can be easily flashed on the Pico by dragging it on the Pico filesystem after button-press connecting it to your computer.

Now lets build an example firmware with Embassy. Important here there are two versions of blinky: blinky.rs is for the Pico and the wifi_blinky.rs for the Pico W. I have a Pico W connected so I did this to compile (as described in the Getting started but with some Archlinux):

# setup rust (on Archlinux)
sudo pacman -S rustup cargo-binstall
# choose stable rust
rustup default stable

git clone https://github.com/embassy-rs/embassy.git
cd embassy/examples/rp
# build Pico W example
cargo build --bin wifi_blinky --release

# install probe-rs software - the binary will land in ~/.cargo/bin/probe-rs
cargo binstall probe-rs

Wire the Debugprobe Pico to the Pico we want to get our code on. My version of this:

img1

In the Appendix A of the Getting started with Raspberry Pi Pico is a schematic which is lot clearer than my photo!

I don't want to use sudo to use the Debugprobe, so we need a udev rule. This is described in the getting started of probe-rs:

curl https://probe.rs/files/69-probe-rs.rules > 69-probe-rs.rules
sudo mv 69-probe-rs.rules /etc/udev/rules.d
sudo udevadm control --reload
sudo udevadm trigger

Check that probe-rs is finding the Debugprobe Pico:

~/.cargo/bin/probe-rs list
# should return:
[0]: Debugprobe on Pico (CMSIS-DAP) (VID: 2e8a, PID: 000c, Serial: E660C06213776B27, CmsisDap

Finally run the blinky example:

cargo run --bin wifi_blinky --release

If successful this shows a lot of prints like this on your shell after flashing and initializing:

1.238451 INFO  led on!
└─ wifi_blinky::____embassy_main_task::{async_fn#0} @ src/bin/wifi_blinky.rs:58
1.238481 DEBUG set gpioout = [01, 00, 00, 00, 01, 00, 00, 00]
└─ cyw43::control::{impl#1}::set_iovar_v::{async_fn#0} @ /home/mfa/pico/embassy/cyw43/src/fmt.rs:130
2.239012 INFO  led off!
└─ wifi_blinky::____embassy_main_task::{async_fn#0} @ src/bin/wifi_blinky.rs:62
2.239030 DEBUG set gpioout = [01, 00, 00, 00, 00, 00, 00, 00]
└─ cyw43::control::{impl#1}::set_iovar_v::{async_fn#0} @ /home/mfa/pico/embassy/cyw43/src/fmt.rs:130