cancel
Showing results for 
Search instead for 
Did you mean: 

STM32CubeIDE: Configure USB HID CUSTOM_HID_ReportDesc_FS structure

MWebj
Associate III

The CUSTOM_HID_ReportDesc_FS is defined in usbd_custome_hid_if.c as

~~~

__ALIGN_BEGIN static uint8_t CUSTOM_HID_ReportDesc_FS[USBD_CUSTOM_HID_REPORT_DESC_SIZE] __ALIGN_END

~~~

The question the arises where to define USBD_CUSTOM_HID_REPORT_DESC_SIZE to match the actual report size in custom project, because it turns out that when usbd_custome_hid_if.c is built it invokes (in order)

  • usbd_conf.h which unconditionally defines it to 2U
  • usbd_customhid.h which conditionally defines it to 163U (Why ??????)
  • usbd_custome_hid_if.h which doesn't define any value.

What is worse, usbd_customhid.c uses USBD_CUSTOM_HID_REPORT_DESC_SIZE to build USBD_CUSTOM_HID_CfgFSDesc, USBD_CUSTOM_HID_CfgHSDesc, USBD_CUSTOM_HID_OtherSpeedCfgDesc and USBD_CUSTOM_HID_Desc based on definitions in usbd_customhid.h . This means that there is a dependancy from the application into the Middleware code.

I've added a definition of USBD_CUSTOM_HID_REPORT_DESC_SIZE before usbd_custome_hid_if.h is included, but build of usbd_custome_hid_if.c then fails because it is already unconditionally defined in usbd_conf.h .

So, what is the correct way of defining USBD_CUSTOM_HID_REPORT_DESC_SIZE so that both usbd_customhid.c and usbd_custome_hid_if.c are provided with correct values ?

3 REPLIES 3
MWebj
Associate III

Seems I found the answer myself: It's configured in STM32Cube under USBDEVICE/Parameter Settings

IChud
Associate II

That is right, but configuration descriptors still have only 2 bytes for input and output report sizes. While functions for preparing USB transaction use USBD_CUSTOM_HID_REPORT_DESC_SIZE.

To fix that you have to go to usbd_customhid.h and change CUSTOM_HID_EPIN_SIZE and CUSTOM_HID_EPOUT_SIZE to the desired value (not more than 0x40 for FS)

I believe this is a bug by ST and it should be fixed. Programmer should be able to change these constants.

I thought to change those descriptors in code before USB Init, but they are static in usbd_customhid.c and this file does not have USER CODE segments

FLast.3.72
Associate II

USBD_CUSTOM_HID_REPORT_DESC_SIZE is used in the Config Descriptors, and requires two bytes. The generated code is

USBD_CUSTOM_HID_REPORT_DESC_SIZE, /* wItemLength */

0x00,

which is OK if the value is <= 255. If greater, the [-Woverflow] compiler warning occurs.

Change this to

 LOBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE), /*wItemLength: Total length of Report descriptor*/

 HIBYTE(USBD_CUSTOM_HID_REPORT_DESC_SIZE),

and any size of USBD_CUSTOM_HID_REPORT_DESC_SIZE works.