2026-04-24 12:20 PM
Hello
Currently I am working with NUCLEO-N657X0-Q by using
Trying to investigate and migrate CDC ACM feature in to the my own project. As basis I am using Ux_Device_CDC_ACM Example provided by ST as reference.
It was discovered that Ux_Device_CDC_ACM example would not work properly after MxCube project regeneration -- it goes to the HardFault_Handler() at some point (not defined currently at which point)
The investigation showed that the issue is connected with the Optimization level (MxCube updated STM32CubeIDE project files) just only for the one single source file: "stm32n6xx_hal_rcc_ex.c". If optimization level is set to "-O0" for the mentioned file -- HardFault_Handler() is observed. By changing it to the "-O3" -- the application works successfully.
Could you please explain this "hidden" dependency, and what is the reason of this?
2026-04-24 12:43 PM - edited 2026-04-24 12:46 PM
> it goes to the HardFault_Handler() at some point (not defined currently at which point)
Can you tell more how to reproduce this? What does the program do when the HardFault occurs? Do you have the register values? Change in the optimization level in one .c file can just move code & data of other modules to other addresses, it may not be the root cause at all.
2026-04-24 1:25 PM
The simplest way to reproduce it:
2026-04-27 1:46 AM
Hello @bureau
Since -O0 generally produces larger stack frames than -O3, the HardFault may be caused by an insufficient stack allocation rather than by the RCC source file itself. For this reason, we recommend increasing the stack size as a first diagnostic step.
2026-04-27 1:56 AM
Debugging Cortex-M Hard Faults: