cancel
Showing results for 
Search instead for 
Did you mean: 

priority interrupt

SDall
Associate II

hi I am handling two different interrupts:

- tim3 interrupt

- gpio external interrupt

now I want gpio external interrupt to have a higher priority than tim3 and that can also interrupt tim3 ....

How can set i?

 HAL_NVIC_SetPriority (EXTI15_10_IRQn, 0, 0);

 HAL_NVIC_SetPriority(TIM3_IRQn, 0, 0);...…

6 REPLIES 6

TIM3_IRQn will need larger priority/preemption settings.

I think Joseph Yiu's books have a chapter on the NVIC, group settings and tail-chaining, you should read that, and similar texts on the topic.

Unless EXTI15_10_IRQn preempts TIM3_IRQn an active TIM3 IRQ will not yield, and will run to completion.

What part? Cortex-M0 has different behaviour to CM3/CM4

System Handlers also behave slightly differently.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SDall
Associate II

no I have an m4 and I need that if the tim3 is running it is interrupted by an external interrupt given by reading an encoder and not the other way around!

Yeah, you want the EXTI15_10 to preempt the TIM3

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..

NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_2); // 4 preemption levels, 4 sub-priority level

HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); // Will preempt TIM3

HAL_NVIC_SetPriority(TIM3_IRQn, 1, 1);

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
SDall
Associate II

Could be​

HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0); // Will preempt TIM3

HAL_NVIC_SetPriority(TIM3_IRQn, 0, 1);?​

No. That will set the "sub-prority" of TIM3 to lower than EXTI15, but the "priority" will be the same. The sub-priority only counts if both interrupts happen at the same time. If the TIM3 interrupt is already being serviced when the ESTI15 interrupt occurs, the EXTI15 interrupt will not be able to pre-empt the TIM3 interrupt and will wait until the TIM3 interrupt is done. You need to set the TIM3 priority (2nd param) to 1 (or higher). For this example, the sub-priority (3rd param) doesn't matter and, without my morning coffee, I think zero or one would work just as well.

And don't forget the NVIC_SetPriorityGrouping() call. None of it will work without that.