Figured this was probably the best place to post this as it relates to the packaged toolchain from the Debian repository.
I'm in the process of developing some firmware for a device based on an ARM Cortex-M0 processor (specifically the STM32F051), to do this I'm using the gcc-arm-none-eabi toolchain from the Debian Jessie repo. My toolchain/build environment is up and working a this stage but I've run into some snags.
The Cortex-M0 only supports thumb instructions, however it appears that the linker is pulling in the ARM version of (presumably) newlib.
Any usercode I write is fine until the point that it calls out, at which point my processor HardFaults. Backtracing I always find that the cause of the HardFault is due to a call to an __aeabi_<somefunc>_from_thumb api, looking at the disassembly around the area of the code in question, it appears to be a stub to switch instruction mode to ARM and call an ARM function, which of course doesn't work on a thumb-only processor.
- Code: Select all
8001798: 4778 bx pc
800179a: 46c0 nop ; (mov r8, r8)
800179c: eafffa48 b 80000c4 <__aeabi_uidiv>
It seems that rather than pulling in the thumb versions of newlib it's pulling in ARM code instead.
My CFLAGS are;
-mlittle-endian -mcpu=cortex-m0 -march=armv6-m -mthumb -Wall -g -O0 -mfloat-abi=soft -ffunction-sections -fdata-sections -ffreestanding -nostdlib --specs=nano.specs
My LDFLAGS are;
-Wl,--gc-sections,-Map=$@.map,-cref $(INCLUDE_DIRS) $(LIBRARY_DIRS) -T stm32.ld
-I . -I $(PERIPH_LIB_PATH)$(PERIPH_DRIVER_PATH)inc -I $(PERIPH_LIB_PATH)CMSIS/Include
-L . -L $(PERIPH_LIB_PATH)$(PERIPH_DRIVER_PATH)src -L linker
PERIPH_LIB_PATH just points to the ST Micro provided Peripherals Library.
Initially I wondered if it was because there were no architecture specific libs under /usr/lib/arm-none-eabi/newlib i.e. no armv6-m directory there, so I pulled in Jessie Backports because the 4.9.4 package there did have an armv6-m directory in the lib tree, this doesn't appear to have made any difference, I also tried explicitly adding the armv6-m directory to my LIBRARY_DIRS, again no change.
I'm very new to this whole cross-compiling malarkey so it's entirely possible I'm just doing something stupid.
Any assistance would be greatly appreciated.