Demo to read and write to both SD and USB File System

Dependencies:   mbed

Example (more detailed example in the main.cpp file):

#include "mbed.h"
#include "MSCFileSystem.h"
#include "SDFileSystem.h"

MSCFileSystem fs("fs");
SDFileSystem sd(p5, p6, p7, p8, "sd", p11, SDFileSystem::SWITCH_NEG_NO, 15000000);


// CAUTION: Return values should ALWAYS be checked. Not shown here for brevity.

int main() {
...
    FileHandle * sdfile = sd.open("test.txt", O_WRONLY | O_CREAT | O_TRUNC);
    sdfile->write("hello", 6);
    sdfile->close();
...

    FILE * file = fopen("nextest.txt", "w");
    fwrite(buffer, 1, sizeof(buffer), file);
    fclose(file);
...
    mkdir("/sd/sd_dir", 0777);
    mkdir("/fs/fs_dir", 0777);

    remove("/sd/sdfinal.log");
    rename("/sd/sdfinal.txt", "/sd/sdfinal.log");
...
}
Committer:
chris
Date:
Tue Oct 16 15:47:35 2012 +0000
Revision:
2:c887cf1c3ed9
Parent:
0:22a5db2c7926
Child:
3:a72f30142261
Adapted from USBFlashDiskTest

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chris 2:c887cf1c3ed9 1 #include "mbed.h"
chris 2:c887cf1c3ed9 2 #include "MSCFileSystem.h"
chris 2:c887cf1c3ed9 3
chris 2:c887cf1c3ed9 4 MSCFileSystem fs("fs");
chris 2:c887cf1c3ed9 5 DigitalOut led(LED1);
chris 2:c887cf1c3ed9 6 AnalogIn pot1(p19);
chris 2:c887cf1c3ed9 7
chris 2:c887cf1c3ed9 8 int main()
chris 2:c887cf1c3ed9 9 {
chris 2:c887cf1c3ed9 10 FILE *fp = fopen("/fs/test.csv","w");
chris 2:c887cf1c3ed9 11 printf("Create filehandle for test.csv\n");
chris 2:c887cf1c3ed9 12
chris 2:c887cf1c3ed9 13 printf("Writing to file\n");
chris 2:c887cf1c3ed9 14 for (int i=0; i<100; i++) {
chris 2:c887cf1c3ed9 15 fprintf(fp,"%.2f\n",pot1.read());
chris 2:c887cf1c3ed9 16 wait(0.05);
chris 2:c887cf1c3ed9 17 led=!led;
chris 2:c887cf1c3ed9 18 }
chris 2:c887cf1c3ed9 19
chris 2:c887cf1c3ed9 20 fclose(fp);
chris 2:c887cf1c3ed9 21 printf("Close the handle\n");
chris 2:c887cf1c3ed9 22 led=1;
chris 2:c887cf1c3ed9 23 }