# STM32L4 USB Device with VBUS Sensing

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 ?

• 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? – dim May 23 '18 at 7:20
• 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. – aep May 23 '18 at 23:33
• 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. – aep May 23 '18 at 23:47

• 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. – aep May 23 '18 at 23:42