rp2350
Hardware Abstraction Layer for RP2350 microcontrollers.
rp2350 provides a no_std HAL for RP2350-based boards, along with the
runtime and PAC re-exports needed to bring up a bare-metal application on the
Raspberry Pi Pico 2 family.
What it includes
- GPIO, UART, SPI, I2C, PWM, ADC, DMA, timer, watchdog, TRNG, and multicore APIs
- Re-exports of
rp2350-pacasrp2350::pacandrp2350-rtasrp2350::rt - Attribute macros such as
#[entry],#[exception], and#[bind] - Optional
defmtintegration and a built-in panic handler for bare-metal targets
Features
defmt: enabledefmtlogging supportrp2350a: target RP2350A with GPIO 0-29 (default)rp2350b: target RP2350B with GPIO 0-47critical-section-impl: register this crate as thecritical-sectionproviderpanic-handler: enable the built-in panic handler ontarget_os = "none"boot2: bare switch for the optional second stage boot loader below, see the section on flash bootboot2-w25q80: link that boot loader for W25Q80-family quad flashboot2-generic-03h: same, for flash that only supports03hserial reads
Default features: defmt, rp2350a, critical-section-impl, panic-handler.
Flash boot and boot2
RP2350 does not need a second stage boot loader to start. The boot ROM configures
XIP well enough by itself and enters the image through the IMAGE_DEF boot block
that #[main] emits. What the ROM does not do is make XIP fast.
The boot2-w25q80 feature links an optional 256-byte XIP setup function from
rp2350-boot2. The reset handler copies it into RAM and calls it there before
.data is initialised, because it rewrites the QMI timing registers that govern
instruction fetch. It raises the interface clock, sets an RX sampling delay and
switches the flash to quad continuous reads (EBh with mode bits) instead of
single-bit 03h reads. boot2-generic-03h does everything except the quad
switch, for flash that cannot do it.
The features are split in two layers: boot2 is the bare switch (rp2350-rt
then calls the blob from Reset), and each boot2-<part> feature selects the
flash part, implying the switch. Feature names carry the part number, so further
variants can be added later; enabling boot2 without a part is a compile error
rather than a silently empty .boot2.
Both are off by default. Enable one per application:
= { = "0.1", = ["boot2-w25q80"] }
See docs/boot2.md in the repository for what the blob does, the 256-byte limit
and how to verify a build.
Quick start
Add the HAL to your embedded crate. If you want the same defmt logging setup as
the workspace blink example, add defmt-rtt as well:
[]
= "0.1"
= "1.2"
Complete blink example with comments:
use *;
use defmt_rtt as _;
use Delay;
use ImageDef;
use entry;
use Pins;
use Peripherals;
use Peripherals as CorePeripherals;
/// RP2350 Boot Block - tells the Boot ROM this is a valid ARM executable
pub static IMAGE_DEF: ImageDef = exe;
/// RP2350 default boot clock frequency
/// At boot, RP2350 runs from ROSC at approximately 12 MHz
const CLOCK_FREQ_HZ: u32 = 12_000_000;
!
Common imports
rp2350 re-exports the most commonly used types from the HAL root, so simple
applications can often import directly from the crate:
use ;
For lower-level access, use:
use pac;
use rt;
Notes
- This crate is intended for bare-metal RP2350 targets such as
thumbv8m.main-none-eabihf. - If your final binary defines its own
#[panic_handler], disable thepanic-handlerfeature. - If you are targeting RP2350B, disable the default chip feature and enable
rp2350binstead.
Examples
The workspace contains runnable examples covering GPIO, clocks, DMA, PIO, USB,
BLDC control, and more in the rp2350-examples crate.