Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: SDFileSystem mbed
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 #define LEN 2048 00004 SDFileSystem sd(PA_14, PA_13, PA_12, PA_11, "sd"); // the pinout on the mbed Cool Components workshop board SDFileSystem sd(PB_03, PB_02, PB_01, PB_00, "sd"); 00005 //SDFileSystem sd(PB_03, PB_02, PB_01, PB_00, "sd"); 00006 Serial uart1(PA_13,PA_14); 00007 FILE *fp; 00008 char buf[LEN]; 00009 int main() { 00010 uart1.baud(9600); 00011 uart1.printf("SD Card FAT FileSystem Testing....\r\n"); 00012 00013 mkdir("/sd/mydir", 0777); 00014 00015 if((fp = fopen("/sd/mydir/sdtest.txt", "w")) == NULL){ 00016 error("Could not open file for write\r\n"); 00017 return -1; 00018 } 00019 fprintf(fp, "DFRobot Test String ABCDEFG......\r\n"); 00020 fclose(fp); 00021 00022 if((fp = fopen("/sd/mydir/sdtest.txt", "r")) == NULL){ 00023 error("Could not open file for write\r\n"); 00024 return -1; 00025 } 00026 memset(buf,0,LEN); 00027 fread(buf,LEN,1,fp); 00028 buf[LEN-1] = 0; 00029 fclose(fp); 00030 uart1.printf("------------read sdtest.txt-----------\r\n"); 00031 uart1.printf("%s",buf); 00032 uart1.printf("------------end-----------\r\n"); 00033 }
Generated on Thu Jul 14 2022 10:56:35 by
1.7.2