Skip to content

Stop losing USB console output on Zephyr boards - #11586

Merged
tannewt merged 1 commit into
adafruit:mainfrom
mikeysklar:usb-console-tx-drop
Oct 13, 2026
Merged

tannewt merged 1 commit into
adafruit:mainfrom
mikeysklar:usb-console-tx-drop

Conversation

@mikeysklar

Copy link
Copy Markdown
Collaborator

What

While a terminal is open, the USB console now waits instead of dropping output.

Why

A long print lost about 800 characters with a terminal reading.

TinyUSB ports only drop output when no terminal is open.

The lost USB output mentioned in #11578.

Tests

nRF54LM20 DK, Linux host.

Test main This PR
print('L' * 20000), port open lost 712-818 chars, 0/5 complete 5/5 complete
Ctrl-C during a print loop 4/5 5/5
Close the port mid-print, reopen 3/3 prompt 5/5 prompt
Unplug USB mid-print, replug, Ctrl-C 3/3 prompt 3/3 KeyboardInterrupt
Reset with the port closed, code.py prints 120 KB 3/3 finishes 5/5 finishes

Pico W (raspberrypi_rpi_pico_w_zephyr, no VBUS detection), 20000 characters as 20 prints of 1000:

Test Before This PR
Long print, port open 3/3 complete 3/3 complete
Ctrl-C during a print loop 3/3 3/3
Close the port mid-print, reopen 3/3 prompt 3/3 prompt
Power cycle with the port closed, then open not run 5/5 prompt

Not tested: host suspend with the port open.

usb_cdc.data is unchanged and still drops when full.

Written with Claude; tested on hardware by me.

🤖 Generated with Claude Code

The CDC ACM driver drops poll_out bytes when its TX buffer is full and
flow control is off, so a long print lost a few hundred characters even
with a terminal reading. Turn the driver flow control on for the console
while USB is configured, not suspended, and the host holds DTR, and off
otherwise. This matches TinyUSB, which only overwrites its TX FIFO when
the host is not connected, so a closed, suspended or unplugged port
still never blocks output.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>

@tannewt tannewt left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

@tannewt
tannewt merged commit 72cd3ff into adafruit:main Oct 13, 2026
48 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants