liveBook · Manning

ITM

As explained in Embedded Software with Rust

The Instrumentation Trace Macrocell is an Arm trace component that emits instrumentation data through trace interfaces such as SWO.

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

How Embedded Software with Rust covers it

How deep it goes
Explains stimulus-port logging, capture setup, host decoding, hardware requirements and clock-related failure symptoms.
Examples
Shows a Rust message on stimulus port 0, OpenOCD capture commands and itmdump decoding.
What you can do after
Apply ITM logging via cortex-m, OpenOCD and itmdump to capture and inspect firmware messages.
How it connects
Connects ITM to CoreSight, SWO, OpenOCD, GDB and defmt transport backends.

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.