Skip to main content
retro
Associate III
March 19, 2020
Solved

HAL_delay not working?

  • March 19, 2020
  • 7 replies
  • 2381 views

SOS

I have tried the other forum suggestions but nothing seems to work so far for me. Basically I am just trying to turn an LED on/off with a set delay:

 while (1)

 {

   /* USER CODE END WHILE */

    HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, 0);

    HAL_Delay(1000);

    HAL_GPIO_WritePin(LED1_GPIO_Port, LED1_Pin, 1);

    /* USER CODE BEGIN 3 */

 }

It just hangs at HAL_Delay(1000). I am using a STM32L496G-DISCO board.

    This topic has been closed for replies.
    Best answer by KnarfB

    What happens if you step into HAL_Delay ?

    What does 'hanging' exactly mean?

    Btw: You need another delay to see the LED blinking, because its now 1000ms on + 0ms off.

    7 replies

    Vivek yadav1
    Associate III
    March 19, 2020

    Hi @retro​ 

    Check your RCC clock config.

    retro
    retroAuthor
    Associate III
    March 19, 2020

    is that in the .ioc - clock configuration? I cannot see anything about RCC

    Vivek yadav1
    Associate III
    March 19, 2020

    @retro​ 

    Are you using CubeMx for auto code generation ?

    Which board are you using ?

    Did you config GPIO port Pin as output ?

    /*********************************

    I Set GPIOC pin 0 as output.

    while(1)

    {

      HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_RESET);

        HAL_Delay(1000);

       HAL_GPIO_WritePin(GPIOC, GPIO_PIN_0, GPIO_PIN_SET);

     HAL_Delay(1000);

    }

    /*********************************

    Still facing issue let me know.

    KnarfB
    KnarfBBest answer
    Super User
    March 19, 2020

    What happens if you step into HAL_Delay ?

    What does 'hanging' exactly mean?

    Btw: You need another delay to see the LED blinking, because its now 1000ms on + 0ms off.

    retro
    retroAuthor
    Associate III
    March 19, 2020

    Yes this was the problem - I am actually smart I swear