8. Interrupts and events

This Section applies to the whole STM32F20x and STM32F21x family, unless otherwise specified.

8.1 Nested vectored interrupt controller (NVIC)

8.1.1 NVIC features

The nested vector interrupt controller NVIC includes the following features:

The NVIC and the processor core interface are closely coupled, which enables low latency interrupt processing and efficient processing of late arriving interrupts.

All interrupts including the core exceptions are managed by the NVIC. For more information on exceptions and NVIC programming, refer to PM0056 programming manual.

8.1.2 SysTick calibration value register

The SysTick calibration value is fixed to 15000, which gives a reference time base of 1 ms with the SysTick clock set to 15 MHz (max HCLK/8).

8.1.3 Interrupt and exception vectors

Table 20 is the vector table for the STM32F20x and STM32F21x devices.

Table 20. Vector table

PositionPriorityType of priorityAcronymDescriptionAddress
---Reserved0x0000_0000
-3FixedResetReset0x0000_0004
-2FixedNMINon maskable interrupt. The RCC Clock Security System (CSS) is linked to the NMI vector.0x0000_0008
-1FixedHardFaultAll class of fault0x0000_000C
0SettableMemManageMemory management0x0000_0010

Table 20. Vector table (continued)

PositionPriorityType of priorityAcronymDescriptionAddress
1SettableBusFaultPre-fetch fault, memory access fault0x0000_0014
2SettableUsageFaultUndefined instruction or illegal state0x0000_0018
---Reserved0x0000_001C -
0x0000_002B
3SettableSVCallSystem service call via SWI instruction0x0000_002C
4SettableDebug MonitorDebug Monitor0x0000_0030
---Reserved0x0000_0034
5SettablePendSVPendable request for system service0x0000_0038
6SettableSysTickSystem tick timer0x0000_003C
07SettableWWDGWindow Watchdog interrupt0x0000_0040
18SettablePVDPVD through EXTI line detection interrupt0x0000_0044
29SettableTAMP_STAMPTamper and TimeStamp interrupts through the EXTI line0x0000_0048
310SettableRTC_WKUPRTC wake-up interrupt through the EXTI line0x0000_004C
411SettableFLASHFlash global interrupt0x0000_0050
512SettableRCCRCC global interrupt0x0000_0054
613SettableEXTI0EXTI Line0 interrupt0x0000_0058
714SettableEXTI1EXTI Line1 interrupt0x0000_005C
815SettableEXTI2EXTI Line2 interrupt0x0000_0060
916SettableEXTI3EXTI Line3 interrupt0x0000_0064
1017SettableEXTI4EXTI Line4 interrupt0x0000_0068
1118SettableDMA1_Stream0DMA1 Stream0 global interrupt0x0000_006C
1219SettableDMA1_Stream1DMA1 Stream1 global interrupt0x0000_0070
1320SettableDMA1_Stream2DMA1 Stream2 global interrupt0x0000_0074
1421SettableDMA1_Stream3DMA1 Stream3 global interrupt0x0000_0078
1522SettableDMA1_Stream4DMA1 Stream4 global interrupt0x0000_007C
1623SettableDMA1_Stream5DMA1 Stream5 global interrupt0x0000_0080
1724SettableDMA1_Stream6DMA1 Stream6 global interrupt0x0000_0084

Table 20. Vector table (continued)

