From 075e255dbd21960bdaaf953f5eee8662ca2c6aae Mon Sep 17 00:00:00 2001 From: gitcnd Date: Wed, 17 Jan 2024 14:50:05 +0000 Subject: [PATCH 1/3] tools/pyboard.py: Fix RTS esp32 lockups. Signed-off-by: gitcnd --- tools/pyboard.py | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/pyboard.py b/tools/pyboard.py index c422b64ac5..5180ec8da5 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -265,7 +265,14 @@ class ProcessPtyToTerminal: class Pyboard: def __init__( - self, device, baudrate=115200, user="micro", password="python", wait=0, exclusive=True + self, + device, + baudrate=115200, + user="micro", + password="python", + wait=0, + exclusive=True, + hard_reset=False, ): self.in_raw_repl = False self.use_raw_paste = True @@ -300,7 +307,30 @@ class Pyboard: self.serial.rts = False # RTS False = EN High = MCU enabled self.serial.open() else: - self.serial = serial.Serial(device, **serial_kwargs) + # Must not put device in .Serial(), else RTS line locks up ESP8266/ESP32 + self.serial = serial.Serial() + self.serial.dtr = False # DTR False = gpio0 High = Normal boot + self.serial.rts = False # RTS False = EN High = MCU enabled + self.serial.port = device + self.serial.baudrate = serial_kwargs["baudrate"] + # Do not use hardware flow control (rts used for MCU reset) + self.serial.rtscts = 0 + # Do not use hardware flow control (dtr used for gpio0) + self.serial.dsrdtr = 0 + self.serial.inter_byte_timeout = serial_kwargs["interCharTimeout"] + if "exclusive" in serial_kwargs: + self.serial.exclusive = serial_kwargs["exclusive"] + self.serial.open() + + if hard_reset: + # pause ( the above open() only just pulled the line low ) + time.sleep(0.2) + # this is reset (setting this "high" resets MCU boards that use RTS/CTS for flashing) + self.serial.rts = True + time.sleep(0.2) + self.serial.rts = False + # must wait for the reset, otherwise subsequent commands (the ctrl-A) get lost + time.sleep(2.0) break except (OSError, IOError): # Py2 and Py3 have different errors if wait == 0: From bf57f9eeb5c3dfebe5675eeba89ab330b39019d7 Mon Sep 17 00:00:00 2001 From: gitcnd Date: Wed, 17 Jan 2024 14:54:00 +0000 Subject: [PATCH 2/3] tools/pyboard.py: Fix RTS esp32 lockups. Signed-off-by: gitcnd --- tools/pyboard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/pyboard.py b/tools/pyboard.py index 5180ec8da5..a74508c958 100755 --- a/tools/pyboard.py +++ b/tools/pyboard.py @@ -307,7 +307,7 @@ class Pyboard: self.serial.rts = False # RTS False = EN High = MCU enabled self.serial.open() else: - # Must not put device in .Serial(), else RTS line locks up ESP8266/ESP32 + # Must not put device in .Serial(), else RTS line locks up ESP8266/ESP32 self.serial = serial.Serial() self.serial.dtr = False # DTR False = gpio0 High = Normal boot self.serial.rts = False # RTS False = EN High = MCU enabled From 09125942e2f415dc0457eaf41afc9b5fa73866da Mon Sep 17 00:00:00 2001 From: gitcnd Date: Wed, 17 Jan 2024 14:55:57 +0000 Subject: [PATCH 3/3] tools/mpremote/mpremote/transport_serial.py: Fix RTS esp32 lockups. Signed-off-by: gitcnd --- tools/mpremote/mpremote/transport_serial.py | 34 +++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/tools/mpremote/mpremote/transport_serial.py b/tools/mpremote/mpremote/transport_serial.py index 3b4cd00078..75a34102bb 100644 --- a/tools/mpremote/mpremote/transport_serial.py +++ b/tools/mpremote/mpremote/transport_serial.py @@ -59,7 +59,14 @@ def reraise_filesystem_error(e, info): class SerialTransport(Transport): - def __init__(self, device, baudrate=115200, wait=0, exclusive=True): + def __init__( + self, + device, + baudrate=115200, + wait=0, + exclusive=True, + hard_reset=False, + ): self.in_raw_repl = False self.use_raw_paste = True self.device_name = device @@ -90,7 +97,30 @@ class SerialTransport(Transport): self.serial.rts = False # RTS False = EN High = MCU enabled self.serial.open() else: - self.serial = serial.Serial(device, **serial_kwargs) + # Must not put device in .Serial(), else rts locks up ESP8266/ESP32 + self.serial = serial.Serial() + self.serial.dtr = False # DTR False = gpio0 High = Normal boot + self.serial.rts = False # RTS False = EN High = MCU enabled + self.serial.port = device + self.serial.baudrate = serial_kwargs["baudrate"] + # Do not use hardware flow control (rts used for MCU reset) + self.serial.rtscts = 0 + # Do not use hardware flow control (dtr used for gpio0) + self.serial.dsrdtr = 0 + self.serial.inter_byte_timeout = serial_kwargs["interCharTimeout"] + if "exclusive" in serial_kwargs: + self.serial.exclusive = serial_kwargs["exclusive"] + self.serial.open() + + if hard_reset: + # pause ( the above open() only just pulled the line low ) + time.sleep(0.2) + # this is reset (setting this "high" resets MCU boards that use RTS/CTS for flashing) + self.serial.rts = True + time.sleep(0.2) + self.serial.rts = False + # must wait for the reset, otherwise subsequent commands (the ctrl-A) get lost + time.sleep(2.0) break except OSError: if wait == 0: