ESP32 launch bootloader

Viewed 2004

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?

2 Answers

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
}

A better solution is that not using firmware update mode for programmatically software updates, use it only for only bootloader updates. Split your code into two-part bootloader and logical program part.

To update your logical program part, your bootloader should handle burning the remaining addresses except for the bootloader. (Your bootloader code can burn any address on the microcontroller, filesystem libraries do that) So don't try to switch into firmware update mode which is available for whole firmware updates. The more advanced solution is using OTA update features as possible as.

In this way, you guarantee that you always have the bootable device in the field, which is ready to update any corrupted logical part. Any mistake during burning the bootloader in the field may cost your device shipment.

Related