PositionPriorityType of priorityAcronymDescriptionAddress
1825SettableADCADC1, ADC2 and ADC3 global interrupts0x0000_0088
1926SettableCAN1_TXCAN1 TX interrupts0x0000_008C
2027SettableCAN1_RX0CAN1 RX0 interrupts0x0000_0090
2128SettableCAN1_RX1CAN1 RX1 interrupt0x0000_0094
2229SettableCAN1_SCECAN1 SCE interrupt0x0000_0098
2330SettableEXTI9_5EXTI Line[9:5] interrupts0x0000_009C
2431SettableTIM1_BRK_TIM9TIM1 Break interrupt and TIM9 global interrupt0x0000_00A0
2532SettableTIM1_UP_TIM10TIM1 Update interrupt and TIM10 global interrupt0x0000_00A4
2633SettableTIM1_TRG_COM_TIM11TIM1 Trigger and Commutation interrupts and TIM11 global interrupt0x0000_00A8
2734SettableTIM1_CCTIM1 Capture Compare interrupt0x0000_00AC
2835SettableTIM2TIM2 global interrupt0x0000_00B0
2936SettableTIM3TIM3 global interrupt0x0000_00B4
3037SettableTIM4TIM4 global interrupt0x0000_00B8
3138SettableI2C1_EVI 2 C1 event interrupt0x0000_00BC
3239SettableI2C1_ERI 2 C1 error interrupt0x0000_00C0
3340SettableI2C2_EVI 2 C2 event interrupt0x0000_00C4
3441SettableI2C2_ERI 2 C2 error interrupt0x0000_00C8
3542SettableSPI1SPI1 global interrupt0x0000_00CC
3643SettableSPI2SPI2 global interrupt0x0000_00D0
3744SettableUSART1USART1 global interrupt0x0000_00D4
3845SettableUSART2USART2 global interrupt0x0000_00D8
3946SettableUSART3USART3 global interrupt0x0000_00DC
4047SettableEXTI15_10EXTI Line[15:10] interrupts0x0000_00E0
4148SettableRTC_AlarmRTC Alarms (A and B) through EXTI line interrupt0x0000_00E4
4249SettableOTG_FS_WKUPUSB On-The-Go FS wake-up through EXTI line interrupt0x0000_00E8
4350SettableTIM8_BRK_TIM12TIM8 Break interrupt and TIM12 global interrupt0x0000_00EC

Table 20. Vector table (continued)

PositionPriorityType of priorityAcronymDescriptionAddress
4451SettableTIM8_UP_TIM13TIM8 Update interrupt and TIM13 global interrupt0x0000_00F0
4552SettableTIM8_TRG_COM_TIM14TIM8 Trigger and Commutation interrupts and TIM14 global interrupt0x0000_00F4
4653SettableTIM8_CCTIM8 Capture Compare interrupt0x0000_00F8
4754SettableDMA1_Stream7DMA1 Stream7 global interrupt0x0000_00FC
4855SettableFSMCFSMC global interrupt0x0000_0100
4956SettableSDIOSDIO global interrupt0x0000_0104
5057SettableTIM5TIM5 global interrupt0x0000_0108
5158SettableSPI3SPI3 global interrupt0x0000_010C
5259SettableUART4UART4 global interrupt0x0000_0110
5360SettableUART5UART5 global interrupt0x0000_0114
5461SettableTIM6_DACTIM6 global interrupt, DAC1 and DAC2 underrun error interrupts0x0000_0118
5562SettableTIM7TIM7 global interrupt0x0000_011C
5663SettableDMA2_Stream0DMA2 Stream0 global interrupt0x0000_0120
5764SettableDMA2_Stream1DMA2 Stream1 global interrupt0x0000_0124
5865SettableDMA2_Stream2DMA2 Stream2 global interrupt0x0000_0128
5966SettableDMA2_Stream3DMA2 Stream3 global interrupt0x0000_012C
6067SettableDMA2_Stream4DMA2 Stream4 global interrupt0x0000_0130
6168SettableETHEthernet global interrupt0x0000_0134
6269SettableETH_WKUPEthernet wake-up through EXTI line interrupt0x0000_0138
6370SettableCAN2_TXCAN2 TX interrupts0x0000_013C
6471SettableCAN2_RX0CAN2 RX0 interrupts0x0000_0140
6572SettableCAN2_RX1CAN2 RX1 interrupt0x0000_0144
6673SettableCAN2_SCECAN2 SCE interrupt0x0000_0148
6774SettableOTG_FSUSB On The Go FS global interrupt0x0000_014C
6875SettableDMA2_Stream5DMA2 Stream5 global interrupt0x0000_0150
6976SettableDMA2_Stream6DMA2 Stream6 global interrupt0x0000_0154
7077SettableDMA2_Stream7DMA2 Stream7 global interrupt0x0000_0158

