Electronic – Error when compiling start-up file on STM32


I am attempting to provide custom interrupt handlers for my Cortex M3 (reference manual here). ST kindly provides a standard library, which has various startup files all called "startup_stm32f2xx.s". Each is in a different folder according to IDE.

Now I do not use an IDE (I compile directly with Yagarto, a modified version of the gcc toolchain). I have already asked which of the start-up to use. However, having now tried all the available startup files, I always get the same error:

/startup_stm32f2xx.s:1:0: error: target CPU does not support ARM mode

A quick Google search reveals that this probably means that the assembler code has instructions that my ARM cannot understand, which is surprising given that the code was provided for my board.

How can I compile the startup file that defines the interrupt vector on my STM32?

Edit: In each of the files, startup_stm32f2xx.s:1:0 is the beginning of a comment. Also, I'm using the flag -mcpu=cortex-m3. Here is the complete error message:

$ make all
arm-none-eabi-gcc -x assembler-with-cpp -c -g -mcpu=cortex-m3 -gdwarf-2 -Wa,-amhls=startup_stm32f2xx.lst   startup_stm32f2xx.s -o startup_stm32f2xx.o
startup_stm32f2xx.s:1:0: error: target CPU does not support ARM mode
makefile:46: recipe for target `startup_stm32f2xx.o' failed
make: *** [startup_stm32f2xx.o] Error 1

Best Answer

You may also need -mthumb -mno-thumb-interwork -mfpu=vfp -msoft-float -mfix-cortex-m3-ldrd as compiler options for arm-none-eabi-gcc. For the assembler, use -mcpu=cortex-m3 -mthumb as options.


The -mthumb switches gcc and the assembler into "thumb" mode - they will generate arm mode instructions per default, which do not work on Cortex M3.

Since there is no ARM mode, we don't need ARM/Tumb interworking, thus -mno-thumb-interwork.

The compiler needed -mfpu=vfp -msoft-float for floating point support. Cortex M3 has no hardware floating point AFAIK, at least I am not aware of any silicon that has both Cortex M3 and floating point in hardware. There are some Cortex M4 that have.

Most Cortex M3 need -mfix-cortex-m3-ldrd, this is in the errata documentation for the Cortex M3 core versions.

For more info see GCC Documentation and ARM infocenter.