1.USB类描述
usb_desc cdc_desc0 = /*CDC类描述*/
{
.dev_desc = (uint8_t *)&cdc_dev_desc0, /*设备描述*/
.config_desc = (uint8_t *)&cdc_config_desc0, /*接口描述*/
.strings = usbd_cdc0_strings /*字符串描述*/
};
2.USB设备描述
/* note:it should use the C99 standard when compiling the below codes */
/* USB standard device descriptor */
const usb_desc_dev cdc_dev_desc0 =
{
.header =
{
.bLength = USB_DEV_DESC_LEN, /*描述符的长度*/
.bDescriptorType = USB_DESCTYPE_DEV, /*描述符的类型*/
},
.bcdUSB = 0x0200U, /*USB的协议版本,此处是USB2.0*/
.bDeviceClass = USB_CLASS_CDC, /*类代码:此处配置的是CDC通信类代码*/
.bDeviceSubClass = 0x00U, /*子类代码*/
.bDeviceProtocol = 0x00U, /*设备所使用的协议*/
.bMaxPacketSize0 = USB_FS_EP0_MAX_LEN, /*端点0最大包长*/
.idVendor = USBD_VID, /*厂商ID*/
.idProduct = USBD_PID, /*产品ID*/
.bcdDevice = 0x0100U, /*设备版本号*/
.iManufacturer = STR_IDX_MFC, /*描述厂商的字符串索引*/
.iProduct = STR_IDX_PRODUCT, /*描述设备的字符串索引*/
.iSerialNumber = STR_IDX_SERIAL, /*设备序列号字符串索引*/
.bNumberConfigurations = USBD_CFG_MAX_NUM, /*配置表个数*/
};
3.USB配置描述
/* USB device configuration descriptor */
const usb_cdc_desc_config_set cdc_config_desc0 =
{
.config = /*配置描述*/
{
.header =
{
.bLength = sizeof(usb_desc_config),
.bDescriptorType = USB_DESCTYPE_CONFIG,
},
.wTotalLength = USB_CDC_ACM_CONFIG_DESC_SIZE, /*表示整个配置描述符的长度*/
.bNumInterfaces = 0x02U, /*表示所支持的接口数量*/
.bConfigurationValue = 0x01U, /*表示该配置的字符串索引值*/
.iConfiguration = 0x00U, /*表示该配置的字符串索引值*/
.bmAttributes = 0x80U, /*表示设备的特性:
D7:保留位,需要设置为1;
D6:表示供电方式:0表示设备总线供电、1表示自供电;
D5: 表示是否支持远程唤醒,1表示支持;
D4~0: 预留,全为0*/
.bMaxPower = 0x32U /*表示设备需要从总线上获取的电流,单位2mA,0x32*2=100mA*/
},
.cmd_itf = /*接口描述*/
{
.header =
{
.bLength = sizeof(usb_desc_itf),
.bDescriptorType = USB_DESCTYPE_ITF
},
.bInterfaceNumber = 0x00U, /*表示接口的编号*/
.bAlternateSetting = 0x00U, /*表示接口的备用编号*/
.bNumEndpoints = 0x01U, /*表示该接口使用的端点数,不包括端点0*/
.bInterfaceClass = USB_CLASS_CDC, /*表示该接口使用的大类,此处是CDC*/
.bInterfaceSubClass = USB_CDC_SUBCLASS_ACM, /*表示该接口使用的子类,此处是ACM*/
.bInterfaceProtocol = USB_CDC_PROTOCOL_AT, /*表示接口类协议*/
.iInterface = 0x00U
},
.cdc_header =
{
.header =
{
.bLength = sizeof(usb_desc_header_func),
.bDescriptorType = USB_DESCTYPE_CS_INTERFACE
},
.bDescriptorSubtype = 0x00U,
.bcdCDC = 0x0110U
},
.cdc_call_managment =
{
.header =
{
.bLength = sizeof(usb_desc_call_managment_func),
.bDescriptorType = USB_DESCTYPE_CS_INTERFACE
},
.bDescriptorSubtype = 0x01U,
.bmCapabilities = 0x00U,
.bDataInterface = 0x01U
},
.cdc_acm =
{
.header =
{
.bLength = sizeof(usb_desc_acm_func),
.bDescriptorType = USB_DESCTYPE_CS_INTERFACE
},
.bDescriptorSubtype = 0x02U,
.bmCapabilities = 0x02U,
},
.cdc_union =
{
.header =
{
.bLength = sizeof(usb_desc_union_func),
.bDescriptorType = USB_DESCTYPE_CS_INTERFACE
},
.bDescriptorSubtype = 0x06U,
.bMasterInterface = 0x00U,
.bSlaveInterface0 = 0x01U,
},
.cdc_cmd_endpoint = /*端点描述(命令)*/
{
.header =
{
.bLength = sizeof(usb_desc_ep),
.bDescriptorType = USB_DESCTYPE_EP,
},
.bEndpointAddress = CDC_CMD_EP0, /*表示该端点的地址,D7表示传输方向位,1表示输入、0表示输出,D3~0表示端点号,其它位保留*/
.bmAttributes = USB_EP_ATTR_INT, /*表示该端点的属性,D1~0:表示传输类型,0-控制传输、1-登时传输、2-批量传输、3-表示中断传输*/
.wMaxPacketSize = USB_CDC_CMD_PACKET_SIZE, /*表示该端点支持的最大包长*/
.bInterval = 0x0AU /*表示中断和等时端点的服务时长,在这期间,主机必须在这个间隔里安排事务*/
},
.cdc_data_interface = /*端点描述(数据)*/
{
.header =
{
.bLength = sizeof(usb_desc_itf),
.bDescriptorType = USB_DESCTYPE_ITF,
},
.bInterfaceNumber = 0x01U, /*在当前配置中的接口序号,此处为接口1*/
.bAlternateSetting = 0x00U, /*备用的接口序号*/
.bNumEndpoints = 0x02U, /*端点的个数,此处有2个端点*/
.bInterfaceClass = USB_CLASS_DATA, /*表示数据接口类*/
.bInterfaceSubClass = 0x00U, /*表示数据接口子类*/
.bInterfaceProtocol = USB_CDC_PROTOCOL_NONE, /*表示接口类协议*/
.iInterface = 0x00U
},
.cdc_out_endpoint = /*输出端点描述*/
{
.header =
{
.bLength = sizeof(usb_desc_ep),
.bDescriptorType = USB_DESCTYPE_EP,
},
.bEndpointAddress = CDC_DATA_OUT_EP0, /*端点地址*/
.bmAttributes = USB_EP_ATTR_BULK, /*端点类型为批量传输*/
.wMaxPacketSize = USB_CDC_DATA_PACKET_SIZE, /*数据包大小*/
.bInterval = 0x00U
},
.cdc_in_endpoint = /*输入端点描述*/
{
.header =
{
.bLength = sizeof(usb_desc_ep),
.bDescriptorType = USB_DESCTYPE_EP
},
.bEndpointAddress = CDC_DATA_IN_EP0, /*端点地址*/
.bmAttributes = USB_EP_ATTR_BULK, /*端点类型为批量传输*/
.wMaxPacketSize = USB_CDC_DATA_PACKET_SIZE, /*数据包大小*/
.bInterval = 0x00U
}
};
4.字符串描述
/* USB string descriptor set */
void *const usbd_cdc0_strings[] =
{
[STR_IDX_LANGID] = (uint8_t *)&usbd_language_id_desc, /*语言ID描述*/
[STR_IDX_MFC] = (uint8_t *)&manufacturer_string, /*制造商描述*/
[STR_IDX_PRODUCT] = (uint8_t *)&product_string, /*产品描述*/
[STR_IDX_SERIAL] = (uint8_t *)&serial_string /*序列号描述*/
};