From 8b9d05d0f78e0eafe615dd83b802dc4b572ea586 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 27 Oct 2023 03:37:01 -0700 Subject: [PATCH] s32k1xx:Serial overcome race where DMA has not fetched TCD again" With TCD set to loop, there is a window where the DMA has raised Done, but not reloaded the TCD, resetting count and clearing Done. In this window imxrt_dmach_getcount could then return 0. Resulting in imxrt_dma_nextrx returning RXDMA_BUFFER_SIZE. Which is not a valid index in the FIFO. Since the count will be set to RXDMA_BUFFER_SIZE. When the DMA engine completes the TCD reload. The imxrt_dma_nextrx would return 0. Therefore: (RXDMA_BUFFER_SIZE - dmaresidual) % RXDMA_BUFFER_SIZE accomplishes this. --- arch/arm/src/s32k1xx/s32k1xx_serial.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/arm/src/s32k1xx/s32k1xx_serial.c b/arch/arm/src/s32k1xx/s32k1xx_serial.c index 50fad28005..de1ed6ef80 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_serial.c +++ b/arch/arm/src/s32k1xx/s32k1xx_serial.c @@ -658,7 +658,7 @@ static int s32k1xx_dma_nextrx(struct s32k1xx_uart_s *priv) { int dmaresidual = s32k1xx_dmach_getcount(priv->rxdma); - return RXDMA_BUFFER_SIZE - dmaresidual; + return (RXDMA_BUFFER_SIZE - dmaresidual) % RXDMA_BUFFER_SIZE; } #endif