Skip to content

Commit e13d573

Browse files
authored
Merge branch 'espressif:master' into pioarduino
2 parents a8de5b6 + 8298cdc commit e13d573

File tree

17 files changed

+257
-93
lines changed

17 files changed

+257
-93
lines changed

.gitlab-ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -297,6 +297,8 @@ target_esp32s2_usbcdc:
297297
extends: .target_esptool_test
298298
tags:
299299
- esptool_esp32s2_cdc_target
300+
variables:
301+
ESPTOOL_TEST_USB_OTG: "1"
300302
script:
301303
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S2_USBCDC --chip esp32s2 --baud 115200
302304

@@ -347,6 +349,8 @@ target_esp32s3_usbcdc:
347349
extends: .target_esptool_test
348350
tags:
349351
- esptool_esp32s3_cdc_target
352+
variables:
353+
ESPTOOL_TEST_USB_OTG: "1"
350354
script:
351355
- coverage run --parallel-mode -m pytest ${CI_PROJECT_DIR}/test/test_esptool.py --port /dev/serial_ports/ESP32S3_USBCDC --chip esp32s3 --baud 115200
352356

docs/en/esptool/advanced-options.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ The ``--after`` argument allows you to specify whether the chip should be reset
3131

3232
.. list::
3333

34-
* ``--after hard_reset`` is the default. The DTR serial control line is used to reset the chip into a normal boot sequence.
35-
:esp8266:* ``--after soft_reset`` This runs the user firmware, but any subsequent reset will return to the serial bootloader. This was the reset behaviour in esptool v1.x.
34+
* ``--after hard_reset`` is the default. The RTS serial control line is used to reset the chip into a normal boot sequence.
35+
:esp8266: * ``--after soft_reset`` runs the user firmware, but any subsequent reset will return to the serial bootloader. This was the reset behaviour in esptool v1.x.
3636
* ``--after no_reset`` leaves the chip in the serial bootloader, no reset is performed.
3737
* ``--after no_reset_stub`` leaves the chip in the stub bootloader, no reset is performed.
3838

docs/en/esptool/configuration-file.rst

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,19 @@ Complete list of configurable options:
111111
+------------------------------+-----------------------------------------------------------+----------+
112112
| custom_reset_sequence | Custom reset sequence for resetting into the bootloader | |
113113
+------------------------------+-----------------------------------------------------------+----------+
114+
| custom_hard_reset_sequence | Custom reset sequence for hard resetting the chip | |
115+
+------------------------------+-----------------------------------------------------------+----------+
114116

115-
Custom Reset Sequence
116-
---------------------
117+
Custom Reset Sequences
118+
----------------------
117119

118120
The ``custom_reset_sequence`` configuration option allows you to define a reset sequence which will get
119121
used when an :ref:`automatic reset into the serial bootloader <automatic-bootloader>` is performed.
120122

121-
The sequence is defined with a string in the following format:
123+
The ``custom_hard_reset_sequence`` option allows you to define a reset sequence which will get
124+
used when a hard reset (a reset out of the bootloader) is performed.
125+
126+
A sequence is defined with a string in the following format:
122127

123128
- Consists of individual commands divided by ``|`` (e.g. ``R0|D1|W0.5``).
124129
- Commands (e.g. ``R0``) are defined by a code (``R``) and an argument (``0``).
@@ -148,3 +153,11 @@ For example: ``D0|R1|W0.1|D1|R0|W0.5|D0`` represents the following classic reset
148153
_setRTS(False) # EN=HIGH, chip out of reset
149154
time.sleep(0.05)
150155
_setDTR(False) # IO0=HIGH, done
156+
157+
Similarly, ``R1|W0.1|R0`` represents the classic hard reset sequence:
158+
159+
.. code-block:: python
160+
161+
_setRTS(True) # EN=LOW, chip in reset
162+
time.sleep(0.1)
163+
_setRTS(False) # EN=HIGH, chip out of reset

esp_rfc2217_server/esp_port_manager.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,11 @@ def _hard_reset_thread(self):
7474
"""
7575
if self.logger:
7676
self.logger.info("Activating hard reset in thread")
77-
HardReset(self.serial)()
77+
cfg_custom_hard_reset_sequence = cfg.get("custom_hard_reset_sequence")
78+
if cfg_custom_hard_reset_sequence is not None:
79+
CustomReset(self.serial, cfg_custom_hard_reset_sequence)()
80+
else:
81+
HardReset(self.serial)()
7882

7983
def _reset_thread(self):
8084
"""

esptool/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"merge_bin",
1919
"read_flash",
2020
"read_flash_status",
21+
"read_flash_sfdp",
2122
"read_mac",
2223
"read_mem",
2324
"run",

esptool/config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"reset_delay",
2222
"open_port_attempts",
2323
"custom_reset_sequence",
24+
"custom_hard_reset_sequence",
2425
]
2526

2627

esptool/loader.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1525,9 +1525,13 @@ def get_crystal_freq(self):
15251525
)
15261526
return norm_xtal
15271527

