Fix HardFault on stm32h7 with arm native toolchain, with CubeIDE it works fine

49 views Asked by At

I have the following function that serializes the RTC data of the microcontroller:

string serialize() const {
    return "\"counter\": " + to_string(counter);
}

Besides the clear mistake using this serialization in a microcontroller is,I have the following issue, when compiling with the native arm-toolchain I get a HardFault at runtime when running "\"counter: " + to_string(counter), note that with just that it crashes. But when I compile using stm32CubeIDE toolchain, it runs fine. Is this a bug on the arm compiler?

For reference the compiler for CubeIDE can be found under <your-install-dir>/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.11.3.rel1.linux64_1.1./tools/bin.

I reckon this compiler is different because cubeIDE passes some flags like -fcyclomatic-complexity, which are not available on the native arm compiler. However I would expect the code snippet to behave the same way with both compilers.

Also the code runs fine on Ubuntu using g++, so it looks like an issue on the arm compiler

Changing the line to:

return string{"counter:"} + to_string(counter); 

doesn't cause this HardFault

0

There are 0 answers