From 8394333cab3ad4f0627a7d4931ba833815b8d3d7 Mon Sep 17 00:00:00 2001 From: Johny Mattsson Date: Thu, 2 Jul 2015 20:09:32 +1000 Subject: [PATCH] Pull in upstream fixes for getting board into flash mode. --- tools/esptool.py | 56 +++++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 31 deletions(-) diff --git a/tools/esptool.py b/tools/esptool.py index 53e10041..17311fb5 100755 --- a/tools/esptool.py +++ b/tools/esptool.py @@ -128,38 +128,32 @@ class ESPROM: def connect(self): print 'Connecting...' - # RTS = CH_PD (i.e reset) - # DTR = GPIO0 - # self._port.setRTS(True) - # self._port.setDTR(True) - # self._port.setRTS(False) - # time.sleep(0.1) - # self._port.setDTR(False) + for _ in xrange(4): + # issue reset-to-bootloader: + # RTS = either CH_PD or nRESET (both active low = chip in reset) + # DTR = GPIO0 (active low = boot to flasher) + self._port.setDTR(False) + self._port.setRTS(True) + time.sleep(0.05) + self._port.setDTR(True) + self._port.setRTS(False) + time.sleep(0.05) + self._port.setDTR(False) - # NodeMCU devkit - self._port.setRTS(True) - self._port.setDTR(True) - time.sleep(0.1) - self._port.setRTS(False) - self._port.setDTR(False) - time.sleep(0.1) - self._port.setRTS(True) - time.sleep(0.1) - self._port.setDTR(True) - self._port.setRTS(False) - time.sleep(0.3) - self._port.setDTR(True) - - self._port.timeout = 0.5 - for i in xrange(10): - try: - self._port.flushInput() - self._port.flushOutput() - self.sync() - self._port.timeout = 5 - return - except: - time.sleep(0.1) + self._port.timeout = 0.3 # worst-case latency timer should be 255ms (probably <20ms) + for _ in xrange(4): + try: + self._port.flushInput() + self._port.flushOutput() + self.sync() + self._port.timeout = 5 + return + except: + time.sleep(0.05) + # this is a workaround for the CH340 serial driver on current versions of Linux, + # which seems to sometimes set the serial port up with wrong parameters + self._port.close() + self._port.open() raise Exception('Failed to connect') """ Read memory address in target """