Author Topic: STM32F411 Custom HID device problem  (Read 6892 times)

0 Members and 1 Guest are viewing this topic.

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
STM32F411 Custom HID device problem
« on: April 17, 2016, 06:25:15 am »
Hello
I 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 fine

https://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[HID_MOUSE_REPORT_DESC_SIZE]  __ALIGN_END =
{

// system control collection
   0x85, 0x01,         // REPORT_ID
   0x05, 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 bits
   0x95, 0x06,         //   REPORT_COUNT (6)
   0x81, 0x03,         //   INPUT (Cnst,Var,Abs)
   0xc0,               // END_COLLECTION

// Consumer control collection
   0x85, 0x02,         // REPORT_ID
   0x05, 0x0c,         // USAGE_PAGE (Consumer Devices)
   0x09, 0x01,         // USAGE (Consumer Control)
   0xa1, 0x01,         // COLLECTION (Application)
               // -------------------- common global items
   0x15, 0x00,         //   LOGICAL_MINIMUM (0)
   0x25, 0x01,         //   LOGICAL_MAXIMUM (1)
   0x75, 0x01,         //   REPORT_SIZE (1)
               // -------------------- misc bits
   0x95, 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 bits
   0x95, 0x02,         //   REPORT_COUNT (2)
   0x09, 0xe9,         //   USAGE (Volume Up)
   0x09, 0xea,         //   USAGE (Volume Down)
   0x81, 0x02,         //   INPUT (Data,Var,Abs)  - absolute inputs
               // -------------------- padding bit
   0x95, 0x01,         //   REPORT_COUNT (1)
   0x81, 0x01,         //   INPUT (Cnst,Ary,Abs)
   0xc0,               // END_COLLECTION
// Keyboard collection
   0x85, 0x03,         // REPORT_ID
   0x05, 0x01,         // USAGE_PAGE (Generic Desktop)
   0x09, 0x06,         // USAGE (Keyboard)
   0xa1, 0x01,         // COLLECTION (Application)
               // -------------------- modifier keys
   0x15, 0x00,         //   LOGICAL_MINIMUM (0)
   0x25, 0x01,         //   LOGICAL_MAXIMUM (1)
   0x75, 0x01,         //   REPORT_SIZE (1)
   0x95, 0x08,         //   REPORT_COUNT (8)
   0x19, 0xe0,         //   USAGE_MINIMUM (Keyboard LeftControl)
   0x29, 0xe7,         //   USAGE_MAXIMUM (Keyboard Right GUI)
   0x81, 0x02,         //   INPUT (Data,Var,Abs)

               // -------------------- keycode array

   0x15, 0x00,         //   LOGICAL_MINIMUM (0)
   0x25, 0x65,         //   LOGICAL_MAXIMUM (101)
   0x75, 0x08,         //   REPORT_SIZE (8)
   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,

 

offset

   0    report ID (3)

   1    bit map of modifier keys

   2    keycode array[0]

   3         :

   4         :

   5         :

   6         :

   7    keycode array[5]

 

The keycodes (Usages) are,

 

right arrow: 0x4F

left  arrow: 0x50

down  arrow: 0x51

up    arrow: 0x52

enter: 0x28

tab  : 0x2B

home : 0x4A

 

 

The 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 key

 

Also, 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 arrow


windows 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 !
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: STM32F411 Custom HID device problem
« Reply #1 on: April 17, 2016, 07:10:55 am »
So this is mouse config, it does work just fine
http://pastebin.com/LY2Bz1aA

But 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 connected
Device actual bus speed: FullSpeed
Device is hub: No
Device address: 0x0014
Current configuration value: 0x00
Number of open pipes: 0

Device Descriptor:
------------------------------
0x12   bLength
0x01   bDescriptorType
0x0200   bcdUSB
0x00   bDeviceClass   
0x00   bDeviceSubClass   
0x00   bDeviceProtocol   
0x40   bMaxPacketSize0   (64 Bytes)
0x0483   idVendor
0x5710   idProduct
0x0200   bcdDevice
0x01   iManufacturer
0x02   iProduct
0x03   iSerialNumber
0x01   bNumConfigurations

Configuration descriptor and all subsequent descriptors are not available. Error code: 0x000000AA

Microsoft OS Descriptor is not available. Error code: 0x000000AA

String Descriptor Table
--------------------------------
Index  LANGID  String
0x00   0x0000 
0x01   0x0000  Request failed with 0x000000AA
0x02   0x0000  Request failed with 0x000000AA
0x03   0x0000  Request failed with 0x000000AA

------------------------------ |O
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: STM32F411 Custom HID device problem
« Reply #2 on: April 17, 2016, 07:55:51 am »
Assuming you are using ST library, post your usb_device.c and if possible, main.c.

https://my.st.com/public/STe2ecommunities/mcu/Lists/cortex_mx_stm32/Attachments/65162/STM32F411.rar
This 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...
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: STM32F411 Custom HID device problem
« Reply #3 on: April 17, 2016, 08:09:58 am »
Ok, some development:
I ported this code to work with my board, it does work, i get some keyboard keys, but not keys i need  :palm:
http://stm32f4-discovery.com/2014/09/library-34-stm32f4-usb-hid-device/
__ALIGN_BEGIN static uint8_t HID_MOUSE_ReportDesc[HID_MOUSE_REPORT_DESC_SIZE] __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 (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
    0x95, 0x06,                    //   REPORT_COUNT (6)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    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_COLLECTION
   
    0x05, 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 (8)
    0x95, 0x03,                    //     REPORT_COUNT (3)
    0x81, 0x06,                    //     INPUT (Data,Var,Rel)
    0xc0,                          //   END_COLLECTION
    0xc0,                          // END_COLLECTION

    0x05, 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 (8)
    0x95, 0x04,                    //     REPORT_COUNT (4)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0xc0,                          //   END_COLLECTION
    0xc0,                          // END_COLLECTION

    0x05, 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 (8)
    0x95, 0x04,                    //     REPORT_COUNT (4)
    0x81, 0x02,                    //     INPUT (Data,Var,Abs)
    0xc0,                          //     END_COLLECTION
    0xc0,                           // END_COLLECTION
};

Keys i need are:
  discriptor = 1
    0  : Sleep
    1  : Wake up
    discriptor = 2
    0  : Next               1     
    1  : Previous         2
    2  : Stop               4
    3  : Play/Pause     8
    4  : Mute              16
    5  : Volume Up      32
    6  : Volume Down    64
    7  : 0 (padding) */
discriptor = 3
    0  : Home ( like android home button)   
    1  : Arrow_up         
    2  : Arrow_down
    3  : Arrow_Left         
    4 : Arrow_Right
    5 : Tab         
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: STM32F411 Custom HID device problem
« Reply #4 on: April 17, 2016, 08:39:05 am »
If so, I think you might want to read USB HID class specification. There are tutorial style explained version online, as well as official documents.
The driver itself looks to be working.
Yes, 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 (8)
    0x81, 0x02,                    //   INPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    0x81, 0x03,                    //   INPUT (Cnst,Var,Abs)
    0x95, 0x06,                    //   REPORT_COUNT (6)
    0x75, 0x08,                    //   REPORT_SIZE (8)
    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_COLLECTION

Placing only this into array, and adjusting array size does not work, i am clearly missing something....
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: STM32F411 Custom HID device problem
« Reply #5 on: April 18, 2016, 03:11:10 pm »
Just to make it more interesting, if some one will give me correct answer I will donate few STM32F429 micros in lqfp-144 package :)
 

Offline Narmaraktuk

  • Contributor
  • Posts: 20
  • Country: nl
Re: STM32F411 Custom HID device problem
« Reply #6 on: April 18, 2016, 03:43:37 pm »
During my last STM32F1 usb project I 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
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: STM32F411 Custom HID device problem
« Reply #7 on: April 21, 2016, 06:50:38 am »
During my last STM32F1 usb project I 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

I 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
« Last Edit: April 21, 2016, 07:41:54 am by kilohercas »
 

Offline kilohercasTopic starter

  • Regular Contributor
  • *
  • Posts: 60
  • Country: 00
  • Engineer
Re: STM32F411 Custom HID device problem
« Reply #8 on: April 28, 2016, 04:48:08 am »
So no one want FREE STM32F7 or STM32L4 MCU's and/or devkits ?
 

Offline d_nedelchev

  • Newbie
  • Posts: 1
  • Country: bg
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 protocol

The 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  - None

Apparently 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.
« Last Edit: December 16, 2016, 03:49:07 pm by d_nedelchev »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf