USNHostMSD Hello World

Dependencies:   USBHost mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "USBHostMSD.h"
00003 
00004 DigitalOut led(LED1);
00005 
00006 void msd_task(void const *) {
00007     
00008     USBHostMSD msd("usb");
00009     int i = 0;
00010     
00011     while(1) {
00012         
00013         // try to connect a MSD device
00014         while(!msd.connect()) {
00015             Thread::wait(500);
00016         }
00017         
00018         // in a loop, append a file
00019         // if the device is disconnected, we try to connect it again
00020         while(1) {
00021             
00022             // append a file
00023             FILE * fp = fopen("/usb/test1.txt", "a");
00024         
00025             if (fp != NULL) {
00026                 fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++);
00027                 printf("Goodbye World!\r\n");
00028                 fclose(fp);
00029             } else {
00030                 printf("FILE == NULL\r\n");
00031             }
00032             
00033             Thread::wait(500);
00034         
00035             // if device disconnected, try to connect again
00036             if (!msd.connected())
00037                 break;
00038         }
00039             
00040     }
00041 }
00042 
00043 
00044 int main() {
00045     Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4);
00046     while(1) {
00047         led=!led;
00048         Thread::wait(500);
00049     }
00050 }