cancel
Showing results for 
Search instead for 
Did you mean: 

How to disable HAL_TIM_PeriodElapsedCallback on a timer

RPG
Senior

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.

1 ACCEPTED SOLUTION

Accepted Solutions
Petr DAVID
ST Employee

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

View solution in original post

5 REPLIES 5
Petr DAVID
ST Employee

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
Senior

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
ST Employee

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
Senior

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

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