From e480f49e583d778c88c3375b8c4a10ba6a5fce54 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Sat, 7 Dec 2019 08:53:10 +0000 Subject: [PATCH] Tentative SPIv1 I2S driver fix. git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@13212 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/hal/ports/STM32/LLD/SPIv1/hal_i2s_lld.c | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/os/hal/ports/STM32/LLD/SPIv1/hal_i2s_lld.c b/os/hal/ports/STM32/LLD/SPIv1/hal_i2s_lld.c index 8782bd8e6..235d2b813 100644 --- a/os/hal/ports/STM32/LLD/SPIv1/hal_i2s_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv1/hal_i2s_lld.c @@ -557,14 +557,26 @@ void i2s_lld_stop_exchange(I2SDriver *i2sp) { to wait for TXE = 1 and BSY = 0.*/ while ((i2sp->spi->SR & (SPI_SR_TXE | SPI_SR_BSY)) != SPI_SR_TXE) ; + + /* Stop SPI/I2S peripheral.*/ + i2sp->spi->I2SCFGR &= ~SPI_I2SCFGR_I2SE; } - /* Stop SPI/I2S peripheral.*/ - i2sp->spi->I2SCFGR &= ~SPI_I2SCFGR_I2SE; - - /* Stop RX DMA, if enabled.*/ - if (NULL != i2sp->dmarx) + /* Stop RX DMA, if enabled then draining the RX DR.*/ + if (NULL != i2sp->dmarx) { dmaStreamDisable(i2sp->dmarx); + + /* Waiting for some data to be present in RX DR.*/ + while ((i2sp->spi->SR & SPI_SR_RXNE) != SPI_SR_RXNE) + ; + + /* Stop SPI/I2S peripheral.*/ + i2sp->spi->I2SCFGR &= ~SPI_I2SCFGR_I2SE; + + /* Purging data in DR.*/ + while ((i2sp->spi->SR & SPI_SR_RXNE) != 0) + (void) i2sp->spi->DR; + } } #endif /* HAL_USE_I2S */