ejolson
Posts: 8900
Joined: Tue Mar 18, 2014 11:47 am

Unable to enumerate USB device

Sun Jun 27, 2021 10:10 pm

I'm getting

Code: Select all

[2500445.930374] usb 8-1: new full-speed USB device number 8 using ohci-pci
[2500451.212435] usb 8-1: device descriptor read/all, error -110
[2500451.348249] usb 8-1: new full-speed USB device number 9 using ohci-pci
[2500467.217880] usb 8-1: device descriptor read/64, error -110
[2500484.185486] usb 8-1: device not accepting address 9, error -110
[2500484.185544] usb usb8-port1: attempt power cycle
[2500484.861475] usb 8-1: new full-speed USB device number 10 using ohci-pci
[2500495.961214] usb 8-1: device not accepting address 10, error -110
[2500496.097213] usb 8-1: new full-speed USB device number 11 using ohci-pci
[2500507.224954] usb 8-1: device not accepting address 11, error -110
[2500507.225012] usb usb8-port1: unable to enumerate USB device
in dmesg of a Linux computer to which I am attaching a Pico that will communicate using serial over USB. Has anyone seen these messages before?

ejolson
Posts: 8900
Joined: Tue Mar 18, 2014 11:47 am

Re: Unable to enumerate USB device

Mon Jun 28, 2021 3:25 am

ejolson wrote:
Sun Jun 27, 2021 10:10 pm
Has anyone seen these messages before?
In case anyone else has the same problem, the work around I found was to start the program with

Code: Select all

