Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
6 years, 8 months ago.
USB lib issue
Why USBHost_custom lib does not work with mbed-os newer than 5.4.3? For example if you try to use MSD with OS v5.6 and above, the program stucsks before main() on some funcion called semafore error. With OS v5.4.3 the things are slightly better, but still no files can be opened for read or write. Standart fopen() function always returns NULL pointer. Why. I 've used the lib before (with the classic OS) and there were no problems then.
Question relating to:
1 Answer
6 years, 8 months ago.
In v5.6, the OS has changed to RTOS2, so USBHost_custom lib does not work. The USBHost_custom lib for RTOS2 is under preparation.
For v5.4 and later, "fs.mount (&usb);" is required. Please refer to the following for details.
#include "mbed.h" #include "FATFileSystem.h" #include "USBHostMSD.h" int main() { int i = 0; FATFileSystem fs("storage"); USBHostMSD usb; while(1) { // try to connect a storage device while (1) { if (usb.connect()) { fs.mount(&usb); // #### mount #### break; } Thread::wait(500); } // in a loop, append a file // if the device is disconnected, we try to connect it again while(1) { // append a file FILE * fp = fopen("/storage/test1.txt", "a"); if (fp != NULL) { fprintf(fp, "Hello USB memory World: %d!\r\n", i++); printf("Goodbye World!\r\n"); fclose(fp); } else { printf("FILE == NULL\r\n"); } Thread::wait(500); // if device disconnected, try to connect again if (!usb.connected()) break; } fs.unmount(); } }
These incompatibilities that we don't know about scare me to death. I haven't moved to MBED OS because I can't tell if a given library is compatible with it. I'm often not sure when looking at a piece of API documentation whether it is for old or new, or if it is the same in both.
posted by Alfred Hume 28 Mar 2018