Skip to content

Commit e4ba57c

Browse files
committed
tools/pyboard.py: Add "soft_reset" option to Pyboard.enter_raw_repl().
Signed-off-by: Damien George <[email protected]>
1 parent 4982d09 commit e4ba57c

File tree

1 file changed

+17
-12
lines changed

1 file changed

+17
-12
lines changed

tools/pyboard.py

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -322,7 +322,7 @@ def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None):
322322
time.sleep(0.01)
323323
return data
324324

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

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

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

340-
self.serial.write(b"\x04") # ctrl-D: soft reset
341-
data = self.read_until(1, b"soft reboot\r\n")
342-
if not data.endswith(b"soft reboot\r\n"):
343-
print(data)
344-
raise PyboardError("could not enter raw repl")
345-
# By splitting this into 2 reads, it allows boot.py to print stuff,
346-
# which will show up after the soft reboot and before the raw REPL.
336+
if soft_reset:
337+
data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n>")
338+
if not data.endswith(b"raw REPL; CTRL-B to exit\r\n>"):
339+
print(data)
340+
raise PyboardError("could not enter raw repl")
341+
342+
self.serial.write(b"\x04") # ctrl-D: soft reset
343+
344+
# Waiting for "soft reboot" independently to "raw REPL" (done below)
345+
# allows boot.py to print, which will show up after "soft reboot"
346+
# and before "raw REPL".
347+
data = self.read_until(1, b"soft reboot\r\n")
348+
if not data.endswith(b"soft reboot\r\n"):
349+
print(data)
350+
raise PyboardError("could not enter raw repl")
351+
347352
data = self.read_until(1, b"raw REPL; CTRL-B to exit\r\n")
348353
if not data.endswith(b"raw REPL; CTRL-B to exit\r\n"):
349354
print(data)

0 commit comments

Comments
 (0)