STM32 USB 复合设备开发的技巧

利用 IDA  描述符  将两个USB设备 做成复合设备

usb_desc.c 文件



/* USB Standard Device Descriptor */
const uint8_t Composite_DeviceDescriptor[Composite_SIZ_DEVICE_DESC] = {
	0x12,                       //bLength
	USB_DEVICE_DESCRIPTOR_TYPE, //bDescriptorType
	0x00,                       //bcdUSB 
	0x02,
	0x00,                       //bDeviceClass
	0x00,                       //bDeviceSubClass
	0x00,                       //bDeviceProtocol
	0x40,                       //bMaxPacketSize40
	0x83,                       //idVendor (0x0483)
	0x04,
	0x40,                       //idProduct = 0x5750
	0x57,
	0x00,                       //bcdDevice rel. 2.00
	0x02,
	1,                          //Index of string descriptor describing  manufacturer 
                                             
	2,                          //Index of string descriptor describing product
                                             
	3,                          //Index of string descriptor describing the device serial number 
                                             
	0x01                        //bNumConfigurations
}
; 




const uint8_t Composite_ConfigDescriptor[Composite_SIZ_CONFIG_DESC] = {
	0x09, 																	/* bLength: Configuration Descriptor size */
	USB_CONFIGURATION_DESCRIPTOR_TYPE, 			/* bDescriptorType: Configuration */
	Composite_SIZ_CONFIG_DESC,

	0x00,
	0x03,         													/* bNumInterfaces: 2 interfaces, 1 for keyboard, 2 for virtual COM port */
	0x01,         													/* bConfigurationValue: Configuration value */
	0x00,         													/* iConfiguration: Index of string descriptor describing the configuration*/
                                 
	0xC0,         													/* bmAttributes: Self powered */
	0x32,        														/* MaxPower 100 mA: this current is used for detecting Vbus */

	
	/*********************************IAD Descriptor*********************************/
	0x08,					//描述符大小
	0x0B, 				//IAD描述符类型
	0x00,					//bFirstInterface
	0x01,					//bInferfaceCount
	0x03,					//bFunctionClass:HID
	0x00,					//bFunctionSubClass
	0x00,					//bFunctionProtocol
	/*16*/
	0x05,					//iFunction



	/************** Descriptor of Keyboard 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 */
	0x01,         /* bInterfaceSubClass : 1=BOOT, 0=no boot */
	0x01,         /* nInterfaceProtocol : 0=none, 1=keyboard, 2=mouse */
	0,            /* iInterface: Index of string descriptor */
	/******************** Descriptor of Keyboard HID HID ********************/
	/* 18 */
	0x09,         /* bLength: HID Descriptor size */
	HID_DESCRIPTOR_TYPE, /* bDescriptorType: HID */
	0x00,         /* bcdHID: HID Class Spec release number */
	0x01,
	0x00,         /* bCountryCode: Hardware target country */
	0x01,         /* bNumDescriptors: Number of HID class descriptors to follow */
	0x22,         /* bDescriptorType */
	KEYBOARD_SIZ_REPORT_DESC,/* wItemLength: Total length of Report descriptor */
	0x00,
	/******************** Descriptor of Keyboard HID endpoints ******************/
	/* 27 */
	0x07,          /* bLength: Endpoint Descriptor size */
	USB_ENDPOINT_DESCRIPTOR_TYPE, /* bDescriptorType: */

	0x81,          /* bEndpointAddress: Endpoint Address (IN) */
	0x03,          /* bmAttributes: Interrupt endpoint */
	0x08,          /* wMaxPacketSize: 8 Bytes max */
	0x00,
	0x20,          /* bInterval: Polling Interval (32 ms) */
	/* 34 */

	0x07,	/* bLength: Endpoint Descriptor size */
	USB_ENDPOINT_DESCRIPTOR_TYPE,	/* bDescriptorType: */
	/*	Endpoint descriptor type */
	0x01,	/* bEndpointAddress: */
	/*	Endpoint Address (OUT) */
	0x03,	/* bmAttributes: Interrupt endpoint */
	0x08,	/* wMaxPacketSize: 8 Bytes max  */
	0x00,
	0x20,	/* bInterval: Polling Interval (20 ms) */
	/* 41 */

	/*********************************IAD Descriptor*********************************/
	0x08,					/*描述符大小*/
	0x0B,					/*IAD描述符类型*/
	0x01,					/*bFirstInterface*/
	0x02,					/*bInterfaceCOunt*/
	0x02,					/*bFunctionClass:CDC Class*/
	0x02,					/*bFunctionSubClass*/
	0x01,					/*bFunctionProtocol*/
	/*56*/
	0x04,					/*iFunction*/

	/******************** Descriptor of virtual COM interface ********************/
	/* 41 */
	0x09,   /* bLength: Interface Descriptor size */
	USB_INTERFACE_DESCRIPTOR_TYPE,   /* bDescriptorType: */
	/*      Interface descriptor type */
	0x01,   /* bInterfaceNumber: Number of Interface */
	0x00,   /* bAlternateSetting: Alternate setting */
	0x01,   /* bNumEndpoints*/
	0x02,   /* bInterfaceClass: Communication Interface Class */
	0x02,   /* bInterfaceSubClass : Abstract Control Model*/
	0x01,   /* nInterfaceProtocol : Common AT commands*/
	0x00,   /* iInterface: Index of string descripto*/
	/*Header Functional Descriptor*/
	/* 50 */
	0x05,   /* bLength: Endpoint Descriptor size */
	0x24,   /* bDescriptorType: CS_INTERFACE */
	0x00,   /* bDescriptorSubtype: Header Func Desc */
	0x10,   /* bcdCDC: spec release number */
	0x01,
	/*Call Management Functional Descriptor*/
	/* 55 */
	0x05,   /* bFunctionLength */
	0x24,   /* bDescriptorType: CS_INTERFACE */
	0x01,   /* bDescriptorSubtype: Call Management Func Desc */
	0x00,   /* bmCapabilities: D0+D1 */
	0x02,   /* bDataInterface: 2 */
	/*ACM Functional Descriptor*/
	/* 60 */
	0x04,   /* bFunctionLength */
	0x24,   /* bDescriptorType: CS_INTERFACE */
	0x02,   /* bDescriptorSubtype: Abstract Control Management desc */
	0x02,   /* bmCapabilities */
	/*Union Functional Descriptor*/
	/* 64 */
	0x05,   /* bFunctionLength */
	0x24,   /* bDescriptorType: CS_INTERFACE */
	0x06,   /* bDescriptorSubtype: Union func desc */
	0x01,   /* bMasterInterface: Communication class interface */
	0x02,   /* bSlaveInterface0: Data Class Interface */
	/*Endpoint 2 Descriptor*/
	/* 69 */
	0x07,   /* bLength: Endpoint Descriptor size */
	USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
	0x82,   /* bEndpointAddress: (IN2) */
	0x03,   /* bmAttributes: Interrupt */
	VIRTUAL_COM_PORT_INT_SIZE,      /* wMaxPacketSize: */
	0x00,
	0xFF,   /* bInterval: */
	/*Data class interface descriptor*/
	/* 76 */
	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*/
	/* 85 */
	0x07,   /* bLength: Endpoint Descriptor size */
	USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
	0x03,   /* bEndpointAddress: (OUT3) */
	0x02,   /* bmAttributes: Bulk */
	VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
	0x00,
	0x00,   /* bInterval: ignore for Bulk transfer */
	/*Endpoint 4 Descriptor*/
	/* 92 */
	0x07,   /* bLength: Endpoint Descriptor size */
	USB_ENDPOINT_DESCRIPTOR_TYPE,   /* bDescriptorType: Endpoint */
	0x84,   /* bEndpointAddress: (IN4) */
	0x02,   /* bmAttributes: Bulk */
	VIRTUAL_COM_PORT_DATA_SIZE,             /* wMaxPacketSize: */
	0x00,
	0x00    /* bInterval */
	/* 99 */
}; /* Composite_ConfigDescriptor */
/* 66 */

