Library 38- External interrupts for STM32F4

A new library is here. 38th are external interrupts. This library allows you to very easly use external interrupts for your needs with just one function and function handler. I have written everything you need to start.

For more informations on how external interrupts works on STM32F4 with pins and lines and so on, you should look at my external interrupts tutorial. I tried explain there everything as best as I can. I think it’s quite understandable.

I will just say here, that you can connect only one pin to one line at a time. For more, look at tutorial.

So, my library is below.



  • Attach external interrupt on specific pin
  • Detach external interrupt on specific pin
  • Selectable trigger for interrupt
    • Rising edge
    • Falling edge
    • Both edges


    • STM32F4xx
    • STM32F4xx RCC
    • STM32F4xx GPIO
    • STM32F4xx EXTI
    • STM32F4xx SYSCFG
    • misc.h
  • TM
    • TM GPIO
    • defines.h
    • attributes.h
Line 0 PA0 PB0 PC0 PD0 PE0 PF0 PG0 PH0 PI0 PJ0 PK0
Line 1 PA1 PB1 PC1 PD1 PE1 PF1 PG1 PH1 PI1 PJ1 PK1
Line 2 PA2 PB2 PC2 PD2 PE2 PF2 PG2 PH2 PI2 PJ2 PK2
Line 3 PA3 PB3 PC3 PD3 PE3 PF3 PG3 PH3 PI3 PJ3 PK3
Line 4 PA4 PB4 PC4 PD4 PE4 PF4 PG4 PH4 PI4 PJ4 PK4
Line 5 PA5 PB5 PC5 PD5 PE5 PF5 PG5 PH5 PI5 PJ5 PK5
Line 6 PA6 PB6 PC6 PD6 PE6 PF6 PG6 PH6 PI6 PJ6 PK6
Line 7 PA7 PB7 PC7 PD7 PE7 PF7 PG7 PH7 PI7 PJ7 PK7
Line 8 PA8 PB8 PC8 PD8 PE8 PF8 PG8 PH8 PI8 PJ8 PK8
Line 9 PA9 PB9 PC9 PD9 PE9 PF9 PG9 PH9 PI9 PJ9 PK9
Line 10 PA10 PB10 PC10 PD10 PE10 PF10 PG10 PH10 PI10 PJ10 PK10
Line 11 PA11 PB11 PC11 PD11 PE11 PF11 PG11 PH11 PI11 PJ11 PK11
Line 12 PA12 PB12 PC12 PD12 PE12 PF12 PG12 PH12 PI12 PJ12 PK12
Line 13 PA13 PB13 PC13 PD13 PE13 PF13 PG13 PH13 PI13 PJ13 PK13
Line 14 PA14 PB14 PC14 PD14 PE14 PF14 PG14 PH14 PI14 PJ14 PK14
Line 15 PA15 PB15 PC15 PD15 PE15 PF15 PG15 PH15 PI15 PJ15 PK15

Yeah, you are right. There are many GPIOxs available on STM32F4 devices. So, this table describes you, which pins are used for specific line. So let’s say Line 11 has pins PA11 to PK11.

I had to implement default interrupt handlers if I want to use interrupts. So 7 functions with default names in my library. If you need any of this functions (names below) then you can disable this functionality in library by adding some defines to defines.h file.

By default, external interrupts have priority in NVIC set to 0x0A. If you want higher priority, add line below in defines.h file and edit it. Lower number means higher priority. Sub priorities are set like pins. Px0 has highest priority, Px15 lowest.

Functions and enumerations


Example is set to work with both, discovery boards and nucleo boards.

  • Discovery boards
    • Button connected to PA0
    • Rising edge when you press button
    • Line0 selected
  • Nucleo boards
    • Button connected to PC13
    • Falling edge when you press button
    • Line13 selected
  • Every click on button will toggle led
    • After 10 clicks on button, interrupt for specific line is detached

Project is available on Github, download library here.


Owner of this site. Application engineer, currently employed by STMicroelectronics. Exploring latest technologies and owner of different libraries posted on Github.

You may also like...