STM32F411 Custom HID device problem - Page 1
Forum section: electronics / general

author: kilohercas
author_rank: Regular Contributor
timestamp: April 17, 2016, 06:25:15 am
content: HelloI am making headunit from Lenovo phab plus for my car, and i need simple commands for interaction , like wakeup, sleep, music controls, and enter/arrow/tap buttons.In STM32 forum i get response, but it does not want to work, any one could help me out ?Tested my hardware with sample joystick code, works just finehttps://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Flat.aspx?RootFolder=https%3a%2f%2fmy.st.com%2fpublic%2fSTe2ecommunities%2fmcu%2fLists%2fcortex_mx_stm32%2fAdding%20HID%20messages%20to%20USB%20HID%20device%20on%20STM32F411&FolderCTID=0x01200200770978C69A1141439FE559EB459D7580009C4E14902C3CDE46A77F0FFD06506F5B&currentviews=87//usbd_hid_core.c__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc __ALIGN_END ={// system control collection0x85, 0x01, // REPORT_ID0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x80, // USAGE (System Control)0xa1, 0x01, // COLLECTION (Application)0x19, 0x82, // USAGE_MINIMUM (System Sleep)0x29, 0x83, // USAGE_MAXIMUM (System Wake Up)0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x75, 0x01, // REPORT_SIZE (1)0x95, 0x02, // REPORT_COUNT (2)0x81, 0x06, // INPUT (Data,Var,Rel)// -------------------- padding bits0x95, 0x06, // REPORT_COUNT (6)0x81, 0x03, // INPUT (Cnst,Var,Abs)0xc0, // END_COLLECTION// Consumer control collection0x85, 0x02, // REPORT_ID0x05, 0x0c, // USAGE_PAGE (Consumer Devices)0x09, 0x01, // USAGE (Consumer Control)0xa1, 0x01, // COLLECTION (Application)// -------------------- common global items0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x75, 0x01, // REPORT_SIZE (1)// -------------------- misc bits0x95, 0x05, // REPORT_COUNT (5)0x09, 0xb5, // USAGE (Scan Next Track)0x09, 0xb6, // USAGE (Scan Previous Track)0x09, 0xb7, // USAGE (Stop)0x09, 0xcd, // USAGE (Play/Pause)0x09, 0xe2, // USAGE (Mute)0x81, 0x06, // INPUT (Data,Var,Rel) - relative inputs// -------------------- volume up/down bits0x95, 0x02, // REPORT_COUNT (2)0x09, 0xe9, // USAGE (Volume Up)0x09, 0xea, // USAGE (Volume Down)0x81, 0x02, // INPUT (Data,Var,Abs) - absolute inputs// -------------------- padding bit0x95, 0x01, // REPORT_COUNT (1)0x81, 0x01, // INPUT (Cnst,Ary,Abs)0xc0, // END_COLLECTION// Keyboard collection0x85, 0x03, // REPORT_ID0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x06, // USAGE (Keyboard)0xa1, 0x01, // COLLECTION (Application)// -------------------- modifier keys0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x75, 0x01, // REPORT_SIZE (1)0x95, 0x08, // REPORT_COUNT (0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)0x81, 0x02, // INPUT (Data,Var,Abs)// -------------------- keycode array0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x65, // LOGICAL_MAXIMUM (101)0x75, 0x08, // REPORT_SIZE (0x95, 0x06, // REPORT_COUNT (6)0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)0x81, 0x00, // INPUT (Data,Ary,Abs)0xc0 // END_COLLECTION};// usbd_hid_core.h#define USB_HID_CONFIG_DESC_SIZ 34#define USB_HID_DESC_SIZ 9#define HID_MOUSE_REPORT_DESC_SIZE 105//(68 + 37)#define HID_DESCRIPTOR_TYPE 0x21#define HID_REPORT_DESC 0x22#define HID_HS_BINTERVAL 0x07#define HID_FS_BINTERVAL 0x0A#define HID_REQ_SET_PROTOCOL 0x0B#define HID_REQ_GET_PROTOCOL 0x03#define HID_REQ_SET_IDLE 0x0A#define HID_REQ_GET_IDLE 0x02#define HID_REQ_SET_REPORT 0x09#define HID_REQ_GET_REPORT 0x01#ifndef __USBD_CONF__H__#define __USBD_CONF__H__#include "usb_conf.h"#define USBD_CFG_MAX_NUM 1#define USBD_ITF_MAX_NUM 1#define USB_MAX_STR_DESC_SIZ 64#define USBD_SELF_POWERED#define USBD_DYNAMIC_DESCRIPTOR_CHANGE_ENABLED#define HID_IN_EP 0x81#define HID_IN_PACKET 8#endif /* __USBD_CONF__H__ */The format of keyboard report is,offset0 report ID (3)1 bit map of modifier keys2 keycode array3 :4 :5 :6 :7 keycode arrayThe keycodes (Usages) are,right arrow: 0x4Fleft arrow: 0x50down arrow: 0x51up arrow: 0x52enter: 0x28tab : 0x2Bhome : 0x4AThe device sends the keyboard report both at push down / release of a key{0x03, 0x00, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00} // push enter key{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // release enter keyAlso, two or more keys (up to 6) are pushed at the same time.Here is a sequence.{0x03, 0x00, 0x4F, 0x00, 0x00, 0x00, 0x00, 0x00} // push right arrow{0x03, 0x00, 0x4F, 0x52, 0x00, 0x00, 0x00, 0x00} // push up arrow, with right{0x03, 0x00, 0x52, 0x00, 0x00, 0x00, 0x00, 0x00} // release right arrow, but don't release up{0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // release up arrowwindows still thinks that device can't start, and it does nothing Any one ? Will try to read about USB, but it is hard to get whole picture !

