Skip to content

Conversation

dhalbert
Copy link
Collaborator

@dhalbert dhalbert commented Aug 26, 2025

-- Fixes #10533

On Fruit Jam and Metro RP2350, a usb_host.Port object is always created on restart, using board.USB_HOST_DATA_MINUS and board.USB_HOST_DATA_PLUS. However, the pins were not claimed in common_hal_usb_host_port_construct(). This made them accidentally available for other uses, such as trying to create an I2C 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() the usb_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 an hcd_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 like microcontroller.cpu) and added usb_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.

@dhalbert dhalbert requested review from tannewt and FoamyGuy August 26, 2025 22:11
Copy link
Collaborator

@FoamyGuy FoamyGuy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I confirmed that this resolves the hard crash that was reported in the issue using the reproducer scripts also from the issue.

Thanks for the fix!

@tannewt
Copy link
Member

tannewt commented Aug 27, 2025

I'm not sure whether it's possible to reverse the TinyUSB setup. There is an hcd_deinit(), so maybe it is. Any comments on this welcome.

I don't think it is possible. I believe host is going forever after it is started.

Copy link
Member

@tannewt tannewt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@tannewt tannewt merged commit 3b1b700 into adafruit:main Aug 27, 2025
153 checks passed
@dhalbert dhalbert deleted the claim-usb_host-pins branch August 27, 2025 21:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Hardcrash on Fruit Jam with I2C pin finding script
3 participants