![shequ.stmicroelectronics.cn](./template/st_v1/static/img/logo2.png)
我用STM32F103 开发一个USB 自定义设备, 因为STM32CUBE 里没有自定义设备,所以我选择CDC然后更改设备描述符,我之前在407的芯片上这样做没有任何问题,但是我在103上更改,电脑就经常是显示还是CDC设备,有时候就找不到设备,很奇怪 我尝试单步调试USB的描述符加载过程,发现在USBD_LL_Init 里有强行指定了3个endpoint ,跟我的设置不一样,但是设备描述符他自己还是加载的CDC的没搞清楚 HAL_PCDEx_PMAConfig((PCD_HandleTypeDef)pdev->pData , 0x00 , PCD_SNG_BUF, 0x18); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef)pdev->pData , 0x80 , PCD_SNG_BUF, 0x58); / USER CODE END EndPoint_Configuration / / USER CODE BEGIN EndPoint_Configuration_CDC / HAL_PCDEx_PMAConfig((PCD_HandleTypeDef)pdev->pData , 0x81 , PCD_SNG_BUF, 0xC0); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef)pdev->pData , 0x01 , PCD_SNG_BUF, 0x110); HAL_PCDEx_PMAConfig((PCD_HandleTypeDef*)pdev->pData , 0x82 , PCD_SNG_BUF, 0x100); 下面是我修改的 usb_cdc.C / USB CDC device Configuration Descriptor / ALIGN_BEGIN uint8_t USBD_CDC_CfgHSDesc[USB_CDC_CONFIG_DESC_SIZ] ALIGN_END = { /Configuration Descriptor/ 0x09, / bLength: Configuration Descriptor size / USB_DESC_TYPE_CONFIGURATION, / bDescriptorType: Configuration / USB_CDC_CONFIG_DESC_SIZ, / wTotalLength:no of returned bytes / 0x00, 0x01, / bNumInterfaces: 2 interface / 0x01, / bConfigurationValue: Configuration value / 0x00, / iConfiguration: Index of string descriptor describing the configuration / 0xC0, / bmAttributes: self powered / 0x32, / MaxPower 0 mA / /---------------------------------------------------------------------------/ /Interface Descriptor / 0x09, / bLength: Interface Descriptor size / USB_DESC_TYPE_INTERFACE, / bDescriptorType: Interface / / Interface descriptor type / 0x00, / bInterfaceNumber: Number of Interface / 0x00, / bAlternateSetting: Alternate setting / 0x02, / bNumEndpoints: One endpoints used / 0xff, / bInterfaceClass: Communication Interface Class / 0xff, / bInterfaceSubClass: Abstract Control Model / 0x00, / bInterfaceProtocol: Common AT commands / 0x00, / iInterface: / /Endpoint OUT Descriptor/ 0x07, / bLength: Endpoint Descriptor size / USB_DESC_TYPE_ENDPOINT, / bDescriptorType: Endpoint / CDC_OUT_EP, / bEndpointAddress / 0x02, / bmAttributes: Bulk / LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), / wMaxPacketSize: / HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, / bInterval: ignore for Bulk transfer / /Endpoint IN Descriptor/ 0x07, / bLength: Endpoint Descriptor size / USB_DESC_TYPE_ENDPOINT, / bDescriptorType: Endpoint / CDC_IN_EP, / bEndpointAddress / 0x02, / bmAttributes: Bulk / LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), / wMaxPacketSize: / HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00 / bInterval: ignore for Bulk transfer / } ; / USB CDC device Configuration Descriptor / ALIGN_BEGIN uint8_t USBD_CDC_CfgFSDesc[USB_CDC_CONFIG_DESC_SIZ] ALIGN_END = { /Configuration Descriptor/ 0x09, / bLength: Configuration Descriptor size / USB_DESC_TYPE_CONFIGURATION, / bDescriptorType: Configuration / USB_CDC_CONFIG_DESC_SIZ, / wTotalLength:no of returned bytes / 0x00, 0x01, / bNumInterfaces: 2 interface / 0x01, / bConfigurationValue: Configuration value / 0x00, / iConfiguration: Index of string descriptor describing the configuration / 0xC0, / bmAttributes: self powered / 0x32, / MaxPower 0 mA / /---------------------------------------------------------------------------/ /Interface Descriptor / 0x09, / bLength: Interface Descriptor size / USB_DESC_TYPE_INTERFACE, / bDescriptorType: Interface / / Interface descriptor type / 0x00, / bInterfaceNumber: Number of Interface / 0x00, / bAlternateSetting: Alternate setting / 0x02, / bNumEndpoints: One endpoints used / 0xff, / bInterfaceClass: Communication Interface Class / 0xff, / bInterfaceSubClass: Abstract Control Model / 0x00, / bInterfaceProtocol: Common AT commands / 0x00, / iInterface: / /Endpoint OUT Descriptor/ 0x07, / bLength: Endpoint Descriptor size / USB_DESC_TYPE_ENDPOINT, / bDescriptorType: Endpoint / CDC_OUT_EP, / bEndpointAddress / 0x02, / bmAttributes: Bulk / LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), / wMaxPacketSize: / HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00, / bInterval: ignore for Bulk transfer / /Endpoint IN Descriptor/ 0x07, / bLength: Endpoint Descriptor size / USB_DESC_TYPE_ENDPOINT, / bDescriptorType: Endpoint / CDC_IN_EP, / bEndpointAddress / 0x02, / bmAttributes: Bulk / LOBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), / wMaxPacketSize: / HIBYTE(CDC_DATA_FS_MAX_PACKET_SIZE), 0x00 / bInterval: ignore for Bulk transfer / } ; ALIGN_BEGIN uint8_t USBD_CDC_OtherSpeedCfgDesc[USB_CDC_CONFIG_DESC_SIZ] ALIGN_END = { 0x09, / bLength: Configuation Descriptor size / USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION, USB_CDC_CONFIG_DESC_SIZ, 0x00, 0x01, / bNumInterfaces: 2 interfaces / 0x01, / bConfigurationValue: / 0x00, / iConfiguration: / 0xC0, / bmAttributes: / 0x32, / MaxPower 100 mA / /Interface Descriptor / 0x09, / bLength: Interface Descriptor size / USB_DESC_TYPE_INTERFACE, / bDescriptorType: Interface / / Interface descriptor type / 0x00, / bInterfaceNumber: Number of Interface / 0x00, / bAlternateSetting: Alternate setting / 0x02, / bNumEndpoints: One endpoints used / 0xff, / bInterfaceClass: Communication Interface Class / 0xff, / bInterfaceSubClass: Abstract Control Model / 0x00, / bInterfaceProtocol: Common AT commands / 0x00, / iInterface: / /Endpoint OUT Descriptor/ 0x07, / bLength: Endpoint Descriptor size / USB_DESC_TYPE_ENDPOINT, / bDescriptorType: Endpoint / CDC_OUT_EP, / bEndpointAddress / 0x02, / bmAttributes: Bulk / 0x40, / wMaxPacketSize: / 0x00, 0x00, / bInterval: ignore for Bulk transfer / /Endpoint IN Descriptor/ 0x07, / bLength: Endpoint Descriptor size / USB_DESC_TYPE_ENDPOINT, / bDescriptorType: Endpoint / CDC_IN_EP, / bEndpointAddress / 0x02, / bmAttributes: Bulk / 0x40, / wMaxPacketSize: / 0x00, 0x00 / bInterval / }; 下面是我修改的 usb_cdc.H define CDC_IN_EP 0x82U / EP1 for data IN /define CDC_OUT_EP 0x01U / EP1 for data OUT /define CDC_CMD_EP 0x83U / EP2 for CDC commands /ifndef CDC_HS_BINTERVALdefine CDC_HS_BINTERVAL 0x10Uendif / CDC_HS_BINTERVAL /ifndef CDC_FS_BINTERVALdefine CDC_FS_BINTERVAL 0x10Uendif / CDC_FS_BINTERVAL // CDC Endpoints parameters: you can fine tune these values depending on the needed baudrates and performance. / define CDC_DATA_HS_MAX_PACKET_SIZE 512U / Endpoint IN & OUT Packet size /define CDC_DATA_FS_MAX_PACKET_SIZE 64U / Endpoint IN & OUT Packet size /define CDC_CMD_PACKET_SIZE 8U / Control Endpoint Packet size /define USB_CDC_CONFIG_DESC_SIZ 32U//67U |
IAR 9.x环境下STM32重定向串口scanf如何实现?
stm32cubeide生成的freertos断言失败
STM32cubeide报错,但是使用STM32cubeprogram可以正常烧写程序
STM32F103定时器输入捕获最小可以捕获多大的周期
HAL库,驱动步进电机不转
STM32 ST-LINK Utility无法检测到芯片
STM32是小端模式,但为什么Keil中memory窗口和反汇编窗口的32位指令不一致?
STM32烧录时报错could not stop cortez-m device
STM32F103 通过HAL库配置ADC DMA传输,出现hardfault
stm32跑rtc时运行10s就会报错,电压波动2mV,使用32.768k 12.5pf 20ppm爱普生无源晶振,一旦跑起来就没事,跑不起来就卡死,这是怎么回事?在线等挺着急的!
很多相关的地方都要修改的,首先你要确定使用是什么class设备。
修改设备描述符,配置描述符,类型描述符。
修改使用的端点。将以前识别的CDC设备卸载驱动或者更换VID,PID。
F4和F1系列在包缓冲这块配置有明显不一样,你要重点比较核对下。
STM32F4系列的接收缓冲就是共用1个,发送缓冲基于不同端点或通道分开配置。
而F1系列的包缓冲则基于缓冲描述表和收发缓冲来配置,每个端点的收发缓冲单独配置,即不同端点
的接收缓冲地址、发送缓冲地址都是不一样的。首先要基于端点个数把包缓冲描述表自身需要的空间大小定下来,
然后在设置具体各端点的收发缓冲的起始地址及大小。
[md]问题就在这里,我更换了VID和PID,但是电脑上自动加载的驱动尽然显示不是我更改后的VID和PID,我都晕了,想不明白是怎么回事情
[md]那是你没改对地方吧
PID VID 不会改错地方的啊,一搜索就出来了
而且VID PID 是在STM32CUBE 里改的,