cancel
Showing results for 
Search instead for 
Did you mean: 

Can two USBs, both in mass storage mode, work simultanoeusly?

messer79
Associate

Hello,

My cutom device, powered by STM32F429ZI, has two USB ports. Each one is connected via USBLC6-2 (ESD protection) chip to MCU (USB FS and USB HS) pins. VBUS is not used.

I use CubeMX (the latest version) to generate initial code.

0690X000006C5ZmQAK.png

If I configure FS (PA11, PA12 pins) port as a mass storage device (host only) AND leave HS disabled I am able to initialize USB stick and explore files from MCU via FATFS. So this works great.

If I configure HS (PA14, PB15 pins) port as mass storage device (host only) AND leave FS disabled I am, again, able to initialize USB stick and explore files from MCU via FATFS. So this also works OK.

IF I configure FS port as mass storage device (host only) and HS port as a communication device (device only) I am in a position to explore files from MCU and send messages to my computer (they show up in a terminal). This also works if I swap ports functions (make FS a CDC and HS a MSC). So, again, it is OK.

Now the issue occurs:

If I configure both - FS & HS as mass storage devices (host only) then the only one USB stick is initialized (and can be accessed vis FATFS). The second USB stick remains in HOST_IDLE status all the time. I tried swapping sticks and changing USBH instances. Nothing helps.

That's why I am curious if it is possible to run 2 USB ports in mass storage mode. If yes, I am asking you to answer me what I am missing. You could ask me why I needed this configuration. The answer is simple - just a proof of concept. I am just mastering STM32.

Thank you in advance for any answers or hints.

4 REPLIES 4

I would expect the hardware to be capable, I would suspect a failure at the abstraction/object level. With HAL and CubeMX it is a matter of how deep down the rabbit hole to want to go to fix issues and test things.

Tips, buy me a coffee, or three.. PayPal Venmo Up vote any posts that you find helpful, it shows what's working..
Pavel A.
Evangelist III

IIRC the Cube has a small bug when both USB controllers have same host class and you need to fix the generated code manually.

Probably still persists in the current version.

-- pa

messer79
Associate

Thank you for the answer. Are you in a position to tell me where exactly the bug is and maybe you know how to fix it?

Pavel A.
Evangelist III

In one project created long ago with old version of Cube, it was in the function MX_USB_HOST_Init.

It can be named differently in the current version.

Look for assignment of classes to the USB host controllers, like this:

USBH_Init(&hUsbHostHS, USBH_UserProcess, HOST_HS);
USBH_RegisterClass(&hUsbHostHS, USBH_HID_CLASS);
USBH_Start(&hUsbHostHS);
.....
USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS);
USBH_RegisterClass(&hUsbHostFS, USBH_HID_CLASS);
USBH_Start(&hUsbHostFS);

The catch is that USBH_HID_CLASS is actually pointer to a global struct so both instances share it. But it has some writable data that should be private to each instance.

So I've changed it to:

static USBH_ClassTypeDef hidClass2;
...
memcpy(&hidClass2, USBH_HID_CLASS, sizeof(hidClass2));
 
USBH_Init(&hUsbHostHS, USBH_UserProcess, HOST_HS);
USBH_RegisterClass(&hUsbHostHS, USBH_HID_CLASS);
USBH_Start(&hUsbHostHS);
 
USBH_Init(&hUsbHostFS, USBH_UserProcess, HOST_FS);
USBH_RegisterClass(&hUsbHostFS, &hidClass2);
USBH_Start(&hUsbHostFS);

A horrible quick hack, but worked at least for the HID class...

-- pa