Skip to main content
Visitor II
December 7, 2020
Question

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

  • December 7, 2020
  • 5 replies
  • 1183 views

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?

    This topic has been closed for replies.

    5 replies

    FStra.9Author
    Visitor II
    December 7, 2020

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

    Super User
    December 7, 2020

    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.9Author
    Visitor II
    December 11, 2020

    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?

    Visitor II
    January 6, 2021

    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.

    Visitor II
    April 2, 2021

    Hi FStra.9,

    Any updates ?

    Best Regards,

    Ons.