Skip to main content
Rob Keck
Associate
February 2, 2017
Solved

HAL_Delay() causes infinite loop in some cases

  • February 2, 2017
  • 9 replies
  • 3610 views
Posted on February 02, 2017 at 15:44

Hey there, I am relatively new to STM32 Development (coming from an AVR Background).

I am currently working on a LoRaWAN sample project using the STM32L053 Discovery board and the SX1272 Modem with IBM LMiC Library. According to the Docs i have implemented all needed functions.

So there is this function i have to implement: void hal_waitUntil(uint32_t time).

So i just call HAL_Delay(time) inside the function. But if I run the code on the controller the delay never exits.

Getting the Systick Value with GDB or PRINTF shows, that the systick isn't increasing anymore after entering the delay. But if I call HAL_Delay() somewhere in the main.c it works without problems (so the systick must work).

I attached my eclipse project. 

In the src folder there are main.c, hardware.c (where i init the peripherals) and hal.c (where the LMiC functions are declared).

Would be awesome if someone could help me I'm hangin' there for days...

#systick #hal_delay #stm32
This topic has been closed for replies.
Best answer by David SIORPAES
Posted on February 02, 2017 at 16:01

I had a rapid look to the code and it seems that in radio_init() you are disabling all interrupts (including Systick) so the Systick counter stops. Afterwards, you call hal_waitUntil() which never exists as time has stopped.

9 replies

David SIORPAES
David SIORPAESBest answer
ST Employee
February 2, 2017
Posted on February 02, 2017 at 16:01

I had a rapid look to the code and it seems that in radio_init() you are disabling all interrupts (including Systick) so the Systick counter stops. Afterwards, you call hal_waitUntil() which never exists as time has stopped.

Rob Keck
Rob KeckAuthor
Associate
February 2, 2017
Posted on February 02, 2017 at 16:14

Well, yeah, thats it... 

Thanks a lot man! U You saved my day.

RDois
Associate
August 22, 2018

Hi,

I'm having the same problem.

There is no code included in the post. Could anyone tell me where these interrupts are being disabled / how to enable them?

Thanks in advance.

Tesla DeLorean
Guru
August 22, 2018

Check TICK_INT_PRIORITY in stm32fxyz_hal_conf.h

This needs to be a low number so the tick will keep ticking even when you are inside another interrupt (callbacK).

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
RDois
Associate
August 22, 2018

@Community member​ 

I have it set to (uint32_t)0U

Tesla DeLorean
Guru
August 22, 2018

Levels for other interrupts would need to be higher so the SysTick can preempt them so the tick increments, and HAL_Delay() functions.

You should avoid using HAL_Delay() in interrupt, and by inference callback, functions.

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
Ben K
Senior III
August 22, 2018

There is a straightforward way to use the SysTick timer in polling mode for delay, which works even if interrupts are disabled (as long as SysTick is still running), see in this post:

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