11. Interrupts and events

11.1 Nested vectored interrupt controller (NVIC)

11.1.1 NVIC main 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 the PM0215 programming manual.

For code example refer to the Appendix section A.6.1: NVIC initialization .

11.1.2 SysTick calibration value register

The SysTick calibration value is set to 6000, which gives a reference time base of 1 ms with the SysTick clock set to 6 MHz (max \( f_{HCLK} / 8 \) ).

11.1.3 Interrupt and exception vectors

Table 31 is the vector table for STM32F0x0 devices. Consider peripheral availability on your device.

Table 31. 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 classes of fault0x0000 000C
-3SettableSVCallSystem service call via SWI instruction0x0000 002C
-5SettablePendSVPendable request for system service0x0000 0038
-6SettableSysTickSystem tick timer0x0000 003C
07SettableWWDGWindow watchdog interrupt0x0000 0040
1--Reserved-0x0000 0044
29SettableRTCRTC interrupts (combined EXTI lines 17, 19 and 20)0x0000 0048

Table 31. Vector table (continued)

PositionPriorityType of priorityAcronymDescriptionAddress
310SettableFLASHFlash global interrupt0x0000 004C
411SettableRCCRCC global interrupts0x0000 0050
512SettableEXTI0_1EXTI Line[1:0] interrupts0x0000 0054
613SettableEXTI2_3EXTI Line[3:2] interrupts0x0000 0058
714SettableEXTI4_15EXTI Line[15:4] interrupts0x0000 005C
8--Reserved-0x0000 0060
916SettableDMA_CH1DMA channel 1 interrupt0x0000 0064
1017SettableDMA_CH2_3DMA channel 2 and 3 interrupts0x0000 0068
1118SettableDMA_CH4_5DMA channel 4 and 5 interrupts0x0000 006C
1219SettableADCADC interrupts0x0000 0070
1320SettableTIM1_BRK_UP_
TRG_COM
TIM1 break, update, trigger and commutation interrupt0x0000 0074
1421SettableTIM1_CCTIM1 capture compare interrupt0x0000 0078
15--Reserved-0x0000 007C
1623SettableTIM3TIM3 global interrupt0x0000 0080
1724SettableTIM6TIM6 global interrupt0x0000 0084
18--Reserved-0x0000 0088
1926SettableTIM14TIM14 global interrupt0x0000 008C
2027SettableTIM15TIM15 global interrupt0x0000 0090
2128SettableTIM16TIM16 global interrupt0x0000 0094
2229SettableTIM17TIM17 global interrupt0x0000 0098
2330SettableI2C1I 2 C1 global interrupt0x0000 009C
2431SettableI2C2I 2 C2 global interrupt0x0000 00A0
2532SettableSPI1SPI1 global interrupt0x0000 00A4
2633SettableSPI2SPI2 global interrupt0x0000 00A8
2734SettableUSART1USART1 global interrupt0x0000 00AC
2835SettableUSART2USART2 global interrupt0x0000 00B0
2936SettableUSART3_4_5_6USART3, USART4, USART5, USART6 global interrupts0x0000 00B4
30--Reserved-0x0000 00B8
3138SettableUSBUSB global interrupt (combined with EXTI line 18)0x0000 00BC

11.2 Extended interrupts and events controller (EXTI)

The extended interrupts and events controller (EXTI) manages the external and internal asynchronous events/interrupts and generates the event request to the CPU/Interrupt controller and a wake-up request to the Power manager.

The EXTI allows the management of up to 28 external/internal event line (21 external event lines and 7 internal event lines).

The active edge of each external interrupt line can be chosen independently, whilst for internal interrupt the active edge is always the rising one. An interrupt could be left pending: in case of an external one, a status register is instantiated and indicates the source of the interrupt; an event is always a simple pulse and it's used for triggering the core Wake-up (e.g. Cortex-M0 RXEV pin). For internal interrupts, the pending status is assured by the generating IP, so no need for a specific flag. Each input line can be masked independently for interrupt or event generation, in addition the internal lines are sampled only in STOP mode. This controller allows also to emulate the (only) external events by software, multiplexed with the corresponding hardware event line, by writing to a dedicated register.

11.2.1 Main features

The EXTI main features are the following:

11.2.2 Block diagram

The extended interrupt/event block diagram is shown in Figure 21 .

Block diagram of the Extended Interrupts and Events Controller (EXTI). The diagram shows the internal architecture of the EXTI peripheral. At the top, an APB bus connects to a Peripheral interface block, which is also connected to a PCLK input. Below the interface, there are six registers: Falling trigger selection register, Rising trigger selection register, Software interrupt event register, Event mask register, Interrupt mask register, and Pending request register. External events enter an Edge detect circuit. Internal events pass through a Stop mode AND gate and then a Rising edge detect circuit. The outputs of the Edge detect circuit and the Rising edge detect circuit are combined with signals from the registers through a series of AND and OR gates to generate Interrupts, Events, and Wakeup signals. The identifier MS19952V3 is in the bottom right corner.

Figure 21. Extended interrupts and events controller (EXTI) block diagram

