• R/O
  • SSH
  • HTTPS

chibios: 提交


Commit MetaInfo

修订版15837 (tree)
时间2022-11-15 19:43:12
作者gdisirio

Log Message

SPIv1 fixes.

更改概述

差异

--- trunk/os/hal/ports/STM32/LLD/SPIv1/hal_spi_v2_lld.c (revision 15836)
+++ trunk/os/hal/ports/STM32/LLD/SPIv1/hal_spi_v2_lld.c (revision 15837)
@@ -121,18 +121,25 @@
121121 /*===========================================================================*/
122122
123123 static void spi_lld_configure(SPIDriver *spip) {
124+ uint32_t cr1, cr2;
124125
126+ /* Disabling SPI during (re)configuration.*/
127+ spip->spi->CR1 = 0U;
128+
129+ /* Common CR1 and CR2 options.*/
130+ cr1 = spip->config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE);
131+ cr2 = spip->config->cr2 | SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
132+
125133 /* SPI setup.*/
126- if (spip->config->slave) {
127- spip->spi->CR1 = spip->config->cr1 & ~(SPI_CR1_MSTR | SPI_CR1_SPE);
128- spip->spi->CR2 = spip->config->cr2 |
129- SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
134+ if (spip->config->slave == false) {
135+ cr1 |= SPI_CR1_MSTR;
136+ cr2 |= SPI_CR2_SSOE;
130137 }
131- else {
132- spip->spi->CR1 = (spip->config->cr1 | SPI_CR1_MSTR) & ~SPI_CR1_SPE;
133- spip->spi->CR2 = spip->config->cr2 | SPI_CR2_SSOE |
134- SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN;
135- }
138+
139+ /* New configuration.*/
140+ spip->spi->CR2 = cr2;
141+ spip->spi->CR1 = cr1;
142+ spip->spi->CR1 = cr1 | SPI_CR1_SPE;
136143 }
137144
138145 /**
@@ -727,8 +734,6 @@
727734 dmaStreamEnable(spip->dmarx);
728735 dmaStreamEnable(spip->dmatx);
729736
730- spip->spi->CR1 |= SPI_CR1_SPE;
731-
732737 return HAL_RET_SUCCESS;
733738 }
734739
@@ -764,8 +769,6 @@
764769 dmaStreamEnable(spip->dmarx);
765770 dmaStreamEnable(spip->dmatx);
766771
767- spip->spi->CR1 |= SPI_CR1_SPE;
768-
769772 return HAL_RET_SUCCESS;
770773 }
771774
@@ -798,8 +801,6 @@
798801 dmaStreamEnable(spip->dmarx);
799802 dmaStreamEnable(spip->dmatx);
800803
801- spip->spi->CR1 |= SPI_CR1_SPE;
802-
803804 return HAL_RET_SUCCESS;
804805 }
805806
@@ -832,8 +833,6 @@
832833 dmaStreamEnable(spip->dmarx);
833834 dmaStreamEnable(spip->dmatx);
834835
835- spip->spi->CR1 |= SPI_CR1_SPE;
836-
837836 return HAL_RET_SUCCESS;
838837 }
839838
@@ -874,18 +873,10 @@
874873 */
875874 uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
876875
877- /* Enabling SPI for the exchange.*/
878- spip->spi->CR1 |= SPI_CR1_SPE;
879-
880876 spip->spi->DR = frame;
881877 while ((spip->spi->SR & SPI_SR_RXNE) == 0U)
882878 ;
883- frame = spip->spi->DR;
884-
885- /* Disabling SPI and done.*/
886- spip->spi->CR1 &= ~SPI_CR1_SPE;
887-
888- return frame;
879+ return spip->spi->DR;
889880 }
890881
891882 #endif /* HAL_USE_SPI */
Show on old repository browser