diff --git a/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c b/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c index 0cee5729b..067651691 100644 --- a/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv1/hal_spi_lld.c @@ -443,8 +443,9 @@ void spi_lld_stop(SPIDriver *spip) { if (spip->state == SPI_READY) { /* SPI disable.*/ - spip->spi->CR1 = 0; - spip->spi->CR2 = 0; + spip->spi->CR1 &= ~SPI_CR1_SPE; + spip->spi->CR1 = 0; + spip->spi->CR2 = 0; dmaStreamRelease(spip->dmarx); dmaStreamRelease(spip->dmatx); diff --git a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c index b3aafff07..01f894970 100644 --- a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_lld.c @@ -440,13 +440,15 @@ void spi_lld_start(SPIDriver *spip) { * @notapi */ void spi_lld_stop(SPIDriver *spip) { + uint32_t cr1; /* If in ready state then disables the SPI clock.*/ if (spip->state == SPI_READY) { /* SPI disable.*/ - spip->spi->CR1 = 0; - spip->spi->CR2 = 0; + spip->spi->CR1 &= ~SPI_CR1_SPE; + spip->spi->CR1 = 0; + spip->spi->CR2 = 0; dmaStreamRelease(spip->dmarx); dmaStreamRelease(spip->dmatx);