aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--os/hal/platforms/STM32/SPIv2/spi_lld.c24
-rw-r--r--readme.txt1
2 files changed, 21 insertions, 4 deletions
diff --git a/os/hal/platforms/STM32/SPIv2/spi_lld.c b/os/hal/platforms/STM32/SPIv2/spi_lld.c
index 4a14be45f..752c2af66 100644
--- a/os/hal/platforms/STM32/SPIv2/spi_lld.c
+++ b/os/hal/platforms/STM32/SPIv2/spi_lld.c
@@ -475,10 +475,26 @@ void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) {
*/
uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
- spip->spi->DR = frame;
- while ((spip->spi->SR & SPI_SR_RXNE) == 0)
- ;
- return spip->spi->DR;
+ /*
+ * Data register must be accessed with the appropriate data size.
+ * Byte size access (uint8_t *) for transactions that are <= 8-bit.
+ * Halfword size access (uint16_t) for transactions that are <= 8-bit.
+ */
+ if ((spip->config->cr2 & SPI_CR2_DS) <= (SPI_CR2_DS_2 |
+ SPI_CR2_DS_1 |
+ SPI_CR2_DS_0)) {
+ volatile uint8_t *spidr = (volatile uint8_t *)&spip->spi->DR;
+ *spidr = (uint8_t)frame;
+ while ((spip->spi->SR & SPI_SR_RXNE) == 0)
+ ;
+ return (uint16_t)*spidr;
+ }
+ else {
+ spip->spi->DR = frame;
+ while ((spip->spi->SR & SPI_SR_RXNE) == 0)
+ ;
+ return spip->spi->DR;
+ }
}
#endif /* HAL_USE_SPI */
diff --git a/readme.txt b/readme.txt
index 7a56d3b78..a24340aba 100644
--- a/readme.txt
+++ b/readme.txt
@@ -89,6 +89,7 @@
*****************************************************************************
*** 2.5.2 ***
+- FIX: Fixed STM32 SPIv2 polled exchange (bug #372).
- FIX: Fixed wrong macro in PWM driver (bug #407)(backported to 2.4.4).
- FIX: Fixed USB driver possible deadlock under certain configurations (bug
#406)(backported to 2.4.4).