AnsweredAssumed Answered

usb composite (hid+cdc+IAD )

Question asked by karim.karim on Aug 16, 2013
Hello everyone,
I'm trying to make a USB composite device working both CDC and HID, to work as a virtual com port and as HID device at the same time.
I combine both CDC and HID classes on a STM32F103 discovery board with the USB-FS library.
The device is detected by the host but with a yellow warning sign code(10)

DESCRIPTOR FILE

#include "usb_lib.h"
#include "usb_desc.h"


/* USB Standard Device Descriptor */
const uint8_t Virtual_Com_Port_DeviceDescriptor[] =
{
     0x12,                              /* bLength */
     USB_DEVICE_DESCRIPTOR_TYPE,     /* bDescriptorType */
     0x00,
     0x02,                              /* bcdUSB = 2.00 */


    0xEF,     /* bDeviceClass: IAD */
    0x02,     /* bDeviceSubClass */
    0x01,     /* bDeviceProtocol */


    0x40,     /* bMaxPacketSize0 */
    0xEB,
    0x33,     /* idVendor = 0x03EB */
    0x33,
    0x66,     /* idProduct = 0x6133 */
    
    0x00,
    0x02,     /* bcdDevice = 2.00 */
    1,          /* Index of string descriptor describing manufacturer */
    2,          /* Index of string descriptor describing product */
    3,          /* Index of string descriptor describing the device's serial number */
    0x01     /* bNumConfigurations */
};


