From 2e438163606135fae6d5ce9f257b829cd6ce6018 Mon Sep 17 00:00:00 2001 From: Jason2866 <24528715+Jason2866@users.noreply.github.com> Date: Mon, 21 Oct 2024 15:50:21 +0200 Subject: [PATCH] S2: USB rtc_wdt_reset --- esp_flasher/own_esptool.py | 50 ++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 26 deletions(-) diff --git a/esp_flasher/own_esptool.py b/esp_flasher/own_esptool.py index 0989f7f..93d51d7 100644 --- a/esp_flasher/own_esptool.py +++ b/esp_flasher/own_esptool.py @@ -1870,10 +1870,16 @@ class ESP32S2ROM(ESP32ROM): USB_RAM_BLOCK = 0x800 # Max block size USB-OTG is used GPIO_STRAP_REG = 0x3F404038 - GPIO_STRAP_SPI_BOOT_MASK = 0x8 # Not download mode + GPIO_STRAP_SPI_BOOT_MASK = 1 << 3 # Not download mode RTC_CNTL_OPTION1_REG = 0x3F408128 RTC_CNTL_FORCE_DOWNLOAD_BOOT_MASK = 0x1 # Is download mode forced over USB? + RTCCNTL_BASE_REG = 0x3F408000 + RTC_CNTL_WDTCONFIG0_REG = RTCCNTL_BASE_REG + 0x0094 + RTC_CNTL_WDTCONFIG1_REG = RTCCNTL_BASE_REG + 0x0098 + RTC_CNTL_WDTWPROTECT_REG = RTCCNTL_BASE_REG + 0x00AC + RTC_CNTL_WDT_WKEY = 0x50D83AA1 + MEMORY_MAP = [ [0x00000000, 0x00010000, "PADDING"], [0x3F000000, 0x3FF80000, "DROM"], @@ -2045,34 +2051,26 @@ def _post_connect(self): if self.uses_usb(): self.ESP_RAM_BLOCK = self.USB_RAM_BLOCK - def _check_if_can_reset(self): - """ - Check the strapping register to see if we can reset out of download mode. - """ - if os.getenv("ESPTOOL_TESTING") is not None: - print("ESPTOOL_TESTING is set, ignoring strapping mode check") - # Esptool tests over USB-OTG run with GPIO0 strapped low, - # don't complain in this case. - return - strap_reg = self.read_reg(self.GPIO_STRAP_REG) - force_dl_reg = self.read_reg(self.RTC_CNTL_OPTION1_REG) - if ( - strap_reg & self.GPIO_STRAP_SPI_BOOT_MASK == 0 - and force_dl_reg & self.RTC_CNTL_FORCE_DOWNLOAD_BOOT_MASK == 0 - ): - print( - "WARNING: {} chip was placed into download mode using GPIO0.\n" - "esptool.py can not exit the download mode over USB. " - "To run the app, reset the chip manually.\n" - "To suppress this note, set --after option to 'no_reset'.".format( - self.get_chip_description() - ) - ) - raise SystemExit(1) + def rtc_wdt_reset(self): + print("Hard resetting with RTC WDT...") + self.write_reg(self.RTC_CNTL_WDTWPROTECT_REG, self.RTC_CNTL_WDT_WKEY) # unlock + self.write_reg(self.RTC_CNTL_WDTCONFIG1_REG, 5000) # set WDT timeout + self.write_reg( + self.RTC_CNTL_WDTCONFIG0_REG, (1 << 31) | (5 << 28) | (1 << 8) | 2 + ) # enable WDT + self.write_reg(self.RTC_CNTL_WDTWPROTECT_REG, 0) # lock def hard_reset(self): if self.uses_usb(): - self._check_if_can_reset() + # Check the strapping register to see if we can perform RTC WDT reset + strap_reg = self.read_reg(self.GPIO_STRAP_REG) + force_dl_reg = self.read_reg(self.RTC_CNTL_OPTION1_REG) + if ( + strap_reg & self.GPIO_STRAP_SPI_BOOT_MASK == 0 # GPIO0 low + and force_dl_reg & self.RTC_CNTL_FORCE_DOWNLOAD_BOOT_MASK == 0 + ): + self.rtc_wdt_reset() + return print('Hard resetting via RTS pin...') self._setRTS(True) # EN->LOW