From 9ee1f7838e0a1a065ede301d072cd0eb3adcaae2 Mon Sep 17 00:00:00 2001
From: patacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>
Date: Tue, 21 Feb 2012 22:00:28 +0000
Subject: [PATCH] STM32 SDIO DMA:  Ignore DMA FIFO errors; these seem to be
 bogus. SD multiple block transfers result in CRC errors; avoid them by using
 smaller FTP buffer sizes

git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@4410 42af7a65-404d-4744-a932-0658087f49c3
---
 Documentation/NuttxPortingGuide.html |  4 ++--
 TODO                                 | 28 ++++++++++++++++++++++++++--
 arch/arm/src/stm32/stm32_dma.h       |  6 +++---
 arch/arm/src/stm32/stm32_sdio.c      | 21 +--------------------
 arch/arm/src/stm32/stm32f40xxx_dma.c |  7 +++++--
 configs/README.txt                   |  4 ++--
 configs/stm3240g-eval/README.txt     | 22 ++++++++++++++++++++++
 configs/stm3240g-eval/nsh/defconfig  |  5 +++--
 configs/stm3240g-eval/nsh2/defconfig |  5 +++--
 9 files changed, 67 insertions(+), 35 deletions(-)

diff --git a/Documentation/NuttxPortingGuide.html b/Documentation/NuttxPortingGuide.html
index 62f795887f..c9656a6c51 100644
--- a/Documentation/NuttxPortingGuide.html
+++ b/Documentation/NuttxPortingGuide.html
@@ -4923,10 +4923,10 @@ build
     <code>CONFIG_FTPD_SERVERID</code>: The server name to use in FTP communications.  Default: "NuttX FTP Server"
   </li>
   <li>
-    <code>CONFIG_FTPD_CMDBUFFERSIZE</code>: The maximum size of one command.  Default: 512 bytes.
+    <code>CONFIG_FTPD_CMDBUFFERSIZE</code>: The maximum size of one command.  Default: 128 bytes.
   </li>
   <li>
-    <code>CONFIG_FTPD_DATABUFFERSIZE</code>: The size of the I/O buffer for data transfers.  Default: 2048 bytes.
+    <code>CONFIG_FTPD_DATABUFFERSIZE</code>: The size of the I/O buffer for data transfers.  Default: 512 bytes.
   </li>
   <li>
     <code>CONFIG_FTPD_WORKERSTACKSIZE</code>: The stacksize to allocate for each FTP daemon worker thread.  Default:  2048 bytes.
diff --git a/TODO b/TODO
index 44a607ec4b..c62e93a1e8 100644
--- a/TODO
+++ b/TODO
@@ -1,4 +1,4 @@
-NuttX TODO List (Last updated February 12, 2012)
+NuttX TODO List (Last updated February 21, 2012)
 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
 This file summarizes known NuttX bugs, limitations, inconsistencies with 
@@ -31,7 +31,7 @@ nuttx/
   (2)  ARM/LPC313x (arch/arm/src/lpc313x/)
   (3)  ARM/STR71x (arch/arm/src/str71x/)
   (3)  ARM/LM3S6918 (arch/arm/src/lm3s/)
-  (5)  ARM/STM32 (arch/arm/src/stm32/)
+  (7)  ARM/STM32 (arch/arm/src/stm32/)
   (3)  AVR (arch/avr)
   (0)  Intel x86 (arch/x86)
   (4)  8051 / MCS51 (arch/8051/)
@@ -1143,6 +1143,30 @@ o ARM/STM32 (arch/arm/src/stm32/)
   Status:      Open
   Priority:    Medium
 
+  Title:       F4 SDIO MULTI-BLOCK TRANSFER FAILURES
+  Description: If you use a large I/O buffer to access the file system, then the
+               MMCSD driver will perform multiple block SD transfers.  With DMA
+               ON, this seems to result in CRC errors detected by the hardware
+               during the transfer.  Workaround:  Use I/O buffers less the 1024
+               bytes.
+  Status:      Open
+  Priority:    Medium
+
+  Title:       DMA BOUNDARY CROSSING
+  Description: I see this statement in the reference manual:  "The burst
+               configuration has to be selected in order to respect the AHB protocol,
+               where bursts must not cross the 1 KB address boundary because the
+               minimum address space that can be allocated to a single slave
+               is 1 KB. This means that the 1 KB address boundary should not be crossed
+               by a burst block transfer, otherwise an AHB error would be generated,
+               that is not reported by the DMA registers."
+
+               The implication is that there may be some unenforced alignment
+               requirements for some DMAs.  There is nothing in the DMA driver to
+               prevent this now.
+  Status:      Open
+  Priority:    Low (I am not even sure if this is a problem yet).
+
 o AVR (arch/avr)
   ^^^^^^^^^^^^^^
 
diff --git a/arch/arm/src/stm32/stm32_dma.h b/arch/arm/src/stm32/stm32_dma.h
index 84b861e89b..2ebd691d9c 100644
--- a/arch/arm/src/stm32/stm32_dma.h
+++ b/arch/arm/src/stm32/stm32_dma.h
@@ -60,13 +60,13 @@
  */
 
 #if defined(CONFIG_STM32_STM32F10XX)
