Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4803

MicroPython • Re: Trouble with lightsleep() and deepsleep() in MicroPython

$
0
0
I'm not sure reset_cause returns the right result on rp2, making it pretty useless as a "here's how you recover from deepsleep" mechanism.
I recall the documentation is wrong but I think it should work ... 'modmachine.c'

Code:

static mp_int_t mp_machine_reset_cause(void) {    int reset_cause;    if (watchdog_caused_reboot()) {        reset_cause = RP2_RESET_WDT;    } else {        reset_cause = RP2_RESET_PWRON;    }    return reset_cause;}
I believe restarting from 'deep_sleep' is simply a "WDT". One would have to use the non-volatile 'SCRATCH' registers to indicate what had used the Watchdog to force a reset. But it's equivalent if the code doesn't enable Watchdog, doesn't force a Reset, isn't manually reset.

I implemented my own more refined 'reset_cause' and could differentiate restarts following -

Code:

POWER_CYCLED_RESETRESET_BUTTON_PUSHEDDEBUGGER_RESET PROGRAM_UPLOADWATCHDOG_TIMED_OUT
However, when I test that now I just keep seeing PROGRAM_UPLOAD. I guess that's perhaps because I have the order of checking things wrong, though I am sure it used to work.

I can also confirm that 'print' output gets lost if 'lightsleep' or 'deepsleep' is executed before it's had a chance to empty the transmit buffer.

Statistics: Posted by hippy — Wed May 15, 2024 7:46 pm



Viewing all articles
Browse latest Browse all 4803

Trending Articles