Skip to content
RED SAG Skills
hard20 pts · first answer countsmicrocontrollersdebuggingcortex-m

Timing an ISR in CPU cycles

You want the exact cycle count of a function on a Cortex-M4. Which approach is precise and cheap?

CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->CYCCNT = 0;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
uint32_t t0 = DWT->CYCCNT;
filter_step();
uint32_t cycles = DWT->CYCCNT - t0;
Choose one answer

Discussion 0

Join free to post in the discussion.

Related questions