Using PA10 and not USB OTG host ID

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
Gordon_Hardman
Posts: 68
Joined: Sat May 03, 2014 11:31 pm

Using PA10 and not USB OTG host ID

Post by Gordon_Hardman » Thu May 07, 2015 2:48 pm

PA10 is the ID pin for the USB port on the PyBoard. It is grounded when the appropriate connector is inserted, indicating the port is to be set up as a OTG Host. It would be nice to have a way (in Pins?) to have MicroPython ignore it, and go into Device mode. I have not seen anything on the forum where someone is using the Pyboard as a Host, so I assume everyone uses it as a Device. If this is so, maybe that should be the default setting and not tie up a pin? There must be a way to define which pin is to be used as the ID pin, if OTG Host is to be implemented.

Since the ID pin is normally a no-connect for a Device, PA10 could be used right away by soldering a wire on, with no other hardware mods.

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

Re: Using PA10 and not USB OTG host ID

Post by dhylands » Thu May 07, 2015 4:02 pm

Right now, I believe that you can compile the code to be a host or a device, but not auto switch.

Damien did a demo some time ago where he connected a keyboard up and used that and n LCD as a REPL.

I'm not sure how much that code path is tested. I haven't tried it myself.

To use the pin as a GPIO pin, you can reference it as pyb.Pin.board.USB_ID or pyb.Pin.cpu.A10

Gordon_Hardman
Posts: 68
Joined: Sat May 03, 2014 11:31 pm

Re: Using PA10 and not USB OTG host ID

Post by Gordon_Hardman » Thu May 07, 2015 5:31 pm

So if it is set up as pyb.Pin.board.USB_ID, then the USB code totally ignores that pin, and currently goes into Device mode? That would be excellent. I will test later today.

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

Re: Using PA10 and not USB OTG host ID

Post by dhylands » Thu May 07, 2015 6:39 pm

Currently, it looks like it gets initialized as an alternate function.

https://github.com/micropython/micropyt ... oard.h#L78

and this uses that to initialize the AF:

https://github.com/micropython/micropyt ... .c#L78-L85

and this is confirmed in the REPL:

Code: Select all

>>> pyb.Pin.board.USB_ID
Pin(Pin.cpu.A10, mode=Pin.AF_OD, pull=Pin.PULL_UP, af=10)
but you can change it to be regular GPIO:

Code: Select all

>>> pyb.Pin('USB_ID', pyb.Pin.OUT_PP)
Pin(Pin.cpu.A10, mode=Pin.OUT_PP)
>>> pyb.Pin.board.USB_ID
Pin(Pin.cpu.A10, mode=Pin.OUT_PP)

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

Re: Using PA10 and not USB OTG host ID

Post by dhylands » Thu May 07, 2015 6:55 pm

This is what I was looking for:
https://github.com/micropython/micropyt ... #L221-L222
and
https://github.com/micropython/micropyt ... #L227-L292

So we currently only initialize the device one way or the other.

Gordon_Hardman
Posts: 68
Joined: Sat May 03, 2014 11:31 pm

Re: Using PA10 and not USB OTG host ID

Post by Gordon_Hardman » Thu May 14, 2015 8:43 pm

Thanks, Dave. I experimented a bit, and concluded that indeed the pin must be pulled up for the board to boot. In fact, even after it has booted, if you pull it low the board stops- it seems to act just like reset does! I redefined the pin, and it made no difference- no error messages, but it is still Pin.AF_OD.

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

Re: Using PA10 and not USB OTG host ID

Post by dhylands » Thu May 14, 2015 9:11 pm

Hmm. If its still AF_OD then that's probably the problem.

How recent is your firmware?

Changing the value when it's configured as AF_OD probably triggers something in the HW that the code isn't expecting.

Put if you configure is an input (Pin.IN). Pulling it low while it's configured as Pin.OUT_PP is basically shorting out power and ground, which is why it would act as a reset.

Post Reply