SD Card usage example

Dependencies:   mbed SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
ffxx68
Date:
Fri Jul 15 09:05:56 2022 +0000
Parent:
1:e4d7342be507
Commit message:
Initial version

Changed in this revision

SDFileSystem.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e4d7342be507 -r f31ded5c20f3 SDFileSystem.lib
--- a/SDFileSystem.lib	Tue May 16 05:18:55 2017 +0000
+++ b/SDFileSystem.lib	Fri Jul 15 09:05:56 2022 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/SDFileSystem/#8db0d3b02cec
+https://os.mbed.com/users/ffxx68/code/SDFileSystem/#3488faedd0d1
diff -r e4d7342be507 -r f31ded5c20f3 main.cpp
--- a/main.cpp	Tue May 16 05:18:55 2017 +0000
+++ b/main.cpp	Fri Jul 15 09:05:56 2022 +0000
@@ -1,19 +1,23 @@
 #include "mbed.h"
 #include "SDFileSystem.h"
  
-SDFileSystem sd(p5, p6, p7, p8, "sd"); // the pinout on the mbed Cool Components workshop board
- 
+//SDFileSystem sd(p5, p6, p7, p8, "sd"); // mosi, miso, sclk, cs
+SDFileSystem sd(PB_5, PB_4, PB_3, PA_10, "sd"); // mosi, miso, sclk, cs
+
 int main() {
-    printf("Hello World!\n");   
- 
-    mkdir("/sd/mydir", 0777);
-    
-    FILE *fp = fopen("/sd/mydir/sdtest.txt", "w");
-    if(fp == NULL) {
-        error("Could not open file for write\n");
-    }
+     printf("SD Card Testbed\n");   
+     
+     //Perform a write test
+     printf("Writing to SD card... ");
+     FILE *fp = fopen("/sd/sdtest.txt", "w");
+     if (fp != NULL) {
+         fprintf(fp, "We're writing to an SD card!");
+         fclose(fp);
+         printf("success!\n");
+     } else 
+        printf("failed!\n");
     fprintf(fp, "Hello fun SD Card World!");
     fclose(fp); 
- 
+    
     printf("Goodbye World!\n");
 }