Use the thumbv7m-none-eabi target triple with the no_std attribute to compile Rust code for ARM Cortex-M microcontrollers.
#![no_std]
#![no_main]
use panic_halt as _;
#[no_mangle]
pub extern "C" fn _start() -> ! {
loop {}
}
-
Add the Cortex-M target to your toolchain.
rustup target add thumbv7m-none-eabi -
Create a new binary crate with the
no_stdattribute.cargo new --bin cortex-m-app && cd cortex-m-app -
Add the
cortex-mandpanic-haltdependencies to yourCargo.toml.cargo add cortex-m panic-halt -
Compile the project for the specific target architecture.
cargo build --target thumbv7m-none-eabi -
Convert the resulting binary into a flashable ELF file.
objcopy --output-target=elf32-littlerm target/thumbv7m-none-eabi/debug/cortex-m-app cortex-m-app.elf -
Flash the ELF file to your microcontroller using a debugger like OpenOCD. `openocd -f interface/stlink.cfg -f target/stm32f1x.cfg -c "program cortex-m-app.elf verify reset exit"