Skip to content

Commit

Permalink
stm32h7:Serial refactor out tx dma semaphore
Browse files Browse the repository at this point in the history
   Fixes is stuttering output.

   The use of the semaphore was causing blocking
   on non blocking callers. This ensured that
   the TX DAM would be restated, but when it
   was switched to trywait in 660ac6, it left
   data in the xmit queue unsent.

   This solution removes the semaphore and restart
   the DMA on completion if there is more data in
   the xmit queue to be sent.
  • Loading branch information
davids5 authored and xiaoxiang781216 committed Dec 5, 2023
1 parent 7f4cf11 commit f92a906
Showing 1 changed file with 9 additions and 12 deletions.
21 changes: 9 additions & 12 deletions arch/arm/src/stm32h7/stm32_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,7 +628,6 @@ struct up_dev_s
#ifdef SERIAL_HAVE_TXDMA
const unsigned int txdma_channel; /* DMA channel assigned */
DMA_HANDLE txdma; /* currently-open trasnmit DMA stream */
sem_t txdmasem; /* Indicate TX DMA completion */
#endif

/* RX DMA state */
Expand Down Expand Up @@ -3299,8 +3298,9 @@ static bool up_dma_rxavailable(struct uart_dev_s *dev)
* Name: up_dma_txcallback
*
* Description:
* This function clears dma buffer at complete of DMA transfer and wakes up
* threads waiting for space in buffer.
* This function clears dma buffer at completion of DMA transfer. It wakes
* up threads waiting for space in buffer and restarts the DMA if there is
* more data to send.
*
****************************************************************************/

Expand All @@ -3314,11 +3314,7 @@ static void up_dma_txcallback(DMA_HANDLE handle, uint8_t status, void *arg)
* This is important to free TX buffer space by 'uart_xmitchars_done'.
*/

if (status & DMA_SCR_HTIE)
{
priv->dev.dmatx.nbytes += priv->dev.dmatx.length / 2;
}
else if (status & DMA_SCR_TCIE)
if (status & DMA_SCR_TCIE)
{
priv->dev.dmatx.nbytes += priv->dev.dmatx.length;
if (priv->dev.dmatx.nlength)
Expand Down Expand Up @@ -3346,11 +3342,13 @@ static void up_dma_txcallback(DMA_HANDLE handle, uint8_t status, void *arg)
}
}

nxsem_post(&priv->txdmasem);

/* Adjust the pointers */

uart_xmitchars_done(&priv->dev);

/* Send more if availaible */

up_dma_txavailable(&priv->dev);
}
#endif

Expand All @@ -3369,8 +3367,7 @@ static void up_dma_txavailable(struct uart_dev_s *dev)

/* Only send when the DMA is idle */

int rv = nxsem_trywait(&priv->txdmasem);
if (rv == OK)
if (stm32_dmaresidual(priv->txdma) == 0)
{
uart_xmitchars_dma(dev);
}
Expand Down

0 comments on commit f92a906

Please sign in to comment.