cancel
Showing results for 
Search instead for 
Did you mean: 

What bit in what register can be used to know when and if a USB cable is plugged in?

FStra.9
Associate III

I have VBUS sensing enabled and when I step through the call to HAL_PWREx_EnableUSBVoltageDetector(), you'd expect a difference in the bit states in the

OTG_HS_GCCFG register but there is no difference whether the cable is plugged in or not.

I find it especially disconcerting that when the DCDEN bit is set, the DCDET bit is also set whether or not a USB cable is plugged in or not. This is supposed to tell me whether or not it see data lines connected. What am I missing. I want to use the VBUS sensing on PA9 to know if a USB cable is plugged in. What do I need to do?

5 REPLIES 5
FStra.9
Associate III

NOTE: This is on an STM32H743VI part using the v1.80 HAL libraries

I don't use the 'H7 nor Cube/HAL, but on 'F4, GOTGCTL.BSVLD is controlled by the VBUS pin, if VBUS sensing is enabled by GCCFG.VBDEN (or by GCCFG.VBUSBSEN on older models - it's very thoughtful of ST to mess around with the signals and bits names, to keep the users alert and entertained).

JW

FStra.9
Associate III

Can someone from ST please answer this question?

Is it possible to read the output of the VBUS sensing comparators?

How can firmware determine if a USB cable is plugged in when enabling the VBUS sensing on PA9?

Ons KOOLI
Senior III

Hi FStra.9,

The comment about BSVLD is correct (outside of the standard HAL). This is the direct way of knowing the current state of the VBUS detector (and yes as indicated it is dependent on VBDEN enable).

USB33DEN is a voltage regulator enable (specific to H7 in MCUs also similar in MP1), effectively it is not directly linked. It is needed to get the full power-up of the USB IPs.

For battery charging detection, there is in the HAL how to do the software contact detection after a fixed timeout (alternate method, since the direct DCDEN / DCDDET are not reliable).

Hope this is helpful.

Best Regards,

Ons.

Ons KOOLI
Senior III

Hi FStra.9,

Any updates ?

Best Regards,

Ons.