2.34 Data Watchpoint and Trace (DWT)

Data Watchpoint and Trace (DWT) peripheral can be configured as a hardware watchpoint. The first comparator DWT_COMP0 can also compare against the clock cycle counter CYCCNT.

The DWT if present contains counters for:

  • Clock cycles (CYCCNT)

  • Folded instructions

  • Load Store Unit (LSU) operations

  • Sleep cycles

  • CPI, that is all instruction cycles except for the first cycle

Using The Library

A DWT contains one comparator that you can use as a watchpoint and Cycle matching functionality is available in comparator 0.

int main(void)
{
/* Initialize all modules */

SYS_Initialize ( NULL );

/* Generate 1000 ms delay using DWT */

DWT_DelayMs(1000);
}

Library Interface

Data Watchpoint and Trace peripheral library provides the following interfaces:

Functions

NameDescription
DWT_InitializeInitializes Data Watchpoint and Trace (DWT) unit
DWT_DelayUsBlocking function to generate delay in microseconds
DWT_DelayMsBlocking function to generate delay in milliseconds
DWT_CounterResetReset the cycle counter Value
DWT_CounterEnableEnable the cycle counter
DWT_CounterDisableDisable the cycle counter
DWT_CounterGetGet the cycle counter current Value
Note: Not all APIs maybe implemented. See the specific device family section for available APIs.