cancel
Showing results for 
Search instead for 
Did you mean: 

Bug / missing option in STM32CubeMX CustomHID code generation

drojfjord
Associate II
Posted on June 29, 2016 at 08:05

I'm not entirely sure if this is a bug or not, but I thought I'd describe it anyway. Basically, there are options not present in STM32CubeMX for the CustomHID device which mean that it doesn't work properly if you try to send more than 2 bytes at a time.

In the past I've tried making CustomHID devices to pass data to a PC. Lets assume we want a HID device which can pass 64 bytes out ever 1ms.

This can be done by opening STM32Cube, and changing the USB_DEVICE to Custom HID device.

Then, in USB settings, change the EP size to 64 so that the entire 64 bytes can be passed at once through the endpoint. This part is fine.

Next click on 'USB_DEVICE' which opens the settings specific to a custom hid device. Then change the report descriptor size to your liking (lets say 32), and the ''Out-report buffer size'' to 64.

The problem with this is that there are two settings missing in STM32CubeMX which are present in the code, that is:

- ''CUSTOM_HID_EPIN_SIZE'' and ''CUSTOM_HID_EPOUT_SIZE'', in usbd_customhid.h

- polling time , in usbd_customhid.c ''USBD_CUSTOM_HID_CfgDesc[]'' array. By default set to 32ms (0x20)

Without setting the EPOUT size, the above won't work properly, since you're trying to send 64 bytes through an endpoint of size 2. Same goes for if you're trying to receive more than 2 bytes at a time. 

The 'polling time' would also be nice to add, otherwise the only way to change the polling time is through editing the code manually.

I didn't know where to send feedback on the STM32CubeMX software, so I'm posting in this forum.

I'm using version 4.14.0 of STM32CubeMX, with the latest libraries for the STM32F0XXX (I don't think the family makes any difference.) 

#!bug #bug-stm32cubemx
3 REPLIES 3
Amel NASRI
ST Employee
Posted on June 29, 2016 at 12:08

Hi wong.daniel,

Could you please update to the last version of CubeMX (4.15.1)  and let me know if parameters you need are still missing there?

Aren't the parameters ''Total length for Report descriptor (IN ENDPOINT)'' and ''Maximum report buffer size (OUT ENDPOINT)'' that you need here?

-Mayla-

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.

drojfjord
Associate II
Posted on June 29, 2016 at 15:23

I updated to the latest version (4.15.1) and the options are the same.

The ''Maximum report buffer size (OUT ENDPOINT)'' option in STM32CubeMX only modifies the value in the STM32 library to change the buffer size (the ''USBD_CUSTOMHID_OUTREPORT_BUF_SIZE'' variable)

You additionally need to change the ''

CUSTOM_HID_EPOUT_SIZE'' variable to tell the PC what size endpoint to expect (this variable is put in the 

USBD_CUSTOM_HID_CfgDesc[] descriptor). There is also a ''

CUSTOM_HID_EPIN_SIZE'' setting the in endpoint size which cannot be set via STM32Cube. Changing The ''Maximum report buffer size (OUT ENDPOINT)'' does not automatically set these variables so that descriptor reflects the report size. 

I think the ''Maximum report buffer size (OUT ENDPOINT)''/''USBD_CUSTOMHID_OUTREPORT_BUF_SIZE'' actually sets the size for both the input and output report buffers, not just the out buffer (they share the same buffer). So another variable for this is not needed. But it should be renamed as in/out report buffer size, not just outreport buffer size. I think IN reports are not officially supported by the STM32Cube library though.

The ''polling time'' is definitely not present in the settings. It is also in the 

USBD_CUSTOM_HID_CfgDesc[]

. But this is just a feature request, not necessary.

The ''Total length for Report descriptor (IN ENDPOINT)'' setting works correctly. The ''Report Descriptor'' is different from the ''

USBD_CUSTOM_HID_CfgDesc'' descriptor above.

In my comment I stated you need to set EP0 size to 64 in the Connectivity-> USB settings - this is actually unnecessary and unrelated I think.

stm32cube-t
Senior III
Posted on October 07, 2016 at 18:25

Dear user,

Please note that some parameters are fixed within the stack and so, can not be configured via STM32CubeMX:

This parameter is fixed within the HAL driver in the HAL_PCD_Init function - see code extract as example below:

/* Init endpoints structures */

 for (i = 0U; i < 15U; i++)

 {

   /* Init ep structure */

   hpcd->IN_ep[i].is_in = 1U;

   hpcd->IN_ep[i].num = i;

   hpcd->IN_ep[i].tx_fifo_num = i;

   /* Control until ep is activated */

   hpcd->IN_ep[i].type = EP_TYPE_CTRL;

   hpcd->IN_ep[i].maxpacket = 0U;

   hpcd->IN_ep[i].xfer_buff = 0U;

   hpcd->IN_ep[i].xfer_len = 0U;

 }