USB OTG role and MICROPY_HW_USB_VBUS_DETECT_PIN

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
jgriessen
Posts: 186
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

USB OTG role and MICROPY_HW_USB_VBUS_DETECT_PIN

Post by jgriessen » Sat Apr 21, 2018 7:04 pm

Does MICROPY_HW_USB_VBUS_DETECT_PIN have anything to do with OTG roles, or is it true the micropython board is a peripheral and VBUS detect is used so the USB code can be idle when VBUS is low, and go into action when something is plugged in?

Seems that way from the specs: "Connect requests (D+ or D- pull-ups) must occur only if VBUS is present, by USB 2.0 specifications"

So the VBUS_DETECT_PIN seems to be needed in ordinary "micropython board" as-a-peripheral mode.

Also the ID pin of a micro usb type B plug needs to be detected by micropython USB handling code when the micropython board is a peripheral according to the USB 2.0 and OTG specs.

So, MICROPY_HW_USB_OTG_ID_PIN seems to be needed in ordinary "micropython board" as-a-peripheral mode.

have I got that right? Almost any board definition needs these two, since being an OTG host is still compatible with these signals, and being peripheral needs them too?

User avatar
dhylands
Posts: 2753
Joined: Mon Jan 06, 2014 6:08 pm
Location: Shuswap, BC, Canada
Contact:

Re: USB OTG role and MICROPY_HW_USB_VBUS_DETECT_PIN

Post by dhylands » Mon Apr 23, 2018 3:39 pm

jgriessen wrote:
Sat Apr 21, 2018 7:04 pm
Does MICROPY_HW_USB_VBUS_DETECT_PIN have anything to do with OTG roles, or is it true the micropython board is a peripheral and VBUS detect is used so the USB code can be idle when VBUS is low, and go into action when something is plugged in?
MICROPY_HW_USB_VBUS_DETECT_PIN is used to detect that a USB cable is plugged in between a host and the pyboard. It allows the USB peripheral to powerdown when not plugged in and also allows the software to take on different behaviours when plugged in versus not plugged in. If MICROPY_HW_USB_VBUS_DETECT_PIN is not defined, then the software assumes that it is always plugged in. The pin that MICROPY_HW_USB_VBUS_DETECT_PIN defines should be coinnected to VBUS on the USB connector.
jgriessen wrote:
Sat Apr 21, 2018 7:04 pm
Seems that way from the specs: "Connect requests (D+ or D- pull-ups) must occur only if VBUS is present, by USB 2.0 specifications"

So the VBUS_DETECT_PIN seems to be needed in ordinary "micropython board" as-a-peripheral mode.

Also the ID pin of a micro usb type B plug needs to be detected by micropython USB handling code when the micropython board is a peripheral according to the USB 2.0 and OTG specs.

So, MICROPY_HW_USB_OTG_ID_PIN seems to be needed in ordinary "micropython board" as-a-peripheral mode.

have I got that right? Almost any board definition needs these two, since being an OTG host is still compatible with these signals, and being peripheral needs them too?
The ID pin is what is used to determine the role as far as OTG is concerned. I'm not sure that anybody has done any work to allow switching of roles.

User avatar
jgriessen
Posts: 186
Joined: Mon Sep 29, 2014 4:20 pm
Contact:

Re: USB OTG role and MICROPY_HW_USB_VBUS_DETECT_PIN

Post by jgriessen » Thu Apr 26, 2018 7:24 pm

The review of how micropython handles VBUS detecting helped me debug my new platform all the way last night. Once I dropped the assumption that the last command given would be the one taking effect, I was able to think of shutting off USB completely in boot.py, then I coiuld get GPIO PA11 PA12 PA9 to toggle outputs. Next I put USB back and looked at volts here an there and found that a connector had and open on its VBUS pin -- I had not measured through the connector yet. I fixed up the layout footprint so that bad soldering will not be able to hide next time.

Post Reply