const uint8_t KeyBoard_ReportDescriptor[KEYBOARD_SIZ_REPORT_DESC] = {
	0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
	0x09, 0x06,                    // USAGE (Keyboard)

	0xa1, 0x01,                    // COLLECTION (Application)
	0x05, 0x07,                    //  USAGE_PAGE (Keyboard)
	0x19, 0xe0,                    //   USAGE_MINIMUM (Keyboard LeftControl)
	0x29, 0xe7,                    //   USAGE_MAXIMUM (Keyboard Right GUI)
	0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
	0x25, 0x01,                    //   LOGICAL_MAXIMUM (1)
	0x75, 0x01,                    //   REPORT_SIZE (1)
	0x95, 0x08,                    //   REPORT_COUNT (8)
	0x81, 0x02,                    //   INPUT (Data,Var,Abs)

	0x95, 0x01,                    //   REPORT_COUNT (1)
	0x75, 0x08,                    //   REPORT_SIZE (8)
	0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
	
	0x95, 0x05,                    //   REPORT_COUNT (5)
	0x75, 0x01,                    //   REPORT_SIZE (1)
	0x05, 0x08,                    //   USAGE_PAGE (LEDs)
	0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
	0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
	0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)

	0x95, 0x01,                    //   REPORT_COUNT (1)
	0x75, 0x03,                    //   REPORT_SIZE (3)
	0x91, 0x03,                    //   OUTPUT (Cnst,Var,Abs)

	0x95, 0x06,                    //   REPORT_COUNT (6)
	0x75, 0x08,                    //   REPORT_SIZE (8)
	0x15, 0x00,                    //   LOGICAL_MINIMUM (0)
	0x25, 0xFF,                    //   LOGICAL_MAXIMUM (255)
	0x05, 0x07,                    //   USAGE_PAGE (Keyboard)
	0x19, 0x00,                    //   USAGE_MINIMUM (Reserved (no event indicated))
	0x29, 0x65,                    //   USAGE_MAXIMUM (Keyboard Application)
	0x81, 0x00,                    //   INPUT (Data,Ary,Abs)

	0xc0                           // END_COLLECTION
}; /* KeyBoard_ReportDescriptor */

