This is an automated email from the ASF dual-hosted git repository.
xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 28cfbda6658 arch/xtensa/esp32s3: Fix USB Serial/JTAG console dropping
input.
28cfbda6658 is described below
commit 28cfbda665861222ddcee5dd0334542f3f072ab4
Author: ViezeVingertjes <[email protected]>
AuthorDate: Wed Nov 25 20:34:48 2026 +0100
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).
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: ViezeVingertjes <[email protected]>
---
arch/xtensa/src/esp32s3/esp32s3_usbserial.c | 33 +++++++++++++++++++++++++++++
1 file changed, 33 insertions(+)
diff --git a/arch/xtensa/src/esp32s3/esp32s3_usbserial.c
b/arch/xtensa/src/esp32s3/esp32s3_usbserial.c
index 436c01846a4..629ae651ba9 100644
--- a/arch/xtensa/src/esp32s3/esp32s3_usbserial.c
+++ b/arch/xtensa/src/esp32s3/esp32s3_usbserial.c
@@ -396,8 +396,28 @@ static void esp32s3_rxint(struct uart_dev_s *dev, bool
enable)
{
if (enable)
{
+ irqstate_t flags;
+
+ /* The packet-received interrupt only fires for new packets. Data
+ * left in the endpoint FIFO because the receive buffer was full
+ * would otherwise only be read when the host sends more, so pick it
+ * up now that the upper half has made room. Do it with the
+ * interrupt masked, so that the interrupt handler does not fill the
+ * receive buffer at the same time.
+ */
+
+ flags = enter_critical_section();
+ modifyreg32(USB_SERIAL_JTAG_INT_ENA_REG,
+ USB_SERIAL_JTAG_SERIAL_OUT_RECV_PKT_INT_ENA, 0);
+
+ if (esp32s3_rxavailable(dev))
+ {
+ uart_recvchars(dev);
+ }
+
modifyreg32(USB_SERIAL_JTAG_INT_ENA_REG, 0,
USB_SERIAL_JTAG_SERIAL_OUT_RECV_PKT_INT_ENA);
+ leave_critical_section(flags);
}
else
{
@@ -481,8 +501,21 @@ static void esp32s3_detach(struct uart_dev_s *dev)
static bool esp32s3_rxavailable(struct uart_dev_s *dev)
{
+ struct uart_buffer_s *rxbuf = &dev->recv;
+ int nexthead;
uint32_t regval;
+ /* Leave the data in the endpoint FIFO while the receive buffer is full.
+ * The USB controller then NAKs the host until there is room again, so no
+ * data is lost (the data is picked up again in esp32s3_rxint()).
+ */
+
+ nexthead = rxbuf->head + 1 < rxbuf->size ? rxbuf->head + 1 : 0;
+ if (nexthead == rxbuf->tail)
+ {
+ return false;
+ }
+
regval = getreg32(USB_SERIAL_JTAG_EP1_CONF_REG);
return regval & USB_SERIAL_JTAG_SERIAL_OUT_EP_DATA_AVAIL;