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:
21:6253a88675a5
Parent:
20:e34f5e5f307b
Child:
22:5c133291a01d
--- a/main.cpp	Tue Aug 30 20:17:00 2016 +0900
+++ b/main.cpp	Thu Sep 01 17:46:24 2016 +0900
@@ -17,6 +17,35 @@
        ---   :   11       :  10 cd1
        ---   :   12       :  - case GND
 */
+/* SD card pin
+Pin side
+--------------\
+        9     = \    DAT2/NC
+            1 ===|   CS/DAT3    [CS]
+            2 ===|   CMD/DI     [DI]
+            3 ===|   VSS1
+Bottom      4 ===|   VDD
+View        5 ===|   CLK        [CLK]
+            6 ===|   VSS2
+            7 ===|   DO/DAT0    [DO]
+            8   =|   DAT1/IRQ
+-----------------
+
+                                        Arduino      NUCLEO-F411       NUCLEO-F030R8
+Logo side
+-----------------
+            8   =|   DAT1/IRQ
+            7 ===|   DO/DAT0    [DO]     D12           D12/PA_6           D5/PB_4
+            6 ===|   VSS2
+Top         5 ===|   CLK        [CLK]    D13           D13/PA_5           D3/PB_3
+View        4 ===|   VDD
+            3 ===|   VSS1
+            2 ===|   CMD/DI     [DI]     D11           D11/PA_7           D4/PB_5
+            1 ===|   CS/DAT3    [CS]     D8            D10/PB_6           D10/PB_6
+        9     = /    DAT2/NC
+--------------/
+*/
+
 
 /* You should confirm SPI_DEV macro in "spi_device.h" to specify SPI device number.
  * (default is 1 (SPI1))
@@ -28,26 +57,33 @@
 
 Timer timer;
 //Serial pc(PA_9,PA_10);
-Serial pc(USBTX,USBRX);
+Serial pc(USBTX,USBRX); /* Baudrate is 9600bps*/
 
 SDFileSystem sd( MOSI, MISO, SCLK, CS, "sd", SPI_CLOCK_HZ);  
 
-//char buffer[512*1]  __attribute__ ((aligned (4))) ;    /*   512 byte */
-//char buffer[512*2]  __attribute__ ((aligned (4))) ;    /*  1024 byte */
-char buffer[512*4]  __attribute__ ((aligned (4))) ;    /*  2048 byte */
-//char buffer[512*8]  __attribute__ ((aligned (4))) ;    /*  4096 byte */
-//char buffer[512*16] __attribute__ ((aligned (4))) ;    /*  8192 byte */
-//char buffer[512*32] __attribute__ ((aligned (4))) ;    /* 16384 byte */
+//char buffer[512*1]  __attribute__ ((aligned (4))) ;    /*   512 bytes */
+//char buffer[512*2]  __attribute__ ((aligned (4))) ;    /*  1024 bytes */
+char buffer[512*4]  __attribute__ ((aligned (4))) ;      /*  2048 bytes */
+//char buffer[512*8]  __attribute__ ((aligned (4))) ;    /*  4096 bytes */
+//char buffer[512*16] __attribute__ ((aligned (4))) ;    /*  8192 bytes */
+//char buffer[512*32] __attribute__ ((aligned (4))) ;    /* 16384 bytes */
 
 #define X_MEGA_BYTE     ((1)*1024*1024) /* 1Mbyte */
 #define FILE_NAME   "GPATH"
 
