2020-08-17 02:32 AM
Hello Everyone,
I'm new to application development with micro-controllers. Currently I'm using STM32F469IH6 for my project with the help of STM32CUBEIDE.
Can anyone suggest how to measure execution time of a certain piece of code. In traditional linux we will use gettimeoftheday(..) utility. How we can do this in the STM32F4 micro-controllers?
It would be very helpful if you provide example script to do this.
Thanks in advance.
2020-08-17 02:58 AM
There are several possibilities:
2020-08-17 04:07 AM
Hi @KnarfB ,
I did something similar to third method as follow. I would like to confirm with you whether the steps that I have followed are correct or not.
int main(){
volatile uint32_t count = 0;
volatile uint32_t actual_cycle_count = 180000000; // This represent cycles per second and this was based on clock speed of 180MHz for STM32F469IH6
// addresses of registers
volatile uint32_t *DWT_CONTROL = (uint32_t *)0xE0001000;
volatile uint32_t *DWT_CYCCNT = (uint32_t *)0xE0001004;
volatile uint32_t *DEMCR = (uint32_t *)0xE000EDFC;
for(int iter=0; iter<numIter; iter++){
// enable the use DWT
*DEMCR = *DEMCR | 0x01000000;
// Reset cycle counter
*DWT_CYCCNT = 0;
// enable cycle counter
*DWT_CONTROL = *DWT_CONTROL | 1;
/***************************************************/
/****** Code that used to measure execution time *****/
/*************************************************/
count = *DWT_CYCCNT;
milliseconds = ((float)count/actual_cycle_count)*1000;
printf("ElapsedTime:%f in iteration:%d (in ms)\n", milliseconds, iter);
totaltime = totaltime + milliseconds; // sum of milliseconds for numIter.
}
I'm able to run it properly without any issues in debug mode. Please let me know whether i'm doing correctly or not.
Thanks,
Hari
2020-08-17 08:20 AM
Looks okay. The other day I used
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
DWT->LAR = 0xC5ACCE55;
DWT->CYCCNT = 0;
DWT->CTRL |= DWT_CTRL_CYCCNTENA_Msk;
which are define in the CMSIS headers (#include "stm32f4xx.h")