#include "tusb.h"
int main() {
    stdio_init_all();
    printf("waiting for usb host");
    while (!tud_cdc_connected()) {
      printf(".");
      sleep_ms(500);
    }
    printf("\nusb host detected!\n");
as per

viewtopic.php?p=1849534#p1849534

which somehow allowed the Linux host to enumerate the USB serial connection to the Pico. After this it was possible to connect an interactive session through minicom.

Does anyone know if this a bug? Am I doing something wrong?

hippy
Posts: 11219
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Unable to enumerate USB device

Sat Jul 03, 2021 9:37 pm

ejolson wrote:
Sun Jun 27, 2021 10:10 pm
Has anyone seen these messages before?
Just encountered it - viewtopic.php?p=1884819#p1884819

In that case it seems to be caused through initialising USB and returning from main before the host USB handler has caught up. For me that also hung 'lsusb, showed no output, required Ctrl-C.

I haven't tried it yet but I expect the 'tud_connected' fix will solve the problem there.

I am not sure I'd call it a bug; more an unanticipated or 'didn't think of that' issue.

I am also not sure what a generic solution 'fix' would be. It's not needed if using UART serial but may be for USB. But there's no reason a device cannot or should not output over USB even when not connected so waiting for connection as part of stdio_init_all() could cause as many problems as it solves.

My proposal would be for the SDK to automatically wait for USB connection after the return from main.

That will be superfluous but non-problematic if the programmer has waited at start-up. It will ensure the host has had time to sort its side of USB out before it's unable to do that. Any other potential problems can be dismissed with a cheery "you returned from main so who cares what it's doing".

Or, and perhaps an easier option; require an 'stdio_done_all()' call which should be inserted before any main returns.

ejolson
Posts: 8900
Joined: Tue Mar 18, 2014 11:47 am

Re: Unable to enumerate USB device

Sat Jul 03, 2021 10:53 pm

hippy wrote:
Sat Jul 03, 2021 9:37 pm
ejolson wrote:
Sun Jun 27, 2021 10:10 pm
Has anyone seen these messages before?
Just encountered it - viewtopic.php?p=1884819#p1884819

In that case it seems to be caused through initialising USB and returning from main before the host USB handler has caught up. For me that also hung 'lsusb, showed no output, required Ctrl-C.

I haven't tried it yet but I expect the 'tud_connected' fix will solve the problem there.

I am not sure I'd call it a bug; more an unanticipated or 'didn't think of that' issue.

I am also not sure what a generic solution 'fix' would be. It's not needed if using UART serial but may be for USB. But there's no reason a device cannot or should not output over USB even when not connected so waiting for connection as part of stdio_init_all() could cause as many problems as it solves.

My proposal would be for the SDK to automatically wait for USB connection after the return from main.

That will be superfluous but non-problematic if the programmer has waited at start-up. It will ensure the host has had time to sort its side of USB out before it's unable to do that. Any other potential problems can be dismissed with a cheery "you returned from main so who cares what it's doing".

Or, and perhaps an easier option; require an 'stdio_done_all()' call which should be inserted before any main returns.
That's an interesting observation about return from main. Probably what was happening in my case is that the program tried to perform a fgetc from stdin before USB had connected, received an error and exited without me suspecting what had happened. I wonder if it's better to print or do nothing while waiting for the USB to connect.

hippy
Posts: 11219
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Unable to enumerate USB device

Sun Jul 04, 2021 2:17 pm

ejolson wrote:
Sat Jul 03, 2021 10:53 pm
I wonder if it's better to print or do nothing while waiting for the USB to connect.
I would say it doesn't make sense to print anything but 'do nothing' may not be enough to let the USB connected state be arrived at.

Within C Extension Modules for MicroPython, the standard practice is to repeatedly call 'tud_task' to let TinyUSB catch up. I don't know what it should be for Pico-SDK use.

I think I am going to adopt the following model -

Code: Select all

int main() {
    stdio_init_all();
    stdio_init_usb();
    // ...
    stdio_exit_usb();
    stdio_exit_all();
    return 0;
}
"stdio_init_usb", "stdio_exit_usb" and "stdio_exit_all" would probably be just the one aliased function which waits until USB is connected if USB is enabled for now. If it's not using USB or already connected it won't be any overhead, and will solve the problem so long as at least one of the three are included.

The existing "stdio_init_all" appears to call "stdio_usb_init" so maybe that's the best place to put it, but I can see that causing problems if code has been written knowing that 'print' will do nothing if USB is not connected.

~/pico/pico-sdk/src/rp2_common/pico_stdio/include/pico/stdio.h

Code: Select all

  void stdio_init_all(void);
+ void stdio_init_usb(void);
+ void stdio_exit_usb(void);
+ void stdio_exit_all(void);
~/pico/pico-sdk/src/rp2_common/pico_stdio/stdio.c

Code: Select all

+ void stdio_init_usb() {
+ #if LIB_PICO_STDIO_USB
+     // TO DO 
+ #endif 
+ }

+ #define stdio_exit_usb() stdio_init_usb()
+ #define stdio_exit_all() stdio_init_usb()

  int WRAPPER_FUNC(getchar)(void) {
That compiles so now I just have to figure out what goes inside the #if.

SoyaOhnishi
Posts: 3
Joined: Mon Oct 26, 2020 11:55 am

Re: Unable to enumerate USB device

Fri Jul 23, 2021 10:26 pm

I also have a similar problem on Ubuntu 20.04.
In my case, pico often fail to be detected, but sometimes success to be detected.

in failed case, dmesg says

Code: Select all

[ 2169.581945] usb 1-5: new full-speed USB device number 3 using xhci_hcd
[ 2169.769373] usb 1-5: Device not responding to setup address.
[ 2170.005450] usb 1-5: Device not responding to setup address.
[ 2170.213963] usb 1-5: device not accepting address 3, error -71
[ 2170.346206] usb 1-5: new full-speed USB device number 4 using xhci_hcd
[ 2170.502004] usb 1-5: device descriptor read/64, error -71
[ 2170.806118] usb 1-5: device descriptor read/64, error -71
[ 2170.913999] usb usb1-port5: attempt power cycle
[ 2171.565942] usb 1-5: new full-speed USB device number 5 using xhci_hcd
[ 2171.593050] usb 1-5: Device not responding to setup address.
[ 2171.829086] usb 1-5: Device not responding to setup address.
[ 2172.041953] usb 1-5: device not accepting address 5, error -71
[ 2172.237932] usb 1-5: new full-speed USB device number 6 using xhci_hcd
[ 2172.265142] usb 1-5: Device not responding to setup address.
[ 2172.500757] usb 1-5: Device not responding to setup address.
[ 2172.713924] usb 1-5: device not accepting address 6, error -71
[ 2172.713991] usb usb1-port5: unable to enumerate USB device
This failure also happen in BOOTSEL mode.

I used another usb cable ( PS4 controller cable ) and another pico board,
but problem is not solved.

Does anyone have a solution?
If so, please tell me.

hippy
Posts: 11219
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Unable to enumerate USB device

Sat Jul 24, 2021 10:41 am

SoyaOhnishi wrote:
Fri Jul 23, 2021 10:26 pm
This failure also happen in BOOTSEL mode.

Does anyone have a solution?
Not that I know of. I had the same problem with a Pico not being able to enter BOOTSEL mode, giving the same sort of errors as you are seeing -

viewtopic.php?f=144&t=311024.

No replies let alone any solution. It seems to be a case of keep trying it until it works, or move to using another Pico which does work, which is what I did.

ejolson
Posts: 8900
Joined: Tue Mar 18, 2014 11:47 am

Re: Unable to enumerate USB device

Sat Jul 24, 2021 3:55 pm

hippy wrote:
Sat Jul 24, 2021 10:41 am
SoyaOhnishi wrote:
Fri Jul 23, 2021 10:26 pm
This failure also happen in BOOTSEL mode.

Does anyone have a solution?
Not that I know of. I had the same problem with a Pico not being able to enter BOOTSEL mode, giving the same sort of errors as you are seeing -

viewtopic.php?f=144&t=311024.

No replies let alone any solution. It seems to be a case of keep trying it until it works, or move to using another Pico which does work, which is what I did.
Is it possible sometimes the auto mounter in Windows fiddles with the pseudo filesystem presented by the Pico enough for the Pico to think it's time to switch to run mode? This could be triggered by some sort of cache flush when Windows sees what it thinks is the same device reconnect in a short period of time.

hippy
Posts: 11219
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Unable to enumerate USB device

Sat Jul 24, 2021 4:24 pm

ejolson wrote:
Sat Jul 24, 2021 3:55 pm
hippy wrote:
Sat Jul 24, 2021 10:41 am
I had the same problem with a Pico not being able to enter BOOTSEL mode, giving the same sort of errors as you are seeing -
Is it possible sometimes the auto mounter in Windows fiddles with the pseudo filesystem presented by the Pico enough for the Pico to think it's time to switch to run mode? This could be triggered by some sort of cache flush when Windows sees what it thinks is the same device reconnect in a short period of time.
This happened to me on a Pi running Raspberry Pi OS.

ejolson
Posts: 8900
Joined: Tue Mar 18, 2014 11:47 am

Re: Unable to enumerate USB device

Sat Jul 24, 2021 4:36 pm

hippy wrote:
Sat Jul 24, 2021 4:24 pm
ejolson wrote:
Sat Jul 24, 2021 3:55 pm
hippy wrote:
Sat Jul 24, 2021 10:41 am
I had the same problem with a Pico not being able to enter BOOTSEL mode, giving the same sort of errors as you are seeing -
Is it possible sometimes the auto mounter in Windows fiddles with the pseudo filesystem presented by the Pico enough for the Pico to think it's time to switch to run mode? This could be triggered by some sort of cache flush when Windows sees what it thinks is the same device reconnect in a short period of time.
This happened to me on a Pi running Raspberry Pi OS.
I wonder if it would be possible for the pseudo filesystem to stay mounted until a file named run were copied to the device. That would eliminate the accidental disconnects before all the uf2 files are copied over.

hippy
Posts: 11219
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: Unable to enumerate USB device

Sat Jul 24, 2021 5:21 pm

ejolson wrote:
Sat Jul 24, 2021 4:36 pm
I wonder if it would be possible for the pseudo filesystem to stay mounted until a file named run were copied to the device. That would eliminate the accidental disconnects before all the uf2 files are copied over.
It didn't even get mounted. As best I can see Raspberry Pi OS saw the PIco, saw it was in BOOTSEL mode, tried to create a friendship, got an unexpected failure response, and bailed out.

SoyaOhnishi
Posts: 3
Joined: Mon Oct 26, 2020 11:55 am

Re: Unable to enumerate USB device

Mon Jul 26, 2021 11:18 am

I tried to use macbook air as a host, and there are no failures.
So, I suspect Linux usb driver or usb controller of my desktop PC ( I don't know if usb controller could be a cause ) .

Is there anyone who can use pico on Ubuntu 20.04 without any problems?

Return to “General”