In this lesson, you will learn how to correlate disparate hardware trace packets with a global reference clock to reconstruct the precise timing of events across multiple system peripherals.
The Challenge of Asynchronous Tracing
When you enable the Embedded Trace Macrocell (ETM) or Data Watchpoint and Trace (DWT), the hardware generates a massive stream of "events"—such as branch targets, memory accesses, or instruction execution. However, these packets are emitted as quickly as the bus allows, often without an inherent temporal reference. If your system has multiple masters (like a DMA engine and a CPU) interacting with the same peripheral, determining which event happened first becomes impossible if the trace packets simply arrive at the debugger in an arbitrary, non-deterministic order.
Introducing Global Timestamps
To solve this, modern trace architectures inject periodic Timestamp Packets into the stream. A Global Timestamp Counter (GTC) acts as a high-resolution heartbeat for the entire SoC. When the trace hardware is configured to emit timestamps, it inserts a multi-byte synchronization marker into the trace buffer that captures the current cycle count of the GTC.
By anchoring trace data to these time markers, the debugging software performs a linear interpolation. For example, if you see a Memory Write packet followed by a Timestamp: 0x500 and then an Interrupt packet, you can mathematically prove the sequence of operations even if the transport layer (e.g., SWO or high-speed trace port) multiplexed the data slightly out of order due to buffer pressure.
Conceptual Mapping
Imagine your trace stream looks like this:
[PC: 0x08001000] (Instruction)
[Timestamp: 1024]
[PC: 0x08001004] (Instruction)
[Data: 0x20000000] (Peripheral Access)
Without the timestamp, you wouldn't know if that Peripheral Access happened before or after the second instruction executed, especially if they reside in different clock domains. By cross-referencing the timestamp against the system’s trace-clock, you reconstruct the timeline:
T=1024: System registers the event.T=1025: Instruction at0x08001004completes.
This correlation allows you to verify latency requirements, such as ensuring an ISR triggers within a specific window after a DMA transfer completes.
Key Takeaway: Global timestamping transforms raw, unordered trace packets into a synchronized, chronological narrative of hardware execution.