Appropriate way to disable interrupts during runtime / while the application is running?

1.1k Views Asked by At

I see there are two ways of disabling a specific ISR using the STM32 HAL.

To use the Timer Input Capture ISRs as an example, there is HAL_TIM_IC_Start_IT() and HAL_TIM_IC_Stop(), but there is also HAL_NVIC_DisableIRQ(TIMx_IRQn) and HAL_NVIC_EnableIRQ(TIMx_IRQn).

I am tempted to use HAL_TIM API because these allow me to disable certain channels of a timer (ie. TIM_CHANNEL_1, TIM_CHANNEL_2, TIM_CHANNEL_3, etc.), where as using the HAL_NVIC API would disable all interrupts associated with TIMx.

Which API would be the most ideal to use when enabling/disabling interrupts on the fly / while the application is running?

1

There are 1 best solutions below

0
Tom V On

It totally depends what you want to do:

If you disable the interrupt at the NVIC the flags still get set and maybe you want them to be set because you are going to poll for them. Also maybe you would do this because you don't want to deconfigure the peripheral.

Alternatively if you want to stop watching one channel but not others then you need to do this at the channel level.