fix(usb_serial_jtag): flush TX FIFO at end of usb_serial_jtag_write (IDFGH-17790)#18706
Open
MaikVermeulen wants to merge 1 commit into
Open
fix(usb_serial_jtag): flush TX FIFO at end of usb_serial_jtag_write (IDFGH-17790)#18706MaikVermeulen wants to merge 1 commit into
MaikVermeulen wants to merge 1 commit into
Conversation
The VFS write path emits bytes but never flushes the TX FIFO, so the final bytes of a write (and the zero-length packet that terminates a 64-byte-multiple USB transfer) can linger in the FIFO. On ESP32-C6/H2 this intermittently leaves data undelivered across a USB re-enumeration after a chip reset, wedging the host CDC pipe: missing console output, and a dead OpenThread RCP spinel link (every spinel frame is sent via write() -> usb_serial_jtag_write, and otPlatUartFlush() is a no-op). Flushing the TX FIFO at the end of usb_serial_jtag_write() makes the final bytes reach the host. Validated on ESP32-C6 hardware with an A/B cold-plug test: baseline ~33% handshake-timeout rate over the USB serial link dropped to 0/20 with the flush in place. Closes espressif#17432 Ref: https://github.com/orgs/openthread/discussions/11627
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
usb_serial_jtag_write()(the USB-Serial/JTAG VFS write path) emits every byte but never flushes the TX FIFO. The final bytes of a write — and the zero-length packet that terminates a 64-byte-multiple USB transfer — can therefore linger in the FIFO and never be delivered across a USB re-enumeration after a chip reset. On ESP32-C6/H2 this intermittently wedges the host CDC pipe:printf/log output on cold boot, especially with logging disabled.otPlatUartSend → write() → usb_serial_jtag_write, andotPlatUartFlush()is a no-op, so the spinel link goes dead and the host's TLS/handshake never gets a response. Recovery requires a physical unplug.The fix mirrors the existing
'\n'handling inusb_serial_jtag_tx_char_no_driver()and thefsyncpath, which already flush to "make sure the line doesn't linger in fifo" — we simply flush once at the end of every write.Validation
Reproduced and fixed on physical ESP32-C6 hardware via an A/B cold-plug test (physical VBUS power-cycle per iteration, one handshake-over-USB attempt per boot, logging disabled — the condition that exposes the bug). The only difference between the two images was this flush:
References
The fix was first posted by me in the discussion on #17432.