AnsweredAssumed Answered

STM32F1xx USB Custom Hid Example Error

Question asked by tichy.tomas.001 on Mar 27, 2013
Hi All,

I've found mistake in examples from st for stm32f1xx in usb custom hid project.
In usb_prop.c file is defined string descriptor:

ONE_DESCRIPTOR String_Descriptor[4] =
  {
    {(uint8_t*)CustomHID_StringLangID, CUSTOMHID_SIZ_STRING_LANGID},
    {(uint8_t*)CustomHID_StringVendor, CUSTOMHID_SIZ_STRING_VENDOR},
    {(uint8_t*)CustomHID_StringProduct, CUSTOMHID_SIZ_STRING_PRODUCT},
    {(uint8_t*)CustomHID_StringSerial, CUSTOMHID_SIZ_STRING_SERIAL}
  };

This function in same file send string descriptor to PC

/*******************************************************************************
* Function Name  : CustomHID_GetStringDescriptor
* Description    : Gets the string descriptors according to the needed index
* Input          : Length
* Output         : None.
* Return         : The address of the string descriptors.
*******************************************************************************/
uint8_t *CustomHID_GetStringDescriptor(uint16_t Length)
{
  uint8_t wValue0 = pInformation->USBwValue0;
  if (wValue0 > 4)
  {
    return NULL;
  }
  else
  {
    return Standard_GetDescriptorData(Length, &String_Descriptor[wValue0]);
  }
}
There is an error in this function. Number 4 is wrong, because condition than allows to send 5 strings (>4), but only 4 string are defined and when there is something in memory after string descriptor (not case of example but when it is used in bigger program...), function uses invalid pointer and program falls in to Hard_fault(). It is necessary to replace 4 by 3 and it is corrected.


Regards,
Tomáš

Outcomes