const uint8_t Virtual_Com_Port_ConfigDescriptor[] =
{
    /*Configuation Descriptor*/
    0x09,   /* bLength: Configuation Descriptor size */
    USB_CONFIGURATION_DESCRIPTOR_TYPE,      /* bDescriptorType: Configuration */
    VIRTUAL_COM_PORT_SIZ_CONFIG_DESC,       /* wTotalLength:no of returned bytes */
    0x00,
   // 0x04,   /* bNumInterfaces: 4 interface */
       0x03,   /* bNumInterfaces: 3 interface */


    0x01,   /* bConfigurationValue: Configuration value */
    0x00,   /* iConfiguration: Index of string descriptor describing the configuration */
    0xC0,   /* bmAttributes: self powered */
    0x32,   /* MaxPower 100 mA */
       /************** Descriptor of Custom HID interface ****************/
    /* 09 */
    0x09,         /* bLength: Interface Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,/* bDescriptorType: Interface descriptor type */
    0x00,         /* bInterfaceNumber: Number of Interface */
    0x00,         /* bAlternateSetting: Alternate setting */
    0x02,         /* bNumEndpoints */
    0x03,         /* bInterfaceClass: HID */
    0x00,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
    0x00,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
    0,            /* iInterface: Index of string descriptor */
    /******************** Descriptor of Custom HID HID ********************/
    /* 18 */
    0x09,         /* bLength: HID Descriptor size */
    HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
    //0x10,         /* bcdHID: HID Class Spec release number */
          0x00,         /* bcdHID: HID Class Spec release number */
    0x01,
    0x00,         /* bCountryCode: Hardware target country */
    0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
    0x22,         /* bDescriptorType */
    CUSTOMHID_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */
    0x00,
    /******************** Descriptor of Custom HID endpoints ******************/
    /* 27 */
    0x07,          /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */


    0x81,          /* bEndpointAddress: Endpoint Address (IN1) */
 // 0x84,          /* bEndpointAddress: Endpoint Address (IN4) */
    0x03,          /* bmAttributes: Interrupt endpoint */
//    0x02,          /* wMaxPacketSize: 2 Bytes max */
    0x40,          /* wMaxPacketSize: 2 Bytes max */


    0x00,
//    0x20,          /* bInterval: Polling Interval (32 ms) */
    0x01,          /* bInterval: Polling Interval (32 ms) */


    /* 34 */
         
    0x07,     /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,     /* bDescriptorType: */
               /*     Endpoint descriptor type */
    0x01,     /* bEndpointAddress: */
               /*     Endpoint Address (OUT1) */
//  0x04,     /* bEndpointAddress: */
               /*     Endpoint Address (OUT4) */
    0x03,     /* bmAttributes: Interrupt endpoint */
//    0x02,     /* wMaxPacketSize: 2 Bytes max  */
    0x40,          /* wMaxPacketSize: 2 Bytes max */


    0x00,
  //  0x20,     /* bInterval: Polling Interval (20 ms) */
         0x01,          /* bInterval: Polling Interval (32 ms) */

     // IAD
     0x08,     // bLength: Interface Descriptor size
     0x0B,          // bDescriptorType: IAD
     0x02,     // bFirstInterface
     0x02,     // bInterfaceCount
     0x02,     // bFunctionClass: CDC
     0x02,     // bFunctionSubClass
     0x01,     // bFunctionProtocol
     0x02,     // iFunction
    /*Interface Descriptor*/
    0x09,   /* bLength: Interface Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: Interface */
    /* Interface descriptor type */
    0x01,   /* bInterfaceNumber: Number of Interface */
    0x00,   /* bAlternateSetting: Alternate setting */
    0x01,   /* bNumEndpoints: One endpoints used */
    0x02,   /* bInterfaceClass: Communication Interface Class */
    0x02,   /* bInterfaceSubClass: Abstract Control Model */
    0x01,   /* bInterfaceProtocol: Common AT commands */
    0x00,   /* iInterface: */
    /*Header Functional Descriptor*/
    0x05,   /* bLength: Endpoint Descriptor size */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x00,   /* bDescriptorSubtype: Header Func Desc */
    0x10,   /* bcdCDC: spec release number */
    0x01,
    /*Call Managment Functional Descriptor*/
    0x05,   /* bFunctionLength */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x01,   /* bDescriptorSubtype: Call Management Func Desc */
    0x00,   /* bmCapabilities: D0+D1 */
    0x03,   /* !! bDataInterface: */
    /*ACM Functional Descriptor*/
    0x04,   /* bFunctionLength */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
    0x02,   /* bmCapabilities */
    /*Union Functional Descriptor*/
    0x05,   /* bFunctionLength */
    0x24,   /* bDescriptorType: CS_INTERFACE */
    0x06,   /* bDescriptorSubtype: Union func desc */
    0x02,   /* !! bMasterInterface: Communication class interface */
    0x03,   /* !! bSlaveInterface0: Data Class Interface */
    /*Endpoint 2 Descriptor*/
    0x07,   /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
 //   0x85,   /* bEndpointAddress: (IN5) */
          0x82,   /* bEndpointAddress: (IN2) */


    0x03,   /* bmAttributes: Interrupt */
    VIRTUAL_COM_PORT_INT_SIZE,      /* wMaxPacketSize: */
    0x00,
    0xFF,   /* bInterval: */


    /*Data class interface descriptor*/
    0x09,   /* bLength: Endpoint Descriptor size */
    USB_INTERFACE_DESCRIPTOR_TYPE,  /* bDescriptorType: */
    0x02,   /* bInterfaceNumber: Number of Interface */
    0x00,   /* bAlternateSetting: Alternate setting */
    0x02,   /* bNumEndpoints: Two endpoints used */
    0x0A,   /* bInterfaceClass: CDC */
    0x00,   /* bInterfaceSubClass: */
    0x00,   /* bInterfaceProtocol: */
    0x00,   /* iInterface: */
    /*Endpoint 3 Descriptor*/
    0x07,   /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
//0x06,   /* bEndpointAddress: (OUT6) */
          0x03,   /* bEndpointAddress: (OUT3) */


    0x02,   /* bmAttributes: Bulk */
    VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
    0x00,
    0x00,   /* bInterval: ignore for Bulk transfer */
    /*Endpoint 1 Descriptor*/
    0x07,   /* bLength: Endpoint Descriptor size */
    USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
//0x84,   /* bEndpointAddress: (IN4) */
          0x84,   /* bEndpointAddress: (IN4) */


    0x02,   /* bmAttributes: Bulk */
    VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
    0x00,
    0x00    /* bInterval */
};


/* USB String Descriptors */
const uint8_t Virtual_Com_Port_StringLangID[VIRTUAL_COM_PORT_SIZ_STRING_LANGID] =
{
     VIRTUAL_COM_PORT_SIZ_STRING_LANGID,
     USB_STRING_DESCRIPTOR_TYPE,
     0x09,
     0x04 /* LangID = 0x0409: U.S. English */
};


const uint8_t Virtual_Com_Port_StringVendor[VIRTUAL_COM_PORT_SIZ_STRING_VENDOR] =
{
    VIRTUAL_COM_PORT_SIZ_STRING_VENDOR,     /* Size of Vendor string */
    USB_STRING_DESCRIPTOR_TYPE,             /* bDescriptorType*/
    /* Manufacturer: "STMicroelectronics" */
    'S', 0, 'T', 0, 'M', 0, 'i', 0, 'c', 0, 'r', 0, 'o', 0, 'e', 0,
    'l', 0, 'e', 0, 'c', 0, 't', 0, 'r', 0, 'o', 0, 'n', 0, 'i', 0,
    'c', 0, 's', 0
};


