Working version on STM32F411. Test for CLI

Dependencies:   FATFileSystem mbed-rtos mbed

Fork of USBHost by mbed official

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 DigitalOut debug_pin(A5);
00006 
00007 void msd_task(void const*)
00008 {
00009     USBHostMSD msd("usb");
00010     int i = 0;
00011 
00012     debug_pin = 0;
00013 
00014     while(1)
00015     {
00016         // try to connect a MSD device
00017         while(!msd.connect())
00018         {
00019             Thread::wait(500);
00020             printf("Waiting for USB stick..\n");
00021         }
00022        
00023         FILE* fp = fopen("/usb/my_test.txt", "w");
00024        
00025         while(1)
00026         {
00027             if(fp != NULL)
00028             {
00029                 debug_pin = 1;
00030                 
00031                 fprintf(fp, "Hello, SD Card World: that's the string number %d!\r\n", i++);
00032                 //printf("Goodbye World!\r\n");
00033                 //fclose(fp);
00034                 
00035                 debug_pin = 0;
00036             }
00037             else 
00038             {
00039                 printf("FILE == NULL\r\n");
00040             }
00041 
00042             Thread::wait(10);
00043 
00044             // if device disconnected, try to connect again
00045             //if(!msd.connected())
00046             //    break;
00047         }
00048     }
00049 }
00050 
00051 
00052 int main()
00053 {
00054     Thread msdTask(msd_task, NULL, osPriorityNormal, 1024*8);
00055     
00056     while(1)
00057     {
00058         led=!led;
00059         Thread::wait(500);
00060     }
00061 }