Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: test_USBHost mbed
Fork of USBHostMSD_HelloWorld by
main.cpp
00001 #include "mbed.h" 00002 #include "USBHostMSD.h" 00003 #include "ramstats.h" 00004 00005 Serial pc(USBTX, USBRX); // tx, rx 00006 00007 DigitalOut led(LED1); 00008 00009 void msd_task(void const *) { 00010 00011 USBHostMSD msd("usb"); 00012 int i = 0; 00013 00014 while(1) { 00015 00016 // try to connect a MSD device 00017 while(!msd.connect()) { 00018 Thread::wait(500); 00019 } 00020 00021 // in a loop, append a file 00022 // if the device is disconnected, we try to connect it again 00023 while(1) { 00024 00025 // append a file 00026 FILE * fp = fopen("/usb/test1.txt", "a"); 00027 00028 if (fp != NULL) { 00029 fprintf(fp, "Hello fun SD Card World: %d!\r\n", i++); 00030 printf("Goodbye World!\r\n"); 00031 fclose(fp); 00032 } else { 00033 printf("FILE == NULL\r\n"); 00034 } 00035 00036 Thread::wait(500); 00037 00038 // if device disconnected, try to connect again 00039 if (!msd.connected()) 00040 break; 00041 break;} 00042 00043 break;} 00044 DisplayRAMBanks("\r\nmsd thread:\r\n"); 00045 } 00046 00047 00048 int main() { 00049 pc.baud(115200); 00050 Thread msdTask(msd_task, NULL, osPriorityNormal, 1024 * 4); 00051 DisplayRAMBanks("\r\nmain thread:\r\n"); 00052 while(1) { 00053 led=!led; 00054 Thread::wait(500); 00055 } 00056 }
Generated on Sat Jul 16 2022 21:37:10 by
1.7.2
