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_CYCCNT   MMIO32(DWT_BASE + 0x04)
 DWT_CYCCNT register Cycle Count Register (Shows or sets the value of the processor cycle counter, CYCCNT) When enabled, CYCCNT increments on each processor clock cycle. More...
 
#define DWT_CPICNT   MMIO32(DWT_BASE + 0x08)
 DWT_CPICNT register Purpose Counts additional cycles required to execute multi-cycle instructions and instruction fetch stalls. More...
 
#define DWT_EXCCNT   MMIO32(DWT_BASE + 0x0C)
 
#define DWT_SLEEPCNT   MMIO32(DWT_BASE + 0x10)
 
#define DWT_LSUCNT   MMIO32(DWT_BASE + 0x14)
 
#define DWT_FOLDCNT   MMIO32(DWT_BASE + 0x18)
 
#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_CTRL_NOTRCPKT   (1 << 27)
 
#define DWT_CTRL_NOEXTTRIG   (1 << 26)
 
#define DWT_CTRL_NOCYCCNT   (1 << 25)
 
#define DWT_CTRL_NOPRFCCNT   (1 << 24)
 
#define DWT_CTRL_CYCEVTENA   (1 << 22)
 
#define DWT_CTRL_FOLDEVTENA   (1 << 21)
 
#define DWT_CTRL_LSUEVTENA   (1 << 20)
 
#define DWT_CTRL_SLEEPEVTENA   (1 << 19)
 
#define DWT_CTRL_EXCEVTENA   (1 << 18)
 
#define DWT_CTRL_CPIEVTENA   (1 << 17)
 
#define DWT_CTRL_EXCTRCENA   (1 << 16)
 
#define DWT_CTRL_PCSAMPLENA   (1 << 12)
 
#define DWT_CTRL_SYNCTAP_SHIFT   10
 
#define DWT_CTRL_SYNCTAP   (3 << DWT_CTRL_SYNCTAP_SHIFT)
 
#define DWT_CTRL_SYNCTAP_DISABLED   (0 << DWT_CTRL_SYNCTAP_SHIFT)
 
#define DWT_CTRL_SYNCTAP_BIT24   (1 << DWT_CTRL_SYNCTAP_SHIFT)
 
#define DWT_CTRL_SYNCTAP_BIT26   (2 << DWT_CTRL_SYNCTAP_SHIFT)
 
#define DWT_CTRL_SYNCTAP_BIT28   (3 << DWT_CTRL_SYNCTAP_SHIFT)
 
#define DWT_CTRL_CYCTAP   (1 << 9)
 
#define DWT_CTRL_POSTCNT_SHIFT   5
 
#define DWT_CTRL_POSTCNT   (0x0F << DWT_CTRL_POSTCNT_SHIFT)
 
#define DWT_CTRL_POSTPRESET_SHIFT   1
 
#define DWT_CTRL_POSTPRESET   (0x0F << DWT_CTRL_POSTPRESET_SHIFT)
 
#define DWT_CTRL_CYCCNTENA   (1 << 0)
 CYCCNTENA Enables the Cycle counter. More...
 
#define DWT_MASKx_MASK   0x0F
 
#define DWT_FUNCTIONx_MATCHED   (1 << 24)
 
#define DWT_FUNCTIONx_DATAVADDR1_SHIFT   16
 
#define DWT_FUNCTIONx_DATAVADDR1   (15 << DWT_FUNCTIONx_DATAVADDR1_SHIFT)
 
#define DWT_FUNCTIONx_DATAVADDR0_SHIFT   12
 
#define DWT_FUNCTIONx_DATAVADDR0   (15 << DWT_FUNCTIONx_DATAVADDR0_SHIFT)
 
#define DWT_FUNCTIONx_DATAVSIZE_SHIFT   10
 
#define DWT_FUNCTIONx_DATAVSIZE   (3 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)
 
#define DWT_FUNCTIONx_DATAVSIZE_BYTE   (0 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)
 
#define DWT_FUNCTIONx_DATAVSIZE_HALF   (1 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)
 
#define DWT_FUNCTIONx_DATAVSIZE_WORD   (2 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)
 
#define DWT_FUNCTIONx_LNK1ENA   (1 << 9)
 
#define DWT_FUNCTIONx_DATAVMATCH   (1 << 8)
 
#define DWT_FUNCTIONx_CYCMATCH   (1 << 7)
 
#define DWT_FUNCTIONx_EMITRANGE   (1 << 5)
 
