cancel
Showing results for 
Search instead for 
Did you mean: 

Hal delay stuck in infinite loop(newbie)

Antonio Mrzljak
Associate
Posted on September 10, 2017 at 00:59

I generated my code with cubemx, and when i call function HAL_Delay it somehow causes an infinite loop, 

anyone Know how to solve this problem?, using Keil IDE. thank you all

#cube-hal
1 REPLY 1
Ben K
Senior III
Posted on September 11, 2017 at 09:50

The problem is most probably that the HAL_Delay() is called from an ISR of the same (or higher) preemption priority as the SysTick interrupt. In this case the SysTick IRQ cannot preempt the current ISR, which would be essential to be able to update the global ms counter. The root cause might be that you insert a delay in a Callback, which are always called from an interrupt handler. It is generally not recommended to perform waiting inside of an ISR, but then again the HAL library does it (see e.g. SPI), so...

I have previously proposed a better, polling mode implementation of HAL_Delay() in 

https://community.st.com/0D50X00009XkW2MSAV

, if you place this function without the __weak attribute in your code (the current HAL prototype is 'void HAL_Delay(__IO uint32_t Delay)', so make sure you define it like this), the compiler should use this version instead of the original, and you shouldn't run into this problem again.