我用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 |
stm32进入stop模式被莫名其妙唤醒(应该是systick)但是无法被WKUP引脚唤醒。
头文件找不到
软件为keil5,头文件未找到
通过FATFS文件系统读写SD卡创建文件可以了,但加入MSC,一直显示一个没有格式化的U盘盘符,也不能格式化,这是什么问题导致的
stm32f103汇编求助
cubemx 生成的freertos代码 在keil ac6下不能编译,有什么解决的方法吗
报错Could not determine GDB version using command: arm-none-eabi-gdb --version
stm32f107vct6配RTL8201例程
STM32F103VGT6 能代替 STM32F103VFT6 吗?
STM32 读取DHT20,跑的官方的例程一直读取失败,初学者,各位大佬能指点一下不
很多相关的地方都要修改的,首先你要确定使用是什么class设备。
修改设备描述符,配置描述符,类型描述符。
修改使用的端点。将以前识别的CDC设备卸载驱动或者更换VID,PID。
F4和F1系列在包缓冲这块配置有明显不一样,你要重点比较核对下。
STM32F4系列的接收缓冲就是共用1个,发送缓冲基于不同端点或通道分开配置。
而F1系列的包缓冲则基于缓冲描述表和收发缓冲来配置,每个端点的收发缓冲单独配置,即不同端点
的接收缓冲地址、发送缓冲地址都是不一样的。首先要基于端点个数把包缓冲描述表自身需要的空间大小定下来,
然后在设置具体各端点的收发缓冲的起始地址及大小。
[md]问题就在这里,我更换了VID和PID,但是电脑上自动加载的驱动尽然显示不是我更改后的VID和PID,我都晕了,想不明白是怎么回事情
[md]那是你没改对地方吧
PID VID 不会改错地方的啊,一搜索就出来了
而且VID PID 是在STM32CUBE 里改的,