Skip to main content
Visitor II
May 8, 2025
Question

Issues with interrupt priority handling

  • May 8, 2025
  • 1 reply
  • 485 views

Hello,

i have configured a timer interrupt an it seems like that interrupt preempt another adc interrupt. 

I configured the timer interrupt like that:

 NVIC_SetPriority(TIM1_BRK_IRQn, 2U);
 NVIC_SetPriority(TIM1_UP_IRQn, 2U);
 
and the adc interrupt like that:
 NVIC_SetPriority(ADC1_2_IRQn, 1U);
 
So my expectation would be that no preemption occurs from timer interrupt because priority is 2 (priority lower then ADC interrupt priority).
 
To check if the interrupt priority of timer interrupt is the root cause of preemption i set it to 8 and 9 and the adc interrupt with prio 1.
In this case the preemption from timer interrupt i measured has been gone. For my understanding it should make no difference setting the timer interrupt priority to 2, 8 or 9 because in all cases the priority is higher then adc interrupt with priority 1.
 
Additional hints:
Priogroup has been set to 0 for all implementations.
There is no other interrupt that might cause some trouble here
 
I attached some files that are showing the register configurations.
 
Best regards
Shaheen
 

 

    This topic has been closed for replies.

    1 reply

    Super User
    May 8, 2025

    > i have configured a timer interrupt an it seems like that interrupt preempt another adc interrupt. 

    Why does it seem like that?

     

    Expect some jitter in the interrupt with priority group 0. The default (group 4) allows higher priority interrupts to pre-empt lower priority ones.

     

    With priority group 0, no interrupt can pre-empt each other.

    /** @defgroup CORTEX_Preemption_Priority_Group CORTEX Preemption Priority Group
     * @{
     */
    #define NVIC_PRIORITYGROUP_0 ((uint32_t)0x00000007) /*!< 0 bits for pre-emption priority
     4 bits for subpriority */
    #define NVIC_PRIORITYGROUP_1 ((uint32_t)0x00000006) /*!< 1 bits for pre-emption priority
     3 bits for subpriority */
    #define NVIC_PRIORITYGROUP_2 ((uint32_t)0x00000005) /*!< 2 bits for pre-emption priority
     2 bits for subpriority */
    #define NVIC_PRIORITYGROUP_3 ((uint32_t)0x00000004) /*!< 3 bits for pre-emption priority
     1 bits for subpriority */
    #define NVIC_PRIORITYGROUP_4 ((uint32_t)0x00000003) /*!< 4 bits for pre-emption priority
     0 bits for subpriority */