cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_Delay not affecting frequency of a Blinking Light

Splatt
Associate II

I am new to STM32, and I am using a STM32L152c discovery board to run a sample blinking light program. I am using HAL_Delay to control the frequency of the blinking light. However, the frequency does not change when I change the argument to HAL_Delay, or even if I remove HAL_Delay altogether. I would appreciate any assistance. I have included the main function and the HAL_Delay code that was provided in the project setup.

Also, where can I find code documentation? I was trying to find something to help explain HAL_Delay and other functions, but I could not find anything.

int main(void){
  HAL_Init();
  SystemClock_Config();
  MX_GPIO_Init();
  MX_ADC_Init();
  MX_LCD_Init();
  MX_TS_Init();
  while (1){
	  HAL_GPIO_TogglePin(LD3_GPIO_Port, LD3_Pin);
	  HAL_Delay(1000);
  }
}
//This function was sourced from the stm32l1xx_hal.c file generated at project start
__weak void HAL_Delay(uint32_t Delay){
  uint32_t tickstart = HAL_GetTick();
  uint32_t wait = Delay;
 
  /* Add a period to guaranty minimum wait */
  if (wait < HAL_MAX_DELAY)
  {
    wait += (uint32_t)(uwTickFreq);
  }
 
  while((HAL_GetTick() - tickstart) < wait)
  {
  }
}

11 REPLIES 11

Hi @Splatt​ ,

To generate code, you need to click on Project > Generate Code.

-Amel

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

Splatt
Associate II

None of the above methods have worked for some reason. I ended up trying to load the example blink program for the stm32l152c board, and it worked if I did it a very specific way:

  1. Create a new STM32 project for my board (Default ioc setup)
  2. Replace the Src and Inc folders with the folders from the example
  3. Occasionally, a file would need to be added that was not included. For instance, the stm32l152c_discovery.h and .c files were missing, so I got those from GitHub. Would this indicate an incorrect ioc setup?

This way works to load up sample projects, but it ultimately does not answer the question this discussion is about. A second question I would ask is: is there a better way to load a sample program into STM32cubeIDE? I tried converting from one of the included toolchains (SW4STM32), but this resulted in files missing.