The Raspberry Pi Pico 2 represents an exciting evolution in microcontroller development, and Rust provides an excellent foundation for building reliable embedded applications. In this tutorial, we’ll walk through setting up your development environment and creating your first Rust application for the Pico 2.
git clone https://github.com/raspberrypi/pico-sdk
export PICO_SDK_PATH=/path/to/pico-sdk
echo 'export PICO_SDK_PATH=/path/to/pico-sdk' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/raspberrypi/picotool
On macOS:
brew install libusb pkg-config cmake
On Linux:
sudo apt install libusb cmake
cd picotool
mkdir build
cd build
cmake ../
make
This will create the picotool executable that we’ll use to flash our applications.
rustup target add thumbv8m.main-none-eabihf
git clone https://github.com/thejpster/rp-hal-rp2350-public
cd rp-hal-rp2350-public
cargo build --example pwm_blink --target thumbv8m.main-none-eabihf --all-features
picotool info -d
picotool load -t elf ./target/thumbv8m.main-none-eabihf/debug/examples/pwm_blink
picotool makeuf2 -o output.uf2 ./target/thumbv8m.main-none-eabihf/debug/examples/pwm_blink
Then drag the output.uf2 file onto your Pico 2’s bootloader drive.
picotool reboot
You should now see the LED on your Pico 2 blinking!
The PWM blink example uses Pulse Width Modulation to control LED brightness, creating a smooth breathing effect rather than just turning the LED on and off. This demonstrates how Rust can efficiently control hardware peripherals on the Pico 2.
Now that you have a working Rust application on your Pico 2, you can:
You’ve successfully set up a complete Rust development environment for the Raspberry Pi Pico 2 and flashed your first application! This foundation will serve you well as you explore more advanced embedded programming concepts.
The combination of Rust’s memory safety guarantees and the Pico 2’s powerful dual-core ARM Cortex-M33 processor makes for an excellent platform for embedded development. Whether you’re building IoT devices, robotics projects, or custom hardware controllers, you now have the tools to get started.
Happy coding! 🦀