Skip to main content
Visitor II
March 28, 2024
Question

HAL_Delay() not working on STM32F103ZET6 (LED Blinking Example)

  • March 28, 2024
  • 4 replies
  • 3167 views

I am using a stm32F103ZET6 to just blinking a led but the HAL_Delay() is not working.

I change the HAL_Delay() with for loop and it work.
this is the code that i am using :

while (1)

{

HAL_GPIO_WritePin(Led_301_GPIO_Port, Led_301_Pin, 1);

HAL_Delay(500);

//for (int i=0; i < 500000; i++);

HAL_GPIO_WritePin(Led_301_GPIO_Port, Led_301_Pin, 0);

//for (int i=0; i < 500000; i++);

}

}

I want to work with HAL_Delay because i need to use it in a project with this mcu

 

    This topic has been closed for replies.

    4 replies

    Technical Moderator
    March 28, 2024

    Hello,

    Did you configure the GPIO pin? The GPIO clock?

    Could you share your project?

    HelmishAuthor
    Visitor II
    March 28, 2024

    this is the project.

    Technical Moderator
    March 28, 2024

    In your attached project: you're toggling correctly the pin PA8:

    	 HAL_GPIO_WritePin(Led_301_GPIO_Port, Led_301_Pin, 1);
    	 HAL_Delay(500);
    	 //for (int i=0; i < 500000; i++);
    	 HAL_GPIO_WritePin(Led_301_GPIO_Port, Led_301_Pin, 0);
    	 //for (int i=0; i < 500000; i++);
    	 HAL_Delay(500);

    I don't see any issue in your project.

    What do you mean by "HAL_Delay() is not working"? what is the symptom?

     

    Graduate II
    March 28, 2024

    Need two delays otherwise it loops immediately and turns on/off too quickly to see

    Technical Moderator
    March 28, 2024

    Set a breakpoint in HAL_IncTick() in SysTick_Handler() interrupt handler:

    void SysTick_Handler(void)
    {
     /* USER CODE BEGIN SysTick_IRQn 0 */
    
     /* USER CODE END SysTick_IRQn 0 */
     HAL_IncTick();
     /* USER CODE BEGIN SysTick_IRQn 1 */
    
     /* USER CODE END SysTick_IRQn 1 */
    }

    Are you reaching it?

    HelmishAuthor
    Visitor II
    March 28, 2024

    I can't debug because I haven't any debug solution

    Technical Moderator
    March 28, 2024

    Seems you're executing the code from the SRAM (you didn't mentioned that important information) but it overlaps with r/w data and with VTOR. That's why the Systick interrupt (used by HAL_Delay) is not working

    You need to rethink/rework your project.

    HelmishAuthor
    Visitor II
    March 28, 2024

    Can you please explain this. What do you mean by rethink/rework 

    HelmishAuthor
    Visitor II
    March 28, 2024

    Also i have to add some information.

    I change the flash memory in the file .std from 512ko to 484ko and the start address from 0x8000000 to 0x8006000. Because in the project specification i have to do that.