author: kilohercas
author_rank: Regular Contributor
timestamp: April 17, 2016, 07:10:55 am
content: So this is mouse config, it does work just finehttp://pastebin.com/LY2Bz1aABut then i try to use code that some one gave me in st forum ,this what happens:Information for device USB\Vendor_0483_Product_5710:Connection Information:------------------------------Connection status: Device connectedDevice actual bus speed: FullSpeedDevice is hub: NoDevice address: 0x0014Current configuration value: 0x00Number of open pipes: 0Device Descriptor:------------------------------0x12 bLength0x01 bDescriptorType0x0200 bcdUSB0x00 bDeviceClass0x00 bDeviceSubClass0x00 bDeviceProtocol0x40 bMaxPacketSize0 (64 Bytes)0x0483 idVendor0x5710 idProduct0x0200 bcdDevice0x01 iManufacturer0x02 iProduct0x03 iSerialNumber0x01 bNumConfigurationsConfiguration descriptor and all subsequent descriptors are not available. Error code: 0x000000AAMicrosoft OS Descriptor is not available. Error code: 0x000000AAString Descriptor Table--------------------------------Index LANGID String0x00 0x00000x01 0x0000 Request failed with 0x000000AA0x02 0x0000 Request failed with 0x000000AA0x03 0x0000 Request failed with 0x000000AA------------------------------

author: kilohercas
author_rank: Regular Contributor
timestamp: April 17, 2016, 07:55:51 am
content: Quote from: blueskull on April 17, 2016, 07:22:30 amhttps://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/65162/STM32F411.rarThis is example what i use, in main bottom in comments is what i use for sendind reports, and rest only what i do is changing mouse discriptor array and it's size...