Table 20. Vector table (continued)

PositionPriorityType of priorityAcronymDescriptionAddress
7178SettableUSART6USART6 global interrupt0x0000_015C
7279SettableI2C3_EVI 2 C3 event interrupt0x0000_0160
7380SettableI2C3_ERI 2 C3 error interrupt0x0000_0164
7481SettableOTG_HS_EP1_OUTUSB On The Go HS End Point 1 Out global interrupt0x0000_0168
7582SettableOTG_HS_EP1_INUSB On The Go HS End Point 1 In global interrupt0x0000_016C
7683SettableOTG_HS_WKUPUSB On The Go HS wake-up through EXTI interrupt0x0000_0170
7784SettableOTG_HSUSB On The Go HS global interrupt0x0000_0174
7885SettableDCMIDCMI global interrupt0x0000_0178
7986SettableCRYPCRYP crypto global interrupt0x0000_017C
8087SettableHASH_RNGHash and Rng global interrupt0x0000_0180

8.2 External interrupt/event controller (EXTI)

The external interrupt/event controller consists of up to 23 edge detectors for generating event/interrupt requests. Each input line can be independently configured to select the type (interrupt or event) and the corresponding trigger event (rising or falling or both). Each line can also be masked independently. A pending register maintains the status line of the interrupt requests.

8.2.1 EXTI main features

The main features of the EXTI controller are the following:

8.2.2 EXTI block diagram

Figure 19 shows the block diagram.

Figure 19. External interrupt/event controller block diagram

Figure 19. External interrupt/event controller block diagram. The diagram shows the internal architecture of the EXTI controller. At the top, an AMBA APB bus is connected to a Peripheral interface. The Peripheral interface is also connected to PCLK2 and has five 23-bit wide interfaces to the following registers: Pending request register, Interrupt mask register, Software interrupt event Register, Rising trigger selection register, and Falling trigger selection register. The Pending request register is connected to the NVIC interrupt controller. The Interrupt mask register, Software interrupt event Register, Rising trigger selection register, and Falling trigger selection register are connected to an Edge detect circuit. The Edge detect circuit is connected to an Input line. The Software interrupt event Register is also connected to a Pulse generator. The Pulse generator is connected to an Event mask register. The Event mask register is connected to the Edge detect circuit. The Edge detect circuit is connected to the Pending request register. The diagram is labeled ai15896b.
Figure 19. External interrupt/event controller block diagram. The diagram shows the internal architecture of the EXTI controller. At the top, an AMBA APB bus is connected to a Peripheral interface. The Peripheral interface is also connected to PCLK2 and has five 23-bit wide interfaces to the following registers: Pending request register, Interrupt mask register, Software interrupt event Register, Rising trigger selection register, and Falling trigger selection register. The Pending request register is connected to the NVIC interrupt controller. The Interrupt mask register, Software interrupt event Register, Rising trigger selection register, and Falling trigger selection register are connected to an Edge detect circuit. The Edge detect circuit is connected to an Input line. The Software interrupt event Register is also connected to a Pulse generator. The Pulse generator is connected to an Event mask register. The Event mask register is connected to the Edge detect circuit. The Edge detect circuit is connected to the Pending request register. The diagram is labeled ai15896b.

8.2.3 Wake-up event management

The STM32F20x and STM32F21x are able to handle external or internal events in order to wake up the core (WFE). The wake-up event can be generated either by:

To use an external line as a wake-up event, refer to Section 8.2.4: Functional description .

