Skip to main content
DDeba.1
Associate III
February 18, 2025
Solved

STM32 USB Host CDC class: USBH_FindInterface issue

  • February 18, 2025
  • 5 replies
  • 860 views

Hi, 

I am using STM32G0B1CBTX and used the STM32CubeMX to configure USB host with CDC class. When connecting a CDC device, I noticed that it passes the enumeration and configuration but fails to find the interface used. More specifically, it fails the function

interface = USBH_FindInterface(phost, COMMUNICATION_INTERFACE_CLASS_CODE, ABSTRACT_CONTROL_MODEL, COMMON_AT_COMMAND);

at line 158 of the usbh_cdc.c file. Upon deeper inspection, I noticed that the protocol value passed to this function using the macro COMMON_AT_COMMAND is set to 1 while the two interface descriptors I receive from the device both have their interface protocol set to 0. If I manually edit this and use the  NO_CLASS_SPECIFIC_PROTOCOL_CODE macro (value = 0), everything works correctly and I can send and receive data. This part of the library should be fixed and no user editing should be needed. So my question is, is their something wrong with the device's descriptors or can the first call to the USBH_FindInterface be set to have no specific protocol instead of using the COMMON_AT_COMMAND one?

This topic has been closed for replies.
Best answer by FBL

Hi @DDeba.1 

Thank you for reporting! Indeed, after sharing this with our experts, this could be customized since this middleware was intended to find interface only for COMMON_AT_COMMAND. However, the fix could take some time. 

5 replies

ST Technical Moderator
February 21, 2025

Hi @DDeba.1 

Are you using a reference board or custom board? Would you attach the project to reproduce on my end?

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
DDeba.1
DDeba.1Author
Associate III
February 21, 2025

Hi @FBL,

Find attached what requested. Note that this is basically the CubeMX generated code where I only changed line 158 of the usbh_cdc.c file such that the last argument of the USBH_FindInterface is NO_CLASS_SPECIFIC_PROTOCOL_CODE. 

Thanks

FBLBest answer
ST Technical Moderator
February 28, 2025

Hi @DDeba.1 

Thank you for reporting! Indeed, after sharing this with our experts, this could be customized since this middleware was intended to find interface only for COMMON_AT_COMMAND. However, the fix could take some time. 

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL
ST Technical Moderator
March 3, 2025

Hi @DDeba.1 

Unfortunately, no possible workaround in such case, since USBH_FindInterface() is copied from MW layer directly. You need to overwrite it every time you regenerate the code.

To give better visibility on the answered topics, please click on "Best answer" on the reply which solved your issue or answered your question.Best regards,FBL