Zoltan Hudak / Mbed 2 deprecated STM32F103C8T6_SDCard

Dependencies:   mbed SDFileSystem

Files at this revision

API Documentation at this revision

Comitter:
hudakz
Date:
Thu Apr 12 16:56:26 2018 +0000
Child:
1:e8699d7ca61a
Commit message:
Initial release.

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
mbed-STM32F103C8T6.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SDFileSystem.lib	Thu Apr 12 16:56:26 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/Whitworth-EN173-Resources/code/SDFileSystem/#ee903cb278a6
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 12 16:56:26 2018 +0000
@@ -0,0 +1,79 @@
+#include "stm32f103c8t6.h"
+#include "mbed.h"
+#include "SDFileSystem.h"
+#include "errno.h"
+
+Serial              pc(USBTX, USBRX);
+SDFileSystem*       fs;
+FILE*               fp;
+
+int main()
+{
+    confSysClock();     //Configure system clock (72MHz HSE clock, 48MHz USB clock)
+    pc.baud(9600);
+
+    pc.printf("Starting...\r\n");
+    
+    fs = new SDFileSystem(PB_5, PB_4, PB_3, PA_10, "sd"); // mosi, miso, sck, cs
+    
+    int err = fs->mount();
+    pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
+    if (err)
+        return err;
+ 
+    // Open the file.
+    pc.printf("Opening file '/sd/mytest/sdtest.txt'... ");
+ 
+    fp = fopen("/sd/mytest/sdtest.txt", "w+");
+    pc.printf("%s\r\n", (!fp ? "Failed :(\r\n" : "OK\r\n"));
+ 
+    if (!fp)
+    {
+        // Check whether directory '/sd/mytest' exists.
+        pc.printf("\r\nChecking directory '/sd/mytest'...\r\n");
+        struct stat info;
+        err = stat("/sd/mytest", &info);
+        if (err)
+        {
+            pc.printf("Directory '/sd/mytest' does not exist.\r\n");
+            pc.printf("Trying to create it...");
+            err = mkdir("/sd/mytest", 0777);
+            pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
+            if (err)
+              return err;
+        }
+                
+        // Create a new 'sdtest.txt' file.
+        pc.printf("File not found, creating a new one...\r\n");
+        fp = fopen("/sd/mytest/sdtest.txt", "w+");
+        pc.printf("%s\r\n", (!fp ? "Failed :(" : "OK"));
+        if (!fp)
+        {
+            error("error: %s (%d)\r\n", strerror(errno), -errno);
+            return errno;
+        }
+    }
+    
+    for (int i = 0; i < 10; i++)
+    {
+        pc.printf("Writing numbers (%d/%d)... ", i, 10);
+        err = fprintf(fp, "    %d\r\n", i);
+        if (err < 0)
+        {
+            pc.printf("Fail :(\r\n");
+            error("error: %s (%d)\r\n", strerror(errno), -errno);
+        }
+        else
+            pc.printf("OK\r\n");
+    }
+ 
+    pc.printf("Writing numbers (%d/%d)... OK\r\n\r\n", 10, 10);
+    
+    err = fclose(fp);
+    pc.printf("Closing file '/sd/mytest/sdtest.txt'... ");
+    pc.printf("%s\r\n", (err ? "Failed :(\r\n" : "OK\r\n"));
+    if (err)
+      return err;
+ 
+    return 0;
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-STM32F103C8T6.lib	Thu Apr 12 16:56:26 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/hudakz/code/mbed-STM32F103C8T6/#727468adfd1d
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 12 16:56:26 2018 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/994bdf8177cb
\ No newline at end of file