Use of User-Defined Descriptors in a Full Speed USB Component – KBA91688

Version: **


Question: How can you define your own descriptors in a Full Speed USB (USBFS) Component?



After you add the USBFS Component to a project and compile it, you will see the following comments in the USBFS_descr.c file


* User supplied descriptors. If you want to specify your own descriptors,

* remove the comments around the define USER_SUPPLIED_DESCRIPTORS below and

* add your descriptors.


/* `#START USER_DESCRIPTORS_DECLARATIONS` Place your declaration here */

/* `#END` */

You define the USER_SUPPLIED_DESCRIPTORS identifier (using the #define USER_SUPPLIED_DESCRIPTORS directive) and the descriptors in between the #START and #END comments.

Notice that when the identifier USER_SUPPLIED_DESCRIPTORS gets defined, the #if !defined(USER_SUPPLIED_DESCRIPTORS) directive is false and all the descriptors and dispatch tables are excluded from the build. Thus, you will need to define all the descriptors (device descriptors, configuration descriptors, string descriptors, HID descriptors, etc.) and the dispatch tables.

These dispatch tables are crucial. They are being used by the APIs internally to get pointers to the descriptors when needed (e.g., the setupcommand requires the dispatch table to point to the device descriptor) or enable or disable an endpoint's interrupt. The comments above the dispatch tables provide details on each table and tell what its purpose is. It is recommended that you use the USBFS Configuration Window to define the descriptors. This will generate the proper dispatch tables and will avoid problems in the functioning of the firmware due to wrong dispatch tables.

For example, if you want to add an interface manually:

  1.   Generate the descriptors that contain the proper endpoint configurations.
  2.   Copy the whole content in between “#if !defined(USER_SUPPLIED_DESCRIPTORS)” and “#endif”.
  3.   Paste the content in between “/* `#START USER_DESCRIPTORS_DECLARATIONS` Place your declaration here */” and “/* `#END` */"
  4.   After defining the USER_SUPPLIED_DESCRIPTORS directive, manually make the changes that are now required to include the interface.

Because you might change the interface numbers, you will need to change the DEVICE_CONFIGURATION_EP_SETTINGS_TABLE appropriately.