I’m using a STM32H723ZG on a Nucleo-H723ZG board.
I’m able to compile, and debug but the programs crashes into the HardFault_handle when executing the clib_init_array library function, called from the ARM initialization code.
The instruction that causes the crash is below with a → mark.
I think this is related with ARM versus Thumb instruction set.
I think the clib_init_array function that the PlatformIO linker is picking-up is for an ARM instruction set whereas the Cortex-M7 only supports the Thumb instruction set.
Anyone has ideas how to solve this? PlatformIO.ini is below. thanks
__libc_init_array is a function that calls into global constructors (see e.g. here), usually from statically and globally constructed C++ objects which have a constructor function in their class.
I see these possibilities:
you don’t link properly against the library containing __libc_init_array (which should be libc) and the function results in a crash because that’s a nullptr or something
a constructor called inside the __lib_init_array function is crashing
entire different issue, e.g., the previous push instructions hardfaulted the processor because the stack was not setup correctly (e.g., initial SP beyond the bounds of RAM). That was e.g. a bug in a recent platform version in combination with a wrong “RAM size” value in the board definition.
Can you further specify whether it is crashing inside the __libc_init_array function (make sure to switch to assembly mode in the debugger and do a stepi to step into instruction-wise) and whether you are using C++ code in your project? Does this appear with the simplest possible code too, an empty main function?
So 432 kByte of RAM. If an automatic linker script generation is in place it’ll set the initial SP to 0x2000000 (RAM start) plus the amount of RAM. However, if the RAM is not continuous in the memory map, that’ll again lead to the issue described above. And as I read in the reference manual…
PlatformIO caches the generated linkerfile. Delete C:/Users/<user>/.platformio/packages/tool-ldscripts-ststm32/stm32h7/STM32H723ZG_DEFAULT.ld and re-upload the project.