Skip to content

Commit

Permalink
fix(CH9102F): Suggest to install new serial drivers if writing to RAM…
Browse files Browse the repository at this point in the history
… fails
  • Loading branch information
radimkarnis committed Jun 8, 2023
1 parent d984647 commit f4b5914
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
11 changes: 10 additions & 1 deletion esptool/__init__.py
Expand Up @@ -713,7 +713,16 @@ def add_spi_flash_subparsers(parent, allow_keep, auto_detect):
)
args.no_stub = True
else:
esp = esp.run_stub()
try:
esp = esp.run_stub()
except Exception:
# The CH9102 bridge (PID: 0x55D4) can have issues on MacOS
if sys.platform == "darwin" and esp._get_pid() == 0x55D4:
print(
"\nNote: If issues persist, "
"try installing the WCH USB-to-Serial MacOS driver."
)
raise

if args.override_vddsdio:
esp.override_vddsdio(args.override_vddsdio)
Expand Down
9 changes: 7 additions & 2 deletions esptool/loader.py
Expand Up @@ -295,6 +295,7 @@ def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD, trace_enabled=False):
"flash_id": None,
"chip_id": None,
"uart_no": None,
"usb_pid": None,
}

if isinstance(port, str):
Expand Down Expand Up @@ -475,6 +476,9 @@ def sync(self):
self.sync_stub_detected &= val == 0

def _get_pid(self):
if self.cache["usb_pid"] is not None:
return self.cache["usb_pid"]

if list_ports is None:
print(
"\nListing all serial ports is currently not available. "
Expand Down Expand Up @@ -502,10 +506,11 @@ def _get_pid(self):
ports = list_ports.comports()
for p in ports:
if p.device in active_ports:
self.cache["usb_pid"] = p.pid
return p.pid
print(
"\nFailed to get PID of a device on {}, "
"using standard reset sequence.".format(active_port)
f"\nFailed to get PID of a device on {active_port}, "
"using standard reset sequence."
)

def _connect_attempt(self, reset_strategy, mode="default_reset"):
Expand Down

0 comments on commit f4b5914

Please sign in to comment.