Ramblings of an aging IT geek
← Ramblings of an aging IT geek
rust

blinking an led the hard way, in rust

First impressions of writing bare-metal Rust for an STM32 Blue Pill, where the toolchain is delightful and the first blink still takes an afternoon.

Code on a screen

I have a drawer of STM32 Blue Pills that cost about two pounds each, and a weekend with nothing pressing, so naturally I spent it trying to blink an LED in Rust rather than in five lines of Arduino. This is the correct use of a bank holiday.

The good news is that the ecosystem has come a long way. With cortex-m, cortex-m-rt and the stm32f1xx-hal crate you get a genuinely pleasant experience. The HAL hands you the GPIO peripheral, you split it, configure a pin as a push-pull output, and the type system actually stops you doing daft things like writing to a pin you configured as an input. That part feels like the future.

The less good news is the bit nobody screenshots: getting the thing flashed. probe-rs and an ST-Link, a .cargo/config with the right target and runner, a memory.x that matches your actual chip and not the one in the tutorial. My first afternoon was mostly that, plus a satisfyingly stupid hour where nothing worked because I had a clone Blue Pill with 128K of flash declared as 64K. Once it ran, it ran perfectly, and the LED blinked, and I sat there far prouder than two pounds of hardware deserves. Embedded Rust is real now. It just still asks for the afternoon.