Author Topic: Composite Device and Report Descriptor  (Read 27561 times)

ftariq68

  • Member
  • ***
  • Posts: 23
Composite Device and Report Descriptor
« on: November 03, 2011, 07:21:29 pm »
Hello:

I have seen several examples on the internet explaining how the descriptor should be written for a composite device.  I understand that in the Configuration descriptor you indicate the Interface Descriptors for each of the devices in the composite device, which sounds logical.  But then comes the Report Descriptors, how do you deal with those.  If, for example, we have two devices in the composite device then we will have two Report Descriptors,  how do we send those?  What should be the order of sending these?  Should it be back to back one after the other, during setup?  Pardon my ignorance but I am very green in this subject matter.

Thanks in advance.

ft


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Composite Device and Report Descriptor
« Reply #1 on: November 03, 2011, 10:13:35 pm »
In the Setup stage of the Get_Descriptor request for the report descriptor, the low byte of wIndex specifies the interface number.

See 7.1 and 7.1.1 in the HID spec. It's a little confusing because the spec uses the term "HID class descriptor" to refer to all three class-specific descriptors, one of which is the "HID descriptor."

Jan

ftariq68

  • Member
  • ***
  • Posts: 23
Re: Composite Device and Report Descriptor
« Reply #2 on: November 04, 2011, 10:20:18 am »
Thanks Jan... I appreciate your help...   :)

Faisal

ftariq68

  • Member
  • ***
  • Posts: 23
Re: Composite Device and Report Descriptor
« Reply #3 on: November 08, 2011, 11:53:37 am »
Hi Jan:

My composite USB system is failing right during the enumeration after the configuration step?  Please see below.  It reads the device descriptor then the configuration descriptor (composite system) and then quits and the program manager (in windows) offcourse shows a failed device (with the exclamation).  Where do you suppose I am going wrong?

Thanks

ftariq


000000: PnP Event: Device Connected (UP), 08.11.2011 10:46:36.840
The USB device has just been connected to the system.
000001: Get Descriptor Request (DOWN), 08.11.2011 10:46:36.840 +0.0
Descriptor Type: Device
Descriptor Index: 0x0
Transfer Buffer Size: 0x12 bytes
000002: Control Transfer (UP), 08.11.2011 10:46:36.840 +0.0. Status: 0x00000000
Pipe Handle: 0x8608ac54

 12 01 00 02 00 00 00 40 6A 0B 01 50 00 01 01 02   .......@j..P....
 03 01                                             ..
Setup Packet
 80 06 00 01 00 00 12 00                           €.......
Recipient: Device
Request Type: Standard
Direction: Device->Host
Request: 0x6 (GET_DESCRIPTOR)
Value: 0x100
Index: 0x0
Length: 0x12
000003: Get Descriptor Request (DOWN), 08.11.2011 10:46:36.840 +0.0
Descriptor Type: Configuration
Descriptor Index: 0x0
Transfer Buffer Size: 0x9 bytes


000004: Control Transfer (UP), 08.11.2011 10:46:36.840 +0.0. Status: 0x00000000
Pipe Handle: 0x8608ac54

 09 02 42 00 02 01 00 A0 32                        ..B.... 2
Setup Packet
 80 06 00 02 00 00 09 00                           €.......
Recipient: Device
Request Type: Standard
Direction: Device->Host
Request: 0x6 (GET_DESCRIPTOR)
Value: 0x200
Index: 0x0
Length: 0x9

000005: Get Descriptor Request (DOWN), 08.11.2011 10:46:36.840 +0.0
Descriptor Type: Configuration
Descriptor Index: 0x0
Transfer Buffer Size: 0x42 bytes


000006: Control Transfer (UP), 08.11.2011 10:46:36.840 +0.0. Status: 0x00000000
Pipe Handle: 0x8608ac54

 09 02 42 00 02 01 00 A0 32 09 04 00 00 02 03 00   ..B.... 2.......
 00 00 09 21 10 01 00 01 22 35 00 07 05 01 03 40   ...!...."5.....@
 00 01 07 05 82 03 40 00 01 09 04 01 00 01 03 00   ....‚.@.........
 00 00 09 21 10 01 00 01 22 9F 02 07 05 83 03 40   ...!...."Ÿ...ƒ.@
 00 01                                             ..
Setup Packet
 80 06 00 02 00 00 42 00                           €.....B.
Recipient: Device
Request Type: Standard
Direction: Device->Host
Request: 0x6 (GET_DESCRIPTOR)
Value: 0x200
Index: 0x0
Length: 0x42
000007: Select Configuration (DOWN), 08.11.2011 10:46:36.840 +0.0
Configuration Index: 1

000009: Select Configuration (UP), 08.11.2011 10:46:36.840 +0.0. Status: 0xc0000f00
Configuration Index: 1
Configuration Handle: 0x0
000010: PnP Event: Device Disconnected (UP), 08.11.2011 10:46:36.856 +0.015
The USB device has just been removed from the system, all drivers unloaded.


Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Composite Device and Report Descriptor
« Reply #4 on: November 08, 2011, 12:43:11 pm »
What you posted suggests that after sending a Set Configuration request, the device detached from the bus if not physically then electrically by removing the pullup. So I would look at what the device is doing on receiving the Set Configuration request.

