first

Dependencies:   SDFileSystemDMA mbed

Refer to:
https://developer.mbed.org/users/mimi3/code/SDFileSystemDMA

Caution

If your board has SRAM less than or equal to 8KB, the 'buffer' size must be set to 512 Bytes.

NUCLEO-F411RE
About 2.5MBytes/sec
/media/uploads/mimi3/sdfilesystemdma-speed-test-teraterm-output-f411re.png
NUCLEO-L152RE
About 1MBytes/sec
/media/uploads/mimi3/sdfilesystemdma-l152re-cui.png

Revision:
9:289de1b6d378
Parent:
5:fef1667b832e
Child:
10:5f6fc7dc119b
--- a/main.cpp	Sun Feb 14 16:19:34 2016 +0000
+++ b/main.cpp	Sat Feb 20 13:57:35 2016 +0900
@@ -1,39 +1,39 @@
 #include "mbed.h"
 #include "SDFileSystemDMA.h"
 
+/* SD card Interface connection
+ *           :  aitendo   :  General
+ *  MCU sig. : IFB-254-SD :  PIN name
+     ---     :    1       :   9 dat2
+       CS    :    2       :   1 cs/dat3
+      MOSI   :    3       :   2 di/cmd
+       GND   :    4       :   3 vss1
+       VCC   :    5       :   4 vdd
+       CLK   :    6       :   5 clk
+       GND   :    7       :   6 vss2
+      MISO   :    8       :   7 do/dat0
+       ---   :    9       :   8 dat1
+       ---   :   10       :  11 wp
+       ---   :   11       :  10 cd1
+       ---   :   12       :  - case GND
+*/
+
+#include "spi_device.h"
+
 #define UART_KEY_PRESS  1
 
-#if defined(TARGET_NUCLEO_F411RE)|| defined(TARGET_F401RE)
-#define MOSI        D11
-#define MISO        D12
-#define SCLK        D13
-#define CS          D10
-#elif defined(TARGET_STM32F3)
-#define MOSI        PC_12
-#define MISO        PC_11
-#define SCLK        PC_10
-#define CS          PC_9
-#else
-#define MOSI        D4
-#define MISO        D5
-#define SCLK        D3
-#define CS          D10
-#endif
-//#define CD          D9      // detect SD card insertion. Do open always. 
-//#define CD_TYPE     SDFileSystem::SWITCH_POS_NC     // always instertion state
-#define SPI_CLOCK_HZ    ( 12 * 1000000 ) 
+#define SPI_CLOCK_HZ    ( 100 * 1000000 ) 
 Timer timer;
 Serial pc(USBTX,USBRX);
 
 SDFileSystem sd( MOSI, MISO, SCLK, CS, "sd", SPI_CLOCK_HZ);  
-//SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
 
 char buffer[512];
 #define X_MEGA_BYTE     ((1)*1024*1024) /* 1Mbyte */
 #define FILE_NAME   "GPATH"
 void wait_key_press(){
 #if UART_KEY_PRESS
-    printf("\n-- Press any key --\n");  
+    pc.printf("\n-- Select 'r' or 'w' --\n");  
     fflush(stdout); 
     while(!pc.readable());
     volatile int res = pc.getc();
@@ -45,7 +45,7 @@
 void writeTest()
 {
     //Test write performance by creating a 1MB file
-    printf("[Write]: Testing %dByte buffer: write performance...", sizeof(buffer));
+    pc.printf("[Write]: Testing %dByte buffer: write performance...", sizeof(buffer));
     fflush(stdout); 
     FileHandle* file = sd.open(FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC);
     if (file != NULL) {
@@ -53,20 +53,20 @@
         for (uint32_t i = 0; i < (X_MEGA_BYTE / sizeof(buffer)); i++) {
             if (file->write(buffer, sizeof(buffer)) != sizeof(buffer)) {
                 timer.stop();
-                printf("write error!\n");
+                pc.printf("write error!\n");
                 timer.reset();
                 return;
             }
         }
         timer.stop();
         if (file->close())
-            printf("failed to close file!\n");
+            pc.printf("failed to close file!\n");
         else{
-            printf("done!\n\tResult: %d KB/s\n", (  1024 * 1000000 ) / timer.read_us() );
+            pc.printf("done!\n\tResult: %d KB/s\n", (  1024 * 1000000 ) / timer.read_us() );
         }
         timer.reset();
     } else {
-        printf("failed to create file!\n");
+        pc.printf("failed to create file!\n");
     }
 }
 
@@ -74,7 +74,7 @@
 void readTest()
 {
     //Test read performance by reading the 1MB file created by writeTest()
-    printf("[Read]: Testing %dByte buffer: read performance...", sizeof(buffer));
+    pc.printf("[Read]: Testing %dByte buffer: read performance...", sizeof(buffer));
     fflush(stdout); 
     FileHandle* file = sd.open(FILE_NAME, O_RDONLY);
     if (file != NULL) {
@@ -84,30 +84,42 @@
             iterations++;
         timer.stop();
         if (iterations != (X_MEGA_BYTE / sizeof(buffer))){
-            printf("read error!\n");
+            pc.printf("read error!\n");
                 }
         else if (file->close()){
-            printf("failed to close file!\n");
+            pc.printf("failed to close file!\n");
                 }
        // else if (sd.remove(FILE_NAME))
-       //     printf("failed to delete file!\n");
+       //     pc.printf("failed to delete file!\n");
         else{
-            printf("done!\n\tResult: %d KB/s\n",  (  1024 * 1000000 ) / timer.read_us());
+            pc.printf("done!\n\tResult: %d KB/s\n",  (  1024 * 1000000 ) / timer.read_us());
         }
         timer.reset();
     } else {
-        printf("failed to open file!\n");
+        pc.printf("failed to open file!\n");
     }
 }
 
 int main(){
     /* UART Baudrate is 9600bps*/
-    while(1){
-        printf("\nStart SD card accsess test!");
-        printf("\nWriting is very slow, wait several minuts."); 
-        wait_key_press();
-        writeTest();
-        readTest();
-    }
+	while(1){
+		pc.printf("\nSysClock= %d Hz", SystemCoreClock);
+		pc.printf("   mbed rev.%d", MBED_LIBRARY_VERSION);
+		pc.printf("\nStart SD card accsess test!");
+		pc.printf("\n  SPI(%d) device",SPI_DEV);
+		pc.printf("\n[r]: Start Read Test. At least execute [w] onece");
+		pc.printf("\n[w]: Start Write and Read Test");
+		pc.printf("\nWriting is very slow, wait tens of seconds."); 
+		pc.printf("\n-- Select [r] or [w] --\n");  
+		fflush(stdout); 
+		while(!pc.readable());
+		char ch = pc.getc();
+		if( ch =='r' ){
+			readTest();
+		} else if( ch =='w' ){
+			writeTest();
+			readTest();
+		}
+	}
 }