diff --git a/drivers/serial/serial_dma.c b/drivers/serial/serial_dma.c index 17c453a79a4..de82c9c1465 100644 --- a/drivers/serial/serial_dma.c +++ b/drivers/serial/serial_dma.c @@ -193,11 +193,18 @@ void uart_xmitchars_done(FAR uart_dev_t *dev) size_t nbytes = xfer->nbytes; struct uart_buffer_s *txbuf = &dev->xmit; - /* Move tail for nbytes. */ + /* Skip the update if the tail position change which mean + * someone reset (e.g. TCOFLUSH) the xmit buffer during DMA. + */ - txbuf->tail = (txbuf->tail + nbytes) % txbuf->size; - xfer->nbytes = 0; - xfer->length = xfer->nlength = 0; + if (xfer->buffer == &txbuf->buffer[txbuf->tail]) + { + /* Move tail for nbytes. */ + + txbuf->tail = (txbuf->tail + nbytes) % txbuf->size; + xfer->nbytes = 0; + xfer->length = xfer->nlength = 0; + } /* If any bytes were removed from the buffer, inform any waiters there there is * space available.