cargo-embed is a Cargo subcommand for building and flashing embedded firmware, streaming RTT output, and optionally starting a GDB server. It uses probe-rs for probe communication and target control. section 2.6.1 section 6.2.4
Place an optional Embed.toml file in the project root to keep target and debugging settings alongside the source. Settings are grouped into named profiles and sections for the chip, probe, flashing, reset, RTT, and GDB. A bare cargo embed command selects the default profile; a profile name selects another configuration. section 3.1.4 section 6.3.5
[default.general] chip = "STM32F103C8T6" [default.probe] protocol = "Swd" # speed = 4000 # kHz, omit to use the probe default [default.flashing] enabled = true [default.reset] enabled = true halt_afterwards = false [default.rtt] enabled = true [default.gdb] enabled = false
This configuration selects an STM32 target, enables flashing and reset, and opens an RTT terminal. GDB is disabled. section 6.3.5
Use probe-rs chip list to find recognized chip identifiers. For a single probe using SWD, the probe section can be omitted. Set reset halt_afterwards to true to stop at the reset vector for startup debugging; leave it false for normal flash-and-run development. section 6.3.5
cargo embed --release
Run this command to build and deploy a release build using the project configuration. section 2.6.1 section 6.2.4
RTT output requires firmware that writes to an RTT buffer. A debug probe reads that buffer from target RAM while the firmware runs; cargo-embed streams the output to the terminal. It can also handle defmt output when configured for that logging workflow. section 6.2.4 section 6.3.4
#![no_std]
#![no_main]
use cortex_m as _;
use cortex_m_rt::entry;
use panic_halt as _;
use rtt_target::{rprintln, rtt_init_print};
#[entry]
fn main() -> ! {
rtt_init_print!();
rprintln!("RTT log message");
loop {}
}
This firmware initializes RTT printing and writes a message for a host tool to capture. section 6.2.4
For a simple command-line workflow, probe-rs run accepts the chip and ELF path directly. cargo-embed is convenient when probe selection, reset behavior, or RTT channels need reusable project settings. For flashing without live logging or debugging, cargo-flash is a simpler alternative. section 6.2.4 section 2.6.1
