Electrical – STM32L4 USB Device with VBUS Sensing

embeddedstm32stm32cubemxusbusb device

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 ?

Best Answer

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.