I-O DATA DEV2 / Mbed 2 deprecated NUCLEO_32_SD

Dependencies:   mbed SDFileSystem_NUCLEO_32

Files at this revision

API Documentation at this revision

Comitter:
hakusan270
Date:
Fri Dec 18 02:03:24 2020 +0000
Commit message:
sd filre test

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.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	Fri Dec 18 02:03:24 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/teams/I-O-DATA-DEV2/code/SDFileSystem_NUCLEO_32/#88ece4a12d29
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Dec 18 02:03:24 2020 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+DigitalIn btn(D2);
+RawSerial  pc(PA_2, PA_3);
+//SDFileSystem sd(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq
+//SDFileSystem sd(PB_15, PB_14, PB_13, D4, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, CS,name, card detect, sw type, freq
+SDFileSystem sd(D11,D12,D13,A0, "sd", NC, SDFileSystem::SWITCH_NONE,10000000); // mosi, miso, sclk, CS,name, card detect, sw type, freq
+
+// trim '\n'
+void ntrim(char *str)
+{
+    int i;
+    for (i = 0; str[i] != 0; ++i);
+
+    if (i > 0 && str[i - 1] == '\n')
+        str[i - 1] = 0;
+}
+
+
+int main()
+{
+    pc.printf("Hello\r\n");
+    // SD filesystem
+//    SDFileSystem *sd = new SDFileSystem(D11, D12, D13, D10, "sd", NC, SDFileSystem::SWITCH_NONE, 20000000); // mosi, miso, sclk, name, card detect, sw type, freq
+
+    while (1)
+    {
+       // if (btn) continue;
+
+        // file open
+        FILE *fp = fopen("/sd/test.txt", "r");
+        if (fp == NULL)
+        {
+            printf("open error!!\r\n");
+            goto neww;
+            //while(1);
+        }
+        // read text file
+        char buf[1024];
+        while (fgets(buf, sizeof(buf), fp) != NULL)
+        {
+            ntrim(buf);            
+            printf("%s\r\n", buf);
+        }
+    
+        // file close
+        fclose(fp);      
+ neww:         
+     fp = fopen("/sd/test.txt", "a");
+     fprintf(fp,"test write\n");
+     fclose(fp);        
+     while(1);
+
+        wait(1);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Dec 18 02:03:24 2020 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/mbed_official/code/mbed/builds/86740a56073b
\ No newline at end of file