#define DWT_FUNCTIONx_FUNCTION   15
 
#define DWT_FUNCTIONx_FUNCTION_DISABLED   0
 

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_CPICNT

#define DWT_CPICNT   MMIO32(DWT_BASE + 0x08)

DWT_CPICNT register Purpose Counts additional cycles required to execute multi-cycle instructions and instruction fetch stalls.

Usage constraints: The counter initializes to 0 when software enables its counter overflow event by setting the DWT_CTRL.CPIEVTENA bit to 1. Configurations Implemented: only when DWT_CTRL.NOPRFCNT is RAZ, see Control register, DWT_CTRL. If DWT_CTRL.NOPRFCNT is RAO, indicating that the implementation does not include the profiling counters, this register is UNK/SBZP.

Definition at line 80 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_CPIEVTENA

#define DWT_CTRL_CPIEVTENA   (1 << 17)

Definition at line 121 of file dwt.h.

◆ DWT_CTRL_CYCCNTENA

#define DWT_CTRL_CYCCNTENA   (1 << 0)

CYCCNTENA Enables the Cycle counter.

0 = Disabled, 1 = Enabled This bit is UNK/SBZP if the NOCYCCNT bit is RAO.

Definition at line 145 of file dwt.h.

◆ DWT_CTRL_CYCEVTENA

#define DWT_CTRL_CYCEVTENA   (1 << 22)

Definition at line 116 of file dwt.h.

◆ DWT_CTRL_CYCTAP

#define DWT_CTRL_CYCTAP   (1 << 9)

Definition at line 132 of file dwt.h.

◆ DWT_CTRL_EXCEVTENA

#define DWT_CTRL_EXCEVTENA   (1 << 18)

Definition at line 120 of file dwt.h.

◆ DWT_CTRL_EXCTRCENA

#define DWT_CTRL_EXCTRCENA   (1 << 16)

Definition at line 122 of file dwt.h.

◆ DWT_CTRL_FOLDEVTENA

#define DWT_CTRL_FOLDEVTENA   (1 << 21)

Definition at line 117 of file dwt.h.

◆ DWT_CTRL_LSUEVTENA

#define DWT_CTRL_LSUEVTENA   (1 << 20)

Definition at line 118 of file dwt.h.

◆ DWT_CTRL_NOCYCCNT

#define DWT_CTRL_NOCYCCNT   (1 << 25)

Definition at line 113 of file dwt.h.

◆ DWT_CTRL_NOEXTTRIG

#define DWT_CTRL_NOEXTTRIG   (1 << 26)

Definition at line 112 of file dwt.h.

◆ DWT_CTRL_NOPRFCCNT

#define DWT_CTRL_NOPRFCCNT   (1 << 24)

Definition at line 114 of file dwt.h.

◆ DWT_CTRL_NOTRCPKT

#define DWT_CTRL_NOTRCPKT   (1 << 27)

Definition at line 111 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_CTRL_PCSAMPLENA

#define DWT_CTRL_PCSAMPLENA   (1 << 12)

Definition at line 123 of file dwt.h.

◆ DWT_CTRL_POSTCNT

#define DWT_CTRL_POSTCNT   (0x0F << DWT_CTRL_POSTCNT_SHIFT)

Definition at line 135 of file dwt.h.

◆ DWT_CTRL_POSTCNT_SHIFT

#define DWT_CTRL_POSTCNT_SHIFT   5

Definition at line 134 of file dwt.h.

◆ DWT_CTRL_POSTPRESET

#define DWT_CTRL_POSTPRESET   (0x0F << DWT_CTRL_POSTPRESET_SHIFT)

Definition at line 138 of file dwt.h.

◆ DWT_CTRL_POSTPRESET_SHIFT

#define DWT_CTRL_POSTPRESET_SHIFT   1

Definition at line 137 of file dwt.h.

◆ DWT_CTRL_SLEEPEVTENA

#define DWT_CTRL_SLEEPEVTENA   (1 << 19)

Definition at line 119 of file dwt.h.

◆ DWT_CTRL_SYNCTAP

#define DWT_CTRL_SYNCTAP   (3 << DWT_CTRL_SYNCTAP_SHIFT)

Definition at line 126 of file dwt.h.

◆ DWT_CTRL_SYNCTAP_BIT24

#define DWT_CTRL_SYNCTAP_BIT24   (1 << DWT_CTRL_SYNCTAP_SHIFT)

Definition at line 128 of file dwt.h.