author: kilohercas
author_rank: Regular Contributor
timestamp: April 17, 2016, 08:09:58 am
content: Ok, some development:I ported this code to work with my board, it does work, i get some keyboard keys, but not keys i needhttp://stm32f4-discovery.com/2014/09/library-34-stm32f4-usb-hid-device/__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc __ALIGN_END ={0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x06, // USAGE (Keyboard)0xa1, 0x01, // COLLECTION (Application)0x85, 0x01, // REPORT_ID (1)0x05, 0x07, // USAGE_PAGE (Keyboard)0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x75, 0x01, // REPORT_SIZE (1)0x95, 0x08, // REPORT_COUNT (0x81, 0x02, // INPUT (Data,Var,Abs)0x95, 0x01, // REPORT_COUNT (1)0x75, 0x08, // REPORT_SIZE (0x81, 0x03, // INPUT (Cnst,Var,Abs)0x95, 0x06, // REPORT_COUNT (6)0x75, 0x08, // REPORT_SIZE (0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x65, // LOGICAL_MAXIMUM (101)0x05, 0x07, // USAGE_PAGE (Keyboard)0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)0x81, 0x00, // INPUT (Data,Ary,Abs)0xc0, // END_COLLECTION0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x02, // USAGE (Mouse)0xa1, 0x01, // COLLECTION (Application)0x09, 0x01, // USAGE (Pointer)0xa1, 0x00, // COLLECTION (Physical)0x85, 0x02, // REPORT_ID (2)0x05, 0x09, // USAGE_PAGE (Button)0x19, 0x01, // USAGE_MINIMUM (Button 1)0x29, 0x03, // USAGE_MAXIMUM (Button 3)0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x95, 0x03, // REPORT_COUNT (3)0x75, 0x01, // REPORT_SIZE (1)0x81, 0x02, // INPUT (Data,Var,Abs)0x95, 0x01, // REPORT_COUNT (1)0x75, 0x05, // REPORT_SIZE (5)0x81, 0x03, // INPUT (Cnst,Var,Abs)0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x30, // USAGE (X)0x09, 0x31, // USAGE (Y)0x09, 0x38, // USAGE (Wheel)0x15, 0x81, // LOGICAL_MINIMUM (-127)0x25, 0x7f, // LOGICAL_MAXIMUM (127)0x75, 0x08, // REPORT_SIZE (0x95, 0x03, // REPORT_COUNT (3)0x81, 0x06, // INPUT (Data,Var,Rel)0xc0, // END_COLLECTION0xc0, // END_COLLECTION0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x05, // USAGE (Game Pad)0xa1, 0x01, // COLLECTION (Application)0xa1, 0x00, // COLLECTION (Physical)0x85, 0x03, // REPORT_ID (3)0x05, 0x09, // USAGE_PAGE (Button)0x19, 0x01, // USAGE_MINIMUM (Button 1)0x29, 0x10, // USAGE_MAXIMUM (Button 16)0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x95, 0x10, // REPORT_COUNT (16)0x75, 0x01, // REPORT_SIZE (1)0x81, 0x02, // INPUT (Data,Var,Abs)0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x30, // USAGE (X)0x09, 0x31, // USAGE (Y)0x09, 0x32, // USAGE (Z)0x09, 0x33, // USAGE (Rx)0x15, 0x81, // LOGICAL_MINIMUM (-127)0x25, 0x7f, // LOGICAL_MAXIMUM (127)0x75, 0x08, // REPORT_SIZE (0x95, 0x04, // REPORT_COUNT (4)0x81, 0x02, // INPUT (Data,Var,Abs)0xc0, // END_COLLECTION0xc0, // END_COLLECTION0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x05, // USAGE (Game Pad)0xa1, 0x01, // COLLECTION (Application)0xa1, 0x00, // COLLECTION (Physical)0x85, 0x04, // REPORT_ID (4)0x05, 0x09, // USAGE_PAGE (Button)0x19, 0x01, // USAGE_MINIMUM (Button 1)0x29, 0x10, // USAGE_MAXIMUM (Button 16)0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x95, 0x10, // REPORT_COUNT (16)0x75, 0x01, // REPORT_SIZE (1)0x81, 0x02, // INPUT (Data,Var,Abs)0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x30, // USAGE (X)0x09, 0x31, // USAGE (Y)0x09, 0x32, // USAGE (Z)0x09, 0x33, // USAGE (Rx)0x15, 0x81, // LOGICAL_MINIMUM (-127)0x25, 0x7f, // LOGICAL_MAXIMUM (127)0x75, 0x08, // REPORT_SIZE (0x95, 0x04, // REPORT_COUNT (4)0x81, 0x02, // INPUT (Data,Var,Abs)0xc0, // END_COLLECTION0xc0, // END_COLLECTION};Keys i need are:discriptor = 10 : Sleep1 : Wake updiscriptor = 20 : Next 11 : Previous 22 : Stop 43 : Play/Pause 84 : Mute 165 : Volume Up 326 : Volume Down 647 : 0 (padding) */discriptor = 30 : Home ( like android home button)1 : Arrow_up2 : Arrow_down3 : Arrow_Left4 : Arrow_Right5 : Tab

