STM32 SPI DMA: Fix related to CONFIG_STM32_DMACAPABLE from Ken Pettit

This commit is contained in:
Gregory Nutt 2013-10-27 16:23:44 -06:00
parent 93421a988e
commit 848349bbd7

View File

@ -195,6 +195,8 @@ struct stm32_spidev_s
DMA_HANDLE txdma; /* DMA channel handle for TX transfers */ DMA_HANDLE txdma; /* DMA channel handle for TX transfers */
sem_t rxsem; /* Wait for RX DMA to complete */ sem_t rxsem; /* Wait for RX DMA to complete */
sem_t txsem; /* Wait for TX DMA to complete */ sem_t txsem; /* Wait for TX DMA to complete */
uint32_t txccr; /* DMA control register for TX transfers */
uint32_t rxccr; /* DMA control register for RX transfers */
#endif #endif
#ifndef CONFIG_SPI_OWNBUS #ifndef CONFIG_SPI_OWNBUS
sem_t exclsem; /* Held while chip is selected for mutual exclusion */ sem_t exclsem; /* Held while chip is selected for mutual exclusion */
@ -748,8 +750,6 @@ static void spi_dmatxcallback(DMA_HANDLE handle, uint8_t isr, void *arg)
static void spi_dmarxsetup(FAR struct stm32_spidev_s *priv, FAR void *rxbuffer, static void spi_dmarxsetup(FAR struct stm32_spidev_s *priv, FAR void *rxbuffer,
FAR void *rxdummy, size_t nwords) FAR void *rxdummy, size_t nwords)
{ {
uint32_t ccr;
/* 8- or 16-bit mode? */ /* 8- or 16-bit mode? */
if (spi_16bitmode(priv)) if (spi_16bitmode(priv))
@ -758,12 +758,12 @@ static void spi_dmarxsetup(FAR struct stm32_spidev_s *priv, FAR void *rxbuffer,
if (rxbuffer) if (rxbuffer)
{ {
ccr = SPI_RXDMA16_CONFIG; priv->rxccr = SPI_RXDMA16_CONFIG;
} }
else else
{ {
rxbuffer = rxdummy; rxbuffer = rxdummy;
ccr = SPI_RXDMA16NULL_CONFIG; priv->rxccr = SPI_RXDMA16NULL_CONFIG;
} }
} }
else else
@ -772,18 +772,19 @@ static void spi_dmarxsetup(FAR struct stm32_spidev_s *priv, FAR void *rxbuffer,
if (rxbuffer) if (rxbuffer)
{ {
ccr = SPI_RXDMA8_CONFIG; priv->rxccr = SPI_RXDMA8_CONFIG;
} }
else else
{ {
rxbuffer = rxdummy; rxbuffer = rxdummy;
ccr = SPI_RXDMA8NULL_CONFIG; priv->rxccr = SPI_RXDMA8NULL_CONFIG;
} }
} }
/* Configure the RX DMA */ /* Configure the RX DMA */
stm32_dmasetup(priv->rxdma, priv->spibase + STM32_SPI_DR_OFFSET, (uint32_t)rxbuffer, nwords, ccr); stm32_dmasetup(priv->rxdma, priv->spibase + STM32_SPI_DR_OFFSET,
(uint32_t)rxbuffer, nwords, priv->rxccr);
} }
#endif #endif
@ -799,8 +800,6 @@ static void spi_dmarxsetup(FAR struct stm32_spidev_s *priv, FAR void *rxbuffer,
static void spi_dmatxsetup(FAR struct stm32_spidev_s *priv, FAR const void *txbuffer, static void spi_dmatxsetup(FAR struct stm32_spidev_s *priv, FAR const void *txbuffer,
FAR const void *txdummy, size_t nwords) FAR const void *txdummy, size_t nwords)
{ {
uint32_t ccr;
/* 8- or 16-bit mode? */ /* 8- or 16-bit mode? */
if (spi_16bitmode(priv)) if (spi_16bitmode(priv))
@ -809,12 +808,12 @@ static void spi_dmatxsetup(FAR struct stm32_spidev_s *priv, FAR const void *txbu
if (txbuffer) if (txbuffer)
{ {
ccr = SPI_TXDMA16_CONFIG; priv->txccr = SPI_TXDMA16_CONFIG;
} }
else else
{ {
txbuffer = txdummy; txbuffer = txdummy;
ccr = SPI_TXDMA16NULL_CONFIG; priv->txccr = SPI_TXDMA16NULL_CONFIG;
} }
} }
else else
@ -823,18 +822,19 @@ static void spi_dmatxsetup(FAR struct stm32_spidev_s *priv, FAR const void *txbu
if (txbuffer) if (txbuffer)
{ {
ccr = SPI_TXDMA8_CONFIG; priv->txccr = SPI_TXDMA8_CONFIG;
} }
else else
{ {
txbuffer = txdummy; txbuffer = txdummy;
ccr = SPI_TXDMA8NULL_CONFIG; priv->txccr = SPI_TXDMA8NULL_CONFIG;
} }
} }
/* Setup the TX DMA */ /* Setup the TX DMA */
stm32_dmasetup(priv->txdma, priv->spibase + STM32_SPI_DR_OFFSET,(uint32_t)txbuffer, nwords, ccr); stm32_dmasetup(priv->txdma, priv->spibase + STM32_SPI_DR_OFFSET,
(uint32_t)txbuffer, nwords, priv->txccr);
} }
#endif #endif
@ -1180,7 +1180,7 @@ static void spi_setbits(FAR struct spi_dev_s *dev, int nbits)
spi_modifycr1(priv, 0, SPI_CR1_SPE); spi_modifycr1(priv, 0, SPI_CR1_SPE);
spi_modifycr1(priv, setbits, clrbits); spi_modifycr1(priv, setbits, clrbits);
spi_modifycr1(priv, SPI_CR1_SPE, 0); spi_modifycr1(priv, SPI_CR1_SPE, 0);
/* Save the selection so the subsequence re-configurations will be faster */ /* Save the selection so the subsequence re-configurations will be faster */
#ifndef CONFIG_SPI_OWNBUS #ifndef CONFIG_SPI_OWNBUS
@ -1353,9 +1353,11 @@ static void spi_exchange_nodma(FAR struct spi_dev_s *dev, FAR const void *txbuff
static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer, static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer,
FAR void *rxbuffer, size_t nwords) FAR void *rxbuffer, size_t nwords)
{ {
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev;
#ifdef CONFIG_STM32_DMACAPABLE #ifdef CONFIG_STM32_DMACAPABLE
if ((txbuffer && !stm32_dmacapable((uint32_t)txbuffer)) || if ((txbuffer && !stm32_dmacapable((uint32_t)txbuffer, nwords, priv->txccr)) ||
(rxbuffer && !stm32_dmacapable((uint32_t)rxbuffer))) (rxbuffer && !stm32_dmacapable((uint32_t)rxbuffer, nwords, priv->rxccr)))
{ {
/* Unsupported memory region, fall back to non-DMA method. */ /* Unsupported memory region, fall back to non-DMA method. */
@ -1364,7 +1366,6 @@ static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer,
else else
#endif #endif
{ {
FAR struct stm32_spidev_s *priv = (FAR struct stm32_spidev_s *)dev;
static uint16_t rxdummy = 0xffff; static uint16_t rxdummy = 0xffff;
static const uint16_t txdummy = 0xffff; static const uint16_t txdummy = 0xffff;
@ -1513,7 +1514,7 @@ static void spi_portinitialize(FAR struct stm32_spidev_s *priv)
priv->rxdma = stm32_dmachannel(priv->rxch); priv->rxdma = stm32_dmachannel(priv->rxch);
priv->txdma = stm32_dmachannel(priv->txch); priv->txdma = stm32_dmachannel(priv->txch);
DEBUGASSERT(priv->rxdma && priv->txdma); DEBUGASSERT(priv->rxdma && priv->txdma);
spi_putreg(priv, STM32_SPI_CR2_OFFSET, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN); spi_putreg(priv, STM32_SPI_CR2_OFFSET, SPI_CR2_RXDMAEN | SPI_CR2_TXDMAEN);
#endif #endif