cancel
Showing results for 
Search instead for 
Did you mean: 

transform the function HAL_GetTick() in a 64bit

JJoao.1
Associate III

Hello Everybody,

 

I would like transform the HAL_GetTick() function more than 49 days.

I don't find a NVIC overflow on this function to increment a second variable.

 

In my while I have do this with

 

 

uint32_t		Mem_GetTick;
uint64_t		Tick64;

 

 

 

while (1)
  {
       if (HAL_GetTick() != Mem_GetTick)
	{
		Mem_GetTick = HAL_GetTick();
		Tick64++;
	}
.
.
.
}

 

 

MAybe there is a more efficicent solution

 

Thank you to share your exeprience

 

5 REPLIES 5

>>Maybe there is a more efficient solution

In SysTick or via HAL_IncTick() ??

You really shouldn't have any timeouts / spin loops that wait for 49-50 days, perhaps address those parts of the code.

Try to use delta time measurements, and not wait of things like >= time-in-future or >= (start + delay-time)

 

Some STM32 have a 64-bit count in the ETH-PTP hardware

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

Why don't you use the RTC peripheral? It'll be more accurate than using Systick and incrementing a uint64_t variable. It could drift over time due to n amount of instruction cycles it take to increment the 64 bit value.

Tips and Tricks with TimerCallback https://www.youtube.com/@eebykarl
If you find my solution useful, please click the Accept as Solution so others see the solution.
LCE
Principal

What you are doing in the while loop will go wrong as soon as you do other stuff in there (that takes more than a millisecond).

Why not build a timer with a 1 ms interrupt, in its ISR you can count these 1 ms ticks with a uint64_t.

Or just hack the SysTick interrupt by incrementing an extra uint64_t variable. Or do you need "clean" HAL ?

> Or just hack the SysTick interrupt by incrementing an extra uint64_t variable.

...  and when using it, keep atomicity in mind.

JW

Hi,


@waclawek.jan wrote:

> Or just hack the SysTick interrupt by incrementing an extra uint64_t variable.

...  and when using it, keep atomicity in mind.

JW


If you are going to reference the uint64_t often, then, atomicity may become inconvenient. You could consider using a uint32_t variable inside the SysTick interrupt at different rate - like :-

     if ((uwTick % 10) == 0) myunit32++;    // every 10mS = 490 days'ish....

I hope this helps.

Kind regards
Pedro

AI = Artificial Intelligence, NI = No Intelligence, RI = Real Intelligence.