Electronic – How to distinguish between GPIO interrupts from the same interrupt handler

gpio-external-interruptinterruptsstm32

I'm trying to interface a few modules to my STM32L476 board for which
I need to enable two GPIO interrupts from the same port (portA, pin 5 and portA, pin 6), but the interrupt handler for these pins are handled by an external line common for pins 5 to 9 (EXTI9_5_IRQHandler).

I need to do a different task on both these interrupts, but how would I know which interrupt has occurred as both are handled by same handler?
Are there any flags that I could check to know this?

Best Answer

Read the EXTI->PR1 register to decide

void EXTI9_5_IRQHandler(void) {
    uint32_t pending = EXTI->PR1;
    if(pending & (1 << 5)) {
        EXTI->PR1 = 1 << 5; // clear pending flag, otherwise we'd get endless interrupts
        // handle pin 5 here
    }
    if(pending & (1 << 6)) {
        EXTI->PR1 = 1 << 6;
        // handle pin 6 here
    }
}