libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.
Cortex-M Data Watch and Trace unit.

System Control Space (SCS) => Data Watchpoint and Trace (DWT). More...

Collaboration diagram for Cortex-M Data Watch and Trace unit.:

Macros

#define DWT_CTRL   MMIO32(DWT_BASE + 0x00)
 DWT Control register Purpose Provides configuration and status information for the DWT block, and used to control features of the block Usage constraints: There are no usage constraints. More...
 
#define DWT_PCSR   MMIO32(DWT_BASE + 0x1C)
 
#define DWT_COMP(n)   MMIO32(DWT_BASE + 0x20 + (n) * 16)
 
#define DWT_MASK(n)   MMIO32(DWT_BASE + 0x24 + (n) * 16)
 
#define DWT_FUNCTION(n)   MMIO32(DWT_BASE + 0x28 + (n) * 16)
 
#define DWT_LSR   MMIO32(DWT_BASE + CORESIGHT_LSR_OFFSET)
 
#define DWT_LAR   MMIO32(DWT_BASE + CORESIGHT_LAR_OFFSET)
 
#define DWT_CTRL_NUMCOMP_SHIFT   28
 
#define DWT_CTRL_NUMCOMP   (0x0F << DWT_CTRL_NUMCOMP_SHIFT)
 
#define DWT_MASKx_MASK   0x0F
 
#define DWT_FUNCTIONx_MATCHED   (1 << 24)
 
#define DWT_FUNCTIONx_FUNCTION   15
 
#define DWT_FUNCTIONx_FUNCTION_DISABLED   0
 
#define DWT_FUNCTIONx_FUNCTION_PCWATCH   4
 
#define DWT_FUNCTIONx_FUNCTION_DWATCH_R   5
 
#define DWT_FUNCTIONx_FUNCTION_DWATCH_W   6
 
#define DWT_FUNCTIONx_FUNCTION_DWATCH_RW   7
 

Functions

bool dwt_enable_cycle_counter (void)
 DebugTrace Enable the CPU cycle counter. More...
 
uint32_t dwt_read_cycle_counter (void)
 DebugTrace Read the CPU cycle counter. More...
 

Detailed Description

System Control Space (SCS) => Data Watchpoint and Trace (DWT).

See "ARMv7-M Architecture Reference Manual" and "ARMv6-M Architecture Reference Manual" The DWT is an optional debug unit that provides watchpoints, data tracing, and system profiling for the processor.

Macro Definition Documentation

◆ DWT_COMP

#define DWT_COMP (   n)    MMIO32(DWT_BASE + 0x20 + (n) * 16)

Definition at line 89 of file dwt.h.

◆ DWT_CTRL

#define DWT_CTRL   MMIO32(DWT_BASE + 0x00)

DWT Control register Purpose Provides configuration and status information for the DWT block, and used to control features of the block Usage constraints: There are no usage constraints.

Configurations Always implemented.

Definition at line 47 of file dwt.h.

◆ DWT_CTRL_NUMCOMP

#define DWT_CTRL_NUMCOMP   (0x0F << DWT_CTRL_NUMCOMP_SHIFT)

Definition at line 106 of file dwt.h.

◆ DWT_CTRL_NUMCOMP_SHIFT

#define DWT_CTRL_NUMCOMP_SHIFT   28

Definition at line 105 of file dwt.h.

◆ DWT_FUNCTION

#define DWT_FUNCTION (   n)    MMIO32(DWT_BASE + 0x28 + (n) * 16)

Definition at line 91 of file dwt.h.

◆ DWT_FUNCTIONx_FUNCTION

#define DWT_FUNCTIONx_FUNCTION   15

Definition at line 179 of file dwt.h.

◆ DWT_FUNCTIONx_FUNCTION_DISABLED

#define DWT_FUNCTIONx_FUNCTION_DISABLED   0

Definition at line 180 of file dwt.h.

◆ DWT_FUNCTIONx_FUNCTION_DWATCH_R

#define DWT_FUNCTIONx_FUNCTION_DWATCH_R   5

Definition at line 186 of file dwt.h.

◆ DWT_FUNCTIONx_FUNCTION_DWATCH_RW

#define DWT_FUNCTIONx_FUNCTION_DWATCH_RW   7

Definition at line 188 of file dwt.h.

◆ DWT_FUNCTIONx_FUNCTION_DWATCH_W

#define DWT_FUNCTIONx_FUNCTION_DWATCH_W   6

Definition at line 187 of file dwt.h.

◆ DWT_FUNCTIONx_FUNCTION_PCWATCH

#define DWT_FUNCTIONx_FUNCTION_PCWATCH   4

Definition at line 185 of file dwt.h.

◆ DWT_FUNCTIONx_MATCHED

#define DWT_FUNCTIONx_MATCHED   (1 << 24)

Definition at line 155 of file dwt.h.

◆ DWT_LAR

#define DWT_LAR   MMIO32(DWT_BASE + CORESIGHT_LAR_OFFSET)

Definition at line 96 of file dwt.h.

◆ DWT_LSR

#define DWT_LSR   MMIO32(DWT_BASE + CORESIGHT_LSR_OFFSET)

Definition at line 94 of file dwt.h.

◆ DWT_MASK

#define DWT_MASK (   n)    MMIO32(DWT_BASE + 0x24 + (n) * 16)

Definition at line 90 of file dwt.h.

◆ DWT_MASKx_MASK

#define DWT_MASKx_MASK   0x0F

Definition at line 151 of file dwt.h.

◆ DWT_PCSR

#define DWT_PCSR   MMIO32(DWT_BASE + 0x1C)

Definition at line 88 of file dwt.h.

Function Documentation

◆ dwt_enable_cycle_counter()

bool dwt_enable_cycle_counter ( void  )

DebugTrace Enable the CPU cycle counter.

This function will try to enable the CPU cycle counter that is intended for benchmarking performance of the code. If function fails, the cycle counter isn't available on this architecture.

Returns
true, if success

Definition at line 58 of file dwt.c.

References DWT_CTRL, SCS_DEMCR, and SCS_DEMCR_TRCENA.

◆ dwt_read_cycle_counter()

uint32_t dwt_read_cycle_counter ( void  )

DebugTrace Read the CPU cycle counter.

This function reads the core cycle counter if it is enabled. It is the fastest clock running on the system.

Note
The CPU cycle counter must be enabled by dwt_enable_cycle_counter
Returns
0 if cycle counter is not supported or enabled, the cycle counter value otherwise.

Definition at line 90 of file dwt.c.

References DWT_CTRL.