Skip to main content
RPG
Associate III
June 10, 2022
Solved

How to disable HAL_TIM_PeriodElapsedCallback on a timer

  • June 10, 2022
  • 4 replies
  • 2943 views

Hi I would like to know if I can still get the interrupt updates of a timer but disable the call to the callback HAL_TIM_PeriodElapsedCallback.

This topic has been closed for replies.
Best answer by Petr DAVID

You can disable the update interrupt with resetting appropriate bit in DIER register of the timer. For TIM1 it would be something like:

htim1.Instance->DIER&=~(TIM_DIER_UIE);

There is no possibility to tell HAL not use call a callback function, but as I said earlier you can define your own callback function. Can you maybe further describe your use case? Maybe I am not understanding correctly.

Kind regards,

Petr

4 replies

Petr DAVID
ST Employee
June 14, 2022

Hello RPG,

from your question it is not clear to me what exactly you are trying to achieve. Do you want to call different function intstead of HAL_TIM_PeriodElapsedCallback function? Or do you want to only register different interrupts ie. capture or error interrupts? In stm32fxxx_it.c file you can delete the use of HAL_TIM_IRQHandler and handle the interrupt completely by yourself together with resetting flags. You can also register your own callback functions or you can just disable the update event interrupts. If these possibilities do not answer your question. Please let me know.

With the best regards,

Petr David

RPG
RPGAuthor
Associate III
June 14, 2022

Hi Petr.

I can see that HAL_TIM_PeriodElapsedCallback is called from HAL generated code when the HAL_TIM_IRQHandler is called. Just wanted to know I there is a way to prevent HAL to call that callback (not commenting the calling line of the code) by setting a flag or anything else.

Thanks for the help :)

Best regards,

Raúl Pérez

Petr DAVID
Petr DAVIDBest answer
ST Employee
June 14, 2022

You can disable the update interrupt with resetting appropriate bit in DIER register of the timer. For TIM1 it would be something like:

htim1.Instance->DIER&=~(TIM_DIER_UIE);

There is no possibility to tell HAL not use call a callback function, but as I said earlier you can define your own callback function. Can you maybe further describe your use case? Maybe I am not understanding correctly.

Kind regards,

Petr

RPG
RPGAuthor
Associate III
June 14, 2022

This will do the trick :) Thank you Petr for the help :)

Petr DAVID
ST Employee
June 15, 2022

Great I am glad that you found it useful. Good luck on your project.