cancel
Showing results for 
Search instead for 
Did you mean: 

Management of VBUS sensing for USB device design

ST Community
ST Employee

From a USB specification, a USB device should use VBUS sensing detection: 

When a host connection is detected by the device, the device connects the pull-up resistor either to D+ or to the D- data signal. This allows the host to detect device presence on the bus.

There are two use cases:

  • If the USB device is bus-poweredVBUS sensing is NOT mandatory: USB is connected all the time when the device is powered
  • If the USB device is self-poweredVBUS sensing is mandatory

 

On STM32F2/F4/F7/L4, peripheral USB OTG_FS (OTG_HS without external PHY) is natively dedicated for VBUS sensing with pin PA9 (PB13 for HS), which is a +5 V tolerant pin.


In the datasheet DS10314 section 6.2, table 11, the "Absolute maximum rating" (AMR) table states that a +5 V tolerant pin voltage can be maximally VDD+4 V. So, the situation where the MCU is not powered and 5 V VBUS is connected to PA9 must be avoided because it is violating AMR.

Laurids_PETERSEN_0-1717499972212.png

 

Two solutions can be proposed:

1. With a dedicated VBUS pin (PA9 or PB13)

To reduce the voltage on PA9 below 4 V, the usage of a voltage divider is recommended, so that AMR cannot be violated. But the internal VBUS detection block inside the OTG peripheral has a certain current consumption. 

You can find this mentioned, for example, in STM32F411 datasheet (section 6.3.19 p. 113) or STM32F446 datasheet (section 6.3.20 p. 136):

“When VBUS sensing feature is enabled, PA9 should be left at their default state (floating input), not as alternate function. A typical 200 µA current consumption of the embedded sensing block (current to voltage conversion to determine the different sessions) can be observed on PA9 when the feature is enabled.”


The recommended resistor bridge is "vbus-- R1=4.7k -- R2=10k -- gnd" and then VBUS detection (PA9) can be taken between R1 and R2.

2. Without usage of a dedicated VBUS pin

Any 5V tolerant pin with external interrupt functionality can be used with an external resistor divider, to fulfill AMR conditions. In this case, the recommended values are 2x100 kOhms.

However, the disadvantage of this solution is that the software handling of VBUS presence event needs to be implemented by the user. This is not managed within our STM32 USB library for the time being.
 

Comments
wed
Associate

This information about VBUS sensing requiring a voltage divider seems to be very recent, both as an addition to AN4879, and this post, only updated a week ago.

 

In my application, Vdd=3.3v, and the resistor divider in AN4879 (33k / 82k) does not seem to work, the voltages on this divider swing from 3.38v to 3.73v as the USB voltage is swept from 4.75 to 5.25v. However, when the microcontroller is powered up, the voltage at the divider to Vbus pin collapses to 1.59 to 1.75V over the same USB voltage range, which is below the logic high threshold of the device (STM32F676 in this case). 

Using the values in this post (4k7 / 10k) has a better range of 3.24 to 3.58V as USB voltage is varied from 4.75 to 5.25v, and this time, when the microcontroller circuitry is on, the voltages on Vbus pin range between 2.93v and 3.26v over the same USB voltage range, which seems to satisfy both <4V at all times, and > logic high threshold (2.31v if 0.7xVdd).

Perhaps it would be worth updating AN4879 since the resistor values don't seem to be suitable?

 

Another enquiry about this issue would be is this a new emerging problem with Vbus voltages? Since all the literature about voltage dividers is very recently published, were older STM32 chips more immune to issues with the Vbus pin being >4V? Were they manufactured using a more voltage tolerant process? If we used some STM32s we bought a few years ago, are they more resilient? We never experienced any failures connecting Vbus to 5v in the past (plugging 5V USB into a microcontroller when powered off) until very recently, despite older designs having no resistor dividers for several years. 

Nick Alexeev
Associate II

However, the disadvantage of this solution [without dedicated hardware VBUS detection pin] is that the software handling of VBUS presence event needs to be implemented by the user. This is not managed within our STM32 USB library for the time being.

What should the firmware do when it detects that VBUS is present?  What should the firmware do when VBUS has disappears?  Are there code examples for VBUS detection through GPIO?


[without dedicated hardware VBUS detection pin] Any 5V tolerant pin with external interrupt functionality [...] 


Does the VBUS detection have to be done in an interrupt? Or can it be done in the main loop? If it can be done in the main loop, then are there timing constraints?

Version history
Last update:
‎2024-06-04 04:27 AM
Updated by:
Contributors