Skip to main content
Visitor
June 24, 2026
Question

Incorrect static data initialization when debugging external elf in STM32CubeIDE for Visual Studio Code

  • June 24, 2026
  • 1 reply
  • 8 views

I have an axf file generated by vscode keil studio, then I followed follwoing tutorial to debug in vscode stm32cube ide.

How to debug an external .elf file in VS Code | Community

Then it triggers hard fault, and debugger shows `SystemCoreClock` is not correctly initialized, when it enters into `main`, the value is initialized to `(uint32_t) -1`.

If I terminate gdb and soft reset it in cube programmer, it works fine, it also works fine when I debug it in vscode keil studio.

 

The project is a simple cubemx STM32F407 generated project, and enables serial wire debug, the code in main infinite loop is just two ITM_SendChar.

 

Update:

It only occurs in first time launch, if it enter hard fault then click reset target, it works fine, but data values of SystemCoreClock and uwTickFreq are still -1.

 

1 reply

Visitor
June 24, 2026

Use STM32CubeProgrammer, I can compare device memory and axf, data at end in device meory are all 0xFFFFFFFF, and in axf, they are correct.

Edit:

Found the real image file write to MCU is ST-LINK_GDB_server_axxxx.srec, might be something wrong up there...