ViezeVingertjes opened a new pull request, #22405:
URL: https://github.com/apache/nuttx/pull/22405

   ## Summary
   
   **arch/xtensa/esp32s3: Fix USB Serial/JTAG console dropping input.**
   
   The receive path drained the OUT endpoint FIFO into the 64-byte receive
   buffer on every packet interrupt and dropped whatever did not fit.  Any
   input arriving faster than the reader consumes it (e.g. a pasted line
   longer than 64 characters) lost characters at the buffer boundary.
   
   USB has flow control built in, so use it: report no data available while
   the receive buffer is full, which leaves the data in the endpoint FIFO
   and makes the controller NAK the host.  As the packet interrupt does not
   fire again for data already in the FIFO, pick it up in rxint() when the
   serial upper half re-enables reception after making room (as the
   upper half documents for cdcacm).  Do that with the receive interrupt
   masked, so that the interrupt handler does not write the receive buffer
   at the same time.
   
   Tested on Waveshare ESP32-S3-Touch-AMOLED-2.16: a 120-character command
   line used to lose characters at offset 64 and be truncated; it is now
   received intact, and a 51 KB upload in 400-character lines arrives with
   no errors (previously ~25% of the lines were corrupted).
   
   **arch/xtensa/esp32s3: Do not block the USB Serial/JTAG console without a 
host.**
   
   The IN endpoint FIFO of the USB Serial/JTAG controller only drains when
   the host reads it, which it does not when no terminal has the port open
   or no host is connected at all (e.g. a board running on battery).  The
   transmit buffer of the serial upper half then fills up, the FIFO-empty
   interrupt never comes, and every task that writes to the console blocks
   forever.  esp32s3_usbserial_write(), used for up_putc(), even spins
   forever.
   
   Detect a host that does not read: when the FIFO stays full for 50 ms
   while output is pending, drop the console output instead of blocking,
   like ESP-IDF does.  As soon as the host reads again, output is sent
   normally and nothing is dropped.
   
   Tested on Waveshare ESP32-S3-Touch-AMOLED-2.16: with no program reading
   the USB port, the Dropbear SSH server used to block on its first log
   line and never accept connections; it now answers within 5 s after
   boot.  With a terminal reading, 3 x 16 KB of hexdump output arrived
   complete (1024 of 1024 lines each time).
   
   The last commit fixes the pre-existing nxstyle errors in the touched file 
(whitespace only, no functional change), as CI checks whole files.
   
   ## Impact
   
   * Is new feature added? Is existing feature changed? NO
   * Impact on user (will user need to adapt to change)? NO
   * Impact on build (will build process change)? NO
   * Impact on hardware (will arch(s) / board(s) / driver(s) change)? YES: 
ESP32-S3 USB Serial/JTAG console driver (all boards using 
CONFIG_ESP32S3_USBSERIAL). With a host that reads, nothing changes except that 
input is no longer lost; without one, console output is now dropped after 50 ms 
instead of blocking the writers.
   * Impact on documentation (is update required / provided)? NO
   * Impact on security (any sort of implications)? NO
   * Impact on compatibility (backward/forward/interoperability)? NO
   * Anything else to consider or add? Runtime-tested on Waveshare 
ESP32-S3-Touch-AMOLED-2.16 (board support is in a separate PR) with the same 
driver code; build-tested on esp32s3-box:nsh. Tests on other ESP32-S3 boards 
are welcome.
   
   ## Testing
   
   I confirm that changes are verified on local setup and works as intended:
   * Build Host(s): Linux x86_64, xtensa-esp-elf GCC 15.2.0 
(esp-15.2.0_20251204), riscv32-esp-elf GCC 15.2.0 for the ESP32-C3 build.
   * Target(s): Waveshare ESP32-S3-Touch-AMOLED-2.16 (ESP32-S3R8, 16 MB flash, 
8 MB PSRAM).
   * Input: a 120-character command line and a 51 KB upload in 
120/400-character echo lines over the console. Output: with no program reading 
the USB port, a Dropbear SSH server that logs to the console after boot; with a 
terminal reading, 3 x hexdump of 16 KB checked for completeness.
   
   Builds (each on current master plus this PR only):
   
   * PASS pr/esp32s3-usbserial-rx box esp32s3-box:nsh (warnings: 0)
   
   Testing logs before change:
   
   ```
   Input: line truncated at offset 64, ~25 % of upload lines corrupted. Output: 
with no reader, every task writing to the console blocked forever (JTAG: 
Dropbear waiting in uart_writev on the console transmit lock), so the SSH 
server never accepted connections; esp32s3_usbserial_write() spun forever.
   ```
   
   Testing logs after change:
   
   ```
   Input: received intact, 51 KB upload byte-identical. Output: with no reader, 
SSH logins work within 5 s after boot; with a terminal reading, 1024 of 1024 
hexdump lines each time (no output dropped).
   ```
   
   ## PR verification Self-Check
   
   * [x] This PR introduces only one functional change.
   * [x] I have updated all required description fields above.
   * [x] My PR adheres to Contributing Guidelines and Documentation (git commit 
title and message, coding standard, etc).
   * [ ] My PR is still work in progress (not ready for review).
   * [x] My PR is ready for review and can be safely merged into a codebase.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to