cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_Delay() stopped working

DavidNaviaux
Senior

I have read most of the replies to posts that had the same problem that I am having with HAL_Delay() not working.  None of the solutions that I tried worked. 

It is apparent that the interrupt handler is never getting executed so any attempt to use HAL_Delay() just locks up the firmware.  In an earlier version of this firmware, I did not have any problems, but now I have not been able to restore operation.

Help!  (thanks in advance)

1 ACCEPTED SOLUTION

Accepted Solutions
TDK
Guru

Going to be hard to debug without seeing code, so we can only provide generic advice.

  • Ensure it's not being called in an interrupt context, from an interrupt with equal or higher priority.
  • Ensure interrupts are enabled in general (i.e. no __disable_irq())
  • Ensure SysTick interrupt is enabled. Typically done in HAL_RCC_ClockConfig from SystemClock_Config.
  • Ensure SysTick_Handler is defined and calls HAL_IncTick.
  • Ensure vector table is correctly defined and has the appropriate entry for SysTick_Handler.
If you feel a post has answered your question, please click "Accept as Solution".

View solution in original post

6 REPLIES 6
STTwo-32
ST Employee

Hello @DavidNaviaux 

HAL_Delay function depends on SysTick interrupt, so if you don't assign proper priorities to that, you may have a problem with the HAL_Delay.

Best Regards.

STTwo-32 

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Per the advice in one of the responses to others with this problem, I have added this line of code immediately following the execution of the SystemClock_Config() function in main.c, but it did not solve the problem.  

 

HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);

 

I then forced the vector table location to Flash with the line of code below the at the end of the SystemInit() function in the system_stm32g4xx.c file, again no success:

 

SCB->VTOR = FLASH_BASE | 0x00000000U;

 

I have written my own timing functions and they work fine. Unfortunately, it seems like HAL_Delay() is required by

many of the HAL_ functions and my code won't work unless that function is working.

 

TDK
Guru

Going to be hard to debug without seeing code, so we can only provide generic advice.

  • Ensure it's not being called in an interrupt context, from an interrupt with equal or higher priority.
  • Ensure interrupts are enabled in general (i.e. no __disable_irq())
  • Ensure SysTick interrupt is enabled. Typically done in HAL_RCC_ClockConfig from SystemClock_Config.
  • Ensure SysTick_Handler is defined and calls HAL_IncTick.
  • Ensure vector table is correctly defined and has the appropriate entry for SysTick_Handler.
If you feel a post has answered your question, please click "Accept as Solution".

Maybe a .ioc file would help diagnosis.

TDK,

The problem continued to plague me.  Sometimes it worked fine until I made a small change in the code that should not have done anything.  However, I did find a couple of misused pointers that may have been the root cause.  I have not had the problem with the SysTick for several days and I have done quite a bit of development work.

Thanks, David

Rob.Riggs
Senior II

I hit the same issue when upgrading from L4 HAL from 1.17.1 to 1.17.2.

Reverting stm32l4xx_hal_timebase_tim.c to the version from 1.17.1 fixed it for me.

Update: More in-depth debugging revealed that the root cause of the issues was that I was calling HAL_Delay() from a FreeRTOS thread, rather than calling osDelay(). This issue was hidden by previous releases.