Measuring cycle count
Cortex-M processors provide multiple ways to compare the performance of different implementations of an algorithm. One way is to use a cycle counter register. Another way is to use a timer to measure the time of execution and convert the time into clock cycles using the processor frequency. The most recent Cortex-M microcontrollers contain a full performance monitoring unit (PMU), which enables software to get information about the count of various events occurring while the software is executing. One of the measured events can be a cycle counter, but additional events such as cache and memory accesses can also be counted.
This section will cover how to use the most common methods of counting cycles for a specific section of code on Cortex-M microcontrollers. First, we will introduce System Tick Timer or System Time Tick (SysTick) followed by Data Watchpoint and Trace (DWT). Both these programming interfaces can be used to count clock cycles for a benchmark...