Showing results for 
Search instead for 
Did you mean: 

Problems using FPU and GCC on STM32F3

Associate II
Posted on October 16, 2013 at 20:18


I'm currently working on a motor application where i need to perform some simple math but at a high rate (20khz). Unfortunately, for some reason the computation time is too long, and it is unable to keep up with the update rate. I measured the number of cycles for a simple line such as:

Angle = (float)(Count)*COUNT2ANGLE + THETA_ZERO;

Where COUNT2ANGLE andTHETA_ZERO are floating point constants (using defines). This line requires 200 cycles which is just way too long. Here is the disassembly of the line of code:

208 Angle = (float)(Count)*COUNT2ANGLE + THETA_ZERO;
08000d96: uxth r2, r0
08000d98: vmov s15, r2
08000d9c: vcvt.fu32 s0, s15
08000da0: vmov r0, s0
08000da4: bl 0x80004a4 <
08000da8: add r3, pc, #60 ; (adr r3, 0x8000de8 <
08000daa: ldrd r2, r3, [r3]
08000dae: bl 0x800054c <
08000db2: add r3, pc, #60 ; (adr r3, 0x8000df0 <
08000db4: ldrd r2, r3, [r3]
08000db8: bl 0x80001e8 <
08000dbc: bl 0x80009c0 <

What i don't understand is why are there calls to

__extendsfdf2 fd

, etc. which are floating point emulation functions? its seems the compiler is mixing soft and hard floating point instructions. Im using Atollic (GCC) with the the following compiling options:

-mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=gnu90 -DSTM32F30X -DUSE_STDPERIPH_DRIVER -I../src -I..\Libraries\CMSIS\Include -I..\Libraries\CMSIS\Device\ST\STM32F30x\Include -I..\Libraries\STM32F30x_StdPeriph_Driver\inc -I''C:\cvs_projects\Roboteq FOC\Firmware\Brushless_FOC\FreeRTOS 7.5.2\inc'' -I''C:\cvs_projects\Roboteq FOC\Firmware\Brushless_FOC\inc'' -I''C:\cvs_projects\Roboteq FOC\Firmware\Brushless_FOC\Drivers\inc'' -O3 -ffunction-sections -fdata-sections -g -Wall

Anyone know if there indeed something wrong, and if so, how to fix it? Thanks, Alex
Posted on October 16, 2013 at 20:29

Where  COUNT2ANGLE and THETA_ZERO are floating point constants (using defines).


But how are they defined, Perhaps as doubles, and not as floats? ie 1.23f

The FPU only helps if the math is done totally with floats, and the fairly basic arithmetic supported by the FPU.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Associate II
Posted on October 16, 2013 at 22:59

They were defined as doubles, correcting them as floats did the trick.