I\'m new to using HAL functions. The description of the function HAL_GetTick()
says that it \"provides a tick value in millisecond
I had the same problem, but then found a library function in PlatformIO, which returns the microseconds.
uint32_t getCurrentMicros(void)
{
/* Ensure COUNTFLAG is reset by reading SysTick control and status register */
LL_SYSTICK_IsActiveCounterFlag();
uint32_t m = HAL_GetTick();
const uint32_t tms = SysTick->LOAD + 1;
__IO uint32_t u = tms - SysTick->VAL;
if (LL_SYSTICK_IsActiveCounterFlag()) {
m = HAL_GetTick();
u = tms - SysTick->VAL;
}
return (m * 1000 + (u * 1000) / tms);
}
It is located in ~/.platformio/packages/framework-arduinoststm32/libraries/SrcWrapper/src/stm32/clock.c
But it looks like STM32CubeIde doesn't have it, so I just copied it from PlatformIO. Also I had to copy the LL_SYSTICK_IsActiveCounterFlag() function:
static inline uint32_t LL_SYSTICK_IsActiveCounterFlag(void)
{
return ((SysTick->CTRL & SysTick_CTRL_COUNTFLAG_Msk) == (SysTick_CTRL_COUNTFLAG_Msk));
}