Block diagram of the Extended Interrupts and Events Controller (EXTI). The diagram shows the internal architecture of the EXTI peripheral. At the top, an APB bus connects to a Peripheral interface block, which is also connected to a PCLK input. Below the interface, there are six registers: Falling trigger selection register, Rising trigger selection register, Software interrupt event register, Event mask register, Interrupt mask register, and Pending request register. External events enter an Edge detect circuit. Internal events pass through a Stop mode AND gate and then a Rising edge detect circuit. The outputs of the Edge detect circuit and the Rising edge detect circuit are combined with signals from the registers through a series of AND and OR gates to generate Interrupts, Events, and Wakeup signals. The identifier MS19952V3 is in the bottom right corner.

11.2.3 Event management

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

11.2.4 Functional description

For the external interrupt lines, 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.

For the internal interrupt lines, the active edge is always the rising edge, the interrupt is enabled by default in the interrupt mask register and there is no corresponding pending bit 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.

For the external lines, an interrupt/event request can also be generated by software by writing a '1' in the software interrupt/event register.

Note: The interrupts or events associated to the internal lines can be triggered only when the system is in STOP mode. If the system is still running, no interrupt/event is generated.

For code example refer to the Appendix section A.6.2: External interrupt selection .

Hardware interrupt selection

To configure a line as interrupt source, use the following procedure:

Hardware event selection

To configure a line as event source, use the following procedure:

Software interrupt/event selection

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

11.2.5 External and internal interrupt/event line mapping

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

Figure 22. External interrupt/event GPIO mapping

Diagram showing the mapping of GPIO pins to external interrupt lines (EXTI0, EXTI1, ..., EXTI15). Each line is controlled by bits in the SYSCFG_EXTICR registers. For example, EXTI0 is controlled by SYSCFG_EXTICR1 bits [3:0] and can be connected to PA0, PB0, PC0, PD0, or PF0. EXTI15 is controlled by SYSCFG_EXTICR4 bits [3:0] and can be connected to PA15, PB15, PC15, PD15, or PF15.

The diagram illustrates the mapping of GPIO pins to external interrupt lines. It shows three examples of multiplexers:

Vertical ellipsis between EXTI1 and EXTI15 indicates that the same pattern repeats for lines 2 through 14. The diagram is labeled with MSV36432V1 in the bottom right corner.

Diagram showing the mapping of GPIO pins to external interrupt lines (EXTI0, EXTI1, ..., EXTI15). Each line is controlled by bits in the SYSCFG_EXTICR registers. For example, EXTI0 is controlled by SYSCFG_EXTICR1 bits [3:0] and can be connected to PA0, PB0, PC0, PD0, or PF0. EXTI15 is controlled by SYSCFG_EXTICR4 bits [3:0] and can be connected to PA15, PB15, PC15, PD15, or PF15.

The remaining lines are connected as follow:

Note: EXTI lines which are reserved or not used on some devices are considered as internal.

11.3 EXTI registers

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

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

11.3.1 Interrupt mask register (EXTI_IMR)

Address offset: 0x00

Reset value: 0x0FF4 0000 (STM32F030x4, STM32F030x6 devices)
0x7FF4 0000 (STM32F070x6 devices)
0x0F94 0000 (STM32F030x8 devices)
0x7F84 0000 (STM32F070xB and STM32F030xC devices)

Note: The reset value for the internal lines is set to '1' in order to enable the interrupt by default.

31302928272625242322212019181716
IM31IM30IM29IM28IM27IM26IM25IM24IM23IM22IM21IM20IM19IM18IM17IM16
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
IM15IM14IM13IM12IM11IM10IM9IM8IM7IM6IM5IM4IM3IM2IM1IM0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 IMx : Interrupt Mask on line x (x = 31 to 0)

0: Interrupt request from Line x is masked

1: Interrupt request from Line x is not masked

11.3.2 Event mask register (EXTI_EMR)

Address offset: 0x04

Reset value: 0x0000 0000

31302928272625242322212019181716
EM31EM30EM29EM28EM27EM26EM25EM24EM23EM22EM21EM20EM19EM18EM17EM16
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw
1514131211109876543210
EM15EM14EM13EM12EM11EM10EM9EM8EM7EM6EM5EM4EM3EM2EM1EM0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bits 31:0 EMx : Event mask on line x (x = 31 to 0)

0: Event request from Line x is masked

1: Event request from Line x is not masked

11.3.3 Rising trigger selection register (EXTI_RTSR)

Address offset: 0x08

Reset value: 0x0000 0000

31302928272625242322212019181716
RT31Res.Res.Res.Res.Res.Res.Res.Res.RT22RT21RT20RT19Res.RT17RT16
rwrwrwrwrwrwrw
1514131211109876543210
RT15RT14RT13RT12RT11RT10RT9RT8RT7RT6RT5RT4RT3RT2RT1RT0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 RT31 : Rising trigger event configuration bit of line 31

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

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

Bits 30:23 Reserved, must be kept at reset value.

Bits 22:19 RTx : Rising trigger event configuration bit of line x (x = 22 to 19)

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

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

