Skip to content

Commit

Permalink
tools/pyboard.py: Add "soft_reset" option to Pyboard.enter_raw_repl().
Browse files Browse the repository at this point in the history
Signed-off-by: Damien George <damien@micropython.org>
  • Loading branch information
dpgeorge committed May 29, 2021
1 parent 4982d09 commit e4ba57c
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions tools/pyboard.py
Expand Up @@ -322,7 +322,7 @@ def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None):
time.sleep(0.01)
return data

def enter_raw_repl(self):
def enter_raw_repl(self, soft_reset=True):
self.serial.write(b"\r\x03\x03") # ctrl-C twice: interrupt any running program

# flush input (without relying on serial.flushInput())
Expand All @@ -332,18 +332,23 @@ def enter_raw_repl(self):
n = self.serial.inWaiting()

self.serial.write(b"\r\x01") # ctrl-A: enter raw REPL
data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n>")
if not data.endswith(b"raw REPL; CTRL-B to exit\r\n>"):
print(data)
raise PyboardError("could not enter raw repl")

self.serial.write(b"\x04") # ctrl-D: soft reset
data = self.read_until(1, b"soft reboot\r\n")
if not data.endswith(b"soft reboot\r\n"):
print(data)
raise PyboardError("could not enter raw repl")
# By splitting this into 2 reads, it allows boot.py to print stuff,
# which will show up after the soft reboot and before the raw REPL.
if soft_reset:
data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n>")
if not data.endswith(b"raw REPL; CTRL-B to exit\r\n>"):
print(data)
raise PyboardError("could not enter raw repl")

self.serial.write(b"\x04") # ctrl-D: soft reset

# Waiting for "soft reboot" independently to "raw REPL" (done below)
# allows boot.py to print, which will show up after "soft reboot"
# and before "raw REPL".
data = self.read_until(1, b"soft reboot\r\n")
if not data.endswith(b"soft reboot\r\n"):
print(data)
raise PyboardError("could not enter raw repl")

data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n")
if not data.endswith(b"raw REPL; CTRL-B to exit\r\n"):
print(data)
Expand Down

0 comments on commit e4ba57c

Please sign in to comment.