cancel
Showing results for 
Search instead for 
Did you mean: 

Custom HID on STM32F103C8

Steeve_Osteen
Associate II

Hello Everyone,

Mechanical engineer at heart, I'm still a noob when it comes to STM32 coding.

I'm trying to create a macropad (later this work might lead to a joystick) for a game I use (Starcitizen).

So far, i've managed to get the input for encoders, Hal effect sensors and switches, but i struggle on the main part, the communication with the computer (Windows PC) using custom HID.

I understand at least parts of the issue,

I get the decalration of the elements i sue as input, i understood that i have to declare a descriptor and a report for usb, but that is where i lack, too much files and data which are not easily comprehensible.

What I understood :

  •  the usbd_desc.c file contains the device descriptrt
  • the usbd_customhid.c containes the interface, the config and the descriptor.

But that is almost all i can find.

I've used the ressources on the community and on the web, i'm almost sure all informations are inside but still i'm not able to find beginner level informations which could help on my specific needs, USB norms is quite low level coding and informations available are more on genral level and i don't know how to apply them to my needs.

 

do you have any hint on how to create the descriptor and report ?

thanks for your help.

 

5 REPLIES 5
gbm
Lead III

Get HID class specification from usb.org.

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice
Steeve_Osteen
Associate II

Thanks for your reply,

I already got them (at least Device Class Definition for Human Interface Devices HID V1.11), i think i understand which are the elements of the descriptor and the report, but how do you define the value which are described here..

 

For example, I got 10 buttons, two pots and one HAL sensor connected to the board, how do you define these elements in report and descriptors ? I do not understand  what design 0x00 or 0x07......

I'm not a programmer, that is why i lack this knowledge which might be so common for you all.

Get the usage tables document (https://usb.org/document-library/hid-usage-tables-15). The hardest part of your task is to decide how your device should be visible to the host.

And ignore the AI-generated stuff. ;)

My STM32 stuff on github - compact USB device stack and more: https://github.com/gbm-ii/gbmUSBdevice

So, if i understand, whatever the MCU, HID descriptor migh contain the same elements, and the specifics for ST is just in which files the data are stored ?

 

so now I think i have a little more understood my issues.

For the device descriptor, it "seems" to be the easiest parts and i think i'm ok with that one.

For the report descriptor on the contrary....

ok taking an example, I understand that each line define one element of the report, but what value for what line is what bugs me.. (the code under is extracted from a tutorial for a keyboard)

{
    0x05, 0x01,                    // USAGE_PAGE (Generic Desktop)
    0x09, 0x06,                    // USAGE (Keyboard)
    0xa1, 0x01,                    // COLLECTION (Application)
    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, 0x05,                    //   REPORT_COUNT (5)
    0x75, 0x01,                    //   REPORT_SIZE (1)
    0x05, 0x08,                    //   USAGE_PAGE (LEDs)
    0x19, 0x01,                    //   USAGE_MINIMUM (Num Lock)
    0x29, 0x05,                    //   USAGE_MAXIMUM (Kana)
    0x91, 0x02,                    //   OUTPUT (Data,Var,Abs)
    0x95, 0x01,                    //   REPORT_COUNT (1)
    0x75, 0x03,                    //   REPORT_SIZE (3)
    0x91, 0x03,                    //   OUTPUT (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
};

 One more question, the size of the descriptor (defined in usbd_hid.h) tells that a keyboard length is 63 bytes, but why ?

 

I'll go back into my readings and thanks for your reply.

Hi @Steeve_Osteen 

Total number of bytes in the descriptor array. You can count each byte from the descriptor: Summing these up gives 63 bytes.  

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.