Skip to content
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

retry to enter raw repl #40

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
13 changes: 10 additions & 3 deletions microfs.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def flush_to_msg(serial, msg):
if not data.endswith(msg):
if COMMAND_LINE_FLAG:
print(data)
raise IOError("Could not enter raw REPL.")
raise IOError("Could not enter raw REPL. %s" % data)

def flush(serial):
"""Flush all rx input without relying on serial.flushInput()."""
Expand All @@ -87,8 +87,15 @@ def flush(serial):
time.sleep(0.01)
flush(serial)
# Go into raw mode with CTRL-A.
serial.write(b"\r\x01")
flush_to_msg(serial, raw_repl_msg)
for i in range(3):
# retry to enter raw repl
try:
serial.write(b"\r\x01")
flush_to_msg(serial, raw_repl_msg)
break
except Exception as ex:
if i == 2: # retrying did not help
raise ex
# Soft Reset with CTRL-D
serial.write(b"\x04")
flush_to_msg(serial, b"soft reboot\r\n")
Expand Down