cancel
Showing results for 
Search instead for 
Did you mean: 

STM32U5xx with custom build setup - code crashes at startup entry

lgacnik97
Associate III

I have a custom build setup in VSCode, where I'm using CMake with Ninja to generate build files while using a GCC 12.3 delivered with STM32CubeIDE and GDB as well. For the hardware part I have a standalone STM32U535 MCU with SWD connection and ST-LINK V3 MINI for flash and debug. As for the software, I use HAL, linker script, and startup file which are all generated by STM32CubeMX.

Meanwhile project files build flawlessly and executable is generated, code crashes when first instruction of startup file startup_stm32u535vetxq.s is executed. When I try to stop execution, the execution doesn't end up in HardFault handler but it's simply lost. The stack view implies undefined values, implying there might be some mess-up with stack pointer. However given the default linker script and startup files are used without any modifications, I wouldn't consider this a real problem.

If I compile the same project with STM32CubeIDE and try to debug it, the code execution reaches main() without any issues. Therefore I tried reverse engineering what would normally seem reasonable to inspect - the toolchain flags used for building project files. Yet no obvious flags were different except some optional ones. But still my debugging my custom setup would result in crash.

However, if I use the same custom setup (with change of -mthumb, -mcpu, and -mfloat flags) for the STM32F103 MCU, build and debug it, there is no issue whatsoever and program execution reaches main().

For further clarity find appended startup, linker, and cmake files below. I think the issue might be something related to build flags, since startup and linker files + exact GCC distribution are the same for both my setup and STM32CubeIDE setup. I have also tried increasing heap and stack size to 0x1000 since I'm using C and C++ (but without STL currently) and that didn't resolve the issue either.

Another strange behaviour, possibly irrelevant, is that when I tried the same custom setup but on a different machine (to which I don't have access anymore), code execution managed to reach the following line in startup file and crashed as it tried to execute it:

 

/* Call static constructors */
  bl __libc_init_array

 

In case anyone would prefer the whole project in custom VSCode environment of in STM32CubeIDE environment, I can append this as well.

0 REPLIES 0