Skip to content

Conversation

@jepler
Copy link
Contributor

@jepler jepler commented Dec 20, 2024

Tested on Adafruit Metro RP2350 prototype, which uses pins 32/33. Also requires some small changes to CircuitPython but never mind that :)

image

>>> import usb_host, board, digitalio, usb
>>> usb_host.Port(board.USB_HOST_DATA_PLUS, board.USB_HOST_DATA_MINUS)
>>> pwr = digitalio.DigitalInOut(board.USB_HOST_5V_POWER)
>>> pwr.switch_to_output(True)
>>> list(usb.core.find(find_all=True))
[<Device>]

ping @ladyada

Closes: #133

@jepler
Copy link
Contributor Author

jepler commented Dec 20, 2024

I'll update this branch and make it work with the CI. What SDK versions need to be supported? I think SDK 2.1.0 may be required for some of the APIs used, so I can make them conditional if necessary.

@jepler
Copy link
Contributor Author

jepler commented Dec 20, 2024

CI now runs against SDK 2.1.0 as well as older versions.

@jepler
Copy link
Contributor Author

jepler commented Jan 26, 2025

This has been updated with changes necessary to use RP2350 (A or B)'s PIO2 peripheral instance. Tested in CircuitPython.

@sekigon-gonnoc sekigon-gonnoc merged commit 442af43 into sekigon-gonnoc:main Feb 4, 2025
4 checks passed
@jepler
Copy link
Contributor Author

jepler commented Feb 5, 2025

Thank you!

@fhoedemakers
Copy link

I was asked by Adafruit - John Park to get my RP2350 NES emulator working using a gamecontroller connected to the usb break-out pins of the Adafruit Metro RP2350. (goal is to get it working on the upcoming Fruitjam board) As mentioned in here, these pins use GPIO29 for 5V, GPIO 32 for D+ and GPIO33 for D-.

For starters i tried to get the host_hid_to_device_cdc example to work, but it doesn't. Maybe it's a small detail I'm missing.

See https://github.com/fhoedemakers/Pico-PIO-USB for a stripped down example:

In examples/host_hid_to_device_cdc/host_hid_to_device_cd.c I enabled 5volt to pin 29 in main()

// Enable 5v power on USB port
gpio_put(29, 1);
gpio_set_dir(29, GPIO_OUT);
gpio_set_function(29, GPIO_FUNC_SIO);

And changed the CMakeLists.txt in examples/host_hid_to_device_cdc

# use tinyusb implementation
# Adafruit Metro RP2350 using built-in USB with D+ GPIO32, D- GPIO33 : not working
target_compile_definitions(${target_name} PRIVATE PIO_USB_USE_TINYUSB PIO_USB_DP_PIN_DEFAULT=32 PICO_PIO_USE_GPIO_BASE=1) 
#  Adafruit Metro RP2350 with External USB port on D+ GPIO 4, D- GPIO5 : working
#target_compile_definitions(${target_name} PRIVATE PIO_USB_USE_TINYUSB PIO_USB_DP_PIN_DEFAULT=4)

As i can see from the code, i need to set PICO_PIO_USE_GPIO_BASE=1 in CMakeLists.txt in order for pio to use port 32 and 33.

But i can't get this to work.

When i connect an usb board with DP+ = GPIO4, DP- = GPIO 5. The example just runs fine:

image

@jepler
Copy link
Contributor Author

jepler commented Jun 12, 2025

I will not be able to look into this anytime soon. I'm away from all my hardware, and taking a break from Adafruit work.

Before starting on my break, in addition to working in circuitpython, it was working in at least 2 cmake-based fruit jam usb projects, https://github.com/adafruit/MCUME/tree/master/MCUME_pico2 and https://github.com/adafruit/pico-mac and an arduino fruit jam uisb project adafruit/Adafruit_Learning_System_Guides#2978 -- the git submodules & CI build rules

Those were all working on fruit jam at the time I committed them, albeit often depending on some very specific combinations of libraries. there are clues/traces of information in the exact git submodules & ci scripts.

Make sure you're using sdk 2.1.0 (or newer); on a quick review of this PR's code changes, it'd probably just silently fail if using an older SDK where some of the functions weren't available. It's also vaguely possible that some other sdk changes past 2.1.0 have broken things, so maybe try with exactly sdk 2.1.0.

You might also try with this submodule at exactly 0.7.0 (first release with this change), 7f7ea5b (tip of PR branch) or 442af43 (this project main branch just after merging this PR)

Good luck!

@fhoedemakers
Copy link

Thanks for your quick response. I use 2.1.1 as SDK, but also tried 2.1.0 with no luck.

I will look into the other projects how it's implemented.

Thank you!

@hathach
Copy link
Contributor

hathach commented Jun 12, 2025

I just tested with my metro rp2350 and it working just fine in my repo's example. sdk 2.1.1 may not include the latest pio-usb, make sure you use pio-usb with v0.7.2 and latest tinyusb (master branch, not tagged version). There is a lot of bug fixing for rp2350 with low speed device.

@fhoedemakers
Copy link

fhoedemakers commented Jun 13, 2025

Pulled the master branch from tiyusb and rebuilded all. Using pio-usb 0.7.2 Still no luck. Can you send me the .uf2 file to test it on my device?

image

Are these the correct compile definitions in examples/host_hid_to_device_cdc/CMakeLists.txt?

target_compile_definitions(${target_name} PRIVATE PIO_USB_USE_TINYUSB PIO_USB_DP_PIN_DEFAULT=32 PICO_PIO_USE_GPIO_BASE=1) 

@hathach
Copy link
Contributor

hathach commented Jun 13, 2025

