Skip to content

Commit f305469

Browse files
projectgusGadgetoid
authored andcommitted
WIP: rp2: Make GPIO wakeup from lightsleep consistent.
Before this commit: - A Pin with an irq() trigger is a wakeup source only when machine.lightsleep(n) is used with a timeout, and only if an IRQ handler is set. After this commit: - A Pin with an irq() trigger is a wakeup source from both indefinite machine.lightsleep() and machine.lightsleep(n) with a timeout. - A Pin with an irq() trigger is a wakeup source even if no handler function is set. Issues at present: - Waking RP2040 repeatedly from machine.lightsleep() with no timeout and USB causes the USB connection to misbehave and eventually the CPU hangs. - This implementation doesn't match the machine.Pin docs re: irq(wake=) argument. However, I think only cc3200 port has actually implemented this argument as documented. This work was funded through GitHub Sponsors. Signed-off-by: Angus Gratton <[email protected]>
1 parent 76ad700 commit f305469

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

ports/rp2/machine_pin.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ void machine_pin_deinit(void) {
134134
continue;
135135
}
136136
gpio_set_irq_enabled(i, GPIO_IRQ_ALL, false);
137+
gpio_set_dormant_irq_enabled(i, GPIO_IRQ_ALL, false);
137138
}
138139
irq_remove_handler(IO_IRQ_BANK0, gpio_irq);
139140
}
@@ -458,16 +459,19 @@ void mp_hal_pin_interrupt(mp_hal_pin_obj_t pin, mp_obj_t handler, mp_uint_t trig
458459

459460
// Disable all IRQs while data is updated.
460461
gpio_set_irq_enabled(pin, GPIO_IRQ_ALL, false);
462+
gpio_set_dormant_irq_enabled(pin, GPIO_IRQ_ALL, false);
461463

462464
// Update IRQ data.
463465
irq->base.handler = handler;
464466
irq->base.ishard = hard;
465467
irq->flags = 0;
466468
irq->trigger = trigger;
467469

468-
// Enable IRQ if a handler is given.
469-
if (handler != mp_const_none && trigger != MP_HAL_PIN_TRIGGER_NONE) {
470+
if (trigger != MP_HAL_PIN_TRIGGER_NONE) {
471+
// Enable IRQ even if no handler is set, so pin can wake CPU from WFI/WFE
470472
gpio_set_irq_enabled(pin, trigger, true);
473+
// Also have the IRQ wake us from indefinite lightsleep
474+
gpio_set_dormant_irq_enabled(pin, trigger, true);
471475
}
472476
}
473477

0 commit comments

Comments
 (0)