Skip to main content
Geraldo Pereira
Associate III
December 29, 2021
Question

How get timer state?

  • December 29, 2021
  • 4 replies
  • 2923 views

Hi,

I´m reading the doc of my kits, stm32f767zi and stm32f429zi, but if anyone could help I´ll appreciate. I need start and stop a timer named htim3, as follow:

if (HAL_OK!=HAL_TIM_Base_Start_IT(&htim3))

Error_Handler();

But, if I execute the code twice, I get an error. How can I check if timer was started, before start and stop again? Are there an example code?

I know there´s a register with the information, but I don´t know how use it.

Thanks,

Geraldo.

This topic has been closed for replies.

4 replies

TDK
December 29, 2021

The HAL way is to look at the value of htim3.State.

if (htim->State != HAL_TIM_STATE_READY) {
 // timer is not initialized, or already started
}

https://github.com/STMicroelectronics/STM32CubeF4/blob/4aba24d78fef03d797a82b258f37dbc84728bbb5/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.c#L466

"If you feel a post has answered your question, please click ""Accept as Solution""."
Geraldo Pereira
Associate III
December 29, 2021

Thanks TDK.

I´ve just tested and updated my project.

Best regards,

Piranha
Principal III
December 29, 2021

Actually the HAL way is to use HAL_TIM_Base_GetState() function or one of it's countless useless duplicates.

Geraldo Pereira
Associate III
December 29, 2021

Ok thanks Piranha.