Jan

ftariq68

  • Member
  • ***
  • Posts: 23
Re: Composite Device and Report Descriptor
« Reply #5 on: November 16, 2011, 06:58:06 pm »
Hi Jan:

This was a very good reply.  But unfortunately I did not see anything out of the ordinary, Is there anything else that would cause this reset? 

Thanks

ftariq

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Composite Device and Report Descriptor
« Reply #6 on: November 17, 2011, 10:01:23 am »
One way to try to isolate the problem is to get each function in the the composite device to enumerate separately (edit the configuration descriptor and comment out the descriptors for the other interface(s)), then combine them.

Jan

ftariq68

  • Member
  • ***
  • Posts: 23
Re: Composite Device and Report Descriptor
« Reply #7 on: November 18, 2011, 04:44:50 pm »
Hi Jan:

I started out with two separte firmware for two different functions and they were both working.  I then merged the two.  An interesting experiment I did was changed the bNumInterfaces to 1, instead of 2 that is required for composite devices, while keeping the rest of the configuration descriptor the same (i.e. for a composite device) and wierdly enough the USB is not disconnecting anymore?  Does this give any clues? I can post my device descriptor and configuration descriptor for you to see, if that may be of any help.

Thanks

ftariq 

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Composite Device and Report Descriptor
« Reply #8 on: November 18, 2011, 08:45:06 pm »
If the functions work individually, you've done most of the work.

Yes, post the decoded descriptors.

Jan

ftariq68

  • Member
  • ***
  • Posts: 23
Re: Composite Device and Report Descriptor
« Reply #9 on: November 21, 2011, 07:18:18 pm »
Hi Jan:

I am posting the Device Descriptor and the Configuration Descriptor.  (I am not posting the report descriptors, because one of them is too long, however, if you must see it, do let me know and I will post it as well).

Thanks

ftariq


unsigned char DEVICE_DESCRIPTOR[]=
{
    0x12,           // bLength = 18d
    0x01,           // bDescriptorType = Device (1)
    0x00,0x02,      // bcdUSB(L/H) USB spec rev (BCD)
    0x00,           // bDeviceClass
    0x00,           // bDeviceSubClass
    0x00,           // bDeviceProtocol
    0x40,           // bMaxPacketSize0 EP0 is 64 bytes
    0x6A,0x0B,      // idVendor(L/H)-- USB VID, Maxim is 0B6A
    0x02,0x50,      // idProduct(L/H)-- USB PID, 0x5000
    0x00,0x01,      // bcdDevice--   USB VER, 0x1000 = 01.0x
    0x01,           // iManufacturer, Vendor ID string index
    0x02,           // iProduct, Product ID string index
    0x03,           // iSerialNumber,  Serial Number string index
    0x01            // bNumConfigurations  Number of configurations
};

