A simple serial test program for the re-written SDFileSystem library.

Dependencies:   SDFileSystem mbed

Files at this revision

API Documentation at this revision

Comitter:
neilt6
Date:
Tue Jul 29 20:13:41 2014 +0000
Child:
1:e0c49c5ad6d1
Commit message:
Initial commit

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	Tue Jul 29 20:13:41 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/neilt6/code/SDFileSystem/#2a6d8a096edc
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Jul 29 20:13:41 2014 +0000
@@ -0,0 +1,66 @@
+#include "mbed.h"
+#include "SDFileSystem.h"
+
+DigitalIn button(p21, PullUp);
+SDFileSystem sd(p5, p6, p7, p20, p22, "sd", 6000000);
+
+int main()
+{
+    while(1) {
+        //Print the start message
+        printf("\nPress the button to perform tests: ");
+
+        //Wait for the button to be pressed
+        while(button);
+
+        //Display the card type and capacity
+        printf("\nCard type: ");
+        if (sd.card_type() == SDFileSystem::CARD_NONE)
+            printf("None\n");
+        else if (sd.card_type() == SDFileSystem::CARD_MMC)
+            printf("MMC\n");
+        else if (sd.card_type() == SDFileSystem::CARD_SD)
+            printf("SD\n");
+        else if (sd.card_type() == SDFileSystem::CARD_SDHC)
+            printf("SDHC\n");
+        else
+            printf("Unknown\n");
+        printf("Sectors: %llu\n", sd.disk_sectors());
+        printf("Capacity: %.1fMB\n", (sd.disk_sectors() * 512) / 1048576.0);
+
+        //Format the card
+        /*printf("Formatting card...");
+        if (sd.format() == 0)
+            printf("success!\n");
+        else
+            printf("failed!\n");*/
+
+        //Perform a write test
+        printf("Writing to card...");
+        FILE *fp = fopen("/sd/sdtest.txt", "w");
+        if (fp != NULL) {
+            fprintf(fp, "We're writing to an SD card!");
+            fclose(fp);
+            printf("success!\n");
+        } else {
+            printf("failed!\n");
+        }
+
+        //Perform a read test
+        printf("Reading from card...");
+        fp = fopen("/sd/sdtest.txt", "r");
+        if (fp != NULL) {
+            char c = fgetc(fp);
+            if (c == 'W')
+                printf("success!\n");
+            else
+                printf("incorrect char (%c)!\n", c);
+            fclose(fp);
+        } else {
+            printf("failed!\n");
+        }
+
+        //Delay for 0.2 seconds for simple debouncing
+        wait(0.2);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Jul 29 20:13:41 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/6213f644d804
\ No newline at end of file