cancel
Showing results for 
Search instead for 
Did you mean: 

How get timer state?

Geraldo Pereira
Associate II

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.

4 REPLIES 4
TDK
Guru

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 II

Thanks TDK.

I´ve just tested and updated my project.

Best regards,

Piranha
Chief II

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

Geraldo Pereira
Associate II

Ok thanks Piranha.