The Instrumentation Trace Macrocell (ITM) is an Arm CoreSight component for sending telemetry through Serial Wire Output (SWO). It provides 32 logical channels, implemented as FIFO queues, so different message streams can use different stimulus ports. ITM offers low-intrusion output for timing-sensitive firmware, but requires target trace support and a SWO-capable probe. section 6.2.3 section 6.1.1
#![no_std]
#![no_main]
use cortex_m::{iprintln, Peripherals};
use cortex_m_rt::entry;
use panic_halt as _;
#[entry]
fn main() -> ! {
let mut cp = Peripherals::take().unwrap();
iprintln!(&mut cp.ITM.stim[0], "ITM log message");
loop {}
}
In no_std Rust, cortex-m’s iprintln! sends a message through stimulus port 0. The firmware must also configure its TPIU and ITM peripherals appropriately for tracing. section 6.2.3 section 6.5.7
monitor tpiu config internal /tmp/itm.txt uart off <CPU_CLOCK_HZ> monitor itm port 0 on
In GDB, configure OpenOCD to capture SWO output and enable port 0. Set CPU_CLOCK_HZ to the actual core clock during capture: an incorrect value can produce garbled or absent output without a clear error. section 6.2.3 section 6.5.7
cargo install itm itmdump -F -f /tmp/itm.txt
Install the itm tool and use itmdump to decode the capture. The -F flag follows new output; -s selects a stimulus port and defaults to port 0. section 6.2.3
ITM is Arm-specific and unavailable on RISC-V. For structured logging, defmt-itm can transport defmt’s binary frames over SWO; only one defmt transport may be linked into a firmware image. section 6.3.6 section 6.3.2
