psas / stm32

PSAS STM32F4xx firmware development.
30 stars 20 forks source link

Change build to turn ON FPU by default #18

Closed kwilsonpdx closed 10 years ago

kwilsonpdx commented 10 years ago

The STM32F4 has a very nice FPU...this option appears to be turning it off:

-DCORTEX_USE_FPU=FALSE

ThirteenFish commented 10 years ago

I'm not sure we want to? None of our projects currently use the FPU and turning it on, among other things, adds overhead to thread context switches (See ChibiOS/os/ports/ARMCMx/chcore_v7m.c _port_switch()).

That said, if we have projects that want floating point we should absolutely remember to turn it on. The option is setting USE_FPU to yes on line 47 of the project makeflies. Setting that brings in -DCORTEX_USE_FPU=TRUE -mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant which looks right except maybe we want -mfloat-abi=hard instead.

kwilsonpdx commented 10 years ago

From the Cortex-M4 Technical Reference Manual: VPUSH number of cycles is: 1+N, where N is the number of registers and VPOP is the same

So the cost is 34 cycles every thread switch. At 168Mhz thats...6ns*34 = 204nS

I'd rather leave it ON by default but if none of our applications are using FP then I guess it doesn't really matter.

From chcore_v7m.c:

240 #if CORTEX_USE_FPU
241   asm volatile ("vpush   {s16-s31}" : : : "memory");
242 #endif
243 
244   asm volatile ("str     sp, [%1, #12]                          \n\t"                                           
245                 "ldr     sp, [%0, #12]" : : "r" (ntp), "r" (otp));
246 
247 #if CORTEX_USE_FPU
248   asm volatile ("vpop    {s16-s31}" : : : "memory");
249 #endif
ThirteenFish commented 10 years ago

We discussed this issue at the meeting and and arrived upon the best solution to this being having our build tools generate a warning or a message if it's actually generating any soft float code. This way the developer would be reminded to set USE_FPU when needed.

Unfortunately it's not immediately obvious how to get GCC to do this for us.

ThirteenFish commented 10 years ago

We're not going to make the build tool changes before the next launch so I'm closing this for now. It can be reopened later.