Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20702 Discussions

using the FPU on Cortex A9

Altera_Forum
Honored Contributor II
2,972 Views

Hello, 

 

I'm trying to use the FPU in my baremetal project.  

 

I use the ARM DS-5 (altera edition) with the DS5-GCC. 

 

I try to compile a simple project with the following options:  

-mfloat-abi=hard -mfpu=vfpv3-d16-fp16 -ftree-vectorize -ffast-math -march=armv7-a -mtune=cortex-a9 -mcpu=cortex-a9 

 

The output is always something like this: 

 

gcc version 4.6.3 (Sourcery CodeBench Lite 2012.03-56) arm-none-eabi-g++ -Taltera-socfpga-hosted.ld -g -O0 -mfloat-abi=hard -mfpu=vfpv3-d16-fp16 -ftree-vectorize -ffast-math -march=armv7-a -mtune=cortex-a9 -mcpu=cortex-a9 -Werror -Wall -Wstrict-prototypes hello.o -o hello.axf c:/altera/13.1/embedded/host_tools/mentor/gnu/arm/baremetal/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/bin/ld.exe: error: hello.o uses VFP register arguments, hello.axf does not c:/altera/13.1/embedded/host_tools/mentor/gnu/arm/baremetal/bin/../lib/gcc/arm-none-eabi/4.6.3/../../../../arm-none-eabi/bin/ld.exe: failed to merge target specific data of file hello.o collect2: ld returned 1 exit status make: *** Error 1 

 

Ok, the message let me know, that at least one library (may be i.e. libc...) is not linked for hard floatingpoint.  

Maybe there is generally no hardware-floatingpoint support by the delivered DS5-GCC compiler/toolchain?  

Normally the Codesourcery Lite only supports software-floatingpoint and only the standard and professional versions have hardware floatingpoint support. 

 

using the flag -mfloat-abi=softfp doesn't work for me. In this case all floating point operation will be done by software and that's to slow. 

 

Does anyone know, how to get it work?
0 Kudos
10 Replies
Altera_Forum
Honored Contributor II
1,540 Views

I found Bare metal example in altera\13.1\embedded\ds-5\examples\bare-metal_boards_examples.zip and when I added simple code to test how compiler interprets operations on doubles: 

 

double a = 5.211312; double b = 12.2131; b = b + 1232.21321;  

 

Disassembly looks like this: 

 

S:0xFFFF00D4 : VMOV.F64 d9,d0 S:0xFFFF00D8 : VLDR d0, S:0xFFFF00DC : VMOV.F64 d8,d0 S:0xFFFF00E0 : VLDR d0, S:0xFFFF00E4 : VADD.F64 d0,d8,d0 S:0xFFFF00E8 : VMOV.F64 d8,d0 S:0xFFFF00EC : VMUL.F64 d1,d9,d8 S:0xFFFF00F0 : VMOV.F64 d0,d1 S:0xFFFF00F4 : VMOV r2,r3,d0  

 

You can see that complier uses FPU instructions. 

 

 

If you want to test it on your code, compiler has following settings: 

armcc --c99 -O0 --cpu=Cortex-A9 -g -c -o"hello.o" "../hello.c"
0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

Hi, 

 

you are using the arm compiler, not the gcc.  

The armcc works, I know. But I want a gcc solution.
0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

Sorry, I didn't read your post carefully enough.

0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

The arm calling convertions for sotf-float and hard-float differ so the entire system has to be built for soft-float or hard-float. 

