From 3c2b2f7a4d790c66dbe723c5ed59ec18472baa6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Felix=20D=C3=B6rre?= Date: Tue, 21 Feb 2023 07:11:14 +0000 Subject: [PATCH] rp2/modmachine: Fix lightsleep while wifi is powered off. While cyw43 is deinitialized, an interrupt occurs. That is handled with these lines: ports/rp2/mpnetworkport.c#L59-L61 and as pendsv is disabled while in network code, the poll function then just waits there. When deinit has finished, the poll func is executed, but skipped: src/cyw43_ctrl.c#L222-L225 this skips the `CYW43_POST_POLL_HOOK` which would re-enable interrupts, but also reset `cyw43_has_pending`. And in that state, the lightsleep code, will skip sleeping as it thinks there is a network packet pending to be handled. With this change applied, lightsleep works as expected when the wifi chip is enabled, and when it's powered off. --- ports/rp2/modmachine.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ports/rp2/modmachine.c b/ports/rp2/modmachine.c index 1efbb09312..35c938b54b 100644 --- a/ports/rp2/modmachine.c +++ b/ports/rp2/modmachine.c @@ -146,7 +146,7 @@ STATIC mp_obj_t machine_lightsleep(size_t n_args, const mp_obj_t *args) { uint32_t my_interrupts = save_and_disable_interrupts(); #if MICROPY_PY_NETWORK_CYW43 - if (cyw43_has_pending) { + if (cyw43_has_pending && cyw43_poll != NULL) { restore_interrupts(my_interrupts); return mp_const_none; }