STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf
- 文档编号:16119969
- 上传时间:2022-11-20
- 格式:PDF
- 页数:13
- 大小:729.40KB
STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf
《STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf》由会员分享,可在线阅读,更多相关《STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf(13页珍藏版)》请在冰豆网上搜索。
4.测试PC和单片机的数据通信。
三、三、STM32STM32程序编写程序编写1.完成描述符的修改,修改后的描述符如下(在usb_desc.c文件中)。
配置描述符就包含了端点描述符,我们用了4个端点,两个BULK-OUT端点,两个BULK-IN端点。
A.设备描述符010203040506070809101112131415161718192021constuint8_tCustomHID_DeviceDescriptorCUSTOMHID_SIZ_DEVICE_DESC=0x12,/*bLength*/USB_DEVICE_DESCRIPTOR_TYPE,/*bDescriptorType*/0x00,/*bcdUSB*/0x02,0x00,/*bDeviceClass*/0x00,/*bDeviceSubClass*/0x00,/*bDeviceProtocol*/0x40,/*bMaxPacketSize40*/LOBYTE(USBD_VID),/*idVendor*/HIBYTE(USBD_VID),/*idVendor*/LOBYTE(USBD_PID),/*idVendor*/HIBYTE(USBD_PID),/*idVendor*/0x00,/*bcdDevicerel.2.00*/0x02,1,/*Indexofstringdescriptordescribingmanufacturer*/2,/*Indexofstringdescriptordescribingproduct*/3,/*Indexofstringdescriptordescribingthedeviceserialnumber*/0x01/*bNumConfigurations*/;
/*CustomHID_DeviceDescriptor*/B.配置描述符01020304050607080910constuint8_tCustomHID_ConfigDescriptorCUSTOMHID_SIZ_CONFIG_DESC=0x09,/*bLength:
ConfiguationDescriptorsize*/USB_CONFIGURATION_DESCRIPTOR_TYPE,/*bDescriptorType:
Configuration*/CUSTOMHID_SIZ_CONFIG_DESC,/*wTotalLength:
Bytesreturned*/0x00,0x01,/*bNumInterfaces:
1interface*/0x01,/*bConfigurationValue:
Configurationvalue*/0x00,/*iConfiguration:
Indexofstringdescriptordescribingtheconfiguration*/11121314151617181920212223242526272829303132333435363738394041424344454647484950510xE0,/*bmAttributes:
Buspowered*/*Buspowered:
7thbit,SelfPowered:
6thbit,Remotewakeup:
5thbit,reserved:
4.0bits*/0xFA,/*MaxPower500mA:
thiscurrentisusedfordetectingVbus*/*DescriptorofCustomHIDinterface*/*09*/0x09,/*bLength:
InterfaceDescriptorsize*/USB_INTERFACE_DESCRIPTOR_TYPE,/*bDescriptorType:
Interfacedescriptortype*/0x00,/*bInterfaceNumber:
NumberofInterface*/0x00,/*bAlternateSetting:
Alternatesetting*/0x04,/*bNumEndpoints*/0xDC,/*bInterfaceClass:
Classcode=0DCH*/0xA0,/*bInterfaceSubClass:
Subclasscode=0A0H*/0xB0,/*nInterfaceProtocol:
Protocolcode=0B0H*/0,/*iInterface:
Indexofstringdescriptor*/*endpointdescriptor*/*18*/0x07,/*endpointdescriptorlength=07H*/USB_ENDPOINT_DESCRIPTOR_TYPE,/*endpointdescriptortype=05H*/0x81,/*endpoint1IN*/0x02,/*bulktransfer=02H*/0x40,0x00,/*endpointmaxpacketsize=0040H*/0x00,/*thevalueisinvalidwhenbulktransfer*/0x07,/*endpointdescriptorlength=07H*/USB_ENDPOINT_DESCRIPTOR_TYPE,/*endpointdescriptortype=05H*/0x01,/*endpoint1OUT*/0x02,/*bulktransfer=02H*/0x40,0x00,/*endpointmaxpacketsize=0040H*/0x00,/*thevalueisinvalidwhenbulktransfer*/0x07,/*endpointdescriptorlength=07H*/USB_ENDPOINT_DESCRIPTOR_TYPE,/*endpointdescriptortype=05H*/0x82,/*endpoint2IN*/0x02,/*bulktransfer=02H*/0x40,0x00,/*endpointmaxpacketsize=0040H*/0x00,/*thevalueisinvalidwhenbulktransfer*/0x07,/*endpointdescriptorlength=07H*/USB_ENDPOINT_DESCRIPTOR_TYPE,/*endpointdescriptortype=05H*/0x02,/*endpoint2OUT*/0x02,/*bulktransfer=02H*/0x40,0x00,/*endpointmaxpacketsize=0040H*/0x00,/*thevalueisinvalidwhenbulktransfer*/;
/*CustomHID_ConfigDescriptor*/C.其他的描述符01020304050607/*USBStringDescriptors(optional)*/constuint8_tCustomHID_StringLangIDCUSTOMHID_SIZ_STRING_LANGID=CUSTOMHID_SIZ_STRING_LANGID,USB_STRING_DESCRIPTOR_TYPE,0x09,0x040809101112131415161718192021222324252627;
/*LangID=0x0409:
U.S.English*/constuint8_tCustomHID_StringVendorCUSTOMHID_SIZ_STRING_VENDOR=CUSTOMHID_SIZ_STRING_VENDOR,/*SizeofVendorstring*/USB_STRING_DESCRIPTOR_TYPE,/*bDescriptorType*/Manufacturer:
STMicroelectronicsM,0,y,0,U,0,S,0,B,0,_,0,H,0,I,0,D,0;
constuint8_tCustomHID_StringProductCUSTOMHID_SIZ_STRING_PRODUCT=CUSTOMHID_SIZ_STRING_PRODUCT,/*bLength*/USB_STRING_DESCRIPTOR_TYPE,/*bDescriptorType*/B,0,y,0,0,e,0,m,0,b,0,e,0,d,0,-,0,n,0,e,0,t,0;
uint8_tCustomHID_StringSerialCUSTOMHID_SIZ_STRING_SERIAL=CUSTOMHID_SIZ_STRING_SERIAL,/*bLength*/USB_STRING_DESCRIPTOR_TYPE,/*bDescriptorType*/x,0,x,0,x,0,x,0,x,0,x,0,x,0;
2.根据端点缓冲区大小配置端点缓冲区地址,配置信息如下(在usb_conf.h文件中):
0102030405060708091011121314151617/*buffertablebaseaddress*/#defineBTABLE_ADDRESS(0x00)/*EP0*/*rx/txbufferbaseaddress*/#defineENDP0_RXADDR(0x18)#defineENDP0_TXADDR(0x58)/*EP1*/*txbufferbaseaddress*/地址为32位对其,位4的倍数,不能超过bMaxPacketSize/EP1#defineENDP1_RXADDR(0x98)#defineENDP1_TXADDR(0x98+64)/EP2#defineENDP2_RXADDR(0xA0+64+64)#defineENDP2_TXADDR(0xA0+64+64+64)3.初始化每个端点(在usb_prop.c文件中的CustomHID_Reset函数中)01020304050607080910/*InitializeEndpoint0*/SetEPType(ENDP0,EP_CONTROL);
SetEPTxStatus(ENDP0,EP_TX_STALL);
SetEPRxAddr(ENDP0,ENDP0_RXADDR);
SetEPTxAddr(ENDP0,ENDP0_TXADDR);
Clear_Status_Out(ENDP0);
SetEPRxCount(ENDP0,Device_Property.MaxPacketSize);
SetEPRxValid(ENDP0);
/*InitializeEndpoint1*/SetEPType(ENDP1,EP_BULK);
111213141516171819202122SetEPRxAddr(ENDP1,ENDP1_RXADDR);
SetEPTxAddr(ENDP1,EN
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- STM 自定义 USB 设备 开发 详细 流程 讲解 全套 资料 源码 下载