Search code examples
cgccarmstm32

stm32 arm gcc compile with wrong libraries or specs


When building from STM32CubeIDE, all good (obviously) When building outside IDE, but using exactly the same toolchain (ST's) and the same compiler & link flags, I got some HardwareFault handler :((

So basically, some flags/specs are not good on my side.

Now after investigating a little (-verbose) I noticed there is a difference in IDE's toolchain libraries compared to mine (both at compile & link files)

This is a link example log

IDE's

c:\st\stm32cubeide_1.11.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.100.202210260954\tools\arm-none-eabi\bin\ld.exe: mode armelf
                                                                                                                        
attempt to open c:/st/stm32cubeide_1.11.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/v6-m/nofp/crti.o succeeded

It is choosing ../lib/gcc/arm-none-eabi/10.3.1/thumb/v6-m/nofp/crti.o

Mine

c:\st\stm32cubeide_1.11.0\stm32cubeide\plugins\com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.100.202210260954\tools\arm-none-eabi\bin\ld.exe: mode armelf
attempt to open c:/st/stm32cubeide_1.11.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm3
2.10.3-2021.10.win32_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/nofp/crti.o succeeded

And mine is choosing thumb/nofp/crti.o

For some reason, at my side appears that NANO is not choosen. Moreover, libgcc is choosen in the first place!

This is mine

./Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_rcc.o
attempt to open ../../../test1\libgcc.a failed
attempt to open c:/st/stm32cubeide_1.11.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm3
2.10.3-2021.10.win32_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/nofp\libgcc.a succeeded

This is IDE's

./Drivers/STM32G0xx_HAL_Driver/Src/stm32g0xx_ll_rcc.o
attempt to open c:/st/stm32cubeide_1.11.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/thumb/v6-m/nofp\libc_nano.a failed
attempt to open c:/st/stm32cubeide_1.11.0/stm32cubeide/plugins/com.st.stm32cube.ide.mcu.externaltools.gnu-tools-for-stm32.10.3-2021.10.win32_1.0.100.202210260954/tools/bin/../lib/gcc/arm-none-eabi/10.3.1/../../../../arm-none-eabi/lib/thumb/v6-m/nofp\libc_nano.a succeeded

These are my link flags

`-O0`,
`-Wl,-verbose`,
`--specs=nosys.specs`,
`--specs=nano.specs`,
`-static`,
`-Xlinker --gc-sections`,
`-Xlinker --print-memory-usage`,
`-mfloat-abi=soft`,
`-mthumb`,

And these are IDE's

-mcpu=cortex-m0plus -T"STM32G0B1RETX_FLASH.ld" --specs=nosys.specs -Wl,-Map="${BuildArtifactFileBaseName}.map" -Wl,--gc-sections -Wl,--verbose -static --specs=nano.specs -mfloat-abi=soft -mthumb -Wl,--start-group -lc -lm -Wl,--end-group

What can be wrong?

Thanks in advace,


Solution

  • I would have hoped this was obvious, but you need -mcpu=cortex-m0plus (or -march=armv6-m).