Skip to content

Commit ade981d

Browse files
committed
STM32: Store and restore rising falling config of gpio_irq
Now that rising / falling edge detection is disabled in the gpio_irq_disable function, we also need to restore it when gpio_irq_enable gets called.
1 parent 8877052 commit ade981d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

targets/TARGET_STM/gpio_irq_api.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,18 +254,23 @@ void gpio_irq_free(gpio_irq_t *obj)
254254

255255
void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
256256
{
257+
/* Enable / Disable Edge triggered interrupt and store event */
257258
if (event == IRQ_RISE) {
258259
if (enable) {
259260
LL_EXTI_EnableRisingTrig_0_31(1 << STM_PIN(obj->pin));
261+
obj->event |= IRQ_RISE;
260262
} else {
261263
LL_EXTI_DisableRisingTrig_0_31(1 << STM_PIN(obj->pin));
264+
obj->event &= ~IRQ_RISE;
262265
}
263266
}
264267
if (event == IRQ_FALL) {
265268
if (enable) {
266269
LL_EXTI_EnableFallingTrig_0_31(1 << STM_PIN(obj->pin));
270+
obj->event |= IRQ_FALL;
267271
} else {
268272
LL_EXTI_DisableFallingTrig_0_31(1 << STM_PIN(obj->pin));
273+
obj->event &= ~IRQ_FALL;
269274
}
270275
}
271276
}
@@ -284,6 +289,15 @@ void gpio_irq_enable(gpio_irq_t *obj)
284289

285290
LL_EXTI_EnableIT_0_31(1 << pin_index);
286291

292+
/* Restore previous edge interrupt configuration if applicable */
293+
if (obj->event & IRQ_RISE) {
294+
LL_EXTI_EnableRisingTrig_0_31(1 << STM_PIN(obj->pin));
295+
}
296+
if (obj->event & IRQ_FALL) {
297+
LL_EXTI_EnableFallingTrig_0_31(1 << STM_PIN(obj->pin));
298+
299+
}
300+
287301
NVIC_EnableIRQ(obj->irq_n);
288302
}
289303

@@ -295,5 +309,4 @@ void gpio_irq_disable(gpio_irq_t *obj)
295309
LL_EXTI_DisableIT_0_31(1 << STM_PIN(obj->pin));
296310
NVIC_DisableIRQ(obj->irq_n);
297311
NVIC_ClearPendingIRQ(obj->irq_n);
298-
obj->event = EDGE_NONE;
299312
}

0 commit comments

Comments
 (0)