aboutsummaryrefslogtreecommitdiffstats
path: root/os
diff options
context:
space:
mode:
authorGiovanni Di Sirio <gdisirio@gmail.com>2015-08-22 12:43:17 +0000
committerGiovanni Di Sirio <gdisirio@gmail.com>2015-08-22 12:43:17 +0000
commit6ae7992c99f50928545523325fe717911dac50c2 (patch)
treec873b406a8c774f19d3267f7ef82f6a6833dc829 /os
parenteec9281e9f68e668aa2dc5e47f2ab2bbb42c06fe (diff)
downloadChibiOS-6ae7992c99f50928545523325fe717911dac50c2.tar.gz
ChibiOS-6ae7992c99f50928545523325fe717911dac50c2.tar.bz2
ChibiOS-6ae7992c99f50928545523325fe717911dac50c2.zip
Fixed bug #634.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@8234 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os')
-rw-r--r--os/hal/ports/STM32/LLD/SPIv2/spi_lld.c8
-rw-r--r--os/hal/ports/STM32/LLD/SPIv2/spi_lld.h12
2 files changed, 16 insertions, 4 deletions
diff --git a/os/hal/ports/STM32/LLD/SPIv2/spi_lld.c b/os/hal/ports/STM32/LLD/SPIv2/spi_lld.c
index cc4635122..8a218ac46 100644
--- a/os/hal/ports/STM32/LLD/SPIv2/spi_lld.c
+++ b/os/hal/ports/STM32/LLD/SPIv2/spi_lld.c
@@ -417,6 +417,7 @@ void spi_lld_start(SPIDriver *spip) {
STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE;
spip->txdmamode = (spip->txdmamode & ~STM32_DMA_CR_SIZE_MASK) |
STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE;
+ spip->fsize = sizeof (uint8_t);
}
else {
/* Frame width is larger than 8 bits.*/
@@ -424,6 +425,7 @@ void spi_lld_start(SPIDriver *spip) {
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
spip->txdmamode = (spip->txdmamode & ~STM32_DMA_CR_SIZE_MASK) |
STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD;
+ spip->fsize = sizeof (uint16_t);
}
/* SPI setup and enable.*/
spip->spi->CR1 = 0;
@@ -547,6 +549,9 @@ void spi_lld_ignore(SPIDriver *spip, size_t n) {
void spi_lld_exchange(SPIDriver *spip, size_t n,
const void *txbuf, void *rxbuf) {
+ /* DMA buffer invalidation because data cache.*/
+ dmaBufferInvalidate(rxbuf, (uint8_t *)rxbuf + (n * spip->fsize));
+
dmaStreamSetMemory0(spip->dmarx, rxbuf);
dmaStreamSetTransactionSize(spip->dmarx, n);
dmaStreamSetMode(spip->dmarx, spip->rxdmamode| STM32_DMA_CR_MINC);
@@ -601,6 +606,9 @@ void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf) {
*/
void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) {
+ /* DMA buffer invalidation because data cache.*/
+ dmaBufferInvalidate(rxbuf, (uint8_t *)rxbuf + (n * spip->fsize));
+
dmaStreamSetMemory0(spip->dmarx, rxbuf);
dmaStreamSetTransactionSize(spip->dmarx, n);
dmaStreamSetMode(spip->dmarx, spip->rxdmamode | STM32_DMA_CR_MINC);
diff --git a/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h b/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h
index 235341e35..781aa24fd 100644
--- a/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h
+++ b/os/hal/ports/STM32/LLD/SPIv2/spi_lld.h
@@ -473,21 +473,25 @@ struct SPIDriver {
*/
SPI_TypeDef *spi;
/**
- * @brief Receive DMA stream.
+ * @brief Receive DMA stream.
*/
const stm32_dma_stream_t *dmarx;
/**
- * @brief Transmit DMA stream.
+ * @brief Transmit DMA stream.
*/
const stm32_dma_stream_t *dmatx;
/**
- * @brief RX DMA mode bit mask.
+ * @brief RX DMA mode bit mask.
*/
uint32_t rxdmamode;
/**
- * @brief TX DMA mode bit mask.
+ * @brief TX DMA mode bit mask.
*/
uint32_t txdmamode;
+ /**
+ * @brief Frame size in bytes.
+ */
+ size_t fsize;
};
/*===========================================================================*/