host_info_to_device_cdc.zip
here is my exxample compile from my repo https://github.com/hathach/tinyusb/tree/master/examples/dual/host_info_to_device_cdc using BOARD=adafruit_metro_rp2350 https://github.com/hathach/tinyusb/tree/master/hw/bsp/rp2040/boards/adafruit_metro_rp2350 . The pin is initialized in family.c https://github.com/hathach/tinyusb/blob/master/hw/bsp/rp2040/family.c#L178-L182
What is your git commit hash both for tinyusb and pio-usb ?

@fhoedemakers
Copy link

I tested the .uf2, got a blinking led on the board. Connecting a serial terminal to the built-in usb, does not show any keypresses.

This is the output of git log for tinyusb:

commit e95973d3462cdacd165a4057632d46248ded7b8a (HEAD -> master, origin/master, origin/HEAD)
Merge: 99b4ebeb1 dc0038f61
Author: Ha Thach <[email protected]>
Date:   Thu Jun 12 22:18:17 2025 +0700

    Merge pull request #3137 from HiFiPhile/uac_simplify
    
    uac2: remove support fifo

image

For PIO-USB I used the 0.7.2 from the releases page .

@hathach
Copy link
Contributor

hathach commented Jun 13, 2025

image

How you set up metro rp2350, here is mine using host jumper cable. Example will print out device info via device interface

Device 1: ID 05e3:0736 SN 000000000272
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0200
  bDeviceClass        0
  bDeviceSubClass     0
  bDeviceProtocol     0
  bMaxPacketSize0     64
  idVendor            0x05e3
  idProduct           0x0736
  bcdDevice           0272
  iManufacturer       3     Generic
  iProduct            4     USB Storage
  iSerialNumber       2     000000000272
  bNumConfigurations  1

your git hash look good, not sure what prevent you from getting it working with metro rp2350.

@fhoedemakers
Copy link

fhoedemakers commented Jun 13, 2025

Have the same setup. Usb Keyboard connected to usb header on metro using jumper cable (in stead of usb-storage in your picture) Connected the built-in usb-c ( device interface) to pc and use putty terminal emulator to connect to the com-port. There is nothing appearing on the terminal screen.

Is the blinking led an indicator that's something wrong?

@hathach
Copy link
Contributor

hathach commented Jun 13, 2025

in that example, blinky only changes for device interface. Can you try with another device, pull out and/or pull out and plug-in, the device may print the message before you open termianl or so. If you have another metro rp2350, maybe give it a try. Also can you take the picture of your board, just to check which revision that you got. I got an F revision

@fhoedemakers
Copy link

Will try with another device. I also have another board. Will do this next Monday since I'm not at home till then. Will come back to you then asap. Thanks for your help. Much appreciated.

@fhoedemakers
Copy link

Got some more time for testing. When i connect a sd-card reader, Sony Dual Sense or Sony Dual Shock controller, device info is shown. Connecting an USB keyboard (Cherry KC1000) or USB mouse (Raspberry Pi Mouse), the device is not detected and no info is shown.
Both my Rp2350 Metro devices show the same behaviour.

mounted device 1
Device 1: ID 05e3:0749 SN 000000001532
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0210
  bDeviceClass        0
  bDeviceSubClass     0
  bDeviceProtocol     0
  bMaxPacketSize0     64
  idVendor            0x05e3
  idProduct           0x0749
  bcdDevice           1532
  iManufacturer       3     Generic
  iProduct            4     USB3.0 Card Reader
  iSerialNumber       2     000000001532
  bNumConfigurations  1
unmounted device 1
mounted device 1
Device 1: ID 054c:0ce6 SN /a
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0200
  bDeviceClass        0
  bDeviceSubClass     0
  bDeviceProtocol     0
  bMaxPacketSize0     64
  idVendor            0x054c
  idProduct           0x0ce6
  bcdDevice           0100
  iManufacturer       1     Sony Interactive Entertainment
  iProduct            2     DualSense Wireless Controller
  iSerialNumber       0     /a
  bNumConfigurations  1
unmounted device 1
mounted device 1
Device 1: ID 054c:09cc SN /a
Device Descriptor:
  bLength             18
  bDescriptorType     1
  bcdUSB              0200
  bDeviceClass        0
  bDeviceSubClass     0
  bDeviceProtocol     0
  bMaxPacketSize0     64
  idVendor            0x054c
  idProduct           0x09cc
  bcdDevice           0100
  iManufacturer       1     Sony Interactive Entertainment
  iProduct            2     Wireless Controller
  iSerialNumber       0     /a
  bNumConfigurations  1

See below my device. As i can see from the picture it has also revision F, but with PSRAM. My other device is also an F-revision with PSRAM. As i can see from your device it has no PSRAM. I don't think this will make a difference.

IMG_8800

@hathach
Copy link
Contributor

hathach commented Jun 17, 2025

pio usb host work with high gpio, it just does not work well with certain low speed device. We have tried to solve some of the compatibility issue but not all #179 one of the isssue is errata GPIO-E9 which make get input GPIO complicated. For now, maybe you could try to test a few other mices to find which working and proceed with it. I also have an RPI mouse, I will try to test it out.

@fhoedemakers
Copy link

Thanks,
I was under the impression the mouse would work fine because of this:
The RPI mouse works fine on the Metro RP2350 with this Circuit Python demo: https://learn.adafruit.com/larsio-paint-music/
It needs CircuitPython 10.0.0-alpha.5, so they must have found a way for it to make it work.
But anyway, i can proceed now. It recognizes the USB game controllers, which is my main focus right now.

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.

🪲[BUG] GPIOs > 32 not working

5 participants