mantishell 发表于 2015-3-8 15:24:18

STM32F4的usb_device请教

发现STM32F4的库里的usbd_desc.c文件里没有配置描述符,但使用bus hound抓取的包里含有配置描述符,请问这个配置描述符在哪里?

USBD_DEVICE USR_desc =
{
USBD_USR_DeviceDescriptor,
USBD_USR_LangIDStrDescriptor,
USBD_USR_ManufacturerStrDescriptor,
USBD_USR_ProductStrDescriptor,
USBD_USR_SerialStrDescriptor,
USBD_USR_ConfigStrDescriptor,
USBD_USR_InterfaceStrDescriptor,

};

摘自:usbd_desc.c

拼命三郎 发表于 2015-3-8 17:00:27

mantishell 发表于 2015-3-8 17:37:12

感谢QQ朋友深圳-任性-无钱 的帮助找到了。

先是声明一个结构体
typedef struct _Device_cb{
uint8_t(*Init)         (void *pdev , uint8_t cfgidx);
uint8_t(*DeInit)       (void *pdev , uint8_t cfgidx);
/* Control Endpoints*/
uint8_t(*Setup)      (void *pdev , USB_SETUP_REQ*req);
uint8_t(*EP0_TxSent)   (void *pdev );   
uint8_t(*EP0_RxReady)(void *pdev );
/* Class Specific Endpoints*/
uint8_t(*DataIn)       (void *pdev , uint8_t epnum);   
uint8_t(*DataOut)      (void *pdev , uint8_t epnum);
uint8_t(*SOF)          (void *pdev);
uint8_t(*IsoINIncomplete)(void *pdev);
uint8_t(*IsoOUTIncomplete)(void *pdev);   

uint8_t*(*GetConfigDescriptor)( uint8_t speed , uint16_t *length);
#ifdef USB_OTG_HS_CORE
uint8_t*(*GetOtherConfigDescriptor)( uint8_t speed , uint16_t *length);   
#endif

#ifdef USB_SUPPORT_USER_STRING_DESC
uint8_t*(*GetUsrStrDescriptor)( uint8_t speed ,uint8_t index,uint16_t *length);   
#endif

} USBD_Class_cb_TypeDef;
然后是实例化的结构体
USBD_Class_cb_TypeDefUSBD_MSC_cb =
{
USBD_MSC_Init,
USBD_MSC_DeInit,
USBD_MSC_Setup,
NULL, /*EP0_TxSent*/
NULL, /*EP0_RxReady*/
USBD_MSC_DataIn,
USBD_MSC_DataOut,
NULL, /*SOF */
NULL,
NULL,   
USBD_MSC_GetCfgDesc,
#ifdef USB_OTG_HS_CORE
USBD_MSC_GetOtherCfgDesc,
#endif
};
在这个实例化的结构体里的这个函数USBD_MSC_GetCfgDesc


uint8_t*USBD_MSC_GetCfgDesc (uint8_t speed, uint16_t *length)
{
*length = sizeof (USBD_MSC_CfgDesc);
return USBD_MSC_CfgDesc;
}

追踪到最后在文件usbd_msc_core.c里找到了
__ALIGN_BEGIN uint8_t USBD_MSC_CfgDesc __ALIGN_END =
{

0x09,   /* bLength: Configuation Descriptor size */
USB_DESC_TYPE_CONFIGURATION,   /* bDescriptorType: Configuration */
USB_MSC_CONFIG_DESC_SIZ,

0x00,
0x01,   /* bNumInterfaces: 1 interface */
0x01,   /* bConfigurationValue: */
0x04,   /* iConfiguration: */
0xC0,   /* bmAttributes: */
0x32,   /* MaxPower 100 mA */

/********************Mass Storage interface ********************/
0x09,   /* bLength: Interface Descriptor size */
0x04,   /* bDescriptorType: */
0x00,   /* bInterfaceNumber: Number of Interface */
0x00,   /* bAlternateSetting: Alternate setting */
0x02,   /* bNumEndpoints*/
0x08,   /* bInterfaceClass: MSC Class */
0x06,   /* bInterfaceSubClass : SCSI transparent*/
0x50,   /* nInterfaceProtocol */
0x05,          /* iInterface: */
/********************Mass Storage Endpoints ********************/
0x07,   /*Endpoint descriptor length = 7*/
0x05,   /*Endpoint descriptor type */
MSC_IN_EP,   /*Endpoint address (IN, address 1) */
0x02,   /*Bulk endpoint type */
LOBYTE(MSC_MAX_PACKET),
HIBYTE(MSC_MAX_PACKET),
0x00,   /*Polling interval in milliseconds */

0x07,   /*Endpoint descriptor length = 7 */
0x05,   /*Endpoint descriptor type */
MSC_OUT_EP,   /*Endpoint address (OUT, address 1) */
0x02,   /*Bulk endpoint type */
LOBYTE(MSC_MAX_PACKET),
HIBYTE(MSC_MAX_PACKET),
0x00   /*Polling interval in milliseconds*/
};

bit 发表于 2015-3-8 19:10:23

好 不错哈

MouseCat 发表于 2015-3-8 19:22:39

收藏了帮顶

zfz0122 发表于 2015-3-8 20:20:07

不懂帮顶

zhangdaijin 发表于 2015-3-8 20:59:25

路过顶一下:D

_ilikerome_ 发表于 2015-3-9 08:44:04

学习了,谢谢分享。

发表于 2015-3-9 10:43:40

这个定义的都是函数入口。楼主可以在desc.c中查找到原型函数。
USBD_DEVICE 在STM32F4-Discovery_FW_V1.1.0\Libraries\STM32_USB_OTG_Driver\inc\usb_core.h中有定义.

stary666 发表于 2015-3-9 12:22:21

:loveliness::loveliness::loveliness::loveliness::loveliness:
页: [1] 2
查看完整版本: STM32F4的usb_device请教