Embedded Rust is the use of Rust to develop firmware for embedded targets. Bare-metal firmware runs without an operating system and commonly controls sensors, actuators, and memory-mapped peripherals. Tight memory limits and the need for dependable behavior shape its design. section 1.0 section 1.3
Unlike a desktop Rust program, a bare-metal program typically uses no_std instead of the standard library. It links the core crate and a target-appropriate startup or runtime crate. The optional alloc crate requires an explicitly supplied global allocator; otherwise, firmware can rely on static allocation. A minimal application generally needs an explicit entry point and a panic handler. section 1.3 section 2.1.1 section 1.8
On Cortex-M, startup begins when the processor loads the initial stack pointer and reset vector, then branches to the reset handler. The handler performs initialization before calling the program’s entry point. A linker script defines the memory layout, including FLASH and RAM regions, section placement, the stack, and the vector table. Runtime crates can provide startup support, or the initialization can be implemented manually. section 1.8 section 4.0 section 2.1.1
Interrupt handlers can preempt the main program to respond to hardware events. If both contexts access the same data or peripherals, races and corruption are possible. Ownership and borrowing help structure access, but interrupt-driven sharing still requires careful design. Singleton peripherals and safe sharing patterns are foundational tools for managing that access. section 4.6 section 1.8
A practical firmware workflow includes:
- Configure the toolchain and target for cross-compilation, then use Cargo to build the firmware. section 2.8
- Configure the project and memory layout, using files such as Cargo.toml, .cargo/config.toml, and memory.x. Templates can speed setup, but may become outdated. section 3.0
- Inspect binaries with cargo-binutils or GNU tools, then flash and debug on hardware or run firmware in an emulator such as QEMU. section 2.8 section 2.7
