Skip to content

Commit

Permalink
Display user-friendly error if baud rate unsupported by driver
Browse files Browse the repository at this point in the history
Closes #102
  • Loading branch information
projectgus committed Jun 14, 2017
1 parent 1ee84ca commit 0228f57
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions esptool.py
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,13 @@ def __init__(self, port=DEFAULT_PORT, baud=ESP_ROM_BAUD):
# CH341 driver on some Linux versions (this opens at 9600 then
# sets), shouldn't matter for other platforms/drivers. See
# https://github.com/espressif/esptool/issues/44#issuecomment-107094446
self._port.baudrate = baud
self._set_port_baudrate(baud)

def _set_port_baudrate(self, baud):
try:
self._port.baudrate = baud
except IOError:
raise FatalError("Failed to set baud rate %d. The driver may not support this rate." % baud)

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

Expand Down

0 comments on commit 0228f57

Please sign in to comment.