-#  define DMA_STATUS_FEIF         0
-#  define DMA_STATUS_DMEIF        0
+#  define DMA_STATUS_FEIF         0                 /* (Not available in F1) */
+#  define DMA_STATUS_DMEIF        0                 /* (Not available in F1) */
 #  define DMA_STATUS_TEIF         DMA_CHAN_TEIF_BIT /* Channel Transfer Error */
 #  define DMA_STATUS_HTIF         DMA_CHAN_HTIF_BIT /* Channel Half Transfer */
 #  define DMA_STATUS_TCIF         DMA_CHAN_TCIF_BIT /* Channel Transfer Complete */
 #elif defined(CONFIG_STM32_STM32F40XX)
-#  define DMA_STATUS_FEIF         DMA_STREAM_FEIF_BIT  /* Stream FIFO error */
+#  define DMA_STATUS_FEIF         0                    /* Stream FIFO error (ignored) */
 #  define DMA_STATUS_DMEIF        DMA_STREAM_DMEIF_BIT /* Stream direct mode error */
 #  define DMA_STATUS_TEIF         DMA_STREAM_TEIF_BIT  /* Stream Transfer Error */
 #  define DMA_STATUS_HTIF         DMA_STREAM_HTIF_BIT  /* Stream Half Transfer */
diff --git a/arch/arm/src/stm32/stm32_sdio.c b/arch/arm/src/stm32/stm32_sdio.c
index 60db7373b0..9672aaf0c4 100644
--- a/arch/arm/src/stm32/stm32_sdio.c
+++ b/arch/arm/src/stm32/stm32_sdio.c
@@ -188,26 +188,7 @@
 #  define SDIO_TXDMA32_CONFIG    (CONFIG_SDIO_DMAPRIO|DMA_CCR_MSIZE_32BITS|\
                                   DMA_CCR_PSIZE_32BITS|DMA_CCR_MINC|DMA_CCR_DIR)
 
-/* STM32 F4 stream configuration register (SCR) settings.
- *
- * Hmmm... I see conflicting statements in the Reference Manual.  In the DMA
- * section it says:
- 
- * "Note: The Burst mode is allowed only when incremetation is enabled:
- * – When the PINC bit is at ‘0’, the PBURST bits should also be cleared to ‘00’
- * – When the MINC bit is at ‘0’, the MBURST bits should also be cleared to ‘00’."
- *
- * But in the SDIO section it says:
- *
- * "4. Configure the DMA2 as follows:
- *     ...
- *     c) Program DMA2_Stream3 or DMA2_Stream6 Channel4 control register
- *        (memory increment, not peripheral increment, peripheral and source
- *        width is word size).
- *     ...
- *     e) Configure the incremental burst transfer to 4 beats (at least from
- *        peripheral side)..."
- */
+/* STM32 F4 stream configuration register (SCR) settings. */
 
 #elif defined(CONFIG_STM32_STM32F40XX)
 #  define SDIO_RXDMA32_CONFIG    (DMA_SCR_PFCTRL|DMA_SCR_DIR_P2M|DMA_SCR_MINC|\
