cancel
Showing results for 
Search instead for 
Did you mean: 

STM32 program issue with HAL Driver, running normally only in Debug mode!

Rozakos
Associate II

Hello everyone, i have a custom made board using a STM32L476RCT6, i am able to normally upload the bin files with the programmer etc, it's working properly, except for one thing, i can't use the HAL_drivers as the same way i use them with the Nucleo. For instance if i do

	  HAL_GPIO_WritePin(D1_GPIO_Port,D1_Pin,1);
	  HAL_Delay(1000);
	  HAL_GPIO_WritePin(D1_GPIO_Port,D1_Pin,0);

And run the MCU in debug mode, step by step, it will run just fine, but if i run it normally, it gets stuck on HIGH, never actually blinking.

But if i do:

	  HAL_GPIO_TogglePin(D1_GPIO_Port,D1_Pin);
	  HAL_Delay(1000);

It will work just fine. What is happening?

The code is generated by CubeMX, i will post a github link below:

https://github.com/Rozakos/STM32/blob/master/HELP

Any help is appreciated!

0693W000006F5zmQAC.jpg

1 REPLY 1
TDK
Guru

You need a delay after you reset the pin if you want to be able to see it blink.

while (1)
  {
    /* USER CODE END WHILE */
	  HAL_GPIO_WritePin(D1_GPIO_Port,D1_Pin,1);
	  HAL_Delay(1000);
	  HAL_GPIO_WritePin(D1_GPIO_Port,D1_Pin,0);
    /* USER CODE BEGIN 3 */
  }

Something like this:

while (1)
  {
    /* USER CODE END WHILE */
	  HAL_GPIO_WritePin(D1_GPIO_Port,D1_Pin,1);
	  HAL_Delay(1000);
	  HAL_GPIO_WritePin(D1_GPIO_Port,D1_Pin,0);
	  HAL_Delay(1000); // <--------
    /* USER CODE BEGIN 3 */
  }

Also note that your code is not within USER CODE begin/end comments so it will be erased on regeneration.

If you feel a post has answered your question, please click "Accept as Solution".