Skip to content

Commit 1b15738

Browse files
radimkarnisdobairoland
authored andcommitted
feat(hard_reset): Support custom hard reset sequence configuration
Closes espressif#1004
1 parent 6abd05d commit 1b15738

File tree

9 files changed

+33
-17
lines changed

9 files changed

+33
-17
lines changed

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/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/esp32c5.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
from .esp32c6 import ESP32C6ROM
1010
from ..loader import ESPLoader
11-
from ..reset import HardReset
1211
from ..util import FatalError
1312

1413

@@ -128,8 +127,7 @@ def get_crystal_freq_rom_expect(self):
128127
) >> self.PCR_SYSCLK_XTAL_FREQ_S
129128

130129
def hard_reset(self):
131-
print("Hard resetting via RTS pin...")
132-
HardReset(self._port, self.uses_usb_jtag_serial())()
130+
ESPLoader.hard_reset(self, self.uses_usb_jtag_serial())
133131

134132
def change_baud(self, baud):
135133
if not self.IS_STUB:

esptool/targets/esp32s2.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from .esp32 import ESP32ROM
1111
from ..loader import ESPLoader
12-
from ..reset import HardReset
1312
from ..util import FatalError, NotImplementedInROMError
1413

1514

@@ -310,8 +309,7 @@ def hard_reset(self):
310309
if uses_usb_otg:
311310
self._check_if_can_reset()
312311

313-
print("Hard resetting via RTS pin...")
314-
HardReset(self._port, uses_usb_otg)()
312+
ESPLoader.hard_reset(self, uses_usb_otg)
315313

316314
def change_baud(self, baud):
317315
ESPLoader.change_baud(self, baud)

esptool/targets/esp32s3.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99

1010
from .esp32 import ESP32ROM
1111
from ..loader import ESPLoader
12-
from ..reset import HardReset
1312
from ..util import FatalError, NotImplementedInROMError
1413

1514

@@ -382,8 +381,7 @@ def hard_reset(self):
382381
# Skip if response was not valid and proceed to reset; e.g. when monitoring while resetting
383382
pass
384383

385-
print("Hard resetting via RTS pin...")
386-
HardReset(self._port, uses_usb_otg)()
384+
ESPLoader.hard_reset(self, uses_usb_otg)
387385

388386
def change_baud(self, baud):
389387
ESPLoader.change_baud(self, baud)

test/test_esptool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1604,7 +1604,7 @@ def test_custom_reset_sequence(self):
16041604
with self.ConfigFile(config_file_path, invalid_reset_seq_config):
16051605
output = self.run_esptool_error("flash_id")
16061606
assert f"Loaded custom configuration from {config_file_path}" in output
1607-
assert 'Invalid "custom_reset_sequence" option format:' in output
1607+
assert "Invalid custom reset sequence option format:" in output
16081608

16091609
def test_open_port_attempts(self):
16101610
# Test that the open_port_attempts option is loaded correctly

0 commit comments

Comments
 (0)