Skip to content

Connect to CircuitPython without waiting out timeouts - #166

Merged
bdbarnett merged 7 commits into
mainfrom
fix/cp-connect-time
Oct 27, 2026
Merged

bdbarnett merged 7 commits into
mainfrom
fix/cp-connect-time

Conversation

@bdbarnett

Copy link
Copy Markdown
Collaborator

Fixes #155.

CircuitPython rebuilds its VM on every switch between the friendly and the raw REPL (run_repl in main.c), and bytes that arrive during the rebuild are lost. Connect left raw REPL and entered it again straight away, and the first command after connect did the same, so each waited out a 10 s or 8 s timeout for a raw-REPL banner that never came. MicroPython switches at once, which is why it connected in 1.8 s.

What changes:

  • After Ctrl-B on CircuitPython, wait for the friendly prompt before sending anything else.
  • Don't leave and re-enter raw REPL after entering it (the switch that got us there already rebuilt the VM), and stay in raw REPL when connect finishes. Opening the REPL pane leaves it as before.
  • Don't pulse DTR/RTS and wait 1.6 s on Raspberry Pi and Adafruit native-USB ports, which have no ESP32 download mode.
  • MPFTP_TRACE=1 writes each stage of a connect to stderr (mpftp trace +seconds stage), which the desktop app keeps in host.log.

cli/tests/fake_circuitpython.py is a serial port that behaves like CircuitPython 11 (code.py, "Press any key", VM rebuild on mode switch, raw paste). test_cp_connect_time.py holds time and mode-switch budgets against it; they fail on main.

Not measured on a real board yet.

CircuitPython rebuilds its VM on every switch between the friendly and the
raw REPL and drops what arrives meanwhile. Connect left raw REPL and entered
it again at once, and so did the first command after it, so each waited out a
10 s or 8 s timeout for a banner that never came.

- Wait for the friendly prompt after Ctrl-B on CircuitPython.
- Skip the leave-and-reenter toggle after entering raw REPL, and stay in raw
  REPL when connect finishes.
- Don't pulse DTR/RTS or wait 1.6 s on Raspberry Pi and Adafruit native-USB
  ports, which have no ESP32 download mode.
- MPFTP_TRACE=1 writes the stages of a connect to stderr.

Fixes #155
A pipe nobody read filled with trace lines and hung the connect.
…ompt

The REPL pane dropped keys until the board had left raw REPL, which takes
seconds on CircuitPython; it now holds them and sends them once it's there.
The key that wakes CircuitPython's REPL starts a fresh VM, which drops the
next Ctrl-A, so connect waits for the prompt first. The reset step no longer
runs into a try with no time allowed.
… s for raw REPL

A program that stops while the interrupts are still going out takes one of
them as the key that starts the REPL, and the Ctrl-A after it was lost. The
first raw-REPL try also allowed 3.5 s, and an RP2350 takes 3.2 s or more to
answer.
…low stop

A board sometimes misses the key sent straight after "Press any key", and
then sat there until a raw REPL try 6 s later spent its Ctrl-A as the key:
12 to 15 s connects with code.py running. The key now goes again each
second until the prompt shows. And a program that takes longer to stop
than the storm lasts now gets a second to say so, instead of a raw REPL
try that is lost waking the REPL.
@bdbarnett
bdbarnett merged commit 13a24cf into main Oct 27, 2026
8 checks passed
@bdbarnett
bdbarnett deleted the fix/cp-connect-time branch October 27, 2026 15:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

Desktop: connecting to a CircuitPython board takes about 28 s

1 participant