cancel
Showing results for 
Search instead for 
Did you mean: 

How to create measure the execution time of a function with a timer?

flor.5506
Associate II

Hello,

I am using the STM32F767ZI board and I want to measure the execution time of a function. The function I want to measure is a function I created.

At the moment, I use the timer 9 configured in internal clock (216 MHz) with:

Prescaler = 108

Counter Mode = Up

Counter Period = 59

In my program, to measure the execution time of the function, I use HAL_TIM_Base_Start_IT, HAL_TIM_Base_Stop_IT and HAL_TIM_PeriodElapsedCallback.

HAL_TIM_PeriodElapsedCallback is redefined in the main.c file and increments a variable that allows me to know the number of times the timer has interrupted.

void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef *htim){

                      if(htim->Instance == htim9.Instance){

                                 FinChrono = FinChrono+1;

                      }

}

I was told that it was possible to measure the execution time without using interrupt with the timers but I can’t understand how.

Can you help me ?

11 REPLIES 11

>>which agrees with your methodology

Well a lot of the stuff I've posted here for the last decade+ gets regurgitated over at StackOverflow, and in assorted projects on GitHub, etc, it is a circular universe.

The LAR is present in several of the IP blocks, and across multiple Cortex devices.

Explicitly defining the addresses is often necessary for linker scripts or other uses cases where #including things isn't an option, and things need to be free-standing/self-contained. It also saves a lot of headaches having to explain how to use a compiler and select the right include paths.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

I try to always credit original sources in my postings. Most people don't. Apologies if the S.O. link used your knowledge without attribution and if I seemed to imply otherwise.

In general I'm not a fan of "magic numbers" (raw hex addresses and bitmasks), but yes, in small example snippets they're appropriate and illustrate the information unambigously. I use GNU `ld`which supports symbolic constants and offset arithmetic so that's what my linker scripts look like, but it's a matter of taste.

I always expect ST/ARM/whoever to fully document their hardware -- memory, peripheral, and bitfield layouts -- both in reference/programming manuals and as named addresses/offsets/structs/constants in .h include files. I'm often disappointed on all counts.