liveBook · Manning

Cargo-embed

As explained in Embedded Software with Rust

cargo-embed is a Cargo subcommand for flashing and debugging embedded targets with project-file-based configuration and RTT output streaming.

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

How Embedded Software with Rust covers it

How deep it goes
Explains profile selection, configuration sections, reset behavior, and RTT capture, while deferring the full configuration schema to documentation.
Examples
Uses STM32 configuration, a release invocation, and rtt-target firmware that prints an RTT message.
What you can do after
Operate and configure cargo-embed to flash firmware, stream RTT output, and select reset behavior.
How it connects
Connects probe-rs, RTT, defmt, GDB, SWD, and JTAG to firmware deployment and debugging.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Embedded Software with Rust. The section links point to the parts of the book it draws on.