Hello team,
I am trying to use the DWT unit for getting the cycle count in Debug mode.Below is my configuration:
Although I am unable to get the cycle count in my code. Any additional configuration needed?
thanks,
Aditya
Please refer to these related articles:
"How can I count the number of instructions executed by the processor in a given time interval?"
https://developer.arm.com/documentation/ka001253/1-0/?lang=en
"Using DWT and other methods to count executed instructions on Cortex-M"
https://developer.arm.com/documentation/ka001499/latest
This code below works for me:
// Bit mask definitions (*_Msk) are from core_cm3.h // To use DWT, you have to set the Trace Enable bit in DEMCR... CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk; // Trace DEMCR might not be writable from CPU (only debugger??) if( !(CoreDebug->DEMCR & CoreDebug_DEMCR_TRCENA_Msk) ) { GPIO_PinOutSet( LED1 ); return -1; } // CYCCNT might not be implemented ? if( DWT->CTRL & DWT_CTRL_NOCYCCNT_Msk ) { GPIO_PinOutSet( LED1 ); return -1; } // Reset the cycle counter and enable it, so it starts counting DWT->CYCCNT = 0; DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
Note how I use CoreDebug-> where you used DCB->. Where are you getting the macro 'DCB' from? I don't see it in e.g. core_cm3.h.