Real-Time Transfer (RTT) provides runtime output for embedded firmware without a standard terminal. The target writes to a RAM-resident ring buffer, and a host tool reads that memory through a debug probe while the target runs. SWD and JTAG can provide the required background memory access. section 6.2 section 6.2.4
RTT supports non-blocking, low-overhead output, making it useful when semihosting would disturb timing-sensitive code. It still needs target RAM and a debug connection; UART is an alternative when output must work without a debugger. section 6.1.1 section 6.3.6
#![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 {}
}
Initialize RTT before printing with rprintln!. This minimal no_std Cortex-M program sends one message and then stays running. section 6.2.4
[dependencies]
cortex-m = { version = "0.7", features = ["critical-section-single-core"] }
cortex-m-rt = "0.7"
panic-halt = "1.0.0"
rtt-target = "0.6"
These dependencies support the example, including rtt-target and the single-core critical-section feature. section 6.2.4
cargo install probe-rs-tools probe-rs run --chip STM32F103C8T6 target/thumbv7m-none-eabi/release/app
Install the host tools, then flash the specified ELF and stream RTT output with probe-rs run. Replace the chip and ELF path for your target. section 6.2.4
For a configuration stored with the project, cargo-embed reads settings such as the chip, probe protocol, and RTT enablement from Embed.toml. Both cargo-embed and probe-rs run use probe-rs for probe communication and RTT capture; the main difference is their configuration workflow. section 6.2.4 section 2.6.1
For compact structured logs, defmt encodes binary frames and defmt-rtt transports them over RTT. The logging API and transport are separate: link only one defmt transport into a firmware image, or linking fails. section 2.6.3 section 6.3.2
Reporting timing measurements
Measure execution with the Cortex-M DWT cycle counter, or a SysTick fallback where DWT is unavailable, and send the results to the host through RTT. Avoid semihosting for profiling output because its calls halt the core and distort timing. section 6.6
