Skip to main content
MNapi
Senior II
Jan 14, 2019 8:35 PM UTC
Question

who to implement HAL_GetTick()

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 ?

This topic has been closed for replies.

6 replies

S.Ma
Principal
Jan 14, 2019 9:10 PM UTC

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
MNapiAuthor
Senior II
Jan 14, 2019 10:07 PM UTC

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
Jan 14, 2019 10:17 PM UTC

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
Jan 14, 2019 10:35 PM UTC

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...

Tesla DeLorean
Guru
Jan 14, 2019 11:14 PM UTC

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 (See Profile) Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Jan 15, 2019 12:05 AM UTC

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