OK Connect a US Bstorage stick Configure for HOST Disconnect any other devices !!!!

Dependencies:   USBHost mbed

Fork of USBHostMSD_HelloWorld by Samuel Mokrani

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             printf("waiting\n");
00017         }
00018         
00019         // in a loop, append a file
00020         // if the device is disconnected, we try to connect it again
00021         while(1) {
00022             
00023             // append a file
00024             FILE * fp = fopen("/usb/test1.txt", "a");
00025         
00026             if (fp != NULL) {
00027                 fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++);
00028                 printf("Goodbye World!\r\n");
00029                 fclose(fp);
00030             } else {
00031                 printf("FILE == NULL\r\n");
00032             }
00033             
00034             Thread::wait(500);
00035         
00036             // if device disconnected, try to connect again
00037             if (!msd.connected())
00038                 break;
00039         }
00040             
00041     }
00042 }
00043 
00044 
00045 int main() {
00046     Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4);
00047     while(1) {
00048         led=!led;
00049         Thread::wait(500);
00050     }
00051 }