machine.soft_reset() behaves curiously on esp8266
Hi!
This is related to https://github.com/micropython/micropython/issues/5764
Thanks a lot for implementing it by the way! 😄
If I invoke it from the REPL, everything works as expected, but if it's invoked from a running code, it will drop to REPL (and with no MPY: soft reboot message). Here's an example:
try:
trixie.run()
except KeyboardInterrupt:
trixie.runner.stop()
except trixie.ResetError:
# land here on reset
print('SOFT RESET')
machine.soft_reset()
except trixie.RebootError:
# land here on reboot
print('HARD RESET')
machine.reset()
except Exception as exc:
# we should never end up here
print('EXCEPTION')
trixie.runner.stop()
trixie.run() raises trixie.SoftReset on soft reset intent, after which 'SOFT RESET' is printed, but then it drops to REPL instead.
I saw it in another issue, that it's by design that main.py won't be called on soft-reset, so I tested the snippet above in _boot.py and boot.py also, but it produces the same behavior. Not having 'MPY: soft reset' printed is suspicious. I'm confused if this is indeed a bug, or I'm doing something wrong.
Thanks a lot for looking into this!
esp32: make machine.soft_reset() work in main.py
This patch fixes two issues on the esp32: it enables machine.soft_reset() to be called in main.py and it enables machine.reset_cause() to correctly identify a soft reset. The former is useful in that it enables soft resets in applications that are started at boot time.
The support is patterned after the stm32 port.
No docs changes 'cause this makes things works as documented.
No unit test, I can create one but due to the reset it ends up being pretty messy.