From 577bf5acc9a2a9e5554bc37dc368ccd264efb113 Mon Sep 17 00:00:00 2001 From: Javier Alonso Date: Fri, 24 Jul 2026 12:25:40 +0200 Subject: [PATCH] stm32: Detach GPIO IRQ callbacks upon clearing "setevent" When the interrupts get disabled, the callback(s) are still attached. That structure is never cleared, causing several calls to attach/detach to eventually fail as the callback queue gets full. When the error occurs, the registration fails with error 12 (ENOMEM). By detaching the IRQ and clearing the callbacks, this error doesn't happen again Signed-off-by: Javier Alonso --- arch/arm/src/common/stm32/stm32_exti_gpio_m0_v1.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/arch/arm/src/common/stm32/stm32_exti_gpio_m0_v1.c b/arch/arm/src/common/stm32/stm32_exti_gpio_m0_v1.c index 00b9158085c..b143d31dc9e 100644 --- a/arch/arm/src/common/stm32/stm32_exti_gpio_m0_v1.c +++ b/arch/arm/src/common/stm32/stm32_exti_gpio_m0_v1.c @@ -221,6 +221,7 @@ int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, xcpt_t handler; int nshared; int i; + int ret; /* Select the interrupt handler for this EXTI pin */ @@ -274,6 +275,16 @@ int stm32_gpiosetevent(uint32_t pinset, bool risingedge, bool fallingedge, if (i == nshared) { + /* remove any leftover callback */ + + ret = irq_detach(irq); + if (ret < 0) + { + return ret; + } + + /* disable the interrupt */ + up_disable_irq(irq); } }