You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by ag...@apache.org on 2020/03/02 22:08:36 UTC

[incubator-nuttx] 02/04: arm/stm32f7 add STM32F7_SPI_DMATHRESHOLD

This is an automated email from the ASF dual-hosted git repository.

aguettouche pushed a commit to branch pr420
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git

commit 608b59792e4b1c1d8aa85f4016d3fdc831409796
Author: Daniel Agar <da...@agar.ca>
AuthorDate: Mon Mar 2 16:03:15 2020 -0500

    arm/stm32f7 add STM32F7_SPI_DMATHRESHOLD
---
 arch/arm/src/stm32f7/Kconfig     |  9 +++++++++
 arch/arm/src/stm32f7/stm32_spi.c | 33 ++++++++++++++++++++++++++++-----
 2 files changed, 37 insertions(+), 5 deletions(-)

diff --git a/arch/arm/src/stm32f7/Kconfig b/arch/arm/src/stm32f7/Kconfig
index d6a5e57..806022b 100644
--- a/arch/arm/src/stm32f7/Kconfig
+++ b/arch/arm/src/stm32f7/Kconfig
@@ -2287,6 +2287,15 @@ config STM32F7_SPI_DMA
 	---help---
 		Use DMA to improve SPI transfer performance.  Cannot be used with STM32F7_SPI_INTERRUPT.
 
+config STM32F7_SPI_DMATHRESHOLD
+	int "SPI DMA threshold"
+	default 4
+	depends on STM32F7_SPI_DMA
+	---help---
+		When SPI DMA is enabled, small DMA transfers will still be performed
+		by polling logic.  But we need a threshold value to determine what
+		is small.
+
 config STM32F7_SPI1_DMA
 	bool "SPI1 DMA"
 	default n
diff --git a/arch/arm/src/stm32f7/stm32_spi.c b/arch/arm/src/stm32f7/stm32_spi.c
index 2a3cc782..402f119 100644
--- a/arch/arm/src/stm32f7/stm32_spi.c
+++ b/arch/arm/src/stm32f7/stm32_spi.c
@@ -1646,13 +1646,36 @@ static void spi_exchange(FAR struct spi_dev_s *dev, FAR const void *txbuffer,
 
   DEBUGASSERT(priv != NULL);
 
-#ifdef CONFIG_STM32F7_DMACAPABLE
+#ifdef CONFIG_STM32F7_SPI_DMATHRESHOLD
+  /* Convert the number of word to a number of bytes */
+
+  size_t nbytes = (priv->nbits > 8) ? nwords << 1 : nwords;
+
+  /* If this is a small SPI transfer, then let spi_exchange_nodma() do the work. */
+
+  if (nbytes <= CONFIG_STM32F7_SPI_DMATHRESHOLD)
+    {
+      spi_exchange_nodma(dev, txbuffer, rxbuffer, nwords);
+      return;
+    }
+#endif
+
   if ((priv->rxdma == NULL) || (priv->txdma == NULL) ||
-      (txbuffer && !stm32_dmacapable((uint32_t)txbuffer, nwords, priv->txccr)) ||
-      (rxbuffer && !stm32_dmacapable((uint32_t)rxbuffer, nwords, priv->rxccr)) ||
-      up_interrupt_context() || nwords < CONFIG_STM32F7_SPI_DMA_THRESHOLD)
+      up_interrupt_context())
+    {
+      /* Invalid DMA channels, or interrupt context, fall
+       * back to non-DMA method.
+       */
+
+      spi_exchange_nodma(dev, txbuffer, rxbuffer, nwords);
+      return;
+    }
+
+#ifdef CONFIG_STM32F7_DMACAPABLE
+  if ((txbuffer && !stm32_dmacapable((uint32_t)txbuffer, nwords, priv->txccr)) ||
+      (rxbuffer && !stm32_dmacapable((uint32_t)rxbuffer, nwords, priv->rxccr)))
     {
-      /* Invalid DMA channels, unsupported memory region, or interrupt context, fall back to non-DMA method. */
+      /* Unsupported memory region fall back to non-DMA method. */
 
       spi_exchange_nodma(dev, txbuffer, rxbuffer, nwords);
     }