◆ DWT_CTRL_SYNCTAP_BIT26

#define DWT_CTRL_SYNCTAP_BIT26   (2 << DWT_CTRL_SYNCTAP_SHIFT)

Definition at line 129 of file dwt.h.

◆ DWT_CTRL_SYNCTAP_BIT28

#define DWT_CTRL_SYNCTAP_BIT28   (3 << DWT_CTRL_SYNCTAP_SHIFT)

Definition at line 130 of file dwt.h.

◆ DWT_CTRL_SYNCTAP_DISABLED

#define DWT_CTRL_SYNCTAP_DISABLED   (0 << DWT_CTRL_SYNCTAP_SHIFT)

Definition at line 127 of file dwt.h.

◆ DWT_CTRL_SYNCTAP_SHIFT

#define DWT_CTRL_SYNCTAP_SHIFT   10

Definition at line 125 of file dwt.h.

◆ DWT_CYCCNT

#define DWT_CYCCNT   MMIO32(DWT_BASE + 0x04)

DWT_CYCCNT register Cycle Count Register (Shows or sets the value of the processor cycle counter, CYCCNT) When enabled, CYCCNT increments on each processor clock cycle.

On overflow, CYCCNT wraps to zero.

Purpose Shows or sets the value of the processor cycle counter, CYCCNT. Usage constraints: The DWT unit suspends CYCCNT counting when the processor is in Debug state. Configurations Implemented: only when DWT_CTRL.NOCYCCNT is RAZ, see Control register, DWT_CTRL. When DWT_CTRL.NOCYCCNT is RAO no cycle counter is implemented and this register is UNK/SBZP.

Definition at line 67 of file dwt.h.

◆ DWT_EXCCNT

#define DWT_EXCCNT   MMIO32(DWT_BASE + 0x0C)

Definition at line 81 of file dwt.h.

◆ DWT_FOLDCNT

#define DWT_FOLDCNT   MMIO32(DWT_BASE + 0x18)

Definition at line 84 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_CYCMATCH

#define DWT_FUNCTIONx_CYCMATCH   (1 << 7)

Definition at line 174 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVADDR0

#define DWT_FUNCTIONx_DATAVADDR0   (15 << DWT_FUNCTIONx_DATAVADDR0_SHIFT)

Definition at line 164 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVADDR0_SHIFT

#define DWT_FUNCTIONx_DATAVADDR0_SHIFT   12

Definition at line 163 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVADDR1

#define DWT_FUNCTIONx_DATAVADDR1   (15 << DWT_FUNCTIONx_DATAVADDR1_SHIFT)

Definition at line 161 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVADDR1_SHIFT

#define DWT_FUNCTIONx_DATAVADDR1_SHIFT   16

Definition at line 160 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVMATCH

#define DWT_FUNCTIONx_DATAVMATCH   (1 << 8)

Definition at line 173 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVSIZE

#define DWT_FUNCTIONx_DATAVSIZE   (3 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)

Definition at line 167 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVSIZE_BYTE

#define DWT_FUNCTIONx_DATAVSIZE_BYTE   (0 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)

Definition at line 168 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVSIZE_HALF

#define DWT_FUNCTIONx_DATAVSIZE_HALF   (1 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)

Definition at line 169 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVSIZE_SHIFT

#define DWT_FUNCTIONx_DATAVSIZE_SHIFT   10

Definition at line 166 of file dwt.h.

◆ DWT_FUNCTIONx_DATAVSIZE_WORD

#define DWT_FUNCTIONx_DATAVSIZE_WORD   (2 << DWT_FUNCTIONx_DATAVSIZE_SHIFT)

Definition at line 170 of file dwt.h.

◆ DWT_FUNCTIONx_EMITRANGE

#define DWT_FUNCTIONx_EMITRANGE   (1 << 5)

Definition at line 175 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_LNK1ENA

#define DWT_FUNCTIONx_LNK1ENA   (1 << 9)

Definition at line 172 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_LSUCNT

#define DWT_LSUCNT   MMIO32(DWT_BASE + 0x14)

Definition at line 83 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.

◆ DWT_SLEEPCNT

#define DWT_SLEEPCNT   MMIO32(DWT_BASE + 0x10)

Definition at line 82 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, DWT_CTRL_CYCCNTENA, DWT_CTRL_NOCYCCNT, DWT_CYCCNT, 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, DWT_CTRL_CYCCNTENA, and DWT_CYCCNT.