Skip to main content
Associate II
June 30, 2026
Question

HAL Suggestion: Allow EXTI and AF on same GPIO input

  • June 30, 2026
  • 0 replies
  • 3 views

Some applications have the need to use an external interrupt from an GPIO input that is already configured as alternate function. My use case is to use EXTI on a rising edge of SPI_NSS input to detect a terminated SPI transfer on a slave.

So I need the combination of MODE_AF and EXTI_IT when configuring the GPIO input pin. Unfortunately, HAL does not support this and asserts on IS_GPIO_MODE(__MODE__) for this combination.

However, STM32 MCUs usually support this combination, so it makes sense to support this in HAL.

To allow this, I added some definitions in stm32g4xx_hal_gpio.h:


#define  GPIO_MODE_AF_IT_RISING                    (MODE_AF | EXTI_IT | TRIGGER_RISING)                     /*!< Alternate Function with External Interrupt Mode with Rising edge trigger detection          */

#define  GPIO_MODE_AF_IT_FALLING                   (MODE_AF | EXTI_IT | TRIGGER_FALLING)                    /*!< Alternate Function with External Interrupt Mode with Falling edge trigger detection         */

#define  GPIO_MODE_AF_IT_RISING_FALLING            (MODE_AF | EXTI_IT | TRIGGER_RISING | TRIGGER_FALLING)   /*!< Alternate Function with External Interrupt Mode with Rising/Falling edge trigger detection  */

and updated the 

#define IS_GPIO_MODE(__MODE__)

macro accordingly. No change in stm32g4xx_hal_gpio.c needed.

I suggest to add this to the STM32 HAL drivers of the MCUs that support this combination.

Regards, Norbert