Jump to main content

##

# 3.8.7 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

Name | Description
--- | ---
DWT_Initialize | Initializes Data Watchpoint and Trace (DWT) unit
DWT_DelayUs | Blocking function to generate delay in microseconds
DWT_DelayMs | Blocking function to generate delay in milliseconds
DWT_CounterReset | Reset the cycle counter Value
DWT_CounterEnable | Enable the cycle counter
DWT_CounterDisable | Disable the cycle counter
DWT_CounterGet | Get the cycle counter current Value