From 39d71ac67108498d7008e01bacd696af9d590cfd Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Wed, 5 Aug 2020 16:39:30 +0200 Subject: [PATCH] cpu/sam0_common: GPIO: ignore interrupts when interrupts are disabled If we disable an external interrupt, GPIO events that would generate an interrupt will still set the interrupt flag. That means once we enable the interrupt again, a stale interrupt will be triggered. This is surprising and probably not what the user wants, unfortunately the API documentation is not very clear about what to expect. There is however no way to drop those intermediate interrupts with the current API. Ignoring the events that occurred while the GPIO interrupt were disabled is probably the right (and expected) thing to. --- cpu/sam0_common/periph/gpio.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/cpu/sam0_common/periph/gpio.c b/cpu/sam0_common/periph/gpio.c index 39a3bc0ab0..680f661cf2 100644 --- a/cpu/sam0_common/periph/gpio.c +++ b/cpu/sam0_common/periph/gpio.c @@ -321,6 +321,11 @@ void gpio_irq_enable(gpio_t pin) if (exti == -1) { return; } + + /* clear stale interrupt */ + _EIC->INTFLAG.reg = (1 << exti); + + /* enable interrupt */ _EIC->INTENSET.reg = (1 << exti); }