no_std and Your First Blink
What you give up without the standard library, and how to flash a board.
#![no_std]
#![no_main]
use panic_halt as _;
use cortex_m_rt::entry;
#[entry]
fn main() -> ! {
let dp = pac::Peripherals::take().unwrap();
let mut led = /* configure a GPIO output */;
loop {
led.set_high();
delay(1_000_000);
led.set_low();
delay(1_000_000);
}
}
#![no_std] drops the standard library. No heap, no String, no Vec, no std::io. You
keep all of core: iterators, Option, Result, slices, formatting.
fn main() -> ! never returns β thereβs no OS to return to.
You must declare a panic handler; panic_halt spins forever. Flash with probe-rs, and use
defmt for logging: it sends format indices instead of strings, which matters when your
whole flash budget is 256 KB.