Skip to main content
JBous
Associate
October 20, 2021
Solved

Timer state getting locked in "HAL_TIM_STATE_BUSY" while working in "One pulse mode"

  • October 20, 2021
  • 2 replies
  • 3322 views

While developing my application I ran into the problem that the state of my timers working in "One pulse mode" (configured used STM32CubeMX with HAL libraries) where getting locked in the "HAL_TIM_STATE_BUSY" state after the "HAL_TIM_PeriodElapsedCallback" was executed. Trying to start the timer(s) again to generate a pulse once again didn't work anymore because the "HAL_TIM_Base_Start_IT" returns "HAL_ERROR". I was able to solve this by removing the check and setting of the state as shownin the screenshot in attachment. Is this a known issue and is there a better/correct way to solve this?

Thanks in advance.

This topic has been closed for replies.
Best answer by TDK

Seems like the state is set to busy during HAL_TIM_Base_Start_IT and never set to ready after that:

https://github.com/STMicroelectronics/STM32CubeF2/blob/3c583fca5efc36b1b4caadc527f33e89bc72846c/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c#L472

Setting the state to busy is a recent change to the library. Here's an old version which doesn't do the check:

https://github.com/STMicroelectronics/STM32CubeF2/blob/bd8d1f0427aa155e3a11621590fef59087e78af8/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c#L436

Instead of modifying the HAL source, perhaps just do this after the HAL_TIM_Base_Start_IT call:

htim->State = HAL_TIM_STATE_READY;

Or call HAL_TIM_Base_Stop_IT during the period elapsed callback, which will reset the state to ready:

https://github.com/STMicroelectronics/STM32CubeF2/blob/3c583fca5efc36b1b4caadc527f33e89bc72846c/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c#L512

2 replies

TDK
TDKBest answer
October 20, 2021

Seems like the state is set to busy during HAL_TIM_Base_Start_IT and never set to ready after that:

https://github.com/STMicroelectronics/STM32CubeF2/blob/3c583fca5efc36b1b4caadc527f33e89bc72846c/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c#L472

Setting the state to busy is a recent change to the library. Here's an old version which doesn't do the check:

https://github.com/STMicroelectronics/STM32CubeF2/blob/bd8d1f0427aa155e3a11621590fef59087e78af8/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c#L436

Instead of modifying the HAL source, perhaps just do this after the HAL_TIM_Base_Start_IT call:

htim->State = HAL_TIM_STATE_READY;

Or call HAL_TIM_Base_Stop_IT during the period elapsed callback, which will reset the state to ready:

https://github.com/STMicroelectronics/STM32CubeF2/blob/3c583fca5efc36b1b4caadc527f33e89bc72846c/Drivers/STM32F2xx_HAL_Driver/Src/stm32f2xx_hal_tim.c#L512

"If you feel a post has answered your question, please click ""Accept as Solution""."
JBous
JBousAuthor
Associate
October 20, 2021

Thank you for your reply and suggestions.