Running Rust on Pi Pico (and W and 2)

·

Assumptions

You are able to use a command line/terminal interface. You have some experience in Rust. You have used a Pico with C.

Hardware

  • Raspberry Pi Pico (any version)
    • Pico
    • Pico W
    • Pico 2
    • Pico 2W
  • USB Cable

Install requirements

If you don't have Rust installed use this:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

And if you already have it then update it with:

rustup update

Then install picotool using the instructions given on it's Github. If you have previously used a Pico for C, then you might already have it installed.

Clone example

Download the repository that contains the examples with this command:

git clone https://github.com/embassy-rs/embassy.git

If you are using Pico or Pico W:

cd embassy/examples/rp/

If you are using Pico 2 or Pico 2W:

cd embassy/examples/rp235x/

Compile Example

First, edit .cargo/cargo.toml

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "probe-rs run --chip RP2040"

and replace the 2$^{\text{nd}}$ line with:

[target.'cfg(all(target_arch = "arm", target_os = "none"))']
runner = "picotool load -u -v -x -t elf"
info
Note

If you are using Pico 2 it will say runner = "probe-rs run --chip RP235x" but you can replace it the same way.

Hold down the bootsel button and plug it in, then let go of the button. Make sure it mounts as a new drive. Now if you run:

cargo run --bin blinky

in a few seconds it should upload the blink code and reboot the Pico to it. The builtin LED should be blinking.

warning
Name differences

If you are using the W version, you need to replace blinky with wifi_blinky (Pico W) or blinky_wifi (Pico 2W).