打印
[STM32F1]

STM32F107无法枚举成HID+MSC

[复制链接]
93|3
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
probedog|  楼主 | 2024-9-30 15:26 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
做了很多次尝试,STM32F107 还是无法枚举成 HID+MSC ,哪位能提供下例程?

使用特权

评论回复
沙发
回复就哭哭| | 2024-9-30 23:18 | 只看该作者
// usb_desc.c

#include "usb_desc.h"

// USB标准描述符
const uint8_t USB_DeviceDescriptor[] = {
    // Device Descriptor
    0x12,                   // bLength
    USB_DESC_TYPE_DEVICE,   // bDescriptorType
    0x00, 0x02,             // bcdUSB (USB 2.0)
    0x00,                   // bDeviceClass
    0x00,                   // bDeviceSubClass
    0x00,                   // bDeviceProtocol
    USB_MAX_EP0_SIZE,      // bMaxPacketSize0
    LOBYTE(VENDOR_ID),      // idVendor
    HIBYTE(VENDOR_ID),      // idVendor
    LOBYTE(PRODUCT_ID),     // idProduct
    HIBYTE(PRODUCT_ID),     // idProduct
    0x00, 0x01,             // bcdDevice (v1.00)
    1,                      // Index of manufacturer string descriptor
    2,                      // Index of product string descriptor
    3,                      // Index of serial number string descriptor
    0x01                    // bNumConfigurations
};

// HID和MSC接口描述符定义
const uint8_t USB_ConfigDescriptor[] = {
    // Configuration Descriptor
    0x09,                   // bLength
    USB_DESC_TYPE_CONFIG,   // bDescriptorType
    USB_DESC_LEN_CONFIG,    // wTotalLength (to be defined)
    0x00,                   // bNumInterfaces
    0x01,                   // bConfigurationValue
    0x00,                   // iConfiguration
    0x80,                   // bmAttributes
    USB_MAX_POWER,         // bMaxPower

    // HID Interface Descriptor
    0x09,                   // bLength
    USB_DESC_TYPE_INTERFACE,// bDescriptorType
    0x00,                   // bInterfaceNumber
    0x00,                   // bAlternateSetting
    0x01,                   // bNumEndpoints
    0x03,                   // bInterfaceClass (HID)
    0x01,                   // bInterfaceSubClass
    0x01,                   // bInterfaceProtocol
    0x00,                   // iInterface

    // HID Descriptor
    0x09,                   // bLength
    HID_DESCRIPTOR_TYPE,    // bDescriptorType
    0x11, 0x01,            // bcdHID
    0x00,                   // bCountryCode
    0x01,                   // bNumDescriptors
    0x22,                   // bDescriptorType
    sizeof(HID_ReportDescriptor), 0x00, // wDescriptorLength

    // Endpoint Descriptor
    0x07,                   // bLength
    USB_DESC_TYPE_ENDPOINT, // bDescriptorType
    HID_EP_IN,             // bEndpointAddress
    0x03,                   // bmAttributes (Interrupt)
    LOBYTE(HID_EP_SIZE),    // wMaxPacketSize
    HIBYTE(HID_EP_SIZE),    // wMaxPacketSize
    0x0A,                   // bInterval

    // MSC Interface Descriptor
    0x09,                   // bLength
    USB_DESC_TYPE_INTERFACE,// bDescriptorType
    0x01,                   // bInterfaceNumber
    0x00,                   // bAlternateSetting
    0x02,                   // bNumEndpoints
    0x08,                   // bInterfaceClass (Mass Storage)
    0x06,                   // bInterfaceSubClass
    0x50,                   // bInterfaceProtocol
    0x00,                   // iInterface

    // Bulk IN Endpoint Descriptor
    0x07,                   // bLength
    USB_DESC_TYPE_ENDPOINT, // bDescriptorType
    MSC_EP_IN,             // bEndpointAddress
    0x02,                   // bmAttributes (Bulk)
    LOBYTE(MSC_EP_SIZE),    // wMaxPacketSize
    HIBYTE(MSC_EP_SIZE),    // wMaxPacketSize
    0x00,                   // bInterval

    // Bulk OUT Endpoint Descriptor
    0x07,                   // bLength
    USB_DESC_TYPE_ENDPOINT, // bDescriptorType
    MSC_EP_OUT,            // bEndpointAddress
    0x02,                   // bmAttributes (Bulk)
    LOBYTE(MSC_EP_SIZE),    // wMaxPacketSize
    HIBYTE(MSC_EP_SIZE),    // wMaxPacketSize
    0x00                    // bInterval
};

// HID报告描述符
const uint8_t HID_ReportDescriptor[] = {
    // Your HID report descriptor here
};

使用特权

评论回复
发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

341

主题

1694

帖子

3

粉丝