const uint8_t Virtual_Com_Port_StringProduct[VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT] =
{
    VIRTUAL_COM_PORT_SIZ_STRING_PRODUCT,          /* bLength */
    USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
    /* Product name: "STM32 Virtual COM Port" */
    'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, ' ', 0, 'V', 0, 'i', 0,
    'r', 0, 't', 0, 'u', 0, 'a', 0, 'l', 0, ' ', 0, 'C', 0, 'O', 0,
    'M', 0, ' ', 0, 'P', 0, 'o', 0, 'r', 0, 't', 0, ' ', 0, ' ', 0
};


uint8_t Virtual_Com_Port_StringSerial[VIRTUAL_COM_PORT_SIZ_STRING_SERIAL] =
{
    VIRTUAL_COM_PORT_SIZ_STRING_SERIAL,           /* bLength */
    USB_STRING_DESCRIPTOR_TYPE,                   /* bDescriptorType */
    'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, '1', 0, '0', 0
}
**********************************************************************************************************************************************

usb_endp.c

#include "usb_lib.h"
#include "usb_mem.h"
#include "hw_config.h"
#include "usb_istr.h"


uint8_t Receive_Buffer[2];
extern __IO uint8_t PrevXferComplete;
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/
/*******************************************************************************
* Function Name  : EP1_OUT_Callback.
* Description    : EP1 OUT Callback Routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP1_OUT_Callback(void)
{
 SetEPRxStatus(ENDP1, EP_RX_VALID);
}


/*******************************************************************************
* Function Name  : EP1_IN_Callback.
* Description    : EP1 IN Callback Routine.
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP1_IN_Callback(void)



{
  
}


/*******************************************************************************
* Function Name  : EP4_IN_Callback
* Description    :
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EP4_IN_Callback(void)
{
     USB_USART1_Data.count_in = 0;
}
/*
void EP4_IN_Callback(void)
{
     USB_USART2_Data.count_in = 0;
}
*/
/*******************************************************************************
* Function Name  : EP3_IN_Callback
* Description    :
* Input          : None.
* Output         : None.
* Return         : None.
*******************************************************************************/
void EPx_OUT_Callback(USB_USART_Data_t * data)
{
     /* Get the received data buffer and update the counter */
     data->count_out = USB_SIL_Read(data->EP_OUT_ADDR, data->buffer_out);
}


void EP3_OUT_Callback(void)
{
     EPx_OUT_Callback(&USB_USART1_Data);
}
*********************************************************************************************************************************************************************************************************************


INF file

[Version]
Signature="$Windows NT$"
Class=Ports
ClassGuid={4D36E978-E325-11CE-BFC1-08002BE10318}
Provider=%X893%
DriverVer=01/26/2013,5.2.0.0
CatalogFile.NTx86=STM32F1-vcom_x86.cat
CatalogFile.NTAMD64=STM32F1-vcom_amd64.cat


[Manufacturer]
%X893%=DeviceList,ntamd64


[DeviceList]
%DESCRIPTION%=STM32F1USB, USB\VID_33EB&PID_6633
%COMPOSITE0% =STM32F1USB, USB\VID_33EB&PID_6633&MI_01


[DeviceList.ntamd64]
%DESCRIPTION%=STM32F1USB, USB\VID_33EB&PID_6633
%COMPOSITE0% =STM32F1USB, USB\VID_33EB&PID_6633&MI_01




;------------------------------------------------------------------------------
;  Installation
;------------------------------------------------------------------------------


[SourceDisksFiles]


[SourceDisksNames]


[DestinationDirs]
FakeModemCopyFileSection=12
DefaultDestDir=12


[STM32F1USB]
include=mdmcpq.inf
CopyFiles=FakeModemCopyFileSection
AddReg=STM32F1USB.AddReg


[STM32F1USB.AddReg]
HKR,,DevLoader,,*ntkern
HKR,,NTMPDriver,,usbser.sys
HKR,,EnumPropPages32,,"MsPorts.dll,SerialPortPropPageProvider"


[STM32F1USB.Services]
AddService=usbser, 0x00000002, DriverService


[DriverService]
DisplayName=%DRIVER.SVC%
ServiceType=1
StartType=3
ErrorControl=1
ServiceBinary=%12%\usbser.sys


;------------------------------------------------------------------------------
;  String Definitions
;------------------------------------------------------------------------------


[Strings]
X893       = "X893"
DRIVER.SVC = "STM32F1 USB VCom Driver"
DESCRIPTION= "STM32F1 USB VCom Port"
COMPOSITE0 = "STM32F1 USB VCom Port"
COMPOSITE2 = "STM32F1 USB VCom Port"


can you please help me?

  

Attachments

Outcomes