STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf

上传人:b****1 文档编号:16119969 上传时间:2022-11-20 格式:PDF 页数:13 大小:729.40KB
下载 相关 举报
STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf_第1页
第1页 / 共13页
STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf_第2页
第2页 / 共13页
STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf_第3页
第3页 / 共13页
STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf_第4页
第4页 / 共13页
STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf_第5页
第5页 / 共13页
点击查看更多>>
下载资源
资源描述

STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf

《STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf》由会员分享,可在线阅读,更多相关《STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf(13页珍藏版)》请在冰豆网上搜索。

STM自定义USB设备开发详细流程讲解及全套资料源码下载资料下载.pdf

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

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 总结汇报 > 其它

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1