Search code examples
esp32arduino-esp32

ESP32 launch bootloader


I have an ESP32 board with GPIO0 connected to ground through a switch. The idea is that if I press the button and issue an ESP.restart() the board would get into flash mode. Instead, ESP.restart() just restarts the app, ignoring GPIO0 state.

Is it possible to force the whole boot process, maybe with a direct JMP to the HW reset vector?


Solution

  • According to Ivan Grokhotkov

    On ESP32 there are 3 reset reasons which cause strapping GPIOs to be sampled: power-on, RTC WDT reset, brownout reset.

    So in terms of code, see below. If the pin is strapped it will never get out of the bootloader which will be waiting for a sync on serial.

    #include "soc/rtc_wdt.h"
    void hardReset() {  
      rtc_wdt_protect_off();      //Disable RTC WDT write protection
      //Set stage 0 to trigger a system reset after 1000ms
      rtc_wdt_set_length_of_reset_signal(RTC_WDT_SYS_RESET_SIG, RTC_WDT_LENGTH_3_2us);
      rtc_wdt_set_stage(RTC_WDT_STAGE0, RTC_WDT_STAGE_ACTION_RESET_SYSTEM);
      rtc_wdt_set_time(RTC_WDT_STAGE0, 10000);
      rtc_wdt_enable();           //Start the RTC WDT timer
      rtc_wdt_protect_on();       //Enable RTC WDT write protection
    }