author: kilohercas
author_rank: Regular Contributor
timestamp: April 17, 2016, 08:39:05 am
content: Quote from: blueskull on April 17, 2016, 08:15:19 amYes, i am trying to read USB HID specification, and how to change ReportDesc array. It looks like it is key what i need. I just missing/have wrong number or something. As far i as i understand, in array i have collection of parameters of device, and descriptor is used as link for this device. And i use that device report structure to report what i pressed/unpressed.So part that i am missing is hot to put multiple device parameters into single HID_MOUSE_ReportDesc, and that about it.as example, in that example from website there are multiple devices placed into reportDesc array, how can i have just keyboard ( REPORT_ID 1)0x05, 0x01, // USAGE_PAGE (Generic Desktop)0x09, 0x06, // USAGE (Keyboard)0xa1, 0x01, // COLLECTION (Application)0x85, 0x01, // REPORT_ID (1)0x05, 0x07, // USAGE_PAGE (Keyboard)0x19, 0xe0, // USAGE_MINIMUM (Keyboard LeftControl)0x29, 0xe7, // USAGE_MAXIMUM (Keyboard Right GUI)0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x01, // LOGICAL_MAXIMUM (1)0x75, 0x01, // REPORT_SIZE (1)0x95, 0x08, // REPORT_COUNT (0x81, 0x02, // INPUT (Data,Var,Abs)0x95, 0x01, // REPORT_COUNT (1)0x75, 0x08, // REPORT_SIZE (0x81, 0x03, // INPUT (Cnst,Var,Abs)0x95, 0x06, // REPORT_COUNT (6)0x75, 0x08, // REPORT_SIZE (0x15, 0x00, // LOGICAL_MINIMUM (0)0x25, 0x65, // LOGICAL_MAXIMUM (101)0x05, 0x07, // USAGE_PAGE (Keyboard)0x19, 0x00, // USAGE_MINIMUM (Reserved (no event indicated))0x29, 0x65, // USAGE_MAXIMUM (Keyboard Application)0x81, 0x00, // INPUT (Data,Ary,Abs)0xc0, // END_COLLECTIONPlacing only this into array, and adjusting array size does not work, i am clearly missing something....

author: kilohercas
author_rank: Regular Contributor
timestamp: April 18, 2016, 03:11:10 pm
content: Just to make it more interesting, if some one will give me correct answer I will donate few STM32F429 micros in lqfp-144 package

author: Narmaraktuk
author_rank: Contributor
timestamp: April 18, 2016, 03:43:37 pm
content: During my lastSTM32F1 usb projectI used wireshark on linux to dump and decode usb traffic. Wireshark can also decode the hid promises. If your hid description is broken, it will show up mangled there.HTH

author: kilohercas
author_rank: Regular Contributor
timestamp: April 21, 2016, 06:50:38 am
content: Quote from: Narmaraktuk on April 18, 2016, 03:43:37 pmI already posted in Reply #2 , that device simply could not be initialized, and i simply can't connect or do anything, so don't think traffic will help me here

author: kilohercas
author_rank: Regular Contributor
timestamp: April 28, 2016, 04:48:08 am
content: So no one wantFREESTM32F7 or STM32L4 MCU's and/or devkits ?

author: d_nedelchev
author_rank: Newbie
timestamp: December 16, 2016, 03:40:12 pm
content: I see this question has been asked months ago and the OP probably has already solved his issue but I hope it could be useful for somebody else:I just have experienced exactly the same error with code AA and it turned out to be caused by the Windows driver.It happened this way: I changed the descriptors using the same VID & PID and did NOT reinstall the driver.The previous version of the device had both HID and audio endpoints:.bDeviceClass = 0xEF, // Device class - Misc.bDeviceSubClass = 0x02, // Device Sub-class.bDeviceProtocol = 0x01, // Device protocolThe new (seemingly faulty with code AA) had HID-only endpoints:.bDeviceClass = 0x03, // Device class - HID.bDeviceSubClass = 0x00, // Device Sub-class - None.bDeviceProtocol = 0x00, // Device protocol - NoneApparently the driver got confused of this because either changing ONLY the PID with a new one or uninstalling the driver solved the AA error code.P.S. It is considered a common practice during USB device development to re-install the driver whenever device descriptors are changed.Also for HID-only devices you should be able to go ahead without a dedicated driver at all (OS built-ins should handle it) so you may select a brand new PID freely.