rp2040 Rust Template
The fastest way to write rust for the pi pico. I made this template to save time when creating embedded rust projects. It comes with everything needed to get started: The libraries, the cargo config and the build instructions. On top of that, the readme includes the commands you’ll need to run if you’ve never done embedded before.
To use the template, you just have to clone the repo, switch to your desired branch and update the project name on the Cargo.toml. The following commands will do just that:
git clone https://gitlab.com/slusheea/rp2040-rs-template.git YOUR_PROJECT_NAME
git checkout BRANCH_NAME
projname=$(pwd | awk -F "/" '{print $NF}'); sed -i "s/NAME/${projname}/g" Cargo.toml
There are four branches:
- pico-usb uses the rp2040-hal with the rp-pico BSP and is configured to flash the target directly via USB
- pico-debug uses the rp2040-hal with the rp-pico BSP and is configured to use a debug probe
- pico-debug-embassy uses embassy-rp and is configured to use a debug probe
- xiao-usb uses seeeduino-xiao-rp2040 and is configured to flash the target directly via USB
Depending on what branch you use, the commands you’ll need to run to build and flash your code are different. That’s why i would recommend using the included justfile. It includes build
, flash
, debug
and clippy
.
I created the rp2040-hal templates before the rp-rs team created an official one. But now that there’s an official one, I still use mine. The official one has support for many other rp2040 dev boards, so it needs some pre-configuring to make it work with the pi pico. So I’ve updated mine to use their template with some preconfigured options.