cancel
Showing results for 
Search instead for 
Did you mean: 

who to implement HAL_GetTick()

MNapi
Senior II

I am trying to find time it takes for a loop, am I missing something ?

uint32_t time1 = HAL_GetTick();

...

unit32_t time= HAL_GetTick( ) - time1;

I am using Keil when I add time to watch list I am getting response cannot evaluate.

It does not show anything

Any help with the code, am i missing something, do I need to declare, initialize something first ?

6 REPLIES 6
S.Ma
Principal

to avoid compiler to remove code, declare time1 and time as volatile uint32_t

If the result of the calculation is not used, the compiler will remove the code...

MNapi
Senior II

I am not sure if I got your answer right but I did this

 time = HAL_GetTick();

    for (int i=0; i<100000000; i++)

      { i2cData[0]=0;

      }

      time1 = HAL_GetTick();

      time2 = time1 - time;

and it seams to be working I get time2 = 2778 (in watch in Keil)

my board is 180 Mhz. Any idea ho to translate it into microseconds or milliseconds ?

Daniel Glasser
Associate III

If I understand what you're asking, the HAL_GetTick() function returns a counter that is incremented by the SysTick, which in a default CubeMX project is 1000Hz, (each tick is 1ms).

S.Ma
Principal

volatile uint32_t time_ms, time1_ms, time2_ms; // to be sure

If you put in the variable name the unit and scale (if present), the answer is obvious...

SysTick_Handler() normally calls HAL_IncTick() to advance the count, but requires that the SysTick has higher priority than interrupt/callbacks that might have reliance on it actually advancing.

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

It looks like the old Keil bug. The debugger does not like non-local variables, even declared volatile.

So I have to note the variable's addresses and later use memory views.

Complained several times... but they treat debugger enhancement requests like ST treats Cube bugs here.

-- pa