Example of using SD card with Mbed OS5.

Revision:
1:9a5f06e7969e
Parent:
0:87642278ede6
--- a/main.cpp	Wed Feb 06 18:46:53 2019 +0000
+++ b/main.cpp	Thu Feb 14 10:37:28 2019 +0000
@@ -29,51 +29,16 @@
 #include "FATFileSystem.h"
 
 // Physical block device, can be any device that supports the BlockDevice API
-SDBlockDevice   blockDevice(p5, p6, p7, p8);
+SDBlockDevice   blockDevice(p5, p6, p7, p8);  // mosi, miso, sck, cs
 
 // File system declaration
 FATFileSystem   fileSystem("fs");
 
-// Set up the button to trigger an erase
-InterruptIn     btnErase(p11);
-
-void erase()
-{
-    printf("Initializing the block device... ");
-    fflush(stdout);
-
-    int err = blockDevice.init();
-    printf("%s\n", (err ? "Fail :(" : "OK"));
-    if (err) {
-        error("error: %s (%d)\n", strerror(-err), err);
-    }
-
-    printf("Erasing the block device... ");
-    fflush(stdout);
-    err = blockDevice.erase(0, blockDevice.size());
-    printf("%s\n", (err ? "Fail :(" : "OK"));
-    if (err) {
-        error("error: %s (%d)\n", strerror(-err), err);
-    }
-
-    printf("Deinitializing the block device... ");
-    fflush(stdout);
-    err = blockDevice.deinit();
-    printf("%s\n", (err ? "Fail :(" : "OK"));
-    if (err) {
-        error("error: %s (%d)\n", strerror(-err), err);
-    }
-}
-
 // Entry point for the example
 int main()
 {
     printf("--- Mbed OS filesystem example ---\n");
 
-    // Setup the erase event on button press, use the event queue
-    // to avoid running in interrupt context
-    btnErase.fall(mbed_event_queue()->event(erase));
-
     // Try to mount the filesystem
     printf("Mounting the filesystem... ");
     fflush(stdout);
@@ -222,6 +187,33 @@
     if (err < 0) {
         error("error: %s (%d)\n", strerror(-err), err);
     }
+    
+    printf("Initializing the block device... ");
+    fflush(stdout);
 
+    err = blockDevice.init();
+    printf("%s\n", (err ? "Fail :(" : "OK"));
+    if (err) {
+        error("error: %s (%d)\n", strerror(-err), err);
+    }
+
+    printf("Erasing the block device... ");
+    fflush(stdout);
+    err = blockDevice.erase(0, blockDevice.size());
+    printf("%s\n", (err ? "Fail :(" : "OK"));
+    if (err) {
+        error("error: %s (%d)\n", strerror(-err), err);
+    }
+
+    printf("Deinitializing the block device... ");
+    fflush(stdout);
+    err = blockDevice.deinit();
+    printf("%s\n", (err ? "Fail :(" : "OK"));
+    if (err) {
+        error("error: %s (%d)\n", strerror(-err), err);
+    }
+    
+    printf("\r\n");
+    
     printf("Mbed OS filesystem example done!\n");
 }