Embedded Basics
10 examples introducing no_std, cross targets, and the embedded Rust toolchain.
Busca en todas las páginas de la documentación
10 examples introducing no_std, cross targets, and the embedded Rust toolchain.
cargo install probe-rs-tools for flashing and debugrustup target add thumbv7em-none-eabihfrustup target add thumbv7em-none-eabihf # Cortex-M4F
rustup target add thumbv6m-none-eabi # Cortex-M0+eabihf means hardware floating pointtarget in .cargo/config.toml.cargo/config.toml[build]
target = "thumbv7em-none-eabihf"
[target.thumbv7em-none-eabihf]
runner = "probe-rs run --chip STM32F429ZITx"--target every buildrunner auto-flashes on cargo runprobe-rs databasememory.x)MEMORY
{
FLASH : ORIGIN = 0x08000000, LENGTH = 2048K
RAM : ORIGIN = 0x20000000, LENGTH = 192K
}cortex-m-rt crate expects memory.xno_std Crate#![no_std]
#![no_main]
use panic_halt as _;
#[no_mangle]
pub extern "C" fn main() -> ! {
loop {}
}#![no_std] removes the standard library#![no_main] replaces Rust's main with embedded entrypanic_halt stops on panic (replace with better handler in prod)defmt Logginguse defmt::info;
info!("system started");
info!("tick {}", 42);println! on embeddeddefmt feature on dependenciesdefmt-print on hostRelated: Debugging Firmware
let dp = pac::Peripherals::take().unwrap();
let rcc = dp.RCC.constrain();
let clocks = rcc.cfgr.freeze();
let gpioa = dp.GPIOA.split();pac = peripheral access crate (regs)hal = safe wrappers over pactake() enforces singleton peripheralsstm32* / rp2040 / nrf HAL[features]
default = ["stm32f429"]
stm32f429 = ["stm32f4xx-hal/stm32f429"]probe-rs Flash and Debugprobe-rs list
probe-rs run --chip STM32F429ZITx target/thumbv7em-none-eabihf/debug/appcargo embed config uses probe-rs under the hood#[embassy_executor::main]
async fn main(_spawner: Spawner) {
let p = embassy_stm32::init(Default::default());
// async tasks...
}embassy ecosystem cratesRelated: Async on Embedded (Embassy)
firmware/
.cargo/config.toml
memory.x
build.rs # copy memory.x
src/
main.rs
Cargo.toml # hal + panic + defmt
build.rs links memory.x via cortex-m-rtcargo binutils for size analysis (cargo size)Stack versions: This page was written for Rust 1.97.0 (edition 2024), Tokio 1.x, Axum 0.8, serde 1.0, sqlx 0.8, clap 4, and Polars 0.46+.
Revisado por Chris St. John·Última actualización: 19 jul 2026