Bit 18 Reserved, must be kept at reset value.

Bits 17:0 RTx : Rising trigger event configuration bit of line x (x = 17 to 0)

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 glitches must be generated on these lines. If a rising edge on an external interrupt line occurs during a write operation to the EXTI_RTSR register, the pending bit is not set.

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

11.3.4 Falling trigger selection register (EXTI_FTSR)

Address offset: 0x0C

Reset value: 0x0000 0000

31302928272625242322212019181716
FT31Res.Res.Res.Res.Res.Res.Res.Res.FT22FT21FT20FT19Res.FT17FT16
rwrwrwrwrwrwrw

1514131211109876543210
FT15FT14FT13FT12FT11FT10FT9FT8FT7FT6FT5FT4FT3FT2FT1FT0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 FT31 : Falling trigger event configuration bit of line 31

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

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

Bits 30:23 Reserved, must be kept at reset value.

Bits 22:19 FTx : Falling trigger event configuration bit of line x (x = 22 to 19)

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

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

Bit 18 Reserved, must be kept at reset value.

Bits 17:0 FTx : Falling trigger event configuration bit of line x (x = 17 to 0)

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 glitches must be generated on these lines. If a falling edge on an external interrupt line occurs during a write operation 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 case, both generate a trigger condition.

11.3.5 Software interrupt event register (EXTI_SWIER)

Address offset: 0x10
Reset value: 0x0000 0000

31302928272625242322212019181716
SWI31Res.Res.Res.Res.Res.Res.Res.Res.SWI22SWI21SWI20SWI19Res.SWI17SWI16
rwrwrwrwrwrwrw
1514131211109876543210
SWI15SWI14SWI13SWI12SWI11SWI10SWI9SWI8SWI7SWI6SWI5SWI4SWI3SWI2SWI1SWI0
rwrwrwrwrwrwrwrwrwrwrwrwrwrwrwrw

Bit 31 SWI31 : Software interrupt on line 31
If the interrupt is enabled on this line in the EXTI_IMR, writing a '1' to this bit when it is at '0' sets the corresponding pending bit in EXTI_PR resulting in an interrupt request generation.
This bit is cleared by clearing the corresponding bit of EXTI_PR (by writing a '1' to the bit)

Bits 30:23 Reserved, must be kept at reset value.

Bits 22:19 SWIx : Software interrupt on line x (x = 22 to 19)
If the interrupt is enabled on this line in the EXTI_IMR, writing a '1' to this bit when it is at '0' sets the corresponding pending bit in EXTI_PR resulting in an interrupt request generation.
This bit is cleared by clearing the corresponding bit of EXTI_PR (by writing a '1' to the bit)

Bit 18 Reserved, must be kept at reset value.

Bits 17:0 SWIx : Software interrupt on line x (x = 17 to 0)
If the interrupt is enabled on this line in the EXTI_IMR, writing a '1' to this bit when it is at '0' sets the corresponding pending bit in EXTI_PR resulting in an interrupt request generation.
This bit is cleared by clearing the corresponding bit of EXTI_PR (by writing a '1' to the bit).

11.3.6 Pending register (EXTI_PR)

Address offset: 0x14
Reset value: 0x0000 0000

31302928272625242322212019181716
PIF31Res.Res.Res.Res.Res.Res.Res.Res.PIF22PIF21PIF20PIF19Res.PIF17PIF16
rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1
1514131211109876543210
PIF15PIF14PIF13PIF12PIF11PIF10PIF9PIF8PIF7PIF6PIF5PIF4PIF3PIF2PIF1PIF0
rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1rc_w1

Bit 31 PIF31 : Pending bit on line 31

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.

Bits 30:23 Reserved, must be kept at reset value.

Bits 22:19 PIFx : Pending bit on line x (x = 22 to 19)

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.

Bit 18 Reserved, must be kept at reset value.

Bits 17:0 PIFx : Pending bit on line x (x = 17 to 0)

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.

11.3.7 EXTI register map

The following table gives the EXTI register map and the reset values.

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

OffsetRegister313029282726252423222120191817161514131211109876543210
0x00EXTI_IMRIM[31:0]
Reset value00000000000000000000000000000000
0x04EXTI_EMREM[31:0]
Reset value00000000000000000000000000000000
0x08EXTI_RTSRRT31Res.Res.Res.Res.Res.Res.Res.RT23RT22RT21RT20RT19Res.RT[17:0]
Reset value00000000000000000000000
0x0CEXTI_FTSRFT31Res.Res.Res.Res.Res.Res.Res.FT23FT22FT21FT20FT19Res.FT[17:0]
Reset value00000000000000000000000
0x10EXTI_SWIERSWI31Res.Res.Res.Res.Res.Res.Res.SWI23SWI22SWI21SWI20SWI19Res.SWI[17:0]
Reset value00000000000000000000000
0x14EXTI_PRPIF31Res.Res.Res.Res.Res.Res.Res.PIF23PIF22PIF21PIF20PIF19Res.PIF[17:0]
Reset value00000000000000000000000

Refer to Section 2.2 on page 37 for the register boundary addresses.