pico-blinky/README.md
Mathew Lewis 1f88150d03 Rust blinky for the RP2040 Pico, flashing the digits of pi
Flashes the on-board LED as 3, 1, 4, 1, 5 with pauses between digits and a
longer pause before repeating. The pattern is stepped from the hardware timer
rather than blocking sleeps, so the USB serial port stays responsive and can
reset the board back into BOOTSEL on request.

Includes the original plain 250 ms blink under alt/ and prebuilt .uf2 images.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FrCPgv2NGSEcyuN9KKQKHc
2026-08-25 13:00:00 -07:00

2.3 KiB

pico-blinky

Rust firmware for the Raspberry Pi Pico. Flashes the on-board LED with the digits of pi: three flashes, a pause, one flash, a pause, four, one, five, then a longer pause before it repeats.

Board

This targets the RP2040, the original Pico. It will not run on a Pico 2. Check which one you have by holding BOOTSEL while plugging it in and looking at the volume that mounts:

Volume label Chip This firmware
RPI-RP2 RP2040 yes
RP2350 RP2350 no

Build

rustup target add thumbv6m-none-eabi
cargo install elf2uf2-rs --locked
cargo build --release
elf2uf2-rs target/thumbv6m-none-eabi/release/blinky pi-blink.uf2

Flash

Hold the BOOTSEL button down before the cable goes in, keep it held for a second after, then release. The button is only read at power-on, so pressing it while the board is already running does nothing.

The board mounts as RPI-RP2. Copy the .uf2 onto it. The volume ejects itself once the write completes, which is the bootloader confirming it took the image and jumped to it.

Prebuilt images are in uf2/ if you just want to drag one across.

Getting back into the bootloader

The firmware exposes a USB serial port, so after the first flash you do not need the button again. Either:

  • send b to the serial port, or
  • open the port at 1200 baud and drop DTR, the convention picotool and the Arduino IDE use

Both call reset_to_usb_boot, and the board comes back up as RPI-RP2.

The LED pattern is driven from the hardware timer rather than blocking sleeps, so USB stays responsive while the sequence runs.

Layout

src/main.rs           pi digits + USB reboot-to-bootloader
alt/simple-blink.rs   plain 250 ms on/off blink, the first version
memory.x              flash/RAM layout, reserves 0x100 for the boot2 stage
build.rs              puts memory.x on the linker search path
uf2/                  prebuilt images

Timing

Edit the constants at the top of src/main.rs:

const FLASH_ON_US:  u64 =   150_000;
const FLASH_OFF_US: u64 =   200_000;
const DIGIT_GAP_US: u64 =   800_000;
const CYCLE_GAP_US: u64 = 3_000_000;

DIGIT_GAP_US is the one worth raising if the sequence is hard to count by eye, since 1 and 4 sit next to each other and can run together.