cancel
Showing results for 
Search instead for 
Did you mean: 

How do I detect USB storage devices on the STM32 USB HOST MSC?

SWoon
Associate II

 Hi.

If power is applied while USB is plugged in, it is possible to read and write data with USB MSC and Fatfs.

I am looking for a way for USB to be detected when I plug in USB while STM32 is running.

Even if I look for a way, I found only STM32 device.

If you know how, please let me know.

Thank you.

6 REPLIES 6

I don't quite understand your question, but if you are talking about detecting when devices are attached to OTG module in HOST mode, this is indicated by PCDET bit in OTG_HPRT - see Host detection of a peripheral connection in the OTG chapter in RM.

Whether the attached device is MSC, then of course results from subsequent enumeration process.

JW

SWoon
Associate II

I looked up what you said. You have seen that the PCDET bit in OTG_FS_HPRT tells you the control and status of the host port. However, I need help with usage. I do not know how to use the OTG_FS_HPRT register.

When I try to use a register in main.c I get an error that it is not defined.

How should I use the OTG-related registers in the RM in STM32?

Perhaps review a working example?

STM32Cube_FW_F7_V1.14.0\Projects\STM32756G_EVAL\Applications\USB_Host\MSC_Standalone\readme.txt

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

If you have already some USB stack in place, then that stack takes care of the registers etc. Your application then should rely on the states and/or callbacks provided by that stack - see the documentation accompanying the stack.

JW

I understand that USBH_UserProcess will call back the usb state and change the Appli_state.

In the STM32Cube_FW_F4_V1.24.0 \Projects \STM32F4-Discovery\Applications\FatFs\FatFs_USBDisk example I have found that USBH_UserProcess is called every time a USB device is plugged in or unplugged.

However, in my code generated by CubeMx, USBH_UserProcess is only called at the start of the program.

How do I behave like an example?

Find, what's the difference between the example and the generated code. Find, where is the callback called in the example and find out why isn't it called at the same place in the generated code.

I don't use Cube nor CubeMX.

JW