Skip to main content
MMust.5
Senior
August 2, 2023
Solved

HAL_Delay is stuck in the main function.

If I write HAL_Delay in the main function, then code execution gets stuck at this place.

int main
{
HAL_Delay(1);
}

Code execution does not exit the loop at this point.

while((HAL_GetTick() - tickstart) < wait)

I think because the SysTick_Handler interrupt is not executed and therefore uwTick is not incremented.
I set the SysTick timer to high priority, but nothing changed.

Why is SysTick_Handler not being executed?
SysTick_Handler should execute every 1 millisecond and increment the uwTick variable.

HAL_Delay in the while loop works correctly, HAL_Delay does not work in the main function.

pr.png

 

This topic has been closed for replies.
Mike_ST
Mike_STBest answer
ST Technical Moderator
August 2, 2023

Hello,

you should probably call:

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

before the call to HAL_Delay()

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 

2 replies

Mike_ST
Mike_STBest answer
ST Technical Moderator
August 2, 2023

Hello,

you should probably call:

/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
HAL_Init();

before the call to HAL_Delay()

In order to give better visibility on the answered topics, please click on 'Best answer' on the reply which solved your issue or answered your question. 
MMust.5
MMust.5Author
Senior
August 2, 2023

Thanks.

:rolling_on_the_floor_laughing: I need to get some good sleep.