Skip to main content
Graduate
October 13, 2024
Question

transform the function HAL_GetTick() in a 64bit

  • October 13, 2024
  • 4 replies
  • 1579 views

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

 

    This topic has been closed for replies.

    4 replies

    Graduate II
    October 13, 2024

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

    Graduate II
    October 13, 2024

    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.

    Graduate II
    October 14, 2024

    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 ?

    Super User
    October 14, 2024

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

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

    JW

    Graduate II
    October 14, 2024

    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