sekigon-gonnoc/Pico-PIO-USB

USB Hub causes a CONTROL_ERROR when plugged in

drflamemontgomery opened this issue · 4 comments

I noticed that when using a USB Hub with the capture_hid_report example, it would cause a CONTROL_ERROR. I found that by adding a wait of 1000us in the control_in_protocol function, it would allow the USB Hub to initialize without erroring.

//=======================================
//    src/pio_usb_host.c
//=======================================
static int __no_inline_not_in_flash_func(control_in_protocol)(
    usb_device_t *device, uint8_t *tx_data, uint16_t tx_length,
    uint8_t *rx_buffer, uint16_t request_length) {
  int res = 0;

  control_pipe_t *pipe = &device->control_pipe;

  busy_wait_us(1000); // Adding this line fixes the usb hub

I am using USB Female Module and a USB High Speed Hub with 4 Ports

Did you ever get to the bottom of this ? I'm seeing the same behaviour but sleep doesnt work for me

` usb_device_t *device, uint8_t *tx_data, uint16_t tx_length,
uint8_t *rx_buffer, uint16_t request_length) {
int res = 0;

print_bytes(tx_data, tx_length);

control_pipe_t *pipe = &device->control_pipe;

sleep_ms(1000); `

I unfortunately never found the cause of the behavior.
Have you tried using busy_wait_us or busy_wait_ms?

Would you also be able to print a log of the USB using the capture_hid_report program

I was trying to connect to a Nintendo Switch Pro Controller and was running into this same issue, and the busy_wait_us(1000); change fixed it for me.

Interestingly, the controller would always connect on the third attempt (removing and reinserting the USB cable) after resetting the Pico. But the fix above made it connect on the first attempt.