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:
- 3:8b77055a68ec
- Parent:
- 2:f8bd763b5584
- Child:
- 4:0719b77970da
--- a/main.cpp Fri Feb 12 15:52:44 2016 +0000 +++ b/main.cpp Sat Feb 13 13:27:13 2016 +0000 @@ -1,50 +1,47 @@ #include "mbed.h" #include "SDFileSystemDMA.h" + +#define UART_KEY_PRESS 1 + +#if defined(TARGET_NUCLEO_F411RE) +#define MOSI D11 +#define MISO D12 +#define SCLK D13 +#define CS D10 +#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 ( 12 * 1000000 ) Timer timer; Serial pc(USBTX,USBRX); -SDFileSystem sd( MOSI, MISO, SCLK, CS, "sd"); +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"); + fflush(stdout); while(!pc.readable()); volatile int res = pc.getc(); -} - -int base_test() { - - printf("\nPress any key!\n"); - wait_key_press(); +#else - mkdir("/sd/mydirx", 0777); - - FILE *fp = fopen("/sd/mydirx/sdtest.txt", "w"); - if(fp == NULL) { - error("Could not open file for write\n"); - } - fprintf(fp, "Hello fun SD Card World!"); - fclose(fp); - - printf("Goodbye World!\n"); - return 0; +#endif } void writeTest() { //Test write performance by creating a 1MB file - printf("Testing %dByte buffer: write performance...", sizeof(buffer)); + 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) { timer.start(); @@ -72,7 +69,8 @@ void readTest() { //Test read performance by reading the 1MB file created by writeTest() - printf("Testing %dByte buffer: read performance...", sizeof(buffer)); + printf("[Read]: Testing %dByte buffer: read performance...", sizeof(buffer)); + fflush(stdout); FileHandle* file = sd.open(FILE_NAME, O_RDONLY); if (file != NULL) { timer.start(); @@ -102,7 +100,6 @@ while(1){ printf("\nStart SD card accsess test!"); printf("\nWriting is very slow, wait several minuts."); - printf("\n-- Press any key --\n"); wait_key_press(); writeTest(); readTest();