cancel
Showing results for 
Search instead for 
Did you mean: 

HAL_Delay() not working.. help (newbie)

ckim
Associate II
Posted on December 04, 2015 at 01:51

Hi, 

I tried using HAL_Delay(); I thought I can just use HAL_Delay(500); but it's not working.

the code is below. (from STM32cubeF4)

__weak void HAL_Delay(__IO uint32_t Delay)

{

  uint32_t tickstart = 0;

  tickstart = HAL_GetTick();

  while((HAL_GetTick() - tickstart) < Delay)

  {

  }

}

I found the first time tickstart = HAL_GetTick() is performed, the tickstart has the value 0. The second time, HAL_GetTick() returns some big value so it stays endlessly in while statement.

Is there something I should do before using HAL_Delay()?

#hal_delay
3 REPLIES 3
Posted on December 04, 2015 at 02:32

I found the first time tickstart = HAL_GetTick() is performed, the tickstart has the value 0. The second time, HAL_GetTick() returns some big value so it stays endlessly in while statement.

 

Some big number minus zero is presumably bigger than 500? That would presumably exit the loop, so I'm confused.

SysTick, with it's handler, must be functional for HAL_Delay() to work.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on December 04, 2015 at 14:31

[DEAD LINK /public/STe2ecommunities/mcu/Lists/STM32Discovery/Flat.aspx?RootFolder=/public/STe2ecommunities/mcu/Lists/STM32Discovery/uwTick%20not%20incrementing.%20%28HAL_Delay%28%29%29&FolderCTID=0x01200200770978C69A1141439FE559EB459D75800084C20D8867EAD444A5987D47BE638E0F&TopicsView=https://my.st.com/public/STe2ecommunities/mcu/Lists/STM32Discovery/AllItems.aspx&currentviews=9]Duplicate thread

Isn't the SysTick enabled/configured in HAL_Init() or something? And with handler code?

/**
* @brief This function handles SysTick Handler.
* @param None
* @retval None
*/
void SysTick_Handler(void)
{
HAL_IncTick();
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
ckim
Associate II
Posted on December 04, 2015 at 15:38

clive1, thanks. I later found this problem and inserted in stm32fxx_it.c

void SysTick_Handler(void)

{

 /* USER CODE BEGIN SysTick_IRQn 0 */

  /* USER CODE END SysTick_IRQn 0 */

  HAL_IncTick();

  HAL_SYSTICK_IRQHandler();

  /* USER CODE BEGIN SysTick_IRQn 1 */

  /* USER CODE END SysTick_IRQn 1 */

}

so now HAL_Delay works. BTW, I don't why ST didn't include this in the handler in the example project in the first place..anyway I learned something through the problem.