cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5G9J-DK USBX MSC – How to Reliably Detect Host Connection & Disconnection (No USB PD)

ArunJohn
Associate

Hi all,

I'm working on the STM32U5G9J-DK development board and trying to enable USBX-based MSC (Mass Storage Class) device functionality.

My actual product is a battery-powered device, so USB Power Delivery (PD) is not an option. However, it's critical for my application to detect when a USB host (e.g., PC) connects or disconnects to/from the device, as I need to perform certain app-level tasks on both events.

Since the USBX MSC device example was missing in CubeIDE, I updated the USBX CDC ACM device example to function as an MSC device. The device starts and I receive the "USBD_STORAGE_Activate" callback when a host is connected (when I call HAL_PCD_Start directly after initialization), but I do not receive the "USBD_STORAGE_Deactivate" callback when the host disconnects.

I also tried enabling the VBUS sensing option, but the example started misbehaving when I selected that. So I had to disable it.

What I’m looking for:

  • A reliable method to detect both connection and disconnection events, especially in the absence of USB PD.

  • Is VBUS GPIO-based sensing possible on this DK? If yes, how can it be properly configured and used with USBX?

  • If not, are there any software polling techniques or PCD/USBX state checks I can use inside a task/thread to detect host presence?

  • Is there a way to manually trigger MSC device start/stop (e.g., HAL_PCD_Start/Stop) based on host detection?

Any help, examples, or guidance based on STM32U5 or this DK board would be greatly appreciated.

Thanks in advance!

1 REPLY 1
AScha.3
Super User

Hi,

in USB event loop you can see it -> i set a global info then, usb IN or not...

AScha3_0-1748103376618.png

 

If you feel a post has answered your question, please click "Accept as Solution".