emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

gadget USB device not recognized during boot.

Wed Feb 13, 2019 6:12 pm

I have been using the pi zero with gadgetfs. While the pi is booting I get an error message from the Windows system I have the pi connected to: "USB device not recognized. The Last USB device you connected to this computer malfunctioned and Windows does not recognize it. Windows Explorer". The error message goes away after a few seconds and everything works fine, but I would like to get rid of this error. Does anyone know why I get this error and/or how I can prevent it (pi only solution).

Distributor ID: Raspbian
Description: Raspbian GNU/Linux 9.4 (stretch)
Release: 9.4
Codename: stretch

User avatar
thagrol
Posts: 3766
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: gadget USB device not recognized during boot.

Wed Feb 13, 2019 6:53 pm

I'm not sure that you can get rid of this message. Or rather that there is anything you can do on the Pi side. Nor do I have any idea what can be done on the windows side.

The first thing the USB host sees when the Pi boots is the "BCM2708 Boot" device. AIUI, this is hardcoded in the SoC and cannot be changed. This is almost certainly the devicve that windows is complaining about.

Once the Pi is booting from the Sd card this device disappears. Later in the boot process it's replace with the USB gadgets you have configured in gadgetfs (or by loading one of the preconfigured modules) which windows recognises.

Note: I have no insider knowledge, the above is based on observed behaviour when experimenting with USB gadget mode.
Arguing with strangers on the internet since 1993.

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

Re: gadget USB device not recognized during boot.

Wed Feb 13, 2019 8:15 pm

thagrol wrote:
Wed Feb 13, 2019 6:53 pm
The first thing the USB host sees when the Pi boots is the "BCM2708 Boot" device. AIUI, this is hardcoded in the SoC and cannot be changed. This is almost certainly the devicve that windows is complaining about.
Sounds like that to me. As to why it's giving a "not recognised" it could be that Windows really doesn't know what it is when it first powers-up as a Boot device.

You could try installing rpiboot for and on Windows if you haven't already as that should create a device driver which should make Windows recognise the Boot device. That might get rid of the message.

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: gadget USB device not recognized during boot.

Thu Feb 14, 2019 6:41 pm

hippy wrote: You could try installing rpiboot for and on Windows if you haven't already as that should create a device driver which should make Windows recognise the Boot device. That might get rid of the message.
Thanks for the suggestion, unfortunately I am not able to change anything on the Windows computer.

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

Re: gadget USB device not recognized during boot.

Thu Feb 14, 2019 8:46 pm

Thinking about it; there is no good reason why the Zero should be enumerating as a USB boot device if it is booting from SD Card.

I am starting to recall I had some similar experiences. If the Zero is connected to a Windows PC then, as it boots, before it has gone into gadget mode, it is noticed by the Windows PC, but doesn't yet respond because it's not running as a gadget yet, Windows can't figure out what it is and complains.

I recall the message goes away as you describe. It was more problematic with a digital picture frame, it completely hung that, only worked if the DPF was powered up once the Zero was already in gadget mode with MSD running.

I thought I had a post about that but cannot find it at present. I don't recall there being any solution or workaround suggested, no way to enable dwc/dwc2 only when gadget mode starts.

Unfortunately Dougie Lawson's childish and pathetic "This is a hippy & doctor free zone" signature has made searching for the post via Google rather fruitless.

User avatar
thagrol
Posts: 3766
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: gadget USB device not recognized during boot.

Thu Feb 14, 2019 11:30 pm

hippy wrote:
Thu Feb 14, 2019 8:46 pm
I recall the message goes away as you describe. It was more problematic with a digital picture frame, it completely hung that, only worked if the DPF was powered up once the Zero was already in gadget mode with MSD running.
And there's your work around: power the Zero seperately and only make the data connection to the host when it has booted.

Not ideal, I know and possibly not practical outside the development environment.

If your end users are reasonably capable and the target PC has two free USB ports, you could switch on an LED via gpio once the gadget is ready to signal the user to plug in the second cable.

If they can't be trusted I'd look into developing a small circuit that uses gpio to make the data pin connections once the gadget is ready. One cable from the PC via that circuit to provide power and data. Googling for how the various USB peripheral sharing switches work make be a starting point.

Another option might be to use a gpio circuit that pulls the ID pin low (which puts dwc2 into host mode) and releases it once the gadget is ready. However, that might result in both the PC and the Pi trying to power and probe the USB bus. I've no idea whether that's safe and it's probably not in spec. I guess a diode on the +ve line might help but you'd have to allow for the voltage drop.
Arguing with strangers on the internet since 1993.

