STM32/ARM Cortex-M3 HOWTO: Development under Ubuntu (Debian)

The float ld problem

First out I would like to thank Jakob Heiko for highlighting this problem that I will describe on this page.

When you start to use this toolchain, and tries to use the basic variable type float you will get some strange build problems. And that is what this page is about.

First let's do some basic calculations, using floats.

Filename: main.c

int main(void)
{
    while(1)
    {
        float x = 42;
        float y = 23;
        float z = 7;
        int i = 0;
        for ( i = 0; i < 6; i++ ) {
            z = (x*y)/z;
        }
    }
}

However when you try to build it you will probably get this error that looks something like this:

main.o: In function `main':
/home/cj/stm32/stm32_ld_float/main.c:10: undefined reference to `__aeabi_fmul'
/home/cj/stm32/stm32_ld_float/main.c:10: undefined reference to `__aeabi_fdiv'
make: *** [main.elf] Error 1

The basic problem is that you are supposed to use arm-none-eabi-ld to link your code, but for some reason in this case ld can't this...

So the solution for now is to use gcc as a frontend for ld, and the easiest way is to modify the Makefile from:

LD      = arm-none-eabi-ld -v

to:

LD      = arm-none-eabi-gcc

Filename: Makefile

CC      = arm-none-eabi-gcc
LD      = arm-none-eabi-gcc 
AR      = arm-none-eabi-ar
AS      = arm-none-eabi-as
CP      = arm-none-eabi-objcopy
OD      = arm-none-eabi-objdump
  
CFLAGS  =  -I./ -c -fno-common -O0 -g -mcpu=cortex-m3 -mthumb  
AFLAGS  = -ahls -mcpu=cortex-m3 -mthumb 
LFLAGS  = -Tstm32.ld -nostartfiles
CPFLAGS = -Obinary
ODFLAGS = -S

all: test

clean:
	-rm main.lst main.o main.elf main.bin startup_stm32f10x.lst startup_stm32f10x.o

test: main.elf
	@ echo "...copying"
	$(CP) $(CPFLAGS) main.elf main.bin
	$(OD) $(ODFLAGS) main.elf > main.lst

main.elf: main.o startup_stm32f10x.o stm32.ld  
	@ echo "..linking"
	$(LD) $(LFLAGS) -o main.elf main.o startup_stm32f10x.o

main.o: main.c
	@ echo ".compiling"
	$(CC) $(CFLAGS) main.c

startup_stm32f10x.o: startup_stm32f10x.s
	@ echo ".assembling"
	$(AS) $(AFLAGS) -o startup_stm32f10x.o startup_stm32f10x.s > startup_stm32f10x.lst
Fatal error: Uncaught Error: Call to a member function link_ext() on null in /customers/9/b/5/fun-tech.se/httpd.www/stm32/class.page.php:62 Stack trace: #0 /customers/9/b/5/fun-tech.se/httpd.www/stm32/OlimexBlinky/ld_float.php(76): page->getFoot() #1 {main} thrown in /customers/9/b/5/fun-tech.se/httpd.www/stm32/class.page.php on line 62