SD Card usage example

Dependencies:   mbed SDFileSystem

Committer:
ffxx68
Date:
Fri Jul 15 09:05:56 2022 +0000
Revision:
2:f31ded5c20f3
Parent:
0:bdbd3d6fc5d5
Initial version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
mbed_official 0:bdbd3d6fc5d5 1 #include "mbed.h"
mbed_official 0:bdbd3d6fc5d5 2 #include "SDFileSystem.h"
mbed_official 0:bdbd3d6fc5d5 3
ffxx68 2:f31ded5c20f3 4 //SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs
ffxx68 2:f31ded5c20f3 5 SDFileSystem sd(PB_5, PB_4, PB_3, PA_10, "sd"); // mosi, miso, sclk, cs
ffxx68 2:f31ded5c20f3 6
mbed_official 0:bdbd3d6fc5d5 7 int main() {
ffxx68 2:f31ded5c20f3 8 printf("SD Card Testbed\n");
ffxx68 2:f31ded5c20f3 9
ffxx68 2:f31ded5c20f3 10 //Perform a write test
ffxx68 2:f31ded5c20f3 11 printf("Writing to SD card... ");
ffxx68 2:f31ded5c20f3 12 FILE *fp = fopen("/sd/sdtest.txt", "w");
ffxx68 2:f31ded5c20f3 13 if (fp != NULL) {
ffxx68 2:f31ded5c20f3 14 fprintf(fp, "We're writing to an SD card!");
ffxx68 2:f31ded5c20f3 15 fclose(fp);
ffxx68 2:f31ded5c20f3 16 printf("success!\n");
ffxx68 2:f31ded5c20f3 17 } else
ffxx68 2:f31ded5c20f3 18 printf("failed!\n");
mbed_official 0:bdbd3d6fc5d5 19 fprintf(fp, "Hello fun SD Card World!");
mbed_official 0:bdbd3d6fc5d5 20 fclose(fp);
ffxx68 2:f31ded5c20f3 21
mbed_official 0:bdbd3d6fc5d5 22 printf("Goodbye World!\n");
mbed_official 0:bdbd3d6fc5d5 23 }