From a92bd5d081df52b75c44065828768628b2e9f910 Mon Sep 17 00:00:00 2001 From: David Sidrane Date: Fri, 10 Nov 2023 01:34:19 -0800 Subject: [PATCH] s32k1xx:Serial Do not wait on TXDMA semaphore If using flow control with a high CTS the thread may be blocked forever on the second transmit attempt due to waiting on the txdma semaphore. The calling thread can then never make progress and release any resources it has taken, thus may cause a deadlock in other parts of the system. The implementation differs in behavior from interrupt-driven TX. It should not implicitly wait on a taken semaphore but return immediately and let the upper layers decide on what to do next. --- arch/arm/src/s32k1xx/s32k1xx_serial.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/arm/src/s32k1xx/s32k1xx_serial.c b/arch/arm/src/s32k1xx/s32k1xx_serial.c index de1ed6ef80f..7053b633731 100644 --- a/arch/arm/src/s32k1xx/s32k1xx_serial.c +++ b/arch/arm/src/s32k1xx/s32k1xx_serial.c @@ -1768,9 +1768,12 @@ static void s32k1xx_dma_txavailable(struct uart_dev_s *dev) /* Only send when the DMA is idle */ - nxsem_wait(&priv->txdmasem); + int rv = nxsem_trywait(&priv->txdmasem); - uart_xmitchars_dma(dev); + if (rv == OK) + { + uart_xmitchars_dma(dev); + } } #endif