Skip to content

Commit 0228f57

Browse files
committed
Display user-friendly error if baud rate unsupported by driver
Closes #102
1 parent 1ee84ca commit 0228f57

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

esptool.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,13 @@ def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD):
178178
# CH341 driver on some Linux versions (this opens at 9600 then
179179
# sets), shouldn't matter for other platforms/drivers. See
180180
# https://github.com/espressif/esptool/issues/44#issuecomment-107094446
181-
self._port.baudrate = baud
181+
self._set_port_baudrate(baud)
182+
183+
def _set_port_baudrate(self, baud):
184+
try:
185+
self._port.baudrate = baud
186+
except IOError:
187+
raise FatalError("Failed to set baud rate %d. The driver may not support this rate." % baud)
182188

183189
@staticmethod
184190
def detect_chip(port=DEFAULT_PORT, baud=ESP_ROM_BAUD, connect_mode='default_reset'):
@@ -529,7 +535,7 @@ def change_baud(self, baud):
529535
print("Changing baud rate to %d" % baud)
530536
self.command(self.ESP_CHANGE_BAUDRATE, struct.pack('<II', baud, 0))
531537
print("Changed.")
532-
self._port.baudrate = baud
538+
self._set_port_baudrate(baud)
533539
time.sleep(0.05) # get rid of crap sent during baud rate change
534540
self.flush_input()
535541

0 commit comments

Comments
 (0)