SD card example code for Seeed Wio 3G

Fork of Wio_3G-example-sd-driver by Toyomasa Watarai

Revision:
1:080085a0a3ec
Parent:
0:8eedb2495d52
--- a/main.cpp	Thu Aug 09 01:42:53 2018 +0000
+++ b/main.cpp	Mon Dec 03 08:27:31 2018 +0000
@@ -11,6 +11,8 @@
 DigitalOut SD_POWER(PA_15, 1);
 #endif
 
+// #define DO_FORMAT
+
 SDBlockDevice sd(MBED_CONF_APP_SPI_MOSI, MBED_CONF_APP_SPI_MISO, MBED_CONF_APP_SPI_CLK, MBED_CONF_APP_SPI_CS);
 FATFileSystem fs("sd", &sd);
 Serial pc(USBTX, USBRX, 115200);
@@ -34,7 +36,15 @@
 int main()
 {
     int error = 0;
-    pc.printf("Welcome to the filesystem example.\n");
+
+#if defined(DO_FORMAT)
+    pc.printf("Welcome to the filesystem example.\r\n"
+    "Formatting... ");
+    error = FATFileSystem::format(&sd);
+    return_error(error);
+#else
+    pc.printf("Welcome to the filesystem example.\r\n");
+#endif
 
     pc.printf("Opening a new file, numbers.txt.");
     FILE* fd = fopen("/sd/numbers.txt", "w+");