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.

Committer:
karelv
Date:
Mon Aug 26 19:45:10 2013 +0000
Revision:
0:ce2fc50a859f
Child:
1:c7f66434c692
hello world for USBSDFileSystem

Who changed what in which revision?

UserRevisionLine numberNew contents of line
karelv 0:ce2fc50a859f 1 #include "mbed.h"
karelv 0:ce2fc50a859f 2 #include "USBSDFileSystem.h"
karelv 0:ce2fc50a859f 3
karelv 0:ce2fc50a859f 4 DigitalOut myled(LED1);
karelv 0:ce2fc50a859f 5
karelv 0:ce2fc50a859f 6 USBSDFileSystem sd("sd", p11, p12, p13, p14); // the pinout on the mbed testbed board // mosi, miso, sclk, cs
karelv 0:ce2fc50a859f 7
karelv 0:ce2fc50a859f 8
karelv 0:ce2fc50a859f 9 void mylog (int i)
karelv 0:ce2fc50a859f 10 {
karelv 0:ce2fc50a859f 11 FILE *fp = fopen("/sd/mydir/sdtest.txt", "a");
karelv 0:ce2fc50a859f 12 if(fp == NULL) {
karelv 0:ce2fc50a859f 13 error("Could not open file for write\n");
karelv 0:ce2fc50a859f 14 } else
karelv 0:ce2fc50a859f 15 {
karelv 0:ce2fc50a859f 16 fprintf(fp, "[%d]Hello fun SD Card World!\n", i);
karelv 0:ce2fc50a859f 17 fclose(fp);
karelv 0:ce2fc50a859f 18 }
karelv 0:ce2fc50a859f 19 }
karelv 0:ce2fc50a859f 20
karelv 0:ce2fc50a859f 21 int main() {
karelv 0:ce2fc50a859f 22
karelv 0:ce2fc50a859f 23 printf("Hello World!\n\n");
karelv 0:ce2fc50a859f 24
karelv 0:ce2fc50a859f 25 #if 10
karelv 0:ce2fc50a859f 26 mkdir("/sd/mydir", 0777);
karelv 0:ce2fc50a859f 27 //mylog (0);
karelv 0:ce2fc50a859f 28 #endif
karelv 0:ce2fc50a859f 29
karelv 0:ce2fc50a859f 30 printf("Goodbye World!\n");
karelv 0:ce2fc50a859f 31
karelv 0:ce2fc50a859f 32 int i = 1;
karelv 0:ce2fc50a859f 33 while(1) {
karelv 0:ce2fc50a859f 34 myled = 0;
karelv 0:ce2fc50a859f 35 wait(5);
karelv 0:ce2fc50a859f 36 sd.disconnect ();
karelv 0:ce2fc50a859f 37 mylog (i++);
karelv 0:ce2fc50a859f 38 sd.connect ();
karelv 0:ce2fc50a859f 39 myled = 1;
karelv 0:ce2fc50a859f 40 wait(55);
karelv 0:ce2fc50a859f 41 }
karelv 0:ce2fc50a859f 42 }