-void wait_key_press(){
+#if defined(__GNUC__)       /* GCC        */ 
+#define TOOLCHAIN   "GCC_ARM"
+#elif defined(__CC_ARM)     /* ARMCC      */ 
+#define TOOLCHAIN   "ARM/uARM"
+#elif defined(__ICCARM__)   /* IAR        */
+#define TOOLCHAIN   "IAR"
+#warning "This compiler is not yet supported."
+#endif
+
+int wait_key_press(){
 #if UART_KEY_PRESS
-	pc.printf("\n-- Select 'r' or 'w' --\n");  
-	fflush(stdout); 
 	while(!pc.readable());
-	volatile int res = pc.getc();
+	return  pc.getc();
 #endif
 }
 
@@ -55,7 +91,7 @@
 {
 #if !_FS_READONLY
 	//Test write performance by creating a 1MB file
-	pc.printf("[Write]: Testing %d byte buffer: write performance...", sizeof(buffer));
+	pc.printf("[Write]: Testing %d bytes buffer: write performance...", sizeof(buffer));
 	fflush(stdout); 
 	for(uint32_t k = 0; k < sizeof(buffer); k++){
 		buffer[k] = k & 0xff;
@@ -88,7 +124,7 @@
 void readTest()
 {
 	//Test read performance by reading the 1MB file created by writeTest()
-	pc.printf("[Read]: Testing %d byte buffer: read performance...", sizeof(buffer));
+	pc.printf("[Read]: Testing %d bytes buffer: read performance...", sizeof(buffer));
 	fflush(stdout); 
 	FileHandle* file = sd.open(FILE_NAME, O_RDONLY);
 	if (file != NULL) {
@@ -104,8 +140,6 @@
 		else if (file->close()){
 			pc.printf("failed to close file!\n");
 		}
-		// else if (sd.remove(FILE_NAME))
-		//     pc.printf("failed to delete file!\n");
 		else{
 			pc.printf("done!\n\tResult: %d KB/s\n",  (  1024 * 1000000 ) / timer.read_us());
 		}
@@ -119,7 +153,7 @@
 {
 	int errorCount = 0;
 	//Test read performance by reading the 1MB file created by writeTest()
-	pc.printf("[Read]: Verifying %d byte buffer ...", sizeof(buffer));
+	pc.printf("[Read]: Verifying %d bytes buffer ...", sizeof(buffer));
 	fflush(stdout); 
 	FileHandle* file = sd.open(FILE_NAME, O_RDONLY);
 	if (file != NULL) {
@@ -140,8 +174,6 @@
 		else if (file->close()){
 			pc.printf("failed to close file!\n");
 		}
-		// else if (sd.remove(FILE_NAME))
-		//     pc.printf("failed to delete file!\n");
 		else{
 			//    pc.printf("done!\n\tResult: %d KB/s\n",  (  1024 * 1000000 ) / timer.read_us());
 
@@ -153,21 +185,22 @@
 	pc.printf("\n     Error Count : %d", errorCount);
 }
 
+
 int main(){
-	/* UART Baudrate is 9600bps*/
+    int i = 1;
 	while(1){
-		pc.printf("\n---------------------------------------");
+		pc.printf("\n(%2d)------- SDFileSystemDMA --------------------------------",i++);
+		pc.printf("\nR/W Buffer size: %5d bytes", sizeof(buffer) );
+		pc.printf("\nCompiler: %s, mbed lib Rev.%d", TOOLCHAIN, MBED_LIBRARY_VERSION);
 		pc.printf("\nSPI(%d), SysClock= %d Hz",SPI_DEV, SystemCoreClock);
-		pc.printf("   mbed rev.%d", MBED_LIBRARY_VERSION);
-		pc.printf("\nStart SD card accsess test!");
+		pc.printf("\n\nStart SD card accsess test!");
 		pc.printf("\n[r]: Start Read Test. At least execute [w] onece");
 		pc.printf("\n[w]: Start Write and Read Test");
 		pc.printf("\n[v]: Start Read Verify Test. At least execute [w] onece");
 		pc.printf("\nWriting is very slow, wait tens of seconds."); 
-		pc.printf("\n-- Select [r] or [w] --\n");  
+		pc.printf("\n--- Select [r] or [w] ---\n");  
 		fflush(stdout); 
-		while(!pc.readable());
-		char ch = pc.getc();
+		char ch = wait_key_press();
 		if( ch =='r' ){
 			readTest();
 		} else if( ch =='w' ){
@@ -176,6 +209,12 @@
 		} else if( ch =='v' ){
 			verifyTest();
 		}
+        else{
+            continue;
+        }
+		pc.printf("\n--- Press any key ---\n");  
+		fflush(stdout); 
+		wait_key_press();
 	}
 }