8000 tools/pyboard.py: Fix RTS esp32 lockups. by NoosaHydro · Pull Request #13455 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

tools/pyboard.py: Fix RTS esp32 lockups. #13455

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 32 additions & 2 deletions tools/mpremote/mpremote/transport_serial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -90,7 +97,30 @@ def __init__(self, device, baudrate=115200, wait=0, exclusive=True):
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:
Expand Down
34 changes: 32 additions & 2 deletions tools/pyboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,14 @@ def inWaiting(self):

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
Expand Down Expand Up @@ -300,7 +307,30 @@ def __init__(
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:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No port reset on Windows ?

# 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:
Expand Down
0