Introduction to Interrupts & EXTI:

 Interrupt and NVIC for STM32F4xx family microcontroller:

 Interrupts are important for microcontrollers and processors. For example; someone calling you while you can playing game in phone, firstly you make a phone call then you can continue your game. In this case, the call will be priority. We say the interrupt to priority status. In case of interrupt, stop main program and jump to interrupt subprogram (executing this program) and subprogram is finished, it continues where it left off. (return main program)

  NVIC (Nested Vectored Interrupt Controller):

  • low-latency exception and interrupt handling
  • power management control
  • implementation of system control registers.

 The NVIC supports up to 240 interrupts each with up to 256 levels of priority. You can change the priority of an interrupt dynamically. STM32 has a higher-priority interrupts. STM32 uses 4 bits define priority level. misc.h library priority level definition shown below;


#define NVIC_PriorityGroup_0 /*!< 0 bits for pre-emption priority, 4 bits for subpriority */
#define NVIC_PriorityGroup_1 /*!< 1 bits for pre-emption priority, 3 bits for subpriority */
#define NVIC_PriorityGroup_2 /*!< 2 bits for pre-emption priority, 2 bits for subpriority */
#define NVIC_PriorityGroup_3 /*!< 3 bits for pre-emption priority, 1 bits for subpriority */
#define NVIC_PriorityGroup_4 /*!< 4 bits for pre-emption priority, 0 bits for subpriority */

 Pre-emption priority level ability of one interrupt to interrupt another interrupt. When you use USART- ADC interrupts, you can configure pre-emption priority level. The subpriority level value is used only when two same preempt priority occurred at the same time. When you use USART1- USART2 interrupts, you can configure subpriority priority level. For example you select priority group 1, you use 1 bit pre-emption priority, 3 bit subpriority.

EXTI

 Each STM32F4 device has 23 external interrupt or event sources that can be generate interrupt request upon edge detector. The EXTI controller block diagram shown below (from reference manual);

First time Keil uVision

 There are 23 external interupt lines and 16 external interrupt lines connected with GPIO pins. PA0,PB0,etc. connected the line 0 and PA15,PB15,etc. connected line 15. When we need to EXTI0, we can use either PA0,PB0,etc. We don’t use PB0 and PA0 simultaneously.

First time Keil uVision

 The seven other EXTI lines are connected as follows:

EXTI line 16 is connected to the PVD output
EXTI line 17 is connected to the RTC Alarm event
EXTI line 18 is connected to the USB OTG FS Wakeup event
EXTI line 19 is connected to the Ethernet Wakeup event
EXTI line 20 is connected to the USB OTG HS (configured in FS) Wakeup event
EXTI line 21 is connected to the RTC Tamper and TimeStamp events
EXTI line 22 is connected to the RTC Wakeup event.

 EXTI Code Example:

 I will use use PA0 for external interrupt in stm32f407 microcontroller.

When push the user button on stm32f4 discovery board LED4 (Green LED, connected to PD12) will toggle.

First time Keil uVision

 Library dependencies

  • STM32F4xx_StdPeriph_Driver
    • stm32f4xx.h
    • stm32f4xx_rcc
    • stm32f4xx_gpio
    • misc
    • stm32f4xx_syscfg
    • stm32f4xx_exti

THE END.

Useful link for good information about EXTI:

http://armprogramming.com/stm32f4-discovery-tutorials-interruptexti/

Sharif University of Technology, Tehran, Iran