SAMD21 Micro Trace Buffer (MTB) Overview

Last modified by Microchip on 2023/11/09 09:01

The Micro Trace Buffer (MTB) provides program execution trace capability. It records the Program Counter (PC) value of the command line being executed which is known as trace data since it shows the trail of executed code. Each executed program counter value is stored in SRAM circular buffer.

The accompanying diagram shows the main interfaces on the MTB and how they are connected in a simple Arm® Cortex®-M0+ based system.

main interfaces on the MTB and how they are connected in a simple Arm® Cortex®-M0+ based system

The MTB simultaneously stores trace information into the SRAM and gives the processor access to it. The MTB ensures that trace write accesses have priority over processor accesses.

The execution trace packet consists of a pair of 32-bit words that the MTB generates when it detects the processor PC value changes non-sequentially. A non-sequential PC change can occur during branch instructions or during exception entry. When a jump is made it records both the program counter of where the program was and where the program counter jumped to.

The processor can cause a trace packet to be generated for any instruction.

The MTB can be programmed to stop tracing automatically when the memory fills to a specified watermark level, or to start, or stop tracing by writing directly to the MASTER.EN bit. If the watermarking mechanism is not being used and the trace buffer overflows, the buffer wraps around overwriting previous trace packets in a First-In-First-Out (FIFO) arrangement.

Debugging a Trace

An off-chip debugger tool can extract the trace information using the Debug Access Port to read the trace information from the SRAM. The debugger can then reconstruct the program flow from this information. This can help diagnose programs that run outside the intended execution due to coding or logic errors.