101591 Views
79842 Views
45596 Views
44332 Views
40991 Views
33419 Views
Raspberry Pi Time machine
Now Ad-Free
Guiding Light
Sync Files on your Pis, with Syncthing
NextCloud
Buddy Jr.
Introduction to FreeCAD for Beginners
Building a Robot Arm with Raspberry Pi and PCA9685
Building User Authentication for Static Sites with FastAPI
Mastering Pydantic for Robust Data Validation
Mastering Markdown for Documentation with Jekyll
Introduction to Rust
KevsRobots Learning Platform
77% Percent Complete
By Kevin McAleer, 3 Minutes
The Raspberry Pi Pico is a popular microcontroller for various projects. This lesson will guide you through setting up Rust for development on the Pico, how to install your Rust programs on the device, techniques for debugging, and walking through a sample program.
To develop Rust programs for the Raspberry Pi Pico, you’ll need to set up your build environment:
cross
cargo install cross
rustup target add thumbv6m-none-eabi
After developing your Rust application, you’ll need to compile it for the Pico and upload it:
cargo build --release --target thumbv6m-none-eabi
Convert the compiled program to UF2 format, which is necessary for the Raspberry Pi Pico bootloader.
Push the RESET button on your Pico while holding the BOOTSEL button, release the BOOTSEL after the device is connected. It should mount as a Mass Storage Device.
Copy your .uf2 file to the Raspberry Pi Pico mass storage device.
.uf2
Debugging microcontroller applications can be challenging. Here are some techniques for debugging Rust programs on the Pico:
println!
Here’s a simple Rust program that blinks an LED on the Raspberry Pi Pico:
#![no_std] #![no_main] use panic_halt as _; use rp_pico::hal::{prelude::*, Timer}; use cortex_m_rt::entry; #[entry] fn main() -> ! { let mut pac = rp_pico::pac::Peripherals::take().unwrap(); let mut watchdog = Watchdog::new(pac.WATCHDOG); let clocks = rp_pico::hal::clocks::init_clocks_and_plls( rp2040::XOSC_CRYSTAL_FREQ, pac.XOSC, pac.CLOCKS, pac.PLL_SYS, pac.PLL_USB, &mut pac.RESETS, &mut watchdog, ) .ok() .unwrap(); let mut delay = Timer::new(pac.TIMER, &mut pac.RESETS); let sio = Sio::new(pac.SIO); let pins = rp_pico::Pins::new( pac.IO_BANK0, pac.PADS_BANK0, sio.gpio_bank0, &mut pac.RESETS, ); let mut led_pin = pins.led.into_push_pull_output(); loop { led_pin.set_high().unwrap(); delay.delay_ms(500); led_pin.set_low().unwrap(); delay.delay_ms(500); } }
This program initializes the board’s peripherals, sets up an LED pin, and then blinks the LED on and off every 500 milliseconds.
In this lesson, you’ve learned how to set up a Rust development environment for the Raspberry Pi Pico, how to install Rust programs on the device, strategies for debugging, and you’ve walked through an example program that blinks an LED.
< Previous Next >