From dda3dc7efe360bbefa2864bdbae4320e42246c29 Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Fri, 5 Nov 2021 10:23:18 +0000 Subject: [PATCH] cleanup git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@15006 27425a3e-05d8-49a3-a47f-9c15f0e5edd8 --- os/hal/ports/STM32/LLD/SPIv2/hal_spi_v2_lld.c | 32 +++++++++++-------- 1 file changed, 18 insertions(+), 14 deletions(-) diff --git a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_v2_lld.c b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_v2_lld.c index fd1723335..1431bd9bd 100644 --- a/os/hal/ports/STM32/LLD/SPIv2/hal_spi_v2_lld.c +++ b/os/hal/ports/STM32/LLD/SPIv2/hal_spi_v2_lld.c @@ -120,6 +120,21 @@ SPIDriver SPID6; /* Driver local functions. */ /*===========================================================================*/ +static void spi_lld_configure(SPIDriver *spip) { + + /* SPI setup.*/ + if (spip->config->slave) { + spip->spi->CR1 = spip->config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE); + spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | + SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; + } + else { + spip->spi->CR1 = (spip->config->cr1 | SPI_CR1_MSTR) & ~SPI_CR1_SPE; + spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | + SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; + } +} + /** * @brief Stopping the SPI transaction. * @note This is done nicely or by brutally resetting it depending on @@ -196,9 +211,7 @@ static msg_t spi_lld_stop_abort(SPIDriver *spip) { } /* Reconfiguring SPI.*/ - spip->spi->CR1 = spip->config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE); - spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | - SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; + spi_lld_configure(spip); } return HAL_RET_SUCCESS; @@ -584,17 +597,8 @@ msg_t spi_lld_start(SPIDriver *spip) { spip->txdmamode &= ~(STM32_DMA_CR_CIRC | STM32_DMA_CR_HTIE); } - /* SPI setup and enable.*/ - if (spip->config->slave) { - spip->spi->CR1 = spip->config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE); - spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | - SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; - } - else { - spip->spi->CR1 = (spip->config->cr1 | SPI_CR1_MSTR) & ~SPI_CR1_SPE; - spip->spi->CR2 = spip->config->cr2 | SPI_CR2_FRXTH | SPI_CR2_SSOE | - SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN; - } + /* SPI setup.*/ + spi_lld_configure(spip); return HAL_RET_SUCCESS; }