Skip to main content
Associate II
Mar 28, 2024 9:42 AM UTC
Question

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

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.

15 replies

mƎALLEm
ST Technical Moderator
Mar 28, 2024 10:08 AM UTC

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
Mar 28, 2024 11:40 AM UTC

this is the project.

mƎALLEm
ST Technical Moderator
Mar 28, 2024 12:04 PM UTC

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
Mar 28, 2024 10:15 AM UTC

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

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
mƎALLEm
ST Technical Moderator
Mar 28, 2024 12:06 PM UTC

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
Mar 28, 2024 12:33 PM UTC

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

mƎALLEm
ST Technical Moderator
Mar 28, 2024 5:25 PM UTC

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
Mar 28, 2024 11:32 PM UTC

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

HelmishAuthor
Associate II
Mar 28, 2024 11:38 PM UTC

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.