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!
tools/mpremote: Correctly manage mounted flag during soft-reset.
Currently in mpremote if an error occurs during soft-reboot, there can be a chained exception such as:
MPY: soft reboot
Traceback (most recent call last):
File "c:\python39\lib\site-packages\mpremote\main.py", line 507, in main
do_repl(pyb, args)
File "c:\python39\lib\site-packages\mpremote\main.py", line 367, in do_repl
do_repl_main_loop(
File "c:\python39\lib\site-packages\mpremote\main.py", line 294, in do_repl_main_loop
pyb.soft_reset_with_mount(console_out_write)
File "c:\python39\lib\site-packages\mpremote\pyboardextended.py", line 686, in soft_reset_with_mount
self.exec_(fs_hook_code)
File "c:\python39\lib\site-packages\mpremote\pyboard.py", line 465, in exec_
ret, ret_err = self.exec_raw(command, data_consumer=data_consumer)
File "c:\python39\lib\site-packages\mpremote\pyboard.py", line 456, in exec_raw
self.exec_raw_no_follow(command)
File "c:\python39\lib\site-packages\mpremote\pyboard.py", line 453, in exec_raw_no_follow
raise PyboardError("could not exec command (response: %r)" % data)
mpremote.pyboard.PyboardError: could not exec command (response: b'R\x01')
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "c:\python39\lib\runpy.py", line 197, in _run_module_as_main
return _run_code(code, main_globals, None,
File "c:\python39\lib\runpy.py", line 87, in _run_code
exec(code, run_globals)
File "C:\Python39\Scripts\mpremote.exe\__main__.py", line 7, in <module>
File "c:\python39\lib\site-packages\mpremote\main.py", line 510, in main
do_disconnect(pyb)
File "c:\python39\lib\site-packages\mpremote\main.py", line 262, in do_disconnect
pyb.umount_local()
File "c:\python39\lib\site-packages\mpremote\pyboardextended.py", line 703, in umount_local
self.exec_('uos.umount("/remote")')
File "c:\python39\lib\site-packages\mpremote\pyboard.py", line 467, in exec_
raise PyboardError("exception", ret, ret_err)
mpremote.pyboard.PyboardError: ('exception', b'', b'Traceback (most recent call last):\r\n File "<stdin>", line 1, in <module>\r\nOSError: [Errno 22] EINVAL\r\n')
The second exception here is from an attempt to umount during the PyboardError handler, however it hasn't yet been re-mounted during soft-reset.
This PR simply ignores errors during umount, I can't think of any situations where this would realistically cause issues?