Reply by Wojciech Zabolotny October 5, 20202020-10-05
When preparing nonstandard USB firmwares for STM32 microcontrollers, it would be perfect to have a possibility to use a "CUSTOM CLASS", in "Class for FS IP" list in CubeMX.
Unfortunately it is not available.
I have taken a look into CubeMX, and have found that for example the CUSTOM HID class is implemented in the following way:

In the USB_DEVICE_-STM32???_Configs.xml file there are the following sections:

    <!-- Custom HID Class -->    
    <RefConfig Comment="CUSTOMHID" Name="USB_DEVICE_CUSTOM_HID_FS">
        <CallLibMethod Name="USBD_Init" ReturnHAL="false" Phase="preOS">
            <MethodArg Name="hUsbDevice" ParameterName="hUsbDeviceFS"/>
            <!--<MethodArg Name="USBD_DESC" ParameterName="HID_Desc"/>-->
            <MethodArg Name="USBD_DESC" ParameterName="FS_Desc"/>
            <MethodArg Name="id" ParameterName="DEVICE_FS"/>
        </CallLibMethod> 
        <CallLibMethod Name="USBD_RegisterClass" ReturnHAL="false" Phase="preOS">
            <MethodArg Name="hUsbDevice" ParameterName="hUsbDeviceFS"/>
            <MethodArg Name="USBD_CLASS" ParameterName="USBD_CUSTOM_HID"/>
        </CallLibMethod>  
        <CallLibMethod Name="USBD_CUSTOM_HID_RegisterInterface" ReturnHAL="false" Phase="preOS">
            <MethodArg Name="hUsbDevice" ParameterName="hUsbDeviceFS"/>
            <MethodArg Name="USBD_USER_CALLBACK" ParameterName="USBD_CustomHID_fops_FS"/>
        </CallLibMethod> 
        <CallLibMethod Name="USBD_Start" ReturnHAL="false" Phase="postOS">
            <MethodArg Name="hUsbDevice" ParameterName="hUsbDeviceFS"/>
        </CallLibMethod>  
        <Component Name="Middlewares:USB_DEVICE:CUSTOM_HID"/>
        <ConfigFile Name="USBD_CONF_CUSTOM_HID_H"/>        
        <ConfigFile Name="USBD_CONF_FS_C"/>
        <ConfigFile Name="USBD_DESC_H"/> 
        <ConfigFile Name="USBD_DESC_C"/>
        <ConfigFile Name="USBD_DESC_FS_H"/> 
        <ConfigFile Name="USBD_DESC_CUSTOM_HID_FS_C"/>
        <ConfigFile Name="USBD_INF_CUSTOM_HID_H_FS"/> 
        <ConfigFile Name="USBD_INF_CUSTOM_HID_C_FS"/>
    </RefConfig>
 [...]
    <LibMethod Comment="" Name="USBD_CUSTOM_HID_RegisterInterface">
        <Argument AddressOf="true" Context="global;NOT_INIT" GenericType="struct" Name="hUsbDevice" TypeName="USBD_HandleTypeDef">
            <Argument AddressOf="false" GenericType="simple" Name="dev_config" OptimizationCondition="equal"/>          
        </Argument> 
        <Argument AddressOf="true" Comment="" Context="local;NOT_INIT" GenericType="simple" Name="USBD_USER_CALLBACK" TypeName="int"/>                                 
    </LibMethod>
[...]
         <SubComponent Csub="CUSTOM_HID" Description="Custom Human Interface Device">
            <File Category="header" Name="Class/CustomHID/Inc/usbd_customhid.h"/>
            <File Category="source" Name="Class/CustomHID/Src/usbd_customhid.c"/>
        </SubComponent>  
[...]
     <RefConfigFile Description="Header file for #define" Name="USBD_CONF_CUSTOM_HID_H" Template="usbdconf_f1_h.ftl">      
        <File Category="header" Condition="all" Name="Target/usbd_conf.h" Version=""/>
        <!-- Parameters for Function and Buffer Configurations -->
        <Argument Comment="" GenericType="simple" Name="USBD_MAX_NUM_INTERFACES"/>
        <Argument Comment="" GenericType="simple" Name="USBD_MAX_NUM_CONFIGURATION"/>
        <Argument Comment="" GenericType="simple" Name="USBD_MAX_STR_DESC_SIZ"/>
        <!--<Argument Comment="" GenericType="simple" Name="USBD_SUPPORT_USER_STRING"/>-->     
        <Argument Comment="" GenericType="simple" Name="USBD_DEBUG_LEVEL"/>         
        <Argument Comment="" GenericType="simple" Name="USBD_SELF_POWERED"/>       
        <Argument Comment="" GenericType="simple" Name="USBD_CUSTOMHID_OUTREPORT_BUF_SIZE"/> 
        <Argument Comment="" GenericType="simple" Name="USBD_CUSTOM_HID_REPORT_DESC_SIZE"/>  
         <Argument Comment="" GenericType="simple" Name="CUSTOM_HID_FS_BINTERVAL"/>  
    </RefConfigFile>

Then of course there are various files in the
STM32CubeMX/db/templates directory:
     usbd_custom_hid_if_c.ftl
     usbd_custom_hid_if_l4_c.ftl
     usbd_custom_hid_if_h7_c.ftl       
     usbd_custom_hid_if_f7_c.ftl   
     usbd_custom_hid_if_f4_c.ftl 
     usbd_custom_hid_if_l5_c.ftl  
     usbd_custom_hid_if_g4_c.ftl 
     usbd_custom_hid_if_h.ftl 
     usbd_custom_hid_if_wb_c.ftl 

Has anybody tried to add the support for USB CUSTOM CLASS by adding sections/files similar to the above ones (with custom_hid replaced with custom_class), of course with apprpriately modified contents?
Have I overlooked something else that should be modified?

TIA & Regards,
Wojtek