cancel
Showing results for 
Search instead for 
Did you mean: 

Troubles with HAL_GetTick() in the I2C_WaitOnFlagUntilTimeout functions on a STM32G473 MCU

TCarm.1
Associate

I am currently using the v1.6.1 of STM32CubeIDE and a STM32G473 MCU.

I have implemented an I2C bus and have noticed a major bug with the I2C_WaitOnFlagUntilTimeout functions. There is this condition:

if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))

which is supposed to guarantee that the program doesn't get stuck into the while loop above (while (__HAL_I2C_GET_FLAG(hi2c, Flag) == Status)), but the tick value stop incrementing as soon as the program enters the function for a reason I don't understand. I have tried to increase the preempt priority of System tick timer (by lowering the value) but it didn't change a thing.

Does anyone know how to fix that?

5 REPLIES 5
TDK
Guru

The only reason the ticks would stop increasing is if you're the same or higher priority interrupt, or if interrupts are disabled, or if SysTick is disabled.

If you feel a post has answered your question, please click "Accept as Solution".
TCarm.1
Associate

The thing is I don't even use the I2C bus in interrupt mode. I have no trouble when I don't call the HAL_I2C_Master_Transmit or HAL_I2C_Master_Receive functions, but as soon as I call them I got stuck into an infinite loop in I2C_WaitOnFlagUntilTimeout.

I have tried to low the priority interrupt, without effect, and I didn't disabled SysTick (the HAL_InitTick function returns HAL_OK)

Not sure. I see no reason why calling HAL_I2C_* function would cause the systick to stop functioning. Make sure you don't call it with HAL_MAX_DELAY if you want a timeout.
If you feel a post has answered your question, please click "Accept as Solution".
Eich
Associate III

Could you find a soulution?

I have exactly the same problem. Systick stops and I2C remains in an endless loop waiting that the timeout is reached. That will never happen because Systick is no longer updated.

SCrum.1
Associate III

I also have this exact same problem. STM32G0B0. Somewhere in the HAL_I2C_Master_Transmit function, the tick timer interrupt stops firing. In my case HAL_I2C_Master_Transmit returns an error because the I2C device does not acknowledge. So I try and do a short delay and try again, but its stuck in HAL_Delay as the tick value is no longer updating.