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.
Using PA10 and not USB OTG host ID
Re: Using PA10 and not USB OTG host ID
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
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
-
- Posts: 68
- Joined: Sat May 03, 2014 11:31 pm
Re: Using PA10 and not USB OTG host ID
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.
Re: Using PA10 and not USB OTG host ID
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: but you can change it to be regular GPIO:
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)
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)
Re: Using PA10 and not USB OTG host ID
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.
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.
-
- Posts: 68
- Joined: Sat May 03, 2014 11:31 pm
Re: Using PA10 and not USB OTG host ID
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.
Re: Using PA10 and not USB OTG host ID
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.
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.