1528-
def hard_reset(self):
1528+
def hard_reset(self, uses_usb=False):
15291529
print("Hard resetting via RTS pin...")
1530-
HardReset(self._port)()
1530+
cfg_custom_hard_reset_sequence = cfg.get("custom_hard_reset_sequence")
1531+
if cfg_custom_hard_reset_sequence is not None:
1532+
CustomReset(self._port, cfg_custom_hard_reset_sequence)()
1533+
else:
1534+
HardReset(self._port, uses_usb)()
15311535

15321536
def soft_reset(self, stay_in_bootloader):
15331537
if not self.IS_STUB:

esptool/reset.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,5 +205,5 @@ def _parse_string_to_seq(self, seq_str):
205205
cmds = seq_str.split("|")
206206
fn_calls_list = [self.format_dict[cmd[0]].format(cmd[1:]) for cmd in cmds]
207207
except Exception as e:
208-
raise FatalError(f'Invalid "custom_reset_sequence" option format: {e}')
208+
raise FatalError(f"Invalid custom reset sequence option format: {e}")
209209
return "\n".join(fn_calls_list)

esptool/targets/esp32c2.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2014-2022 Fredrik Ahlberg, Angus Gratton,
1+
# SPDX-FileCopyrightText: 2014-2024 Fredrik Ahlberg, Angus Gratton,
22
# Espressif Systems (Shanghai) CO LTD, other contributors as noted.
33
#
44
# SPDX-License-Identifier: GPL-2.0-or-later
@@ -63,6 +63,12 @@ class ESP32C2ROM(ESP32C3ROM):
6363
[0x4037C000, 0x403C0000, "IRAM"],
6464
]
6565

66+
RTCCNTL_BASE_REG = 0x60008000
67+
RTC_CNTL_WDTCONFIG0_REG = RTCCNTL_BASE_REG + 0x0084
68+
RTC_CNTL_WDTCONFIG1_REG = RTCCNTL_BASE_REG + 0x0088
69+
RTC_CNTL_WDTWPROTECT_REG = RTCCNTL_BASE_REG + 0x009C
70+
RTC_CNTL_WDT_WKEY = 0x50D83AA1
71+
6672
UF2_FAMILY_ID = 0x2B88D29C
6773

6874
KEY_PURPOSES: Dict[int, str] = {}
@@ -130,6 +136,9 @@ def _post_connect(self):
130136
self.stub_is_disabled = True
131137
self.IS_STUB = False
132138

139+
def hard_reset(self):
140+
ESPLoader.hard_reset(self)
141+
133142
""" Try to read (encryption key) and check if it is valid """
134143

135144
def is_flash_encryption_key_valid(self):

esptool/targets/esp32c3.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: 2014-2022 Fredrik Ahlberg, Angus Gratton,
1+
# SPDX-FileCopyrightText: 2014-2024 Fredrik Ahlberg, Angus Gratton,
22
# Espressif Systems (Shanghai) CO LTD, other contributors as noted.
33
#
44
# SPDX-License-Identifier: GPL-2.0-or-later
@@ -83,6 +83,7 @@ class ESP32C3ROM(ESP32ROM):
8383
RTC_CNTL_SWD_WKEY = 0x8F1D312A
8484

8585
RTC_CNTL_WDTCONFIG0_REG = RTCCNTL_BASE_REG + 0x0090
86+
RTC_CNTL_WDTCONFIG1_REG = RTCCNTL_BASE_REG + 0x0094
8687
RTC_CNTL_WDTWPROTECT_REG = RTCCNTL_BASE_REG + 0x00A8
8788
RTC_CNTL_WDT_WKEY = 0x50D83AA1
8889

@@ -252,6 +253,21 @@ def _post_connect(self):
252253
if not self.sync_stub_detected: # Don't run if stub is reused
253254
self.disable_watchdogs()
254255

256+
def hard_reset(self):
257+
if self.uses_usb_jtag_serial():
258+
self.rtc_wdt_reset()
259+
else:
260+
ESPLoader.hard_reset(self)
261+
262+
def rtc_wdt_reset(self):
263+
print("Hard resetting with RTC WDT...")
264+
self.write_reg(self.RTC_CNTL_WDTWPROTECT_REG, self.RTC_CNTL_WDT_WKEY) # unlock
265+
self.write_reg(self.RTC_CNTL_WDTCONFIG1_REG, 5000) # set WDT timeout
266+
self.write_reg(
267+
self.RTC_CNTL_WDTCONFIG0_REG, (1 << 31) | (5 << 28) | (1 << 8) | 2
268+
) # enable WDT
269+
self.write_reg(self.RTC_CNTL_WDTWPROTECT_REG, 0) # lock
270+
255271
def check_spi_connection(self, spi_connection):
256272
if not set(spi_connection).issubset(set(range(0, 22))):
257273
raise FatalError("SPI Pin numbers must be in the range 0-21.")

0 commit comments

Comments
 (0)