Skip to content

Commit d92694c

Browse files
committed
tools: Only issue a single Ctrl-C when entering raw REPL.
A long time ago when there was only the `stm` port, Ctrl-C would trigger a preemptive NLR jump to break out of running code. Then in commit 124df6f a more general approach to asynchronous `KeyboardInterrupt` exceptions was implemented, and `stmhal` supported both approaches, with the general (soft) interrupt taking priority. Then in commit bc1488a `pyboard.py` was updated with a corresponding change to make it issue a double Ctrl-C to break out of any existing code when entering the raw REPL (two Ctrl-C characters were sent in order to more reliably trigger the preemptive NLR jump). No other port has preemptive NLR jumps and so a double Ctrl-C doesn't really behave any differently to a single Ctrl-C: with USB CDC the double Ctrl-C would most likely be in the same USB packet and so processed in the same low-level USB callback, so it's just setting the keyboard interrupt flag twice in a row. The VM/runtime then just sees one keyboard interrupt and acts as though only one Ctrl-C was sent. This commit changes the double Ctrl-C to a single Ctrl-C in `pyboard.py` and `mpremote`. That keeps things as simple as they need to be. Signed-off-by: Damien George <[email protected]>
1 parent 7746785 commit d92694c

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

tools/mpremote/mpremote/transport_serial.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None):
121121
return data
122122

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

126126
# flush input (without relying on serial.flushInput())
127127
n = self.serial.inWaiting()

tools/pyboard.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ def read_until(self, min_num_bytes, ending, timeout=10, data_consumer=None):
348348
return data
349349

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

353353
# flush input (without relying on serial.flushInput())
354354
n = self.serial.inWaiting()

0 commit comments

Comments
 (0)