2

I'd like to add a string to my HID project (to store information about the firmware revision). I've read about string descriptors https://www.beyondlogic.org/usbnutshell/usb5.shtml and my understanding is that a Configuration descriptor or report descriptor lists an index that points to a string. The string is stored somewhere else. and the host can then request the string by the index via a "get"string"Descriptor" request.

I'm pretty mystified by the implementation though. I've been trawling through the STM32F04 example libraries (available for download from STM or duplicated here https://github.com/caozoux/arm/blob/master/stm32/STM32F0x2_USB-FS-Device_Lib%20V1.0.0/Libraries/STM32_USB_Device_Library/Class/dfu/src/usbd_dfu_core.c ) and found this:

    /* USB DFU device Configuration Descriptor */
    const uint8_t usbd_dfu_CfgDesc[USB_DFU_CONFIG_DESC_SIZ] =
    {
      0x09, /* bLength: Configuration Descriptor size */
      USB_CONFIGURATION_DESCRIPTOR_TYPE, /* bDescriptorType: Configuration */
      USB_DFU_CONFIG_DESC_SIZ,
      /* wTotalLength: Bytes returned */
      0x00,
      0x01,         /*bNumInterfaces: 1 interface*/
      0x01,         /*bConfigurationValue: Configuration value*/
      0x02,         /*iConfiguration: Index of string descriptor describing the configuration*/
      0xC0,         /*bmAttributes: bus powered and Supports Remote Wakeup */
      0x32,         /*MaxPower 100 mA: this current is used for detecting Vbus*/
      /* 09 */

which gives the index of iConfiguration at 0x02. I then searched all the files of another reference to 0x02 or a configuration string and found nothing. I expected to find some sort of array of strings that could be indexed into by the 0x02 index or at least a configuration string. Possibly the example files are incomplete but it feels more likely I'm just not searching for the right things.

My questions are, first is my basic assumption of how string descriptors work correct? And if so, how and where are the strings generally stored? Any links to example implementations would be super helpful as well!

Indigo
  • 962
  • 1
  • 8
  • 23
  • Since you're basically asking for help locating a piece of code in a program written by someone else, could you provide a link to the code you're looking at? – David Grayson Oct 09 '19 at 17:10
  • Sure thing, sorry for neglecting that earlier. This repo duplicates all the example code I'm working from, the code snippet specifically comes from this file https://github.com/caozoux/arm/blob/master/stm32/STM32F0x2_USB-FS-Device_Lib%20V1.0.0/Libraries/STM32_USB_Device_Library/Class/dfu/src/usbd_dfu_core.c – Indigo Oct 09 '19 at 20:34

1 Answers1

1

After a brief look at your code, it looks like the code returning string descriptors to the USB host in response to a "Get Descriptor" request is here:

https://github.com/caozoux/arm/blob/e19fc5a/stm32/STM32F0x2_USB-FS-Device_Lib%20V1.0.0/Libraries/STM32_USB_Device_Library/Core/src/usbd_req.c#L313

David Grayson
  • 84,103
  • 24
  • 152
  • 189