unsigned char CONFIG_DESCRIPTOR[]=   // CONFIGURATION Descriptor
{
// Configuration Descriptor

    0x09,       // bLength, Size of this descriptor in bytes
    0x02,       // bDescriptorType, CONFIGURATION descriptor type
    0x42,0x00,  // wTotalLength(L/H) (Config + Interface + HID + EPs) <****
    2,          // bNumInterfaces, Number of interfaces in this cfg, <================
    1,          // bConfigurationValue, Index value of this configuration
    0,          // iConfiguration, Configuration string index
    0xA0,       // bmAttributes, Attributes, see usb_device.h, has to do with power
    50,         // bMaxPower, Max power consumption (2X mA)

/** For TTS **/

// INTERFACE Descriptor
    0x09,      // length = 9
    0x04,      // type = Interface
    0x00,      // bInterfaceNum (1st interface is number 0)
    0x00,      // bAlternate Setting
    0x02,      // bNum Endpoints ( 1 In, 1 Out)
    0x03,      // bInterfaceClass = HID
    0x00,      // bInterfaceSubClas,
    0x00,      // bInterfaceProtocol
    0x00,      // iInterface string index

// HID Descriptor--It's at CD[18]
    0x09,               // bLength
    0x21,      // bDescriptorType = HID
    0x10,0x01,      // bcdHID(L/H) Rev 1.1
    0x00,      // bCountryCode (none)
    0x01,      // bNumDescriptors (one report descriptor)
    0x22,      // bDescriptorType   (0x22 = report)
    53,0,               // wDescriptorLength(L/H) (report desc size)


// Endpoint Descriptor... Host Out Endpoint Desc (EP1 OUT), Data from TTS GUI

    0x07,      // bLength
    0x05,      // bDescriptorType (Endpoint)
    0x01,       // bEndpointAddress (EP1-OUT)      
    0x03,      // bmAttributes   (interrupt)
    64,0,       // wMaxPacketSize (64)
    1,         // bInterval (poll every n msec)


// Endpoint Descriptor... Host IN Endpoint Desc (EP2 IN), Data to TTS GUI
    0x07,      // bLength
    0x05,      // bDescriptorType (Endpoint)
    0x82,      // bEndpointAddress (EP2-IN)      
    0x03,      // bmAttributes   (interrupt)
    64,0,               // wMaxPacketSize (64)
    1,                  // bInterval (poll every n msec)

     
/** For Windows ***/
     
// Interface Descriptor

    0x09,   // Size of this descriptor in bytes
    0x04,       // INTERFACE descriptor type
    1,         // Interface Number
    0,         // Alternate Setting Number
    1,          // Number of endpoints in this intf(1 IN) <****
    0x03,    // 0x03, HID Class code
    0x00,   // bInterfaceSubClas,
    0x00,   // bInterfaceProtocol
    0,     // Interface string index

// HID Class Descriptor--It's at CD[50]

    0x09,      // Size of this descriptor in bytes
    0x21,      // 0x21, HID descriptor type
    0x10,0x01,   // HID Spec Release Number in BCD format (1.11)
    0x00,       // Country Code (0x00 for Not supported)
    1,         // Number of class descriptors, see usbcfg.h
    0x22,      // Report descriptor type
    (0xff & sizeof(REPORT_DESCRIPTOR)),
    (sizeof(REPORT_DESCRIPTOR) >>  8 ),   // Size of the report descriptor
     
     
// Endpoint Descriptor... Host IN Endpoint Desc (EP2 IN), Data to Windows

    0x07,       // sizeof(USB_EP_DSC)
    0x05,    // 0x05, Endpoint Descriptor   
    0x83,       // bEndpointAddress (EP3-IN)
    0x03,       // INTERRUPT Attributes
    64,0,       // wMaxPacketSize (64)

    0x01        // Interval

};

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Composite Device and Report Descriptor
« Reply #10 on: November 21, 2011, 11:07:31 pm »
I don't see any problem with the descriptors (doesn't mean there isn't one). One typo - this comment for the 2nd interface:

// Endpoint Descriptor... Host IN Endpoint Desc (EP2 IN), Data to Windows

should be:

// Endpoint Descriptor... Host IN Endpoint Desc (EP3 IN), Data to Windows

See the last two messages here about causing Windows to forget previous descriptors:

http://www.lvr.com/forum/index.php?topic=420.msg1498#msg1498

Changing the Product ID is another way to do it.

Jan

ftariq68

  • Member
  • ***
  • Posts: 23
Re: Composite Device and Report Descriptor
« Reply #11 on: November 29, 2011, 06:53:50 pm »
Hi Jan:

Do you know if in a composite device we can use the same string descriptor for both interface?  Is that allowed?

Thanks

ftariq

ftariq68

  • Member
  • ***
  • Posts: 23
Re: Composite Device and Report Descriptor
« Reply #12 on: November 29, 2011, 07:38:11 pm »
Hi Jan:

I am finally able to enumerate.  The change was weird and to the DEVICE_DESCRIPTOR?  I changed the iSerialNumber to 0x00 instead of 0x03, (Please see below). Do you know why that would fix this?

Thanks

Faisal



unsigned char DEVICE_DESCRIPTOR[]=
{
    0x12,           // bLength = 18d
    0x01,           // bDescriptorType = Device (1)
    0x00,0x02,      // bcdUSB(L/H) USB spec rev (BCD)
    0x00,           // bDeviceClass
    0x00,           // bDeviceSubClass
    0x00,           // bDeviceProtocol
    0x40,           // bMaxPacketSize0 EP0 is 64 bytes
    0x6A,0x0B,      // idVendor(L/H)-- USB VID, Maxim is 0B6A
    0x02,0x50,      // idProduct(L/H)-- USB PID, 0x5000
    0x00,0x01,      // bcdDevice--   USB VER, 0x1000 = 01.0x
    0x01,           // iManufacturer, Vendor ID string index
    0x02,           // iProduct, Product ID string index
//*    0x03,           // iSerialNumber,  Serial Number string index
    0x00,
    0x01            // bNumConfigurations  Number of configurations
};

Jan Axelson

  • Administrator
  • Frequent Contributor
  • *****
  • Posts: 3033
    • Lakeview Research
Re: Composite Device and Report Descriptor
« Reply #13 on: November 29, 2011, 08:32:20 pm »
From 9.4.3 in the USB 2.0 spec:

The range of values used for a descriptor index is from 0 to one less than the number of descriptors of that type implemented by the device.

Also, string descriptor zero should contain the language ID. See 9.6.7.

Jan

Pat Crowe

  • Member
  • ***
  • Posts: 39
Re: Composite Device and Report Descriptor
« Reply #14 on: November 30, 2011, 04:48:33 am »
The other thing (in case it isn't obvious) is that specifying a iSerialNumber of 0, has the meaning that the device has no serial number string.