From 38ffacf80ed068f858a1054a4e1f7d1187679af3 Mon Sep 17 00:00:00 2001 From: Dominic Clifton Date: Tue, 24 Dec 2019 21:05:02 +0100 Subject: [PATCH] Prevent EXTI handler from crashing when EXTI lines 16-32 are used. Refer to "EXTI Event Input mapping" table in MCU reference manuals. --- src/main/drivers/exti.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/exti.c b/src/main/drivers/exti.c index a1726dc912..4e520ab0e1 100644 --- a/src/main/drivers/exti.c +++ b/src/main/drivers/exti.c @@ -229,9 +229,11 @@ void EXTIEnable(IO_t io, bool enable) #endif } +#define EXTI_EVENT_MASK 0xFFFF // first 16 bits only, see also definition of extiChannelRecs. + void EXTI_IRQHandler(void) { - uint32_t exti_active = EXTI_REG_IMR & EXTI_REG_PR; + uint32_t exti_active = (EXTI_REG_IMR & EXTI_REG_PR) & EXTI_EVENT_MASK; while (exti_active) { unsigned idx = 31 - __builtin_clz(exti_active);