aboutsummaryrefslogtreecommitdiffstats
path: root/os/hal/ports/STM32/LLD/SPIv1
diff options
context:
space:
mode:
authorgdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2016-03-06 08:17:35 +0000
committergdisirio <gdisirio@35acf78f-673a-0410-8e92-d51de3d6d3f4>2016-03-06 08:17:35 +0000
commitab30e97aea7a488710da73d12df6d7a57e733c0f (patch)
tree672825dbb7bc8b862b7a268031a701768f79a508 /os/hal/ports/STM32/LLD/SPIv1
parent08a4706fb29f6eea42762df962132ec37e370eb1 (diff)
downloadChibiOS-ab30e97aea7a488710da73d12df6d7a57e733c0f.tar.gz
ChibiOS-ab30e97aea7a488710da73d12df6d7a57e733c0f.tar.bz2
ChibiOS-ab30e97aea7a488710da73d12df6d7a57e733c0f.zip
Fixed BIDIMODE-related changes in SPI drivers.
git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9030 35acf78f-673a-0410-8e92-d51de3d6d3f4
Diffstat (limited to 'os/hal/ports/STM32/LLD/SPIv1')
-rw-r--r--os/hal/ports/STM32/LLD/SPIv1/spi_lld.c39
1 files changed, 25 insertions, 14 deletions
diff --git a/os/hal/ports/STM32/LLD/SPIv1/spi_lld.c b/os/hal/ports/STM32/LLD/SPIv1/spi_lld.c
index cd993920b..a371eb980 100644
--- a/os/hal/ports/STM32/LLD/SPIv1/spi_lld.c
+++ b/os/hal/ports/STM32/LLD/SPIv1/spi_lld.c
@@ -116,7 +116,8 @@ SPIDriver SPID6;
/* Driver local variables and types. */
/*===========================================================================*/
-static uint16_t dummytx;
+static const uint16_t dummytx = 0xFFFFU;
+static uint16_t dummyrx;
/*===========================================================================*/
/* Driver local functions. */
@@ -145,11 +146,12 @@ static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags) {
#if STM32_SPI_USE_BIDIMODE
spip->spi->CR1 |= SPI_CR1_BIDIOE;
-#endif
- /* Errors reset sequence.*/
+ /* Errors reset sequence. It is required becaue BIDIOE could cause extra
+ clock pulses after DMA stopped reading.*/
(void)spip->spi->DR;
(void)spip->spi->SR;
+#endif
/* Portable SPI ISR code defined in the high level driver, note, it is
a macro.*/
@@ -191,8 +193,6 @@ static void spi_lld_serve_tx_interrupt(SPIDriver *spip, uint32_t flags) {
*/
void spi_lld_init(void) {
- dummytx = 0xFFFF;
-
#if STM32_SPI_USE_SPI1
spiObjectInit(&SPID1);
SPID1.spi = SPI1;
@@ -531,12 +531,18 @@ void spi_lld_ignore(SPIDriver *spip, size_t n) {
if ((spip->spi->CR1 & SPI_CR1_BIDIMODE) != 0) {
osalDbgAssert((spip->spi->CR1 & SPI_CR1_BIDIOE) != 0,
"BIDIOE not set");
+ }
#endif
+ dmaStreamSetMemory0(spip->dmarx, &dummyrx);
+ dmaStreamSetTransactionSize(spip->dmarx, n);
+ dmaStreamSetMode(spip->dmarx, spip->rxdmamode);
+
dmaStreamSetMemory0(spip->dmatx, &dummytx);
dmaStreamSetTransactionSize(spip->dmatx, n);
dmaStreamSetMode(spip->dmatx, spip->txdmamode);
+ dmaStreamEnable(spip->dmarx);
dmaStreamEnable(spip->dmatx);
}
@@ -594,13 +600,19 @@ void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf) {
if ((spip->spi->CR1 & SPI_CR1_BIDIMODE) != 0) {
osalDbgAssert((spip->spi->CR1 & SPI_CR1_BIDIOE) != 0,
"BIDIOE not set");
+ }
#endif
- dmaStreamSetMemory0(spip->dmatx, txbuf);
- dmaStreamSetTransactionSize(spip->dmatx, n);
- dmaStreamSetMode(spip->dmatx, spip->txdmamode | STM32_DMA_CR_MINC);
+ dmaStreamSetMemory0(spip->dmarx, &dummyrx);
+ dmaStreamSetTransactionSize(spip->dmarx, n);
+ dmaStreamSetMode(spip->dmarx, spip->rxdmamode);
- dmaStreamEnable(spip->dmatx);
+ dmaStreamSetMemory0(spip->dmatx, txbuf);
+ dmaStreamSetTransactionSize(spip->dmatx, n);
+ dmaStreamSetMode(spip->dmatx, spip->txdmamode | STM32_DMA_CR_MINC);
+
+ dmaStreamEnable(spip->dmarx);
+ dmaStreamEnable(spip->dmatx);
}
/**
@@ -619,10 +631,11 @@ void spi_lld_send(SPIDriver *spip, size_t n, const void *txbuf) {
void spi_lld_receive(SPIDriver *spip, size_t n, void *rxbuf) {
#if STM32_SPI_USE_BIDIMODE
- osalDbgAssert((spip->spi->CR1 & SPI_CR1_BIDIOE) != 0,
- "BIDIOE not set");
-
if ((spip->spi->CR1 & SPI_CR1_BIDIMODE) != 0) {
+
+ osalDbgAssert((spip->spi->CR1 & SPI_CR1_BIDIOE) != 0,
+ "BIDIOE not set");
+
dmaStreamSetMemory0(spip->dmarx, rxbuf);
dmaStreamSetTransactionSize(spip->dmarx, n);
dmaStreamSetMode(spip->dmarx, spip->rxdmamode | STM32_DMA_CR_MINC);
@@ -666,8 +679,6 @@ uint16_t spi_lld_polled_exchange(SPIDriver *spip, uint16_t frame) {
#if STM32_SPI_USE_BIDIMODE
osalDbgAssert((spip->spi->CR1 & SPI_CR1_BIDIMODE) == 0,
"spiPolledExchange() not possible with BIDIMODE");
- osalDbgAssert((spip->spi->CR1 & SPI_CR1_BIDIOE) != 0,
- "BIDIOE not set");
#endif
spip->spi->DR = frame;