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:

GR-PEACH is an Mbed enabled platform which combines the advantages of the Mbed ecosystem and Arduino UNO form factor.

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

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();
    }
}

Can you give any indication of when you expect to release the USB library for RTOS2?

posted by Steven Crowe 13 Apr 2018