2019-05-30 12:19 PM
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)
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 ?
2019-05-30 12:30 PM
Seems I found the answer myself: It's configured in STM32Cube under USBDEVICE/Parameter Settings
2019-07-17 06:48 PM
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
2019-12-11 02:26 PM
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.