113270 Views
93709 Views
85773 Views
53388 Views
50571 Views
48758 Views
Operation Pico
Raspberry Pi Home Hub
Hacky Temperature and Humidity Sensor
Robot Makers Almanac
High Five Bot
Making a Custom PCB for BurgerBot
Using the Raspberry Pi Pico's Built-in Temperature Sensor
Getting Started with SQL
Introduction to the Linux Command Line on Raspberry Pi OS
How to install MicroPython
Wall Drawing Robot Tutorial
BrachioGraph Tutorial
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 >