libopencm3
A free/libre/open-source firmware library for various ARM Cortex-M3 microcontrollers.

libopencm3 Cortex-M Data Watchpoint and Trace unit More...

Collaboration diagram for DWT:

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

libopencm3 Cortex-M Data Watchpoint and Trace unit

The DWT provides

Which of these features are available is unfortunately implementation defined.

See also
ARMv7m Architecture Reference Manual (Chapter ARMv7-M Debug)

LGPL License Terms libopencm3 License

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.