testing out sd card on sensor pod

Dependencies:   SDFileSystem mbed

Fork of frdm-sdcard by Seiya Ono

Files at this revision

API Documentation at this revision

Comitter:
seiya1225
Date:
Fri Aug 10 16:57:19 2018 +0000
Commit message:
Publish sd card test code

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 Aug 10 16:57:19 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/neilt6/code/SDFileSystem/#e4d2567200db
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Aug 10 16:57:19 2018 +0000
@@ -0,0 +1,57 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+SDFileSystem sd(PTE3, PTE1, PTE2, PTE4, "sd"); // MOSI, MISO, SCK, CS
+DigitalIn sd_cs(PTA16);
+Serial pc(USBTX, USBRX);
+FILE *fp;
+
+uint32_t do_list(const char *fsrc)
+{
+    DIR *d = opendir(fsrc);
+    struct dirent *p;
+    uint32_t counter = 0;
+
+    while ((p = readdir(d)) != NULL) {
+        counter++;
+        printf("%s\n", p->d_name);
+    }
+    closedir(d);
+    return counter;
+}
+
+int main()
+{
+    pc.printf("Initializing \n\r");
+    wait(1);
+    pc.printf("Opening nyah/nyoho.txt\n\r");
+
+    wait(1);
+    fp = fopen("/sd/nyah/nyoho.txt", "r+");
+
+    if (fp == NULL) {
+        pc.printf("Unable to open the file \r\n");
+    } else {
+        pc.printf("\n\rFile pointer address: 0x%X\n\r", &fp);
+        
+        pc.printf("\n\rWriting to nyah/nyoho.txt\n\r");
+        wait(0.25);
+
+        fprintf(fp, "The quick brown fox jumps over the lazy dog");
+
+        rewind(fp);
+        fprintf(fp, "Seiya is trying to eat the SD card please stop him");
+        wait(0.25);
+
+        pc.printf("\n\rFlushing the buffer...\n\r");
+        int flush = fflush(fp);
+        wait(0.25);
+        if (flush == 0) pc.printf("Flush Successful!\n\r");
+        else pc.printf("**WARNING** Flush Failed\n\r");
+    }
+    wait(1);
+    fclose(fp);
+    pc.printf("\n\rDone\r\n");
+    wait(1);
+    exit(3);
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Aug 10 16:57:19 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/a7c7b631e539
\ No newline at end of file