Skip to content

Commit 05553a4

Browse files
committed
fix(autodetection): Remove the Unsupported detection protocol stage
1 parent 07879eb commit 05553a4

File tree

6 files changed

+27
-30
lines changed

6 files changed

+27
-30
lines changed

docs/en/espefuse/dump-cmd.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ The order of registers in the dump:
3434
3535
> espefuse.py dump
3636
37-
Detecting chip type... Unsupported detection protocol, switching and trying again...
38-
Connecting....
37+
Connecting.........
3938
Detecting chip type... ESP32
4039
BLOCK0 ( ) [0 ] read_regs: 00000000 7e5a6e58 00e294b9 0000a200 00000333 00100000 00000004
4140
BLOCK1 (flash_encryption) [1 ] read_regs: 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000

docs/en/espefuse/summary-cmd.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,6 @@ Save Json Format Summary To File
109109
110110
> espefuse.py summary --format json --file efuses.json
111111
112-
Connecting..........
113-
Detecting chip type... Unsupported detection protocol, switching and trying again...
114112
Connecting....
115113
Detecting chip type... ESP32
116114

esptool/cmds.py

Lines changed: 23 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ def check_if_stub(instance: ESPLoader) -> ESPLoader:
128128
This way we use one memory read and compare it to the magic number for each chip.
129129
"""
130130
try:
131-
log.print("Detecting chip type...", end="")
131+
log.print("Detecting chip type...", end="", flush=True)
132132
chip_id = detect_port.get_chip_id()
133133
for cls in ROM_LIST:
134134
# cmd not supported on ESP8266 and ESP32 + ESP32-S2 doesn't return chip-id
@@ -147,39 +147,41 @@ def check_if_stub(instance: ESPLoader) -> ESPLoader:
147147
break
148148
else:
149149
err_msg = f"Unexpected chip ID value {chip_id}."
150-
except (UnsupportedCommandError, struct.error, FatalError) as e:
150+
except (UnsupportedCommandError, struct.error, FatalError):
151151
# UnsupportedCommandError: ESP8266/ESP32 ROM
152152
# struct.error: ESP32-S2
153153
# FatalError: ESP8266/ESP32 STUB
154-
log.print(" Unsupported detection protocol, switching and trying again...")
155154
try:
156-
# ESP32/ESP8266 are reset after an unsupported command, need to reconnect
157-
# (not needed on ESP32-S2)
158-
if not isinstance(e, struct.error):
159-
detect_port.connect(
160-
connect_mode, connect_attempts, detecting=True, warnings=False
161-
)
162-
log.print("Detecting chip type...", end="", flush=True)
163155
chip_magic_value = detect_port.read_reg(
164156
ESPLoader.CHIP_DETECT_MAGIC_REG_ADDR
165157
)
166-
167-
for cls in ROM_LIST:
168-
if not cls.USES_MAGIC_VALUE:
169-
continue
170-
if chip_magic_value == cls.MAGIC_VALUE:
171-
inst = cls(detect_port._port, baud, trace_enabled=trace_enabled)
172-
inst = check_if_stub(inst)
173-
inst._post_connect()
174-
break
175-
else:
176-
err_msg = f"Unexpected chip magic value {chip_magic_value:#010x}."
177158
except UnsupportedCommandError:
178159
raise FatalError(
179160
"Unsupported Command Error received. "
180161
"Probably this means Secure Download Mode is enabled, "
181162
"autodetection will not work. Need to manually specify the chip."
182163
)
164+
except FatalError:
165+
log.print(" Autodetection failed, trying again...")
166+
detect_port.connect(
167+
connect_mode, connect_attempts, detecting=True, warnings=False
168+
)
169+
log.print("Detecting chip type...", end="", flush=True)
170+
chip_magic_value = detect_port.read_reg(
171+
ESPLoader.CHIP_DETECT_MAGIC_REG_ADDR
172+
)
173+
174+
for cls in ROM_LIST:
175+
if not cls.USES_MAGIC_VALUE:
176+
continue
177+
if chip_magic_value == cls.MAGIC_VALUE:
178+
inst = cls(detect_port._port, baud, trace_enabled=trace_enabled)
179+
inst = check_if_stub(inst)
180+
inst._post_connect()
181+
break
182+
else:
183+
err_msg = f"Unexpected chip magic value {chip_magic_value:#010x}."
184+
183185
if inst is not None:
184186
return inst
185187

esptool/loader.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -509,7 +509,8 @@ def command(
509509
if byte(data, 0) != 0 and byte(data, 1) == self.ROM_INVALID_RECV_MSG:
510510
# Unsupported read_reg can result in
511511
# more than one error response for some reason
512-
self.flush_input()
512+
time.sleep(0.2) # Wait for input buffer to fill
513+
self.flush_input() # Flush input buffer of hanging response
513514
raise UnsupportedCommandError(self, op)
514515

515516
finally:

test/test_esptool.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,8 +1379,6 @@ def test_flash_header_no_magic_no_rewrite(self):
13791379
class TestAutoDetect(EsptoolTestCase):
13801380
def _check_output(self, output):
13811381
expected_chip_name = esptool.util.expand_chip_name(arg_chip)
1382-
if arg_chip not in ["esp8266", "esp32", "esp32s2"]:
1383-
assert "Unsupported detection protocol" not in output
13841382
assert f"Detecting chip type... {expected_chip_name}" in output
13851383
assert f"{'Chip type:':<20}{expected_chip_name}" in output
13861384

test/test_esptool_sdm.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,8 @@ def test_auto_detect(self):
3131

3232
if arg_chip == "esp32s2": # no autodetection from security info, only magic no.
3333
assert "Secure Download Mode is enabled" in output
34-
assert "Unsupported detection protocol" in output
34+
assert "autodetection will not work" in output
3535
else:
36-
assert "Unsupported detection protocol" not in output
3736
assert f"Detecting chip type... {self.expected_chip_name}" in output
3837
assert (
3938
f"{'Chip type:':<20}{self.expected_chip_name} "

0 commit comments

Comments
 (0)