claim usb_host pins on construction #10585
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
-- Fixes #10533
On Fruit Jam and Metro RP2350, a
usb_host.Port
object is always created on restart, usingboard.USB_HOST_DATA_MINUS
andboard.USB_HOST_DATA_PLUS
. However, the pins were not claimed incommon_hal_usb_host_port_construct()
. This made them accidentally available for other uses, such as trying to create anI2C
object, and could cause crashes.This PR claims the pins so they can never be used for anything else, and prevents crashes. Perhaps it should be possible to
deinit()
theusb_host.Port
, so you can use the pins for other purposes. When the board is start, TinyUSB is initialized to use those pins as a USB host. I'm not sure whether it's possible to reverse the TinyUSB setup. There is anhcd_deinit()
, so maybe it is. Any comments on this welcome.I tested that trying to the use pins for some other purpose raises an exception like
ValueError: USB_HOST_DATA_MINUS in use
.EDIT: I started doing this by adding a
usb_host.port
(kind of likemicrocontroller.cpu
) and addedusb_host.Port.deinit()
, but ran into some dilemmas about how to handle the "never reset" on the pins.Since this fixes a bug where trying to reuse the pins for non-host purposes would already fail, we could leave this alone and open another issue to allow pin reuse later, after 10.0.0.