Unable to perform a soft reset

All ESP32 boards running MicroPython.
Target audience: MicroPython users with an ESP32 board.
Post Reply
br0kenpixel
Posts: 5
Joined: Sun Dec 06, 2020 3:15 pm

Unable to perform a soft reset

Post by br0kenpixel » Sat Apr 03, 2021 6:01 pm

Hi. I'm trying out my ESP32 board and I noticed that the soft_reset function (in the machine module) does not work.

I have a boot.py file that looks like this:

Code: Select all

import machine
print("Hello World!")
machine.soft_reset()
My ESP32 does not want to soft reboot. Basically, nothing happens. The "Hello World!" string is printed and that's it.

Code: Select all

Hello World!
MicroPython v1.14 on 2021-02-02; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>> 
The function does work if I type it in manually into the REPL.

Code: Select all

>>> machine.soft_reset()
MPY: soft reboot
Hello World!
MicroPython v1.14 on 2021-02-02; ESP32 module (spiram) with ESP32
Type "help()" for more information.
>>> 
Could someone please explain why it's not working? I'm kinda confused. I'm using the official build from MicroPython's website (GENERIC_SPIRAM).

marcidy
Posts: 133
Joined: Sat Dec 12, 2020 11:07 pm

Re: Unable to perform a soft reset

Post by marcidy » Sat Apr 03, 2021 6:39 pm

I assume you know this, but this is not really a good idea, you're going to end up in a boot loop you can't get out of without erasing the flash.

I'm curious why you'd want to do this, and specifically in boot.py rather than main.py?

That being said, looks like boot.py is handled slightly different from the repl and main.py, which isn't a complete answer to your question, but shines light on it.

machine.soft_reset() raises a SystemExit error, rather than executes the soft_reset. The soft_reset is in main.c.

Code: Select all

ports/esp32/modmachine.c
STATIC mp_obj_t machine_soft_reset(void) {
    pyexec_system_exit = PYEXEC_FORCED_EXIT;
    mp_raise_type(&mp_type_SystemExit);
}

When done from main.py or the repl, it looks like it's checked which triggers the actual soft_reset. when executing boot.py, I don't think the particular error is checked / acted on.

Code: Select all

ports/esp32/main.py:119-126

    pyexec_frozen_module("_boot.py");
    pyexec_file_if_exists("boot.py");
    if (pyexec_mode_kind == PYEXEC_MODE_FRIENDLY_REPL) {
        int ret = pyexec_file_if_exists("main.py");
        if (ret & PYEXEC_FORCED_EXIT) {
            goto soft_reset_exit;
        }
    }
notice how the return from pyexec_file_if_exists is not checked for boot.py, but is for main.py.

Post Reply