/* USB String Descriptors (optional) */
const uint8_t Composite_StringLangID[Composite_SIZ_STRING_LANGID] = {
	Composite_SIZ_STRING_LANGID,
	USB_STRING_DESCRIPTOR_TYPE,
	0x09,
	0x04
}
; /* LangID = 0x0409: U.S. English */

const uint8_t Composite_StringVendor[Composite_SIZ_STRING_VENDOR] = {
	Composite_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 Composite_StringProduct[Composite_SIZ_STRING_PRODUCT] = {
	Composite_SIZ_STRING_PRODUCT,          /* bLength */
	USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
	'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0, ' ', 0, 'C', 0,
	'o', 0, 'm', 0, 'p', 0, 'o', 0, 's', 0, 'i', 0, 't', 0,
	'e', 0, ' ', 0, 'M', 0, 'S', 0, 'C', 0, '+', 0, 'H', 0, 'I', 0, 'D', 0
};
uint8_t Composite_StringSerial[Composite_SIZ_STRING_SERIAL] = {
	Composite_SIZ_STRING_SERIAL,           /* bLength */
	USB_STRING_DESCRIPTOR_TYPE,        /* bDescriptorType */
	'S', 0, 'T', 0, 'M', 0, '3', 0, '2', 0
};

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/


QQ 727341554   TEL 13810175694




  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值