diff --git a/arch/arm/src/stm32/stm32f40xxx_dma.c b/arch/arm/src/stm32/stm32f40xxx_dma.c
index 02d9966315..db09cfd2e1 100644
--- a/arch/arm/src/stm32/stm32f40xxx_dma.c
+++ b/arch/arm/src/stm32/stm32f40xxx_dma.c
@@ -676,11 +676,14 @@ void stm32_dmasetup(DMA_HANDLE handle, uint32_t paddr, uint32_t maddr,
    *  case, a FIFO error (flag FEIFx of the DMA_HISR or DMA_LISR register) will be
    *  generated when the stream is enabled, then the stream will be automatically
    *  disabled."
+   *
+   * NOTE: The FEIFx error interrupt is not enabled because the FEIFx seems to
+   * be reported spuriously causing good transfers to be marked as failures.
    */
 
   regval  = dmast_getreg(dmast, STM32_DMA_SFCR_OFFSET);
-  regval &= ~(DMA_SFCR_FTH_MASK | DMA_SFCR_FS_MASK);
-  regval |= (DMA_SFCR_FTH_FULL | DMA_SFCR_DMDIS | DMA_SFCR_FEIE);
+  regval &= ~(DMA_SFCR_FTH_MASK | DMA_SFCR_FS_MASK | DMA_SFCR_FEIE);
+  regval |= (DMA_SFCR_FTH_FULL | DMA_SFCR_DMDIS);
   dmast_putreg(dmast, STM32_DMA_SFCR_OFFSET, regval);
 
   /* "Configure data transfer direction, circular mode, peripheral & memory
diff --git a/configs/README.txt b/configs/README.txt
index 6df7359701..fc8373df9c 100644
--- a/configs/README.txt
+++ b/configs/README.txt
@@ -953,9 +953,9 @@ defconfig -- This is a configuration file similar to the Linux
 		CONFIG_FTPD_SERVERID - The server name to use in FTP communications.
 		  Default: "NuttX FTP Server"
 		CONFIG_FTPD_CMDBUFFERSIZE - The maximum size of one command.  Default:
-		  512 bytes.
+		  128 bytes.
 		CONFIG_FTPD_DATABUFFERSIZE - The size of the I/O buffer for data
-		  transfers.  Default: 2048 bytes.
+		  transfers.  Default: 512 bytes.
 		CONFIG_FTPD_WORKERSTACKSIZE - The stacksize to allocate for each
 		  FTP daemon worker thread.  Default:  2048 bytes.
 
diff --git a/configs/stm3240g-eval/README.txt b/configs/stm3240g-eval/README.txt
index e4902947e2..3c4f7e77c4 100755
--- a/configs/stm3240g-eval/README.txt
+++ b/configs/stm3240g-eval/README.txt
@@ -737,6 +737,28 @@ Where <subdir> is one of the following:
        Then DMA works fine. The downside is, of course, is that we lose 64Kb
        of precious SRAM.
 
+    5. Another SDIO/DMA issue.  This one is probably a software bug.  This is
+       the bug as stated in the TODO list:
+
+       "If you use a large I/O buffer to access the file system, then the
+        MMCSD driver will perform multiple block SD transfers.  With DMA
+        ON, this seems to result in CRC errors detected by the hardware
+        during the transfer.  Workaround:  Use I/O buffers less the 1024
+        bytes."
+
+       For this reason, CONFIG_FTPD_DATABUFFERSIZE=512 appears in the defconfig
+       file.
+
+    6. Another DMA-related concern.  I see this statement in the reference
+       manual:  "The burst configuration has to be selected in order to respect
+       the AHB protocol, where bursts must not cross the 1 KB address boundary
+       because the minimum address space that can be allocated to a single slave
+       is 1 KB. This means that the 1 KB address boundary should not be crossed
+       by a burst block transfer, otherwise an AHB error would be generated,
+       that is not reported by the DMA registers."
+
+       There is nothing in the DMA driver to prevent this now.
+
   ostest:
   ------
     This configuration directory, performs a simple OS test using
diff --git a/configs/stm3240g-eval/nsh/defconfig b/configs/stm3240g-eval/nsh/defconfig
index 76800c6712..bb4b252221 100644
--- a/configs/stm3240g-eval/nsh/defconfig
+++ b/configs/stm3240g-eval/nsh/defconfig
@@ -864,9 +864,9 @@ CONFIG_NET_RESOLV_ENTRIES=4
 # CONFIG_FTPD_SERVERID - The server name to use in FTP communications.
 #   Default: "NuttX FTP Server"
 # CONFIG_FTPD_CMDBUFFERSIZE - The maximum size of one command.  Default:
-#   512 bytes.
+#   128 bytes.
 # CONFIG_FTPD_DATABUFFERSIZE - The size of the I/O buffer for data
-#   transfers.  Default: 2048 bytes.
+#   transfers.  Default: 512 bytes.
 # CONFIG_FTPD_WORKERSTACKSIZE - The stacksize to allocate for each
 #   FTP daemon worker thread.  Default:  2048 bytes.
 # 
@@ -876,6 +876,7 @@ CONFIG_NET_RESOLV_ENTRIES=4
 # CONFIG_DISABLE_PTHREAD - pthread support is required
 # CONFIG_DISABLE_POLL - poll() support is required
 #
+CONFIG_FTPD_CMDBUFFERSIZE=512
 
 #
 # RTC Configuration
diff --git a/configs/stm3240g-eval/nsh2/defconfig b/configs/stm3240g-eval/nsh2/defconfig
index 25ab466b88..1160cc96df 100644
--- a/configs/stm3240g-eval/nsh2/defconfig
+++ b/configs/stm3240g-eval/nsh2/defconfig
@@ -865,9 +865,9 @@ CONFIG_NET_RESOLV_ENTRIES=4
 # CONFIG_FTPD_SERVERID - The server name to use in FTP communications.
 #   Default: "NuttX FTP Server"
 # CONFIG_FTPD_CMDBUFFERSIZE - The maximum size of one command.  Default:
-#   512 bytes.
+#   128 bytes.
 # CONFIG_FTPD_DATABUFFERSIZE - The size of the I/O buffer for data
-#   transfers.  Default: 2048 bytes.
+#   transfers.  Default: 512 bytes.
 # CONFIG_FTPD_WORKERSTACKSIZE - The stacksize to allocate for each
 #   FTP daemon worker thread.  Default:  2048 bytes.
 # 
@@ -877,6 +877,7 @@ CONFIG_NET_RESOLV_ENTRIES=4
 # CONFIG_DISABLE_PTHREAD - pthread support is required
 # CONFIG_DISABLE_POLL - poll() support is required
 #
+CONFIG_FTPD_CMDBUFFERSIZE=512
 
 #
 # RTC Configuration
-- 
GitLab