diff options
author | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-05-04 08:10:31 +0000 |
---|---|---|
committer | gdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4> | 2013-05-04 08:10:31 +0000 |
commit | 2a2598ff1b1e696b2b6f0076a419329911edac30 (patch) | |
tree | 889652f16278d6817c7bfae22a19bd5a5b330ea7 /os/hal/platforms | |
parent | 397bc099cd653fc3dbc73cdb5ceabfa90d5e0755 (diff) | |
download | ChibiOS-2a2598ff1b1e696b2b6f0076a419329911edac30.tar.gz ChibiOS-2a2598ff1b1e696b2b6f0076a419329911edac30.tar.bz2 ChibiOS-2a2598ff1b1e696b2b6f0076a419329911edac30.zip |
Fixed bug #372.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@5672 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/platforms')
-rw-r--r-- | os/hal/platforms/STM32/SPIv2/spi_lld.c | 24 |
1 files changed, 20 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 */
|