2025-07-28 7:59 AM
I'm trying the new VS-Code extension 3.5.1, but I end up in the HardFault_Handler function during the initialization, in the "MX_USBX_Device_Init" function. The same project works correctly when using the "cortex-debug" plugin (separate VS Code profile to avoid conflicts).
It's a very simple project where I did the very minimal config to enable USBX, and "UX Device HS -> Device Class HS -> HID -> MSC" on my STM32U5A5AJH6Q. The IOC file is attached.
It crash in the function "USBD_FrameWork_MSCDesc", at line
/* Append Endpoint descriptor to Configuration descriptor */
__USBD_FRAMEWORK_SET_EP((pdev->tclasslist[pdev->classId].Eps[1].add),
(USBD_EP_TYPE_BULK),
(uint16_t)(pdev->tclasslist[pdev->classId].Eps[1].size),
(0U), (0U));
Solved! Go to Solution.
2025-07-29 1:26 AM
This means that executing the code causes an unaligned access without the "-mno-unaligned-access" option during compilation.
However, it is still possible to ignore it without this option if the UNALIGN_TRP register is not set (this is the behavior of Cortex-Debug and CLion).
If the UNALIGN_TRP is set, then execution goes to the error handler.
This is the case with the ST debug configuration, which sets the register by default.
2025-07-29 12:30 AM
Hi PierreB,
There is a view that shows the type of error occurring:
And I know that the "unaligned access" error is enabled by default in the ST debug configuration.
You can check the attributes starting with "fault", ex: faultUnalignedAccess
2025-07-29 12:55 AM
Yes, it's an Unaligned fault, and there is no error when I add the argument "-mno-unaligned-access", but I'm not sure exactly what that implies, and I'd rather not modify the default cmake configuration, since it works with the cortex-debug plugin and with CLion (with the same elf file).
2025-07-29 1:26 AM
This means that executing the code causes an unaligned access without the "-mno-unaligned-access" option during compilation.
However, it is still possible to ignore it without this option if the UNALIGN_TRP register is not set (this is the behavior of Cortex-Debug and CLion).
If the UNALIGN_TRP is set, then execution goes to the error handler.
This is the case with the ST debug configuration, which sets the register by default.
2025-07-29 1:58 AM
Thanks a lot for that explanation!
I was able to find some documentation about the UNALIGN_TRP register and unaligned access, and it confirms exactly what you described. I found several other developers complaining about the same issue with ST's debug configuration.
Do you know if we can change this option in a setting or something without changing the code with something like that:
SCB->CCR &= ~SCB_CCR_UNALIGN_TRP_Msk;
Thanks again for the help!
2025-07-29 2:10 AM
On my side, I simply disable it by setting the attribute to false in my debug configuration.
2025-07-29 2:16 AM
It's perfect, I checked on CLion and cortex-debug, the “faultDivByZero” is also disabled on this registry.
Anyway, it's all clear to me now.
Thanks again