GPIO Interrupt Causes CPU Exception on Some Pins

Dear Ameba Team,

I’m currently working on enabling GPIO interrupts on several pins, but I encountered CPU exceptions during testing. After evaluating each GPIO pin, I found that the following pins consistently fail when interrupts are enabled:

  • D15 (GPIOE_1): Cannot read after GPIO interrupt is enabled
  • D18 (GPIOD_16): Cannot read after GPIO interrupt is enabled
  • D19 (GPIOD_15): Cannot read after GPIO interrupt is enabled
  • D20 (GPIOD_14): Cannot read after GPIO interrupt is enabled

It seems enabling interrupts on these specific pins results in abnormal behavior or even system crashes.

Could you please help identify the cause and provide a way to make these pins work properly with GPIO interrupts?

I’ve also attached a test file for verifying GPIO behavior. The issue only occurs when D15, D18, D19, or D20 are included in the interrupt test.
If the test excludes these pins — for example:

      if ((i!=15) && (i!=18) && (i!=19) && (i!=20))

then no exceptions occur, and everything works as expected.
However, if any of these pins are included, the CPU exception is triggered.

GPIOReadTest.zip (549 位元組)

Hi @Howard , your GPIOReadTest i saw you are calling digitalRead() after pinMode(pin, INPUT_IRQ_CHANGE) can cause conflicts internally. You may test with this to see all the enabling interrupts. Thank you.

#include "gpio_irq_api.h"

typedef struct {
    const char* label;
    PinName pin;
} GpioPinInfo;

GpioPinInfo testPins[] = {
    {"D0 (PF5)", PF_5},
    {"D1 (PF6)", PF_6},
    {"D2 (PF7)", PF_7},
    {"D3 (PF8)", PF_8},
    {"D4 (PF11)", PF_11},
    {"D5 (PF12)", PF_12},
    {"D6 (PF13)", PF_13},
    {"D7 (PF14)", PF_14},
    {"D8 (PF15)", PF_15},
    {"D9 (PF2)", PF_2},
    {"D10 (PF1)", PF_1},
    {"D11 (PF0)", PF_0},
    {"D12 (PE4)", PE_4},
    {"D13 (PE3)", PE_3},
    {"D14 (PE2)", PE_2},
    {"D15 (PE1)", PE_1},
    {"D16 (PD18)", PD_18},
    {"D17 (PD17)", PD_17},
    {"D18 (PD16)", PD_16},
    {"D19 (PD15)", PD_15},
    {"D20 (PD14)", PD_14},
    {"D21 (PA2)", PA_2},
    {"D22 (PA3)", PA_3}
};

void dummy_handler(uint32_t id, gpio_irq_event event) {
    Serial.print("Interrupt on pin index: ");
    Serial.println(id);
}

void setup() {
    Serial.begin(115200);
    delay(1000);
    Serial.println("=== GPIO IRQ Capability Test ===");

    for (int i = 0; i < sizeof(testPins) / sizeof(testPins[0]); i++) {
        gpio_irq_t irq;
        int result = gpio_irq_init(&irq, testPins[i].pin, dummy_handler, i);
        if (result == 0) {
            Serial.println(testPins[i].label);
            gpio_irq_free(&irq);  // Clean up
        } else {
            Serial.println(testPins[i].label);
        }
    }

    Serial.println("=== Test Complete ===");
}

void loop() {
    // Nothing to do
}