From a20f21723abe9024e422e46ec4f053ec224ec7fc Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sat, 11 Jan 2020 17:27:39 +0800 Subject: [PATCH] arch/stm32 ensure all spi dma handler check the result Signed-off-by: Xiang Xiao --- arch/arm/src/stm32/stm32_spi.c | 20 ++++++++++++++++++-- arch/arm/src/stm32h7/stm32_spi.c | 10 +++++++++- arch/arm/src/stm32l4/stm32l4_spi.c | 10 +++++++++- 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/arch/arm/src/stm32/stm32_spi.c b/arch/arm/src/stm32/stm32_spi.c index 48f2e908b1a34..4c91a9b25ad28 100644 --- a/arch/arm/src/stm32/stm32_spi.c +++ b/arch/arm/src/stm32/stm32_spi.c @@ -800,7 +800,15 @@ static inline bool spi_16bitmode(FAR struct stm32_spidev_s *priv) #ifdef CONFIG_STM32_SPI_DMA static void spi_dmarxwait(FAR struct stm32_spidev_s *priv) { - nxsem_wait_uninterruptible(&priv->rxsem); + /* Take the semaphore (perhaps waiting). If the result is zero, then the DMA + * must not really have completed??? + */ + + do + { + nxsem_wait_uninterruptible(&priv->rxsem); + } + while (priv->rxresult == 0); } #endif @@ -815,7 +823,15 @@ static void spi_dmarxwait(FAR struct stm32_spidev_s *priv) #ifdef CONFIG_STM32_SPI_DMA static void spi_dmatxwait(FAR struct stm32_spidev_s *priv) { - nxsem_wait_uninterruptible(&priv->txsem); + /* Take the semaphore (perhaps waiting). If the result is zero, then the DMA + * must not really have completed??? + */ + + do + { + nxsem_wait_uninterruptible(&priv->txsem); + } + while (priv->txresult == 0); } #endif diff --git a/arch/arm/src/stm32h7/stm32_spi.c b/arch/arm/src/stm32h7/stm32_spi.c index f90578d3ebc2d..513994bd0aa4e 100644 --- a/arch/arm/src/stm32h7/stm32_spi.c +++ b/arch/arm/src/stm32h7/stm32_spi.c @@ -853,7 +853,15 @@ static void spi_dmarxwait(FAR struct stm32_spidev_s *priv) #ifdef CONFIG_STM32H7_SPI_DMA static void spi_dmatxwait(FAR struct stm32_spidev_s *priv) { - nxsem_wait_uninterruptible(&priv->txsem); + /* Take the semaphore (perhaps waiting). If the result is zero, then the DMA + * must not really have completed??? + */ + + do + { + nxsem_wait_uninterruptible(&priv->txsem); + } + while (priv->txresult == 0); } #endif diff --git a/arch/arm/src/stm32l4/stm32l4_spi.c b/arch/arm/src/stm32l4/stm32l4_spi.c index 76a37243487ee..c91218ae97add 100644 --- a/arch/arm/src/stm32l4/stm32l4_spi.c +++ b/arch/arm/src/stm32l4/stm32l4_spi.c @@ -637,7 +637,15 @@ static void spi_dmarxwait(FAR struct stm32l4_spidev_s *priv) #ifdef CONFIG_STM32L4_SPI_DMA static void spi_dmatxwait(FAR struct stm32l4_spidev_s *priv) { - nxsem_wait_uninterruptible(&priv->txsem); + /* Take the semaphore (perhaps waiting). If the result is zero, then the DMA + * must not really have completed??? + */ + + do + { + nxsem_wait_uninterruptible(&priv->txsem); + } + while (priv->txresult == 0); } #endif