SD USB MSD helloworld

Dependencies:   USBFileSystem USBSDFileSystem mbed

Created based on comment from Erik Olieman see https://mbed.org/questions/1181/combine-SDfilesystem-with-USBMSD_SD/?c=7180

As well as based on SDFileSystem library for the spi-access to SD-card.

It gives the next output:

Hello World!

now a USB drive should appear on your PC
create directory and append to log file
appending: '[0]Hello fun SD Card World!'
Entering loop of 1 min cycle time
appending: '[1]Hello fun SD Card World!'
appending: '[2]Hello fun SD Card World!'
...

This works.

Although, I've to admit it is not very convenient, since my win7 pc always disconnect/connect the drive and at disconnect it also closes the explorer which show the content of that drive. It does the same with the editor that has the file opened.

Files at this revision

API Documentation at this revision

Comitter:
karelv
Date:
Tue Aug 27 19:42:29 2013 +0000
Parent:
0:ce2fc50a859f
Child:
2:f7b4edf066de
Commit message:
update after recommendations of Erik Olieman

Changed in this revision

USBSDFileSystem.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
--- a/USBSDFileSystem.lib	Mon Aug 26 19:45:10 2013 +0000
+++ b/USBSDFileSystem.lib	Tue Aug 27 19:42:29 2013 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/karelv/code/USBSDFileSystem/#c3d2e89ca30d
+http://mbed.org/users/karelv/code/USBSDFileSystem/#88089dd56f0e
--- a/main.cpp	Mon Aug 26 19:45:10 2013 +0000
+++ b/main.cpp	Tue Aug 27 19:42:29 2013 +0000
@@ -10,32 +10,36 @@
 {
     FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
     if(fp == NULL) {
-        error("Could not open file for write\n");
+        printf("Could not open file for write\n");
     } else
     {
       fprintf(fp, "[%d]Hello fun SD Card World!\n", i);
+      printf("appending: '[%d]Hello fun SD Card World!'\n", i);
       fclose(fp); 
     }
 }
 
 int main() {
 
+    sd.usbMode (1); // allow fopen/fprintf when connected with USB-drive.
     printf("Hello World!\n\n");   
-
-#if 10
+    
+    printf("now a USB drive should appear on your PC\n");
+    wait (60);
+       
+    printf("create directory and append to log file\n");
     mkdir("/sd/mydir", 0777);
-    //mylog (0);    
-#endif
+    mylog (0);    
 
-    printf("Goodbye World!\n");
+    printf("Entering loop of 1 min cycle time\n");
 
     int i = 1;
     while(1) {
         myled = 0;
-        wait(5);
-        sd.disconnect ();
+        wait(5);        
+        //sd.disconnect ();
         mylog (i++);
-        sd.connect ();
+        //sd.connect ();
         myled = 1;
         wait(55);
     }