This program is an example of of using the MSCUSBHost code with a raw build of ELM Chan Fat Fs. This was done to add both Long File Name Support along with proper time/date stamps (assuming you have a battery hooked up to keep time). This code exposes the Chan API (see main.cpp) and is NOT a c++ class: http://elm-chan.org/fsw/ff/00index_e.html The diskio.c file has the mapping needed to link the filesystem to the MSC stuff

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "ff.h"
00003 
00004 DigitalOut myled(LED1);
00005 Serial pc(USBTX, USBRX); 
00006 
00007 FATFS MyFileSystem;
00008 FIL  MyFile;
00009 
00010 int main()
00011 {
00012       unsigned int BytesWritten;
00013         
00014       //mount the SD card (any drive number will map to the SD card)
00015       f_mount(0,&MyFileSystem);
00016       //Open the file for open and write
00017       f_open(&MyFile,"Test1.2.3.4.txt",FA_WRITE|FA_OPEN_ALWAYS);
00018       //Write some junk
00019       f_write(&MyFile,"Testing!\r\nTesting,1,2,3\r\n",27,&BytesWritten);     
00020       //Close the file
00021       f_close(&MyFile);
00022       
00023     while(1)
00024         {
00025            pc.printf("all done!!\r\n");
00026            wait(1);
00027            myled = !myled;
00028        }
00029 }