Multiple USB components

Hello.

Is it possible to have multiple USB components at the same time? If yes, what do I need to change in the following program to make it work?

I attempted to create a USBMSD device first, it works, and that the Linux host to which the device (a MakerDiary dev board) sees the MSD. Then I add USBSerial to the program, and neither work even when I just instantiate the USBSerial.

The error I see on the serial console is:
++ MbedOS Error Info ++

  • Error Status: 0x80FF0144 Code: 324 Module: 255*
  • Error Message: Assertion failed: ret == NRF_SUCCESS*
  • Location: 0x8911*
  • File: ./mbed-os/targets/TARGET_NORDIC/TARGET_NRF5x/TARGET_NRF52/TARGET_MCU_NRF52840/USBPhy_Nordic.cpp+88*
  • Error Value: 0x0*
  • Current Thread: main Id: 0x20001260 Entry: 0x9B21 StackSize: 0x1000 StackMem: 0x20002A60 SP: 0x2000397C *
  • For more info, visit: mbedos-error*
  • – MbedOS Error Info --*

The example / test program is:
#include “mbed.h”
#include “USBMSD.h”
#include “HeapBlockDevice.h”
#include “FATFileSystem.h”
#include “USBSerial.h”

BlockDevice *bd = new HeapBlockDevice(64 * 1024, 1, 1, 512);
USBMSD usb(bd, 0x0703, 0x0104, 0x0001);
FATFileSystem fs("myfs");

USBSerial pc;

int main()
{
    int err = fs.reformat(bd);
    printf("%s\n", (err ? "Fail :(" : "OK"));
    if (err) { error("error: %s (%d)\n", strerror(-err), err); }

    fs.mount(bd);

    FILE *f = fopen("/myfs/myreadme.txt", "w+");
    if (!f) { error("error: %s (%d)\n", strerror(errno), -errno); }

    err = fprintf(f, "This is an example line\n");
    if (err < 0) { error("error: %s (%d)\n", strerror(errno), -errno); }

    err = fclose(f);
    if (err < 0) { error("error: %s (%d)\n", strerror(errno), -errno); }

    while(true) { usb.process(); }
}
1 Like

Anyone?

Did you manage to solve the issue?

I was also hoping that I could use the USB device with multiple functions (composite device), but this seems to be not considered in the design. The functional USB classes (USBMSD, USBSerial etc.) all derive from the USBDevice class, which wraps the USB driver. Creating multiple USB objects results in multiple USBDevice instances, which probably does not work. It should have been possible to create a USBDevice and then pass it to the functional classes to reuse the same device for multiple functions.

Still, if there is a workaround allowing this, I would be interested.

I was unable to resolve the issue. But a kind response that could help in a way was provided here https://forums.mbed.com/t/re-multiple-usb-components/8276?u=capablegh

The link is unfortunately not visible to the public.

Per comment at the top of the page “function test USBMSD(as external strage for PC USB) and USBSerial. Switching between USBMSD and USBSerial(Not work simultaneously)”.

This was the hint I was given , but that’s it.