8.2.4 Functional description

To generate the interrupt, the interrupt line should be configured and enabled. This is done by programming the two trigger registers with the desired edge detection and by enabling the interrupt request by writing a '1' to the corresponding bit in the interrupt mask register. When the selected edge occurs on the external interrupt line, an interrupt request is

generated. The pending bit corresponding to the interrupt line is also set. This request is reset by writing a '1' in the pending register.

To generate the event, the event line should be configured and enabled. This is done by programming the two trigger registers with the desired edge detection and by enabling the event request by writing a '1' to the corresponding bit in the event mask register. When the selected edge occurs on the event line, an event pulse is generated. The pending bit corresponding to the event line is not set.

An interrupt/event request can also be generated by software by writing a '1' in the software interrupt/event register.

Hardware interrupt selection

To configure the 23 lines as interrupt sources, use the following procedure:

Hardware event selection

To configure the 23 lines as event sources, use the following procedure:

Software interrupt/event selection

The 23 lines can be configured as software interrupt/event lines. The following is the procedure to generate a software interrupt.

8.2.5 External interrupt/event line mapping

The 140 GPIOs are connected to the 16 external interrupt/event lines in the following manner:

Figure 20. External interrupt/event GPIO mapping

Diagram showing the mapping of GPIOs to external interrupt lines. It includes three sections: EXTI0 (PA0-PI0), EXTI1 (PA1-PI1), and EXTI15 (PA15-PH15). Each section shows a list of GPIOs connected to a multiplexer, which is controlled by bits in the SYSCFG_EXTICR registers and outputs to the corresponding EXTI line.

The diagram illustrates the mapping of GPIOs to external interrupt lines. It is divided into three main sections, each representing a different interrupt line and its associated GPIOs.

There is a vertical ellipsis between the EXTI1 and EXTI15 sections, indicating that the same pattern repeats for the remaining interrupt lines. A small code "ai15897" is visible in the bottom right corner of the diagram area.

Diagram showing the mapping of GPIOs to external interrupt lines. It includes three sections: EXTI0 (PA0-PI0), EXTI1 (PA1-PI1), and EXTI15 (PA15-PH15). Each section shows a list of GPIOs connected to a multiplexer, which is controlled by bits in the SYSCFG_EXTICR registers and outputs to the corresponding EXTI line.

The seven other EXTI lines are connected as follows:

8.3 EXTI registers

Refer to Section 1.2 on page 46 for a list of abbreviations used in register descriptions.

The peripheral registers have to be accessed by words (32 bits).

8.3.1 Interrupt mask register (EXTI_IMR)

Address offset: 0x00

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedMR22MR21MR20MR19MR18MR17MR16
r/wr/wr/wr/wr/wr/wr/w
1514131211109876543210
MR15MR14MR13MR12MR11MR10MR9MR8MR7MR6MR5MR4MR3MR2MR1MR0
r/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/w

Bits 31:23 Reserved, must be kept at reset value (0).

Bits 22:0 MRx : Interrupt mask on line x

0: Interrupt request from line x is masked

1: Interrupt request from line x is not masked

8.3.2 Event mask register (EXTI_EMR)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedMR22MR21MR20MR19MR18MR17MR16
r/wr/wr/wr/wr/wr/wr/w
1514131211109876543210
MR15MR14MR13MR12MR11MR10MR9MR8MR7MR6MR5MR4MR3MR2MR1MR0
r/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/wr/w

Bits 31:23 Reserved, must be kept at reset value (0).

Bits 22:0 MRx : Event mask on line x

0: Event request from line x is masked

1: Event request from line x is not masked

8.3.3 Rising trigger selection register (EXTI_RTSR)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedTR22TR21TR20TR19TR18TR17TR16
rwrwrwrwrwrwrw
1514131211109876543210
TR15TR14TR13TR12TR11TR10TR9TR8TR7TR6TR5TR4TR3TR2TR1TR0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:23 Reserved, must be kept at reset value (0).

