I'm trying to get the CubeMX generated sample CDC application working on STM32l475VG IoT board.

By following a document from ST Community, I was able to get the clock configuration right and the CDC application without VBus Sensing works perfectly fine. I used MSE trimmed by LSE as suggested by the document.

However I would like to get the same application with the same clock configuration on the same dev board running with VBus Sensing ON and it doesn't work at all. This time the device is even not seen by the PC at all.

When VBus Sensing is ON even the HAL_PCD_IRQHandler doesn't get triggered upon connection.

I need VBus Sensing since in my real application we're using the uC in a self-powered device.

I am trying out all these experiments under the assumption that HW on dev board readily supports VBus Sensing, since with the datasheets I can't read that HW changes are required.

Is it really safe to assume that sample USB CDC app should work with VBus sensing ON without modifying the dev board HW ?

With the description mentioned in the document, I have a feeling that VBus Sensing is Disabled intentionally for a very specific reason. Is it that the clock configurations have to done differently when it is On ?

Can someone please shed some light on this ?

  • 2
    \$\begingroup\$ There are missing information here: what are the exact differences between the VBUS sensing design (which doesn't work), and the non-vbus sensing design (which works, as you describe)? Is it in your code? Is it in the board jumper configuration? Is it in the way you power your board? By the way, how is the board powered, and what are the jumper configurations? \$\endgroup\$
    – dim
    Commented May 23, 2018 at 7:20
  • \$\begingroup\$ Actually I am powering the board via ST-Link in both cases where VBus is enabled and disabled, but I will try what Ali Chen suggests. \$\endgroup\$
    – aep
    Commented May 23, 2018 at 23:33
  • \$\begingroup\$ As I commented for Ali Chen's answer, it is basically an issue with BCD and not with VBus Sensing. The problem is that whenever VBus Sensing is enabled in CubeMX, BCD automatically gets enabled as well. However I was able to run a working application with only VBus Sensing enabled. \$\endgroup\$
    – aep
    Commented May 23, 2018 at 23:47

1 Answer 1


VBUS sensing is a must feature for self-powered slave USB interface, to prevent drive-back voltage on D+ wire until the u-B cable is plugged in and VBUS is present. This has nothing to do with clocks, clocks should have no difference in both cases.

The STM32L4 Discovery Kit is a fairly sophisticated IoT/SoC device. It has many options, complex OTG USB function, battery-powerd, self-powered, ST-LINK powered, etc. For the VBUS sense to work, at least no jumpers should be in JP4 2X5 header, and USB_OTG_FS_VBUS sense signal is already wired in. The only one thing looks strange - VBUS has +5V, and it goes directly to GPIO of low-voltage MCU without any level translation. Might be 5V-tolerant, but strange.

So the problem is likely in software configuration that handles the USB_OTG_FS_VBUS pin and enables USB stack.

  • 3
    \$\begingroup\$ Actually I dug deeper into this issue. It seems that when I enable VBus Sensing in CubeMX it also enables BCD(Battery Charger Detection). I manually disabled BCD afterwards and the generated code (where only VBus is enabled and BCD is disabled) seems to work fine. I could confirm that USBD_LL_DevConnected and USBD_LL_DevDisconnected callbacks are properly called upon device connection/disconnection. With this results it seems that it is really an issue with BCD. \$\endgroup\$
    – aep
    Commented May 23, 2018 at 23:42
  • \$\begingroup\$ I tried to remove the J4 jumper as you mentioned but it does no difference. \$\endgroup\$
    – aep
    Commented May 23, 2018 at 23:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.