USB host resets my device after 'get configuration descriptor'

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 

USB host resets my device after 'get configuration descriptor'

2,732 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by siangming on Sat Dec 13 01:09:02 MST 2014
hi all

i am using a LPC11U37H to implement a USB 2.0 full-speed device...i am going to implement it with a winusb driver on a windows 7 host pc.

Right now, i am getting a host reset after the 'get configuration descriptor' request.. the request is asking for a 255 bytes data payload.

i have only 1 configuration, 1 interface and 1 endpoint (excluding endpoint 0 IN and OUT). so i send my configuration as below:

typedef struct{
unsigned char bLength;
unsigned char bDescriptorType;
unsigned short int wTotalLength;
unsigned char bNumInterfaces;
unsigned char bConfigurationValue;
unsigned char iConfiguration;
unsigned char bmAttributes;
unsigned char bMaxPower;

unsigned char bLength_interface;
unsigned char bDescriptor_Typeinterface;
unsigned char bInterfaceNumber;
unsigned char bAlternateSetting;
unsigned char bNumEndpoints;
unsigned char bInterfaceClass;
unsigned char bInterfaceSubclass;
unsigned char bInterfaceProtocol;
unsigned char iInterface;

unsigned char bLength0;
unsigned char bDescriptorType0;
unsigned char bEndpointAddress0;
unsigned char bmAttributes0;
unsigned short wMaxPacketSize0;
unsigned char bInterval0;
} getconfig_descriptor;

getconfig_descriptor My_getconfig_desc = {
9,
2,
25, //total length of descriptor and subordinate descriptors
1, //number of interface
1, //configuration number, must be above 00. 00 = not configured.
0, //no string descriptor
0b11000000, //self-powered, NO remote wakeup
0x32, //100mA current

9,
4,
0, //interface number
0, //default alternate setting
1, //number of physical endpoints (excluding EP0)
0xFF, //interface class
0, //interface subclass
0, //interface protocol
0, //no string descriptor

7,
5,
0b10000001, //IN, logical endpoint address
0b00000011, //attributes: interrupt endpoint
64, //Maxpacketsize
0x64 //100ms max latency
};

After the setup request from the host,  i checked that the endpoint0 IN (data stage) and endpoint0 OUT (status stage) completed sucessfully because my endpoint0 IN interrupts fired off and i checked that NBytes are 0, meaning all 255 bytes of data are sent to the host. My endpoint0 OUT interrupt also fired off, meaning i received a ZLP status (stage completion) from the host.
(for the 255 bytes of data to send, i fill up the first 25bytes of the buffer with my structure above and the remaining of the 230 bytes with 0.)

i am thinking there must be something wrong with my descriptors since there is no other reason for the host to reset my device.

can anyone help check my descriptors above?

Note: i did not supply my INF file to the win7 host yet before i plugged in my device.... on the host, i get a 'device not recognised' message after i plugged in the device.
But i guess the INF file does not matter because i supposed if the enumeration went ok, i should see a message asking for drivers if the INF is not found...


thanks
标签 (1)
0 项奖励
回复
4 回复数

2,690 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by siangming on Mon Dec 15 00:22:25 MST 2014

Quote: Tsuneo

Quote:
my endpoint0 IN interrupts fired off and i checked that NBytes are 0, meaning all 255 bytes of data are sent to the host.



As Windows request "255 bytes" for the config descriptor by Get_Descriptor, you have coded to send just this requested size, with padding. But in USB practice, when Get_Descriptor would request more than the target descriptor size, the device should return just the size of the descriptor. No padding is required.

9.4.3 Get Descriptor on USB2.0 spec
If the descriptor is shorter than the wLength field, the device indicates the end of the control transfer by sending a short packet when further data is requested.


Tsuneo




yes, this is the problem... i am sending 255 bytes for 'get configuration descriptor'. after i changed my firmware to only return 25 bytes (configuration descriptor size), the device is able to enumerate fine..
thank you.
0 项奖励
回复

2,690 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Sat Dec 13 07:44:17 MST 2014
In addition to above post,


Quote:
typedef struct{...} getconfig_descriptor;



Is this struct a "packed" one?

GCC: __attribute__ ((__packed__))
Keil, IAR: __packed


What is the bMaxPacketSize0 on the device descriptor?

For full-speed, 8, 16, 32 or 64 bytes are allowed for bMaxPacketSize0.
As we discussed on your another post
http://www.lpcware.com/content/forum/setting-endpoint-maxpacketsize-lpc11u37h
your firmware has to manage MPS (Max Packet Size).
If you would assign 32 or 64 to bMaxPacketSize0, 25 bytes config descriptor is sent by single transaction of this size. But for 8 or 16, your firmware has to split the 25 bytes into 4 (8,8,8,1) or 2 (16, 9) transactions.

Tsuneo
0 项奖励
回复

2,690 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by Tsuneo on Sat Dec 13 06:56:45 MST 2014

Quote:
my endpoint0 IN interrupts fired off and i checked that NBytes are 0, meaning all 255 bytes of data are sent to the host.



As Windows request "255 bytes" for the config descriptor by Get_Descriptor, you have coded to send just this requested size, with padding. But in USB practice, when Get_Descriptor would request more than the target descriptor size, the device should return just the size of the descriptor. No padding is required.

9.4.3 Get Descriptor on USB2.0 spec
If the descriptor is shorter than the wLength field, the device indicates the end of the control transfer by sending a short packet when further data is requested.


Tsuneo
0 项奖励
回复

2,690 次查看
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by capiman on Sat Dec 13 02:45:26 MST 2014
Have you tried usbview?
It displays the descriptor which were received by windows.
If I remember correctly it does some checks (at least length checks) on config descriptor.
Do you perhaps have a USB analyzer where you can check if you really have sent what you have implemented.
Is perhaps alignment a problem?
Have you checked if sizeof(My_getconfig_desc) delivers the correct value?
0 项奖励
回复