cancel
Showing results for 
Search instead for 
Did you mean: 

VS-Code extension 3.5.1: HardFault during USBX initialization on STM32U5A5

PierreB
Associate II

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));

 

1 ACCEPTED SOLUTION

Accepted Solutions

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.

View solution in original post

6 REPLIES 6
ElliotAlderson
Associate II

Hi PierreB,

There is a view that shows the type of error occurring:

1000020417.png

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

PierreB
Associate II

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).

PierreB_0-1753775065500.png

 

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.

PierreB
Associate II

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!

On my side, I simply disable it by setting the attribute to false in my debug configuration. 

1000020418.png

 

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