Friday, March 1, 2013

USB Device Not Recognized in USB 3.0

Unless you’re having this problem:




For USB 3.0 ports on an Arduino-like stack you may safely stop reading. Nothing to see here just trying to fill out the Internet.


The Problem


This problem occurred for me on an ATMEL ATMEGA32U2 chip with the LUFA USB framework for AVRs and the HID USB driver. Everything worked fine for USB 2.0, but on modern PC's it would pop up "USB device not recognized".


In device manager the device showed up as Unknown device. Device status would look like this:


Windows has stopped this device because it has reported problems. (Code 43)

And in the event viewer it showed something like this:


Device USB\VID_0000&PID_0002\5&ea89d57&0&2 had a problem starting. Driver Name: null Class GUID: {00000000-0000-0000-0000-000000000000} Service: Lower Filters: Upper Filters: Problem: 0x2B Status: 0x0

The Solution


Despite a lot of fruitless packet monitoring and upgrading various packages and help from master-hacker Joe Ferner, solving this ultimately boiled down to compiling the GenericHid sample project from LUFA (which did work in USB 3.0) and then commenting out more and more of my project until it worked and then incrementally adding everything back via binary search.


The problem ended up being the amount of time that passed between the call to LUFA's


USB_Init();

And the USB calls in the main program loop. So essentially I was doing something like this:


int main(void);   MCUSR &= ~(1 << WDRF);   wdt_disable();   clock_prescale_set(clock_div_1);   USB_Init();   _delay_ms(500); // <---- DON'T DO THIS   for (;;)   {     HID_Device_USBTask(&Generic_HID_Interface);     USB_USBTask();   } }


Take that delay out and everything works.


Summary


The takeaway: move all of your initialization logic - anything that might take any time at all - prior to the USB_Init call. It might just save you a lot of pain down the road. That's it. Hope this helps someone, somewhere.

No comments: