cancel
Showing results for 
Search instead for 
Did you mean: 

How to setup MCU USB HS peripheral to act as USB Host for Mass Storage Class?

BParh.1
Senior III

So far in various online resources, the sample given is to configure USB FS as USB Host e.g. this https://www.youtube.com/watch?v=dC0d8CVEPrQ

But my board STM32769 Discovery does not have USB FS peripheral routed out of the board which leave me to use USB HS only. I try trial and error blindly to config it as USB Host as MSC class but no luck. Certain settings can't detect at all when I insert my USB thumb drive to USB HS connector, certain setting able to detect but immediately lead to HardFault_Handler() which seems due to memory access violation which I have no idea how that occurred. Could it be my clock setting?

So could someone please give me CubeMX setting (.ioc) how to configure the USB HS as USB Host? Also, there is tab under Middleware->USB_HOST->Platform Settings which gave warning but I have no idea at all what is that and how to configure it.

I'd appreciate the help.

5 REPLIES 5
Khouloud ZEMMELI
ST Employee

Hello @BParh.1​ 

Thanks for your post,

To Configure the USB host as Mass storage class, you need to Enable the USB_OTG_HS first (under connectivity) with Host mode selected, you can notice then, that the USB Host will be available to be configured (under Middleware), just set the Class to Mass storage class, and continue your configuration according to your need.

0693W00000ANAndQAH.pngThe warning message is linked to the platform settings, so to avoid it, you need to choose the Drive_VBUS_HS component, in case you prefer I2C, so it should be activated to find the solution then, otherwise, you should set one pin as Output then select it under Found Solutions.

0693W00000ANAnnQAH.png 

Hope my answer helped you :) When your question is answered please close this topic by choosing Select as best, this will help other user find that answer faster.

Thanks for your contribution, Khouloud

BParh.1
Senior III

Thank you @Khouloud ZEMMELI​ , that helps :grinning_face: . Could you brief me the background of this Drive_VBUS_HS setting please?

  1. What is this for?
  2. When do we choose GPIO and when I2C?
  3. Are all solutions in 'Found' Solutions valid? My base project is based on STM32F769 Discovery board, and I see some 'solutions' already populated. I can just use anyone of them? How this populated, is it automatically by the tool or ST already preconfigured that in the template ?

Sorry for my many questions, but need to resolve this in my prototype to see if USB Host can work in our project. I appreciate your help.

Hi again @BParh.1​ 

Sorry for the delay,

In fact, the purpose of the USB_Host VBUS driver is:

  • To drive the VBUS pin connected to the USB connector to 5V (as mentioned in the image below) to offer power for the USB Device (mouse, smartphone,..).
  • The VBUS is the pin 1 of the CN6
  • To set the 5 volts the board used the component STM32PS2141STR (out pin 1)
  • The OTG_FS_PSO signal is connected to the MCU as a GPIO

0693W00000AO777QAD.pngWhen the USB Host MW need to drive this pin (at least after the stack initialization), the MW call the USBH_LL_DriverVBUS() during the start or during the stop :

USBH_StatusTypeDef  USBH_Start(USBH_HandleTypeDef *phost)
{
  /* Start the low level driver  */
  USBH_LL_Start(phost);
 
  /* Activate VBUS on the port */
  USBH_LL_DriverVBUS(phost, TRUE);
 
  return USBH_OK;
}

Now, to use the I2C or GPIO depends on the board, so the user needs to know on which board the project is running and so can determine if the driver must be connected through a GPIO or an I2C or other connection, not supported by CubeMX.

To do this functionality, CubeMX propose two solutions:

  • Drive the VBUS using a component connected to a GPIO (here when the GPIO goes low, the STM32PS2141STR is enabled and his out go to 5V).
    • Drive the VBUS using a component connected to an I2C, like a GPIO expander.

Hope my answer helped you =) When your question is answered please close this topic by choosing Select as best, this will help other user find that answer faster.

Thanks for your contribution, Khouloud

BParh.1
Senior III

Thank you @Khouloud ZEMMELI​ , I appreciate you take time to explain and attach the layout :).

However from your layout, it was for USB_OTG_FS and I can understand why it needs dedicated GPIO to drive VBUS. But in my case, it is USB_OTG_HS which is connected to external PHY, the connection to VBUS is different as attached, As you can see, to drive 5V VBUS is by external PHY CPEN pin, not by MCU. So it seems to me the 5V is driven by this not by MCU. In this case, I am confused by in CubeMX still asking platform setting which GPIO/I2C to drive this 5V VBUS.

Anyway I am using STM32F769 Discovery Board which only has USB HS connector, no USB FS

0693W00000AO8xOQAT.png

@BParh.1​ Yes, as you've noticed, in host mode of course STM32 does not provide VBUS directly. It drives an external regulator.

If the Cube insists on something different you'll have to fix the code manually.

Now, why I2C? I don't have this board, but a similar H7 Disco has an I2C I/O extender and there's a BSP driver for it.

The output pin that enables the USBH power may be connected thru such extender on your board.

-- pa