Skip to main content
Associate
February 12, 2026
Question

HAL_Delay() stops entire coding

  • February 12, 2026
  • 4 replies
  • 177 views

Im trying to use the HAL_Delay function but it seems like to code does not get passed this function. I have no clue what to even check to figure out what the problem is. I have attached the main fail to this post.

4 replies

Associate II
February 12, 2026

I can't even see the HAL_Delay() you call ...

mƎALLEm
Technical Moderator
February 12, 2026

Hello,

No call to HAL_Delay() in the files you shared.

Could you please double check?

Also you need to tell at which line/file in your code HAL_Delay() is not working as expected.

"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."
HastissssAuthor
Associate
February 12, 2026

Murged threads for the same question.

Im try to use HAL_Delay() to delay my code but it kept getting stuck in HAL_Delay(). I stepped through the code and realized that HAL_GetTickI() kept returning 0. I am using an STM32CubeIDE to program an nucleo F411RE. 

The HAL_Delay() is on line 123 in main.c. 

HAL_GetTick() is defined on line 323 in stm32f4xx_hal.c.

HAL_Delay() is defined on line 390 in stm32f4xx_hal.c.

HastissssAuthor
Associate
February 12, 2026

As I was posting this I accidentally changed line 323 but it used to be this:
__weak void HAL_Delay(uint32_t Delay)

it won't run without this correction but the issue mentioned above still remains even with this correction.

mƎALLEm
Technical Moderator
February 12, 2026

Ok let's proceed step by step.

What if you comment out this code?:

 MX_GPIO_Init();
 MX_USART2_UART_Init();
 MX_TIM1_Init();
 MX_TIM2_Init();
 MX_TIM4_Init();
 /* USER CODE BEGIN 2 */
 	HAL_TIM_Encoder_Start(&htim1, TIM_CHANNEL_ALL);
 HAL_TIM_Encoder_Start(&htim2, TIM_CHANNEL_ALL);
 HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_1);
 HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_2);
 HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_3);
 HAL_TIM_PWM_Start(&htim4, TIM_CHANNEL_4);

Do you reach  turn(1);?

 

 

 

"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."
Associate II
February 12, 2026

Maybe in CubeMX "Pinout & Configuration -> SYS -> Timebase Source" is connected to a timer which is not started?