cancel
Showing results for 
Search instead for 
Did you mean: 

USB VBUSDetect and Battery Charging

Clonimus74
Senior II
Posted on January 30, 2018 at 10:48

Hi,

Can someone please explain what is the VBUS detect (HAL_PCDEx_BCD_VBUSDetect) and battery charging (USBD_LL_BatteryCharging), what is it used for and how to use it (with STM32L4)?

Currently I have an EXTI interrupt on a port that gets the USB VBUS, I use it to turn off the USB peripheral once the VBUS is not present and turn it back on once it is detected again.

I use USB device in VCP mode.

Thanks

#usb-device #usb-vcp #stm32l4
3 REPLIES 3
Posted on January 30, 2018 at 11:08

They appear to be related to Battery Charging Detection functionality of the USB IPs, see respective RM (note that there are two distinct incarnations of that IP, the device-only, and the Synopsys-originated OTG), see

https://en.wikipedia.org/wiki/USB#USB_Battery_Charging

  and see

http://www.usb.org/developers/docs/devclass_docs/BCv1.2_070312.zip

 

That detection happens on DP/DM, so you can't really use that for cable disconnect while communication is ongoing.

The OTG version of USB IP has a dedicated pin for VBUS detection, OTG_FS_VBUS (on PA9).

JW

Posted on January 30, 2018 at 11:54

Thanks, I will read through that.

The PA9 for VBUS is what I use but as EXTI input and not AF, since I didn't see implementation in the peripheral or HAL for VBUS disconnection that turns of the device, if I recall correctly it puts the system in deep sleep mode and that is not desired.

Posted on January 30, 2018 at 12:33

it [VBUS disconnect] puts the system in deep sleep mode

There's no hardware for doing that, so this conclusion comes from observation of behaviour of some arbitrary code.

Disconnectiong VBUS in OTG - if VBUS detection is enabled - results in GOTGINT.SEDET being set, and that - again if not masked - results in interrupt through setting GINTSTS.OTGINT

This in Cube calls HAL_PCD_DisconnectCallback().

JW