cancel
Showing results for 
Search instead for 
Did you mean: 

USBX custom class

grahamm
Associate II

I'm developing firmware on a G0-family device.  I've implemented a CDC-ACM device based on one of the USBX sample applications.  Windows finds it, enumerates it and I can open it as a COM port.  That's all working.

Now I want to add a second interface, using a custom class that I'll define myself.  I'll start with the DPUMP sample application, as found on the USBX GitHub and whose .h file is found at MyProject/Middlewares/ST/usbx/common/core/inc/ux_device_class_dpump.h

In ux_device_descriptors.h, I need to extend USBD_CompositeClassTypeDef to define a new class type, like this:

/* Enum Class Type */
typedef enum
{
CLASS_TYPE_NONE = 0,
CLASS_TYPE_HID = 1,
CLASS_TYPE_CDC_ACM = 2,
CLASS_TYPE_MSC = 3,
CLASS_TYPE_CDC_ECM = 4,
CLASS_TYPE_DFU = 5,
CLASS_TYPE_DPUMP = 6,
} USBD_CompositeClassTypeDef;

But every time I generate code with CubeMX (I'm using STM32CubeIDE), this change gets overwritten because it's not in a USER CODE section.  I've read all the docs I can find but I can't find a technique for doing this.

What's the recommended method for implementing a vendor-defined USB class?  In all of ST's docs advocating the shift to ThreadX/USBX, there was a mention that USBX supported custom classes.  I assume that means there's a clean way to get this happening in CubeMX.

1 ACCEPTED SOLUTION

Accepted Solutions
FBL
ST Employee

Hi @grahamm 

 

I suggest you consider creating a separate header file for your custom class definitions and include it in your project via DPUMP.

In terms of integrating this with CubeMX, unfortunately, there doesn't seem to be a direct way to do this. Under project manager window under code generator, you can keep the original files, by checking 'Backup previously generated files when re-generating'

As for USBX, you would need to define your class and its associated functions, and then register it. This would involve using the ux_device_stack_class_register() function.
Example of an application using DPUMP class runs on STM32U585

fp-ind-datalogmc/Projects/STM32U585AI-STWIN.box/Applications/DATALOGMC at 6614c521ce746e3cc012a218d3ef7838a54870ec · STMicroelectronics/fp-ind-datalogmc (github.com)

I hope this helps!

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.

View solution in original post

3 REPLIES 3
FBL
ST Employee

Hi @grahamm 

 

I suggest you consider creating a separate header file for your custom class definitions and include it in your project via DPUMP.

In terms of integrating this with CubeMX, unfortunately, there doesn't seem to be a direct way to do this. Under project manager window under code generator, you can keep the original files, by checking 'Backup previously generated files when re-generating'

As for USBX, you would need to define your class and its associated functions, and then register it. This would involve using the ux_device_stack_class_register() function.
Example of an application using DPUMP class runs on STM32U585

fp-ind-datalogmc/Projects/STM32U585AI-STWIN.box/Applications/DATALOGMC at 6614c521ce746e3cc012a218d3ef7838a54870ec · STMicroelectronics/fp-ind-datalogmc (github.com)

I hope this helps!

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.

Hi @FBL.

Thanks for confirming that CubeMX can't do this.  I have come up with a temporary work-around by modifying the .FTL files with my project-specific code (yes, I know that won't work once I have more than one vendor-specific project).

The way I see it, your suggestion of "Backup previously generated files" would still mean I need to manually copy the backed-up files back over the source files, right?

Thanks for the tips about registering the class - I've seen the DPUMP source and I have a rough idea of the steps I need to take.

Graham

 

FBL
ST Employee

Hi @grahamm 

This feature allows to save all source files and header with .bak extension before regenerating and you will not need to copy files anymore.

FBL_0-1709021964545.png

It is worthy to give it a try.

 

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.