2026-03-10 11:06 PM - last edited on 2026-03-11 5:10 AM by Andrew Neil
I found what looks like a reproducible STM32CubeMX code generation bug for STM32H5 USBX device projects.
I tested this on a fresh project, so this does not appear to be a migration issue from an older codebase.
Problem
CubeMX generates these USBX init functions:
However, the generated call flow only invokes:
and never calls MX_USBX_Device_Stack_Init().
That is a problem because MX_USBX_Device_Stack_Init() contains the actual device stack setup:
Without that function running, the USB peripheral can start and receive a reset interrupt, but USBX has not been given valid device framework pointers yet.
Observed failure
When USB_DRD_FS_IRQHandler() fires and the USB reset path runs, the code eventually reaches:
and hard faults inside _ux_utility_descriptor_parse, because the device framework pointer was never initialized.
In my case the hard fault occurred at the byte dereference in _ux_utility_descriptor_parse().
Generated code pattern
MX_USBX_Init() does:
but does not call MX_USBX_Device_Stack_Init().
MX_USBX_Device_Stack_Init() is generated correctly, but left unused.
Expected behavior
The generated code should call MX_USBX_Device_Stack_Init() after ux_system_initialize(...) and before MX_USBX_Device_Init(...), so the order is effectively:
Workaround
Manually add the missing call so that MX_USBX_Init() does:
if (ux_system_initialize(pointer, USBX_MEMORY_STACK_SIZE, UX_NULL, 0) != UX_SUCCESS)
{
return UX_ERROR;
}
if (MX_USBX_Device_Stack_Init() != UX_SUCCESS)
{
return UX_ERROR;
}
if (MX_USBX_Device_Init(byte_pool) != UX_SUCCESS)
{
while(1)
{
}
}Why I believe this is a CubeMX bug
I reproduced this with a brand-new test project generated from scratch, not just an upgraded older project.
Has anyone else seen this on STM32H5 + Azure RTOS USBX device projects, and can ST confirm whether this is a known generator issue?
If needed, I can also post the exact generated files showing the missing call path.
Solved! Go to Solution.
2026-03-18 4:27 AM
Hello @KaiY
Your change request for easier user integration has been escalated to the development team under internal ticket ID #0060718.
I will keep you informed of any updates.
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.
2026-03-10 11:19 PM
Hello @KaiY
I'm currently investigating this behaviour. I will get back to you as well as possible.
Thx
Ghofrane
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.
2026-03-11 6:03 AM
Hello @KaiY
After creating a from scratch IOC using the latest version of STM32CubeMX 6.17.0 and generating the code , the mentioned call above is generated successfully as shown below
THX
Ghofrane
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.
2026-03-11 2:49 PM
2026-03-12 1:02 AM
Hello @KaiY
After reviewing your IOC configuration, I compared it with the available examples and found that the Ux_Device_HID example is very similar to your setup.
In this example, the following code is present in the generated sources:
if (MX_USBX_Device_Stack_Init() != UX_SUCCESS)
{
/* USER CODE BEGIN MAIN_INITIALIZE_STACK_ERROR */
Error_Handler();
/* USER CODE END MAIN_INITIALIZE_STACK_ERROR */
}
This check is not inserted automatically by the code generator and must be added manually in the user code section inside app_ux_device_thread_entry, as shown in the following screenshot.
THX
Ghofrane
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.
2026-03-12 1:20 AM
That appears to be pre-loaded code from the example, and not generated by CubeMX, as if I load the project directly into STM32CubeIDE, that code is already there, before generating with CubeMX.
Could you please try importing a project using my .ioc file, generating code in CubeMX, and verifying whether CubeMX emits the necessary function call?
Thank you.
2026-03-12 1:23 AM - edited 2026-03-12 1:23 AM
Hello @KaiY
Yes the code is not generated by STM32CubeMX , you need to add it manually in your code.
THX
Ghofrane
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.
2026-03-13 8:45 PM
Ok, could your team please flag this as a bug in CubeMX to be addressed? This results in out-of-the-box projects not working correctly.
Thank you.
2026-03-18 4:27 AM
Hello @KaiY
Your change request for easier user integration has been escalated to the development team under internal ticket ID #0060718.
I will keep you informed of any updates.
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.