Bits 22:0 TRx : Rising trigger event configuration bit of line x

0: Rising trigger disabled (for Event and Interrupt) for input line

1: Rising trigger enabled (for Event and Interrupt) for input line

Note: The external wake-up lines are edge triggered, no glitch must be generated on these lines. If a rising edge occurs on the external interrupt line while writing to the EXTI_RTSR register, the pending bit is set.

Rising and falling edge triggers can be set for the same interrupt line. In this configuration, both generate a trigger condition.

8.3.4 Falling trigger selection register (EXTI_FTSR)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedTR22TR21TR20TR19TR18TR17TR16
rwrwrwrwrwrwrw
1514131211109876543210
TR15TR14TR13TR12TR11TR10TR9TR8TR7TR6TR5TR4TR3TR2TR1TR0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:23 Reserved, must be kept at reset value (0).

Bits 22:0 TRx : Falling trigger event configuration bit of line x

0: Falling trigger disabled (for Event and Interrupt) for input line

1: Falling trigger enabled (for Event and Interrupt) for input line.

Note: The external wake-up lines are edge triggered, no glitch must be generated on these lines. If a falling edge occurs on the external interrupt line while writing to the EXTI_FTSR register, the pending bit is not set.

Rising and falling edge triggers can be set for the same interrupt line. In this configuration, both generate a trigger condition.

8.3.5 Software interrupt event register (EXTI_SWIER)

Address offset: 0x10

Reset value: 0x0000 0000

31302928272625242322212019181716
ReservedSWIER
22
SWIER
21
SWIER
20
SWIER
19
SWIER
18
SWIER
17
SWIER
16
rwrwrwrwrwrwrw
1514131211109876543210
SWIER
15
SWIER
14
SWIER
13
SWIER
12
SWIER
11
SWIER
10
SWIER
9
SWIER
8
SWIER
7
SWIER
6
SWIER
5
SWIER
4
SWIER
3
SWIER
2
SWIER
1
SWIER
0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:23 Reserved, must be kept at reset value (0).

Bits 22:0 SWIERx : Software Interrupt on line x

Writing a 1 to this bit when it is at 0 sets the corresponding pending bit in EXTI_PR. If the interrupt is enabled on this line on the EXTI_IMR and EXTI_EMR, an interrupt request is generated.

This bit is cleared by clearing the corresponding bit in EXTI_PR (by writing a 1 to the bit).

8.3.6 Pending register (EXTI_PR)

Address offset: 0x14

Reset value: undefined

31302928272625242322212019181716
ReservedPR22PR21PR20PR19PR18PR17PR16
rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1
1514131211109876543210
PR15PR14PR13PR12PR11PR10PR9PR8PR7PR6PR5PR4PR3PR2PR1PR0
rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1

Bits 31:23 Reserved, must be kept at reset value (0).

Bits 22:0 PRx : Pending bit

0: No trigger request occurred

1: selected trigger request occurred

This bit is set when the selected edge event arrives on the external interrupt line. This bit is cleared by writing a 1 to the bit or by changing the sensitivity of the edge detector.

8.3.7 EXTI register map

Table 21 gives the EXTI register map and the reset values.

Table 21. External interrupt/event controller register map and reset values

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00EXTI_IMRReservedMR[22:0]
Reset value00000000000000000000000
0x04EXTI_EMRReservedMR[22:0]
Reset value00000000000000000000000
0x08EXTI_RTSRReservedTR[22:0]
Reset value00000000000000000000000
0x0CEXTI_FTSRReservedTR[22:0]
Reset value00000000000000000000000
0x10EXTI_SWIERReservedSWIER[22:0]
Reset value00000000000000000000000
0x14EXTI_PRReservedPR[22:0]
Reset value00000000000000000000000

Refer to Section 2.3 on page 51 for the register boundary addresses.