diff --git a/src/main/drivers/exti.c b/src/main/drivers/exti.c index 3ef0ef32417..6292bf04af9 100644 --- a/src/main/drivers/exti.c +++ b/src/main/drivers/exti.c @@ -216,11 +216,15 @@ void EXTI_IRQHandler(void) { uint32_t exti_active = EXTI_REG_IMR & EXTI_REG_PR; + // Clear before dispatching (as Betaflight does): an edge on the same line + // while its handler runs must stay pending rather than be wiped when the + // handler returns. + EXTI_REG_PR = exti_active; + while (exti_active) { unsigned idx = 31 - __builtin_clz(exti_active); uint32_t mask = 1 << idx; extiChannelRecs[idx].handler->fn(extiChannelRecs[idx].handler); - EXTI_REG_PR = mask; // clear pending mask (by writing 1) exti_active &= ~mask; } }