Skip to main content
Associate 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

 

4 replies

mƎALLEm
Technical Moderator
March 28, 2024

Hello,

Did you configure the GPIO pin? The GPIO clock?

Could you share your project?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
HelmishAuthor
Associate II
March 28, 2024

this is the project.

mƎALLEm
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?

 

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
Tesla DeLorean
Guru
March 28, 2024

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

Tips, Buy me a coffee, or three.. PayPal VenmoUp vote any posts that you find helpful, it shows what's working..
mƎALLEm
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?

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
HelmishAuthor
Associate II
March 28, 2024

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

mƎALLEm
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.

To give better visibility on the answered topics, please click "Best answer" on the reply which solved your issue or answered your question.
HelmishAuthor
Associate II
March 28, 2024

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

HelmishAuthor
Associate 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.