AnsweredAssumed Answered

STM32 Custom USB HID Tutorial?

Question asked by R. K. on Jun 10, 2018



i want to use an accelerometer as an joystick over USB. My problem is, that all Tutorials on Youtube are not in english. So i can´t understand the important explanations. Alle tutorials not on Youtube are almost not complete, old or use Arduino stuff with ready to use Hard an Software.


As accelerometer i am using the ST LSM6DS33 with STM32F072 Discovery. As software the CubeMX-SW4STM32(Eclipse) toolchain.


With the (Non Custom) HID USB the accelerometer is working fine....but as an mouse. I need it as joystick. I used that tutorial until step 3.


For building the dicriptor i used that (i want to make small steps, thats why it is an mouse discriptor)

Tutorial about USB HID Report Descriptors | Eleccelerator 

And add this under usbd_custom_hid_if.c, showed in that video:

STM32: developing USB HID application with STM32Cube - YouTube 


Now it looks like that:

        0x05, 0x01,// USAGE_PAGE (Generic Desktop)
        0x09, 0x02,//USAGE (Mouse)
        0xa1, 0x01,// COLLECTION (Application)
        0x09, 0x01,//   USAGE (Pointer)
        0xa1, 0x00,//   COLLECTION (Physical)
        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)
        0x15, 0x81,//     LOGICAL_MINIMUM (-127)
        0x25, 0x7f,//     LOGICAL_MAXIMUM (127)
        0x75, 0x08,//     REPORT_SIZE (8)
        0x95, 0x02,//     REPORT_COUNT (2)
        0x81, 0x06,//     INPUT (Data,Var,Rel)
        0xc0,//   END_COLLECTION
        //0xc0                           // END_COLLECTION
  /* USER CODE END 0 */
  0xC0    /*     END_COLLECTION                 */


Eclipse says: "excess elements in array initializer" for each line. With some Google i found out, that the package size isn´t right. I think it is the CubeMX "middlewares" -> "paramter settings" -> "class parameter"

- USBD_Custom_HID_Report_DESC_SIZE



But i haven´t found anything, how i get the that. size. Is it bit, bytes, lines, instructions, bananas? In all tutorials i have found, the size is simple typed in with no explanation or there isn´t said anything about it.


Or is there an other way? Can i use the (non custom) HID? I only need a Standard joystick konfiguration.