User avatar
thagrol
Posts: 3766
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 12:02 am

Despite my comments above, I'm not sure what's actually going on though it has to be somewhere in the interaction between the SoC boot code, windows (which version?), dwc2, the module(s) providing gadgetfs, and the way the OP is configuring their gadget(s).

Unfortunately it's been a while since I've seen it and my windows fu isn't up to the task of low level debugging its USB stack.

@hippy: you're probably right that with SD card boot the zero isn't enumerating as a boot device. I can't speak for windows but a quick test on a linux host only sees the BCM2708 boot device with an unbootable SD card or with no SD card present.

It's midnight so I'm not going to investigate further atm. Maybe tomorrow if time allows.
Arguing with strangers on the internet since 1993.

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

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 12:57 pm

thagrol wrote:
Thu Feb 14, 2019 11:30 pm
hippy wrote:
Thu Feb 14, 2019 8:46 pm
I recall the message goes away as you describe. It was more problematic with a digital picture frame, it completely hung that, only worked if the DPF was powered up once the Zero was already in gadget mode with MSD running.
And there's your work around: power the Zero seperately and only make the data connection to the host when it has booted.
And that was pretty much my solution; keep the Zero permanently powered, put the DPF PSU on a mains timer switch. When the DPF comes on the Zero running MSD is already up and running and it all works great.

Your ideas for keeping the Zero disconnected from the host until gadget mode is up and running should also work. A relay on D+/D- could work and be the simplest solution from the playing around I've done with physically switching USB devices between hosts. Something solid-state would of course be better.

I couldn't find what I thought was my earlier post and I may not have made it. I probably figured I'd just get a shrug and a 'that's how it is', 'no idea how to change it', response, so wasn't worth the effort. I did however find my notes. And the "unknown" / "unrecognised device" which the OP is seeing is documented -

What I am seeing ...

Code: Select all

          .------.-----------------.   .------.-----------  
DPF     --| Init | Wait            |---| Init | MSD Drive
        : `------^-----------------' : `------^-----------
        :           :         :      :
        Power-up    :         :      Power-cycle          
                    :         :
                    .---------.---------------------------
Windows ------------| Unknown | MSD Drive 
        :           `---------^---------------------------
        Power-up    :         :
                    :         :
                    .---------.---------------------------
Pi Zero           --| DWC2    | g_mass_storage
                  : `---------^---------------------------
                  :           :
                  Power-up    modprobe
What I would like ...

Code: Select all

          .------.------------.---------------------------  
DPF     --| Init | Wait       | MSD Drive
        : `------^------------^---------------------------
        Power-up              :      
                              :
                              .---------------------------
Windows ----------------------| MSD Drive 
        :                     `---------------------------
        Power-up              :
                              :
                    .- - - - -.---------------------------
