2024-10-03 11:01 PM
Hello,
I'm currently using MX version 6.11.1 to generate code for the STM32U5G9ZJT6Q for the USB Video Class (UVC). However, I've noticed that the generated function for USB initialization, MX_USBX_Device_Init(), is mostly empty, and I'm unable to find a starting point for my implementation.
The generated code for the UVC initialization is as follows:
UINT MX_USBX_Device_Init(VOID)
{
UINT ret = UX_SUCCESS;
UX_PARAMETER_NOT_USED(ux_device_byte_pool_buffer);
return ret;
}
In contrast, when I generate the code for the CDC class, it includes comprehensive initializations and is structured as shown below:
UINT MX_USBX_Device_Init(VOID)
{
UINT ret = UX_SUCCESS;
UCHAR *device_framework_high_speed;
UCHAR *device_framework_full_speed;
ULONG device_framework_hs_length;
ULONG device_framework_fs_length;
ULONG string_framework_length;
ULONG language_id_framework_length;
UCHAR *string_framework;
UCHAR *language_id_framework;
UCHAR *pointer;
/* USER CODE BEGIN MX_USBX_Device_Init0 */
/* USER CODE END MX_USBX_Device_Init0 */
pointer = ux_device_byte_pool_buffer;
/* Initialize USBX Memory */
if (ux_system_initialize(pointer, USBX_DEVICE_MEMORY_STACK_SIZE, UX_NULL, 0) != UX_SUCCESS)
{
/* USER CODE BEGIN USBX_SYSTEM_INITIALIZE_ERROR */
return UX_ERROR;
/* USER CODE END USBX_SYSTEM_INITIALIZE_ERROR */
}
/* Get Device Framework High Speed and get the length */
device_framework_high_speed = USBD_Get_Device_Framework_Speed(USBD_HIGH_SPEED, &device_framework_hs_length);
/* Get Device Framework Full Speed and get the length */
device_framework_full_speed = USBD_Get_Device_Framework_Speed(USBD_FULL_SPEED, &device_framework_fs_length);
/* Get String Framework and get the length */
string_framework = USBD_Get_String_Framework(&string_framework_length);
/* Get Language Id Framework and get the length */
language_id_framework = USBD_Get_Language_Id_Framework(&language_id_framework_length);
/* Install the device portion of USBX */
if (ux_device_stack_initialize(device_framework_high_speed, device_framework_hs_length, device_framework_full_speed, device_framework_fs_length, string_framework, string_framework_length, language_id_framework, language_id_framework_length, USBD_ChangeFunction) != UX_SUCCESS)
{
/* USER CODE BEGIN USBX_DEVICE_INITIALIZE_ERROR */
return UX_ERROR;
/* USER CODE END USBX_DEVICE_INITIALIZE_ERROR */
}
/* Initialize the cdc acm class parameters for the device */ cdc_acm_parameter.ux_slave_class_cdc_acm_instance_activate = USBD_CDC_ACM_Activate; cdc_acm_parameter.ux_slave_class_cdc_acm_instance_deactivate = USBD_CDC_ACM_Deactivate; cdc_acm_parameter.ux_slave_class_cdc_acm_parameter_change = USBD_CDC_ACM_ParameterChange;
/* USER CODE BEGIN CDC_ACM_PARAMETER */
/* USER CODE END CDC_ACM_PARAMETER */
/* Get cdc acm configuration number */
cdc_acm_configuration_number = USBD_Get_Configuration_Number(CLASS_TYPE_CDC_ACM, 0);
/* Find cdc acm interface number */
cdc_acm_interface_number = USBD_Get_Interface_Number(CLASS_TYPE_CDC_ACM, 0);
/* Initialize the device cdc acm class */
if (ux_device_stack_class_register(_ux_system_slave_class_cdc_acm_name, ux_device_class_cdc_acm_entry, cdc_acm_configuration_number, cdc_acm_interface_number, &cdc_acm_parameter) != UX_SUCCESS)
{
/* USER CODE BEGIN USBX_DEVICE_CDC_ACM_REGISTER_ERROR */
return UX_ERROR;
/* USER CODE END USBX_DEVICE_CDC_ACM_REGISTER_ERROR */
}
/* USER CODE BEGIN MX_USBX_Device_Init1 */
/* USER CODE END MX_USBX_Device_Init1 */
return ret;
}
Why is there such a significant difference in the initialization function when generating code for UVC compared to CDC? Is there something I might be missing in the configuration, or is this a known issue with the MX version?
Thank you for your assistance!
2024-10-07 05:47 AM
Hello @saikumar
First let me thank you for posting.
UVC is a relatively large and complex device class. And for a host, it requires considerable bandwidth for video streams, memory for buffering frames, and CPU power .
The CubeMX is designed to simplify the initialization process for CDC compared to UVC ,because that UVC require more specific or custom configurations.
You might consider the manual implementation: if necessary, you might need to manually add the missing initialization steps for UVC based on the USB specification and requirements for UVC devices. You can refer to the USB Video Class specification for guidance on initializing UVC devices.
THX
Ghofrane