It is possible to use a soft-float library that uses the hard-fp instructions (dunno where you'd find one).
0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

Hi, 

 

I switched to the armcc compiler now. HardFP works fine in the hello world sample project. 

Now I want to get it run in a larger project. But there are some problems. 

 

- Compilation works. 

- I can load the Programm 

- Execution fails 

 

The project uses a Preloader, to initialize Hardware and RAM.  

The Execution of the Preloader was successfull, but when the main application is loaded, the execution fails (near the entry point). 

 

Now the question, does the preloader also have to be compiled with hard floating point support? 

The effect can be easily reproduced, if you take the sample project Altera-SoCFPGA-HardwareLib-16550-CV-ARMCC and compile it with hard-fpu support. 

 

Any advices?
0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

Hi, 

 

ok, my mistake, I found the solution, why the code crashed... 

I had to initialize the FPU before the initialization of the ARM C Library...
0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

Hi, 

 

Please help me to update my project for hardware floating point. 

 

my make file is like this: 

//====================================== 

 

 

SOCEDS_ROOT ?= $(SOCEDS_DEST_ROOT) 

HWLIBS_ROOT = $(SOCEDS_ROOT)/ip/altera/hps/altera_hps/hwlib 

 

HWLIBS_SRC :=  

EXAMPLE_SRC := hello.c io.c  

C_SRC := $(EXAMPLE_SRC) $(HWLIBS_SRC) alt_fpga_manager.c alt_bridge_manager.c alt_clock_manager.c i2c.c cascade_header.c  

 

LINKER_SCRIPT := cycloneV-dk-ram-modified.ld 

 

MULTILIBFLAGS := -mcpu=cortex-a9 -mfloat-abi=softfp -mfpu=neon-fp16 

CFLAGS := -g -O0 -Wall -Werror -std=c99 $(MULTILIBFLAGS) -I$(HWLIBS_ROOT)/include 

LDFLAGS := -T$(LINKER_SCRIPT) $(MULTILIBFLAGS) 

 

CROSS_COMPILE := arm-altera-eabi- 

CC := $(CROSS_COMPILE)gcc 

LD := $(CROSS_COMPILE)g++ 

OC := $(CROSS_COMPILE)objcopy 

MKIMAGE := mkimage 

RM := rm -rf 

CP := cp -f 

 

ELF ?= $(basename $(firstword $(C_SRC))).axf 

OBJ := $(patsubst %.c,%.o,$(C_SRC)) 

BIN = $(basename $(firstword $(C_SRC))).bin 

IMG = $(basename $(firstword $(C_SRC)))-mkimage.bin 

 

.PHONY: all 

all: $(BIN) $(ELF) $(IMG) $(SPL) 

 

.PHONY: clean 

clean: 

$(RM) $(ELF) $(HWLIBS_SRC) $(OBJ) $(BIN) $(IMG) 

 

%.c: $(HWLIBS_ROOT)/src/hwmgr/%.c 

$(CP) $< $@ 

 

$(OBJ): %.o: %.c Makefile 

$(CC) $(CFLAGS) -c $< -o $@ 

 

$(ELF): $(OBJ) 

$(LD) $(LDFLAGS) $(OBJ) -o $@ 

 

$(BIN): $(ELF) 

$(OC) -O binary $(ELF) $(BIN) 

 

$(IMG): $(BIN) 

$(MKIMAGE) -A arm -T standalone -C none -a 0x100040 -e 0 -n "baremetal image" -d $(BIN) $(IMG) 

 

//====================================== 

where I need to change ?? 

I have tried with hard in place of softfp and it gives me error in build project  

 

error is like this: 

//================= 

error: hello.o uses VFP register arguments, hello.axf does not 

//================= 

 

please help me as soon as possible  

Thanks in advance.
0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

Hi stefmaster, 

can u please let me know what I need to change to use hard mfpu in my design. 

whan I update my makefile like this: 

MULTILIBFLAGS := -mcpu=cortex-a9 -mfloat-abi=hard -mfpu=neon-fp16 

 

I got error that: 

hello.o uses VFP register arguments, hello.axf does not 

 

I am working on cyclone V soc with GCC compiler.
0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

is your gcc compiler is free one? i check the release note that only the paid version of compiler allowed to use the hard floating point.

0 Kudos
Altera_Forum
Honored Contributor II
1,540 Views

HI,  

Can anyone indicate the solution for the above problem? Since I am having the same problem and need to know how to solve it.  

When I set the -mfloat-abi to "hard" I get the error "AAA.o uses VFP register arguments, BBB.axf does not". I have read that the problem might be that part of the system is using soft-float ABI, but I don't know how I can solve it. 

Any help is greatly appreciated.
0 Kudos
Reply