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
NUCLEO-L152RE
About 1MBytes/sec
Diff: main.cpp
- Revision:
- 11:d5fc11ac948a
- Parent:
- 10:5f6fc7dc119b
- Child:
- 12:dfa39c797789
--- a/main.cpp Sat Feb 20 14:04:54 2016 +0900 +++ b/main.cpp Sun Feb 21 21:25:55 2016 +0900 @@ -27,11 +27,12 @@ #define SPI_CLOCK_HZ ( 12 * 1000000 ) Timer timer; + Serial pc(USBTX,USBRX); SDFileSystem sd( MOSI, MISO, SCLK, CS, "sd", SPI_CLOCK_HZ); -char buffer[512]; +char buffer[512] __attribute__ ((aligned (4))) ; #define X_MEGA_BYTE ((1)*1024*1024) /* 1Mbyte */ #define FILE_NAME "GPATH" void wait_key_press(){ @@ -48,7 +49,7 @@ void writeTest() { //Test write performance by creating a 1MB file - pc.printf("[Write]: Testing %dByte buffer: write performance...", sizeof(buffer)); + pc.printf("[Write]: Testing %d byte buffer: write performance...", sizeof(buffer)); fflush(stdout); FileHandle* file = sd.open(FILE_NAME, O_WRONLY | O_CREAT | O_TRUNC); if (file != NULL) { @@ -77,7 +78,7 @@ void readTest() { //Test read performance by reading the 1MB file created by writeTest() - pc.printf("[Read]: Testing %dByte buffer: read performance...", sizeof(buffer)); + pc.printf("[Read]: Testing %d byte buffer: read performance...", sizeof(buffer)); fflush(stdout); FileHandle* file = sd.open(FILE_NAME, O_RDONLY); if (file != NULL) { @@ -105,14 +106,14 @@ int main(){ /* UART Baudrate is 9600bps*/ - while(1){ - pc.printf("\nSysClock= %d Hz", SystemCoreClock); + while(1){ + pc.printf("\n---------------------------------------"); + 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 SPI(%d) device",SPI_DEV); + pc.printf("\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("\nWriting is very slow, wait tens of seconds."); + pc.printf("\nWriting is very slow, wait tens of seconds."); pc.printf("\n-- Select [r] or [w] --\n"); fflush(stdout); while(!pc.readable()); @@ -120,9 +121,9 @@ if( ch =='r' ){ readTest(); } else if( ch =='w' ){ - writeTest(); - readTest(); + writeTest(); + readTest(); } - } + } }