Skip to content

Commit 21dbbc5

Browse files
author
Cruz Monrreal
authored
Merge pull request #7510 from mattbrown015/fix_stm32_gpio_irq_deepsleep
STM32: Improve GPIO IRQ edge detection when waking from deepsleep
2 parents 25bb200 + 7ef7022 commit 21dbbc5

File tree

1 file changed

+22
-4
lines changed

1 file changed

+22
-4
lines changed

targets/TARGET_STM/gpio_irq_api.c

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -94,12 +94,30 @@ static void handle_interrupt_in(uint32_t irq_index, uint32_t max_num_pin_line)
9494
continue;
9595
}
9696

97-
// Check which edge has generated the irq
98-
if ((gpio->IDR & pin) == 0) {
99-
irq_handler(gpio_channel->channel_ids[gpio_idx], IRQ_FALL);
97+
// Trying to discern which edge caused the IRQ
98+
gpio_irq_event event = IRQ_NONE;
99+
if (LL_EXTI_IsEnabledFallingTrig_0_31(pin) && !LL_EXTI_IsEnabledRisingTrig_0_31(pin)) {
100+
// Only the fall handler is active, so this must be a falling edge
101+
event = IRQ_FALL;
102+
} else if (LL_EXTI_IsEnabledRisingTrig_0_31(pin) && !LL_EXTI_IsEnabledFallingTrig_0_31(pin)) {
103+
// Only the rise handler is active, so this must be a rising edge
104+
event = IRQ_RISE;
100105
} else {
101-
irq_handler(gpio_channel->channel_ids[gpio_idx], IRQ_RISE);
106+
// Ambiguous as to which edge caused the IRQ
107+
//
108+
// The state of the pin could/should indicate which edge
109+
// has occurred but this can go wrong if the IRQ caused a
110+
// transition from a low power mode. In some circumstances
111+
// only the trailing edge callback will be called.
112+
if ((gpio->IDR & pin) == 0) {
113+
event = IRQ_FALL;
114+
} else {
115+
event = IRQ_RISE;
116+
}
102117
}
118+
119+
irq_handler(gpio_channel->channel_ids[gpio_idx], event);
120+
103121
return;
104122
}
105123
}

0 commit comments

Comments
 (0)