USB VBUS detection

RP2040 based microcontroller boards running MicroPython.
Target audience: MicroPython users with an RP2040 boards.
This does not include conventional Linux-based Raspberry Pi boards.
Post Reply
User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

USB VBUS detection

Post by marfis » Thu Sep 09, 2021 11:48 am

small helper to detect if USB is powered:

Code: Select all

import machine
def is_usb_connected():
    #  SIE_STATUS register, VBUS_DETECTED bit0
    return machine.mem32[0x50+0x50110000] & 0x1

ex_piro
Posts: 5
Joined: Thu Sep 09, 2021 11:46 pm

Re: USB VBUS detection

Post by ex_piro » Fri Sep 10, 2021 12:12 am

On the pico, VBUS is wired to GPIO24. I must be missing something here.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: USB VBUS detection

Post by marfis » Sat Sep 11, 2021 5:36 am

some (most?) rp2040 based boards do not wire vbus to a gpio.

ex_piro
Posts: 5
Joined: Thu Sep 09, 2021 11:46 pm

Re: USB VBUS detection

Post by ex_piro » Sat Sep 11, 2021 9:08 am

I assumed the pico board because the USB power is labelled VBUS. The only other board I have is the sparkfun pro micro (which I have not used yet) and USB power is labelled V_USB. On both boards the USB power and external power inputs feed the 3.3 volt regulator which then feeds the MCU (IOVDD, VREG_VIN, ADC_AVDD, and USB_VDD pins on the RP2040). How could the MCU know that USB power is powering the regulator unless there is a separate input from USB power to the MCU?

I have not looked at other RP2040 board schematics, but I suspect most boards will use a single 3.3 volt supply as shown in the RP2040 data sheet section 2.9.7.1.

NameOfTheRose
Posts: 7
Joined: Tue Jun 29, 2021 7:12 am

Re: USB VBUS detection

Post by NameOfTheRose » Sat Sep 11, 2021 12:19 pm

On page 18, §4.4. Powerchain of the pico datasheet it is mentioned: «GPIO24 monitors the existence of VBUS, while R10 and R1 act to pull VBUS down to make sure it is 0V if VBUS is not present.» referring to figure 14 on the same page. So if you just want to know wheteher power is actully coming from the USB connector, GPIO24 is also providing this information. But this is specific to the pico. is_usb_connected() applies to all boards. I̶ t̶h̶i̶n̶k̶ t̶h̶a̶t̶ t̶h̶e̶ U̶S̶B̶ P̶e̶r̶i̶p̶h̶e̶r̶a̶l̶ s̶e̶t̶s̶ V̶B̶U̶S̶_̶D̶E̶T̶E̶C̶T̶E̶D̶ b̶y̶ m̶o̶n̶i̶t̶o̶r̶i̶n̶g̶ D̶+̶, D̶-̶ b̶u̶t̶ I̶ m̶i̶g̶h̶t̶ b̶e̶ w̶r̶o̶n̶g̶. I was wrong, USB Peripheral depends on an external VBUS_DETECTED circuit.
Please note that either above function is_usb_connected() or GPIO24 returning 1 does not mean that an actual serial connection exists.
You might want to have a look at my post rpi pico: How to detect that sys.stdout is connected.

User avatar
marfis
Posts: 215
Joined: Fri Oct 31, 2014 10:29 am
Location: Zurich / Switzerland

Re: USB VBUS detection

Post by marfis » Mon Sep 13, 2021 5:06 am

How could the MCU know that USB power is powering the regulator unless there is a separate input from USB power to the MCU?
You are completly right. I somehow assumed it was powered by USB directly, rather than via the 3.3V regulator. So yes, for all those HW designs mentioned, there is little benefit in using the code above.

I‘m not sure if it would have made sense to make a HW with two 3.3V regulators, one exlusively for USB, might be better for low power applications?
You might want to have a look at my post
good information, thanks for the pointer. indeed that‘s what I really needed.

Post Reply