Keil Logo

Nested Vectored Interrupt Controller

The Nested Vectored Interrupt Controller (NVIC) offers very fast interrupt handling and provides the vector table as a set of real vectors (addresses).

In addition, the NVIC:

  • Saves and restores automatically a set of the CPU registers (R0-R3, R12, PC, PSR, and LR).
  • Does a quick entry to the next pending interrupt without a complete pop/push sequence.
  • Serves a complete set of 255 (240 external) interrupts.

Interrupt Numbers

In CMSIS, interrupts are enumerated from negative to positive numbers:

  • Core interrupt numbers rank from [-15 .. -1].
  • External interrupts rank from [0 .. n].

Example of an Interrupt Table for an STM32:

typedef enum IRQn
/****** Cortex -M3 Processor Exceptions Numbers ***********************************************/
   NonMaskableInt_IRQn      = -14,  // 2 Non Maskable Interrupt
   MemoryManagement_IRQn    = -12,  // 4 Memory Management Interrupt
   BusFault_IRQn            = -11,  // 5 Bus Fault Interrupt
   UsageFault_IRQn          = -10,  // 6 Usage Fault Interrupt
   SVCall_IRQn              = -5,   // 11 SV Call Interrupt
   DebugMonitor_IRQn        = -4,   // 12 Debug Monitor Interrupt
   PendSV_IRQn              = -2,   // 14 Pend SV Interrupt
   SysTick_IRQn             = -1,   // 15 System Tick Interrupt

/****** STM32 specific Interrupt Numbers *****************************************************/
   WWDG_IRQn                = 0,    // 16 Window WatchDog Interrupt
   PVD_IRQn                 = 1,    // 17 PVD through EXTI Line detection Interrupt
   TAMPER_IRQn              = 2,    // 18 Tamper Interrupt
   TIM1_UP_IRQn             = 25,   // n Timer1 Update Interrupt
} IRQn_Type ;

NVIC functions

The CMSIS core module core_cm3.h provides a set of inlined functions and helper functions.

  Function definition Description
void NVIC_SystemReset (void) Resets the whole system including peripherals.
void NVIC_SetPriorityGrouping (uint32_t priority_grouping) Sets the priority grouping.
uint32_t NVIC_GetPriorityGrouping (void) Returns the value of the current priority grouping.
void NVIC_EnableIRQ(IRQn_Type IRQn) Enables the interrupt IRQn.
void NVIC_DisableIRQ (IRQn_Type IRQn) Disables the interrupt IRQn.
void NVIC_SetPriority (IRQn_Type IRQn, int32_t priority) Sets the priority for the interrupt IRQn.
uint32_t NVIC_GetPriority (IRQn_Type IRQn) Returns the priority for the specified interrupt.
void NVIC_SetPendingIRQ (IRQn_Type IRQn) Sets the interrupt IRQn pending.
IRQn_Type NVIC_GetPendingIRQ (IRQn_Type IRQn) Returns the pending status of the interrupt IRQn.
void NVIC_ClearPendingIRQ (IRQn_Type IRQn) Clears the pending status of the interrupt IRQn, if it is not already running or active.
IRQn_Type NVIC_GetActive (IRQn_Type IRQn) Returns the active status for the interrupt IRQn.

Example of using NVIC functions:

NVIC_SetPriorityGrouping (3);       // sets PRIGROUP 4.4 (or 4.0 on STM32 )
NVIC_SetPriority (2);               // sets priority value 2 to the IRQ
NVIC_EnableIRQ (TIM1_UP_IRQn);      // enables Timer 1 UP IRQ

void TIM1_UP_IRQn (void)  {


  • NVIC functions work only in Privileged Mode, which is the default mode for Cortex-M microcontroller.
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.