2022-04-21 01:31 AM
CPU hangs when calling I2C_WaitOnFlagUntilTimeout because I2C DMA interrupt handler has higher priority than system handle, so that tickcount cannot hit the Timeout. How can I resolve this trouble without consuming too much CPU ? I saw some topics about STM32 I2C bug they reject that make I2C interrupted by others, so I wonder to know is it really okay when I set I2C RxTx interrupt with lower priority than system handle? I has freertos in my project.
Solved! Go to Solution.
2022-04-21 06:20 AM
If you use HAL functions that make use of HAL_GetTick (such as HAL_I2C_* functions) from within an interrupt context, you need to ensure the system tick interrupt is a higher priority than the context from which you're calling.
Better yet, don't use blocking functions in interrupts. Set flags instead and handle them in a non-interrupt thread.
2022-04-21 05:29 AM
> system handle
What is that? Looks like some random "smart" words sticked together without meaning.
> because I2C DMA interrupt handler has higher priority than system handle, so that tickcount cannot hit the Timeout
So you know the problem, but... Just want to talk about it? Adjust the priorities as necessary!
2022-04-21 06:20 AM
If you use HAL functions that make use of HAL_GetTick (such as HAL_I2C_* functions) from within an interrupt context, you need to ensure the system tick interrupt is a higher priority than the context from which you're calling.
Better yet, don't use blocking functions in interrupts. Set flags instead and handle them in a non-interrupt thread.