Pi Zero           --| Nothing | g_mass_storage
                  : `- - - - -^---------------------------
                  :           :
                  Power-up    modprobe

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 1:47 pm

Thanks again guys
hippy wrote: Another option might be to use a gpio circuit that pulls the ID pin low (which puts dwc2 into host mode) and releases it once the gadget is ready. However, that might result in both the PC and the Pi trying to power and probe the USB bus. I've no idea whether that's safe and it's probably not in spec. I guess a diode on the +ve line might help but you'd have to allow for the voltage drop.
I have to add a small board anyhow, so this is the kludge I was thinking of trying if I couldn't find a proper solution. Since I will be powering the Pi Zero from the host the power issue will not be a problem. Also the pi zero (w) has no control logic for +ve (it is tied directly to the +5V line) so any problems you would have with power will happen regardless of putting it into host mode.

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

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 3:05 pm

So long as the Zero isn't powered by anything else, only gets its power from the PC USB Port you won't need a diode in the Vusb power line.

I don't know what the on-chip electrical interface is for a typical USB host so don't know how that would fare as host connected to host. We don't have full circuit diagrams so can't tell if there are any inline resistors on D+ or D- signals; there wasn't on the original A and B. It might be worth adding a couple while experimenting.

Please do let us know how you get on using the ID line to keep it in host mode until gadget mode is ready to roll as it does sound like a good solution if it works,

User avatar
thagrol
Posts: 3766
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 3:55 pm

OK.

I've dome some more digging.

It appears tha the dwc2 module is the culprit, well that and windows.

At some point, before your gadgets have loaded/been configured windows seems to be requesting a device descriptor. dwc2 isn't responding to that request (windows device manager shows "Unknown USB Device (Device Descriptor Request Failed)") so you get the error.

The configuration used above was with "dtoverlay=dwc2" in config.txt and selected modules loaded via rc.local (edit: or no module)

Now. here's the odd thing: if I remove the modprobe from rc.local and add, say, "modules-load=dwc2,g_serial" to cmdline.txt (and reboot, obviously) windows does not throw the error instead just detects a serial port.

So, assuminng that is reliably reproducable, that you can pass valid module parametrs via cmdline.txt, and that you're using one of the g_* modules we have a software work around. It won't help when using libcomposite/gadgetfs though.

g_mass_storage may be a problem however as the backing store may not be available at that point in the boot sequence. In which case I'd try setting "removable=1" (however you do that via cmdline.txt) then specifying the backing store later via sysfs.

Edit #2: For clarity, that's Windows 10 Home.
Last edited by thagrol on Fri Feb 15, 2019 4:03 pm, edited 2 times in total.
Arguing with strangers on the internet since 1993.

User avatar
thagrol
Posts: 3766
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 3:58 pm

emw wrote:
Fri Feb 15, 2019 1:47 pm
Thanks again guys
hippy wrote: Another option might be to use a gpio circuit that pulls the ID pin low (which puts dwc2 into host mode) and releases it once the gadget is ready. However, that might result in both the PC and the Pi trying to power and probe the USB bus. I've no idea whether that's safe and it's probably not in spec. I guess a diode on the +ve line might help but you'd have to allow for the voltage drop.
That wasn't hippy, that was me.

I have to add a small board anyhow, so this is the kludge I was thinking of trying if I couldn't find a proper solution. Since I will be powering the Pi Zero from the host the power issue will not be a problem. Also the pi zero (w) has no control logic for +ve (it is tied directly to the +5V line) so any problems you would have with power will happen regardless of putting it into host mode.
You still have the potential that both the Pi and the host will try to drive D+ and D- at the same time. I don't know if that's going to be a problem or what potential it has for hardware damage.
Arguing with strangers on the internet since 1993.

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 4:46 pm

thagrol wrote:That wasn't hippy, that was me.
sorry about that... just used the quote function in the editor and didn't check that it quoted the right person.

Yes I agree about it being a problem with the data lines driving each other... that's one of the reasons I call it kludge.

your comment about passing valid module parameters via cmdline.txt, is interesting. Unfortunately I'm not using g_* modules (and to be honest am not to familiar with them... something to look into). This does show that it is possible to implement a software only solution....just how to do it with my application. For reference I am using usbProxy to manipulate some data being sent to a USB printer. This is often (but not always) from a windows computer.

User avatar
thagrol
Posts: 3766
Joined: Fri Jan 13, 2012 4:41 pm
Location: Darkest Somerset, UK
Contact: Website

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 6:37 pm

emw wrote:
Fri Feb 15, 2019 4:46 pm
thagrol wrote:That wasn't hippy, that was me.
sorry about that... just used the quote function in the editor and didn't check that it quoted the right person.
np. Just making sure blame goes the right way :)
For reference I am using usbProxy to manipulate some data being sent to a USB printer. This is often (but not always) from a windows computer.
I'll give you the benefit of the doubt here in that you're not using usbProxy for malicious purposes.

More importantly, how are you getting around its requirement that you have both a host port and a slave port on the device running it? Pi that can do USB gadget only have one USB port that work either as a host port or as a slave port (or swap between the two). They can't do both simultaneously.

If you've yet to address that, it might be wise to do so before commiting further time and resources to the project.

Edit: Technically all Pi only have one USB port. All B(+) series have a USB hub on board to provide ethernet and the four USB sockets.
Arguing with strangers on the internet since 1993.

emw
Posts: 52
Joined: Tue Apr 12, 2016 2:53 pm

Re: gadget USB device not recognized during boot.

Fri Feb 15, 2019 7:07 pm

thagrol wrote: I'll give you the benefit of the doubt here in that you're not using usbProxy for malicious purposes.
No malicious intent here, but given the topic I can see why you might think so.
thagrol wrote: More importantly, how are you getting around its requirement that you have both a host port and a slave port on the device running it? Pi that can do USB gadget only have one USB port that work either as a host port or as a slave port (or swap between the two). They can't do both simultaneously.
I have MAX3421E SPI to USB bridge as the host port. So far it seems to be working well.

Return to “Advanced users”