i’m trying to write an usb device by stm32f103c8t6, which is detected as keyboard to send key code to windows, and vendor-defined to send-receive custom data.
But only keyboard work.
Here is usb treeview:
usb view
Here is descriptors:
static __code const unsigned char _USB_HID_Custom_ReportDecriptor_Data[] = {
/*Usage Page (vendor define), */ 0x06, 0x00, 0xFF,
/*Usage (id 1), */ 0x09, 1,
/*Collection (Application), */ 0xA1, 0x01,
/* Usage Minimum (1), */ 0x19, 1,
/* Usage Maximum (1), */ 0x29, 1,
/* Logical Minimum (0), */ 0x15, 0,
/* Logical Maximum (255), */ 0x25, 255,
/* Report Size (8), */ 0x75, 8,
/* Report Count (8), */ 0x95, 8,
/* Input (Data, Variable, Absolute), ;Modifier byte */ 0x81, 0x02,
/* Usage Minimum (1), */ 0x19, 1,
/* Usage Maximum (1), */ 0x29, 1,
/* Output(Data, Variable, Absolute), ;Modifier byte */ 0x91, 0x02,
/*End Collection */ 0xC0,
};
static __code const unsigned char _USB_HID_Keyboard_ReportDecriptor_Data[] = {
/*Usage Page (Generic Desktop), */ 0x05, 0x01,
/*Usage (Keyboard), */ 0x09, 0x06,
/*Collection (Application), */ 0xA1, 0x01,
/* Usage Page (Key Codes); */ 0x05, 0x07,
/* Report ID (0x01) */ 0x85, 0x01,
/* Usage Minimum (224), */ 0x19, 0xE0,
/* Usage Maximum (231), */ 0x29, 0xE7,
/* Logical Minimum (0), */ 0x15, 0x00,
/* Logical Maximum (1), */ 0x25, 0x01,
/* Report Size (1), */ 0x75, 0x01,
/* Report Count (8), */ 0x95, 0x08,
/* Input (Data, Variable, Absolute), ;Modifier byte */ 0x81, 0x02,
/* Usage Page (Key Codes), */ 0x05, 0x07,
/* Usage Minimum (0), */ 0x19, 0x00,
/* Usage Maximum (101), */ 0x29, 0x65,
/* Logical Minimum (0), */ 0x15, 0x00,
/* Logical Maximum(101), */ 0x25, 0x65,
/* Report Count (6), */ 0x95, 0x06,
/* Report Size (8), */ 0x75, 0x08,
/* Input (Data, Array), ;Key arrays (6 bytes) */ 0x81, 0x00,
/*End Collection */ 0xC0,
};
static __code const unsigned char _USB_DeviceDescriptor_Data[] = {
/*bLength */ 0x12, //(18 bytes)
/*bDescriptorType */ 0x01, //(Device Descriptor)
/*bcdUSB */ 0x00, 0x02, //(USB Version 2.0) -> but device is Low-Speed only
/*bDeviceClass */ 0x00, //(defined by the interface descriptors)
/*bDeviceSubClass */ 0x00,
/*bDeviceProtocol */ 0x00,
/*bMaxPacketSize0 */ 0x40, //(64 bytes)
/*idVendor */ 'M', 'S',
/*idProduct */ 0, 'D',
/*bcdDevice */ 0x01, 0x00,
/*iManufacturer */ 0x01, //(String Descriptor 1)
/*iProduct */ 0x02, //(String Descriptor 2)
/*iSerialNumber */ 0x00, //(No String Descriptor)
/*bNumConfigurations */ 0x01, //(1 Configuration)
};
static __code const unsigned char _USB_ConfigurationDescription_Data[] = {
/*bLength */ 0x09, //(9 bytes)
/*bDescriptorType */ 0x02, //(Configuration Descriptor)
/*wTotalLength */ 9 + 9 + 9 + 7 + 9 + 9 + 7, 0x00,
/*bNumInterfaces */ 0x02, //(2 Interfaces)
/*bConfigurationValue */ 0x01, //(Configuration 1)
/*iConfiguration */ 0x00, //(No String Descriptor)
/*bmAttributes */ 0x00,
/*MaxPower */ 0x32, //(100 mA)
//-----------------------------------
//-----------------------------------
//-----------------------------------
/*bLength */ 0x09, //(9 bytes)
/*bDescriptorType */ 0x04, //(Interface Descriptor)
/*bInterfaceNumber */ 0x00, //(Interface 0)
/*bAlternateSetting */ 0x00,
/*bNumEndpoints */ 0x01, //(1 Endpoint)
/*bInterfaceClass */ 0x03, //(HID - Human Interface Device)
/*bInterfaceSubClass */ 0x01, //(Boot Interface)
/*bInterfaceProtocol */ 0x01, //(Keyboard)
/*iInterface */ 0x00, //(No String Descriptor)
//-----------------------------------
/*bLength */ 0x09, //(9 bytes)
/*bDescriptorType */ 0x21, //(HID Descriptor)
/*bcdHID */ 0x11, 0x01, //(HID Version 1.11)
/*bCountryCode */ 0x00, //(00 = not localized)
/*bNumDescriptors */ 0x01,
/*bDescriptorType */ 0x22, //(Class=Report)
/*wDescriptorLength */ sizeof(_USB_HID_Keyboard_ReportDecriptor_Data), 0x00,
//-----------------------------------
/*bLength */ 0x07, //(7 bytes)
/*bDescriptorType */ 0x05, //(Endpoint Descriptor)
/*bEndpointAddress */ 0x81, //(Direction=IN EndpointID=1)
/*bmAttributes */ 0x03, //(TransferType=Interrupt)
/*wMaxPacketSize */ 0x08, 0x00,
/*bInterval */ 0x0A, //(10 ms)
//-----------------------------------
//-----------------------------------
//-----------------------------------
/*bLength */ 0x09, //(9 bytes)
/*bDescriptorType */ 0x04, //(Interface Descriptor)
/*bInterfaceNumber */ 0x01, //(Interface 1)
/*bAlternateSetting */ 0x00,
/*bNumEndpoints */ 0x01, //(1 Endpoint)
/*bInterfaceClass */ 0x03, //(HID - Human Interface Device)
/*bInterfaceSubClass */ 0x00, //(None)
/*bInterfaceProtocol */ 0x00, //(None)
/*iInterface */ 0x00, //(No String Descriptor)
//-----------------------------------
/*bLength */ 0x09, //(9 bytes)
/*bDescriptorType */ 0x21, //(HID Descriptor)
/*bcdHID */ 0x11, 0x01, //(HID Version 1.11)
/*bCountryCode */ 0x00, //(00 = not localized)
/*bNumDescriptors */ 0x01,
/*bDescriptorType */ 0x22, //(Class=Report)
/*wDescriptorLength */ sizeof(_USB_HID_Custom_ReportDecriptor_Data), 0x00,
//-----------------------------------
/*bLength */ 0x07, //(7 bytes)
/*bDescriptorType */ 0x05, //(Endpoint Descriptor)
/*bEndpointAddress */ 0x01, //(Direction=OUT EndpointID=1)
/*bmAttributes */ 0x03, //(TransferType=Interrupt)
/*wMaxPacketSize */ 0x08, 0x00,
/*bInterval */ 0x0A, //(10 ms)
};
If only use vendor-defined is work too: HidDevice send to stm32
Do have anyway to send from computer to stm32 device?
You need to sign in to view this answers