FPU on F407 - how to

Limited support for STM32F4 Discovery, Nucleo and custom F4 boards
User avatar
Pito
Posts: 815
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: FPU on F407 - how to

Postby Pito » Fri Apr 21, 2017 12:05 pm

Updated the first post.
@407 experts and users: do start using the FPU and do publish your findings here in this thread. After gathering practical experience we will update.
Happy FPUing :)
Pukao Hats Cleaning Services Ltd.

User avatar
Rick Kimball
Posts: 754
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: FPU on F407 - how to

Postby Rick Kimball » Fri Apr 21, 2017 12:18 pm

edogaldo wrote:I'd also suggest to put this in function "init()" of "boards.c".


I'd put it in the reset interrupt hander code, before any constructors are ever called. To be safe you want to make sure it is called
before any of the __preinit_array functions are called. Right after the BSS sections has been zeroed would be a great place.

Probably right here:

https://github.com/stevstrong/Arduino_S ... rt_c.c#L82
-rick

edogaldo
Posts: 213
Joined: Fri Jun 03, 2016 8:19 am

Re: FPU on F407 - how to

Postby edogaldo » Fri Apr 21, 2017 12:30 pm

Rick Kimball wrote:
edogaldo wrote:I'd also suggest to put this in function "init()" of "boards.c".


I'd put it in the reset interrupt hander code, before any constructors are ever called. To be safe you want to make sure it is called
before any of the __preinit_array functions are called. Right after the BSS sections has been zeroed would be a great place.

Probably right here:

https://github.com/stevstrong/Arduino_S ... rt_c.c#L82

It can be fine as well but why in variants?!
Is there any F4 where this makes no sense at all?!

I'd put it here: https://github.com/stevstrong/Arduino_S ... ds.cpp#L54

User avatar
Rick Kimball
Posts: 754
Joined: Tue Apr 28, 2015 1:26 am
Location: Eastern NC, US
Contact:

Re: FPU on F407 - how to

Postby Rick Kimball » Fri Apr 21, 2017 12:53 pm

edogaldo wrote:It can be fine as well but why in variants?!

I didn't put the reset function in the variant. That is just where it seems to be. Myself, I'd move the start up code to the core directory.



Unfortunately, calling it in init() doesn't guarantee that it will be called before any of the _pre_init constructors.
-rick

edogaldo
Posts: 213
Joined: Fri Jun 03, 2016 8:19 am

Re: FPU on F407 - how to

Postby edogaldo » Fri Apr 21, 2017 1:47 pm

Rick Kimball wrote:Unfortunately, calling it in init() doesn't guarantee that it will be called before any of the _pre_init constructors.

You are right, I confused the execution order, then I agree that probably the best place is where you said.
About the startup code, I think it would need a significant review..

@Pito: wherever you want to put the check, using the standard GCC declarations __GNUC__, __VFP_FP__ and __SOFTFP__ keeps consistency between the compilation options and the code avoiding the risk to use inconsistent combinations (i.e. WITH_FPU=1 and -mfloat-abi=soft or worst WITH_FPU=0 (or not defined) and -mfloat-abi=softfs/hard) which could cause hard faults..

Furhermore, I modified both platform.txt and boards.txt:
- in platform.txt I applied these changes:

Code: Select all

build.fpu_flags=
...
recipe.c.o.pattern=[...]{build.extra_flags} {build.fpu_flags}[...]
recipe.cpp.o.pattern=[...]{build.extra_flags} {build.fpu_flags}[...]
recipe.c.combine.pattern=[...]{build.extra_flags} {build.fpu_flags}[...]

- in boards.txt I added a sub-menu to select the fpu options:

Code: Select all

menu.device_variant=Variant
...
discovery_f407.menu.device_variant.SkipFPU=SkipFPU
discovery_f407.menu.device_variant.SoftFPU=SoftFPU
discovery_f407.menu.device_variant.SoftFPU.build.fpu_flags=-mfloat-abi=softfp -mfpu=fpv4-sp-d16 -fsingle-precision-constant
discovery_f407.menu.device_variant.HardFPU=HardFPU
discovery_f407.menu.device_variant.HardFPU.build.fpu_flags=-mfloat-abi=hard -mfpu=fpv4-sp-d16 -fsingle-precision-constant

this is how it appers:
Untitled.jpg
Untitled.jpg (70.62 KiB) Viewed 65 times

User avatar
Pito
Posts: 815
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: FPU on F407 - how to

Postby Pito » Fri Apr 21, 2017 3:25 pm

FYI
-Os, -g, 4.8.3-2014q1, Maple Mini, No FPU, 72MHz

Code: Select all

Numerical Integration Benchmark starts..
Single Precision with No FPU, v1.0

F1 Result: 0.00671211394423041159587
leftrect  num: 6.720000e-3 ana: 6.712139e-3
righrect  num: 6.705780e-3 ana: 6.712139e-3
midrect   num: 6.712879e-3 ana: 6.712139e-3
trapezium num: 6.712058e-3 ana: 6.712139e-3
simpson   num: 6.712050e-3 ana: 6.712139e-3

F2 Result: -0.00261227114510560413684
leftrect  num: -2.613795e-3 ana: -2.612248e-3
righrect  num: -2.613944e-3 ana: -2.612248e-3
midrect   num: -2.613871e-3 ana: -2.612248e-3
trapezium num: -2.612268e-3 ana: -2.612248e-3
simpson   num: -2.612271e-3 ana: -2.612248e-3

F3 Result: 0.28247911095899395473
leftrect  num: 2.825554e-1 ana: 2.824790e-1
righrect  num: 2.824033e-1 ana: 2.824790e-1
midrect   num: 2.824792e-1 ana: 2.824790e-1
trapezium num: 2.824792e-1 ana: 2.824790e-1
simpson   num: 2.824791e-1 ana: 2.824790e-1

F4 Result: 0.660105195382224847535
leftrect  num: 6.603576e-1 ana: 6.601052e-1
righrect  num: 6.598577e-1 ana: 6.601052e-1
midrect   num: 6.601063e-1 ana: 6.601052e-1
trapezium num: 6.601086e-1 ana: 6.601052e-1
simpson   num: 6.601073e-1 ana: 6.601052e-1

Benchmark ends, elapsed 23992225 microsecs..

23.9secs against 617msecs (407 with -O3 settings @240MHz)..

@edogaldo: yes your boards.txt mod is the way to go. I am using 1y old repo, which is a mess, so I will wait until guys consolidate the new F407 repo (current activity of victor, steve, ag123 and others). They may introduce the changes.
Also pls decide where to insert the enable fpu asm chunk.
Last edited by Pito on Fri Apr 21, 2017 5:43 pm, edited 4 times in total.
Pukao Hats Cleaning Services Ltd.

ag123
Posts: 312
Joined: Thu Jul 21, 2016 4:24 pm

Re: FPU on F407 - how to

Postby ag123 » Fri Apr 21, 2017 4:44 pm

actually it just show that stm32f4 + ART accelerator + fpu + -fsingle-precision-constant + float specific math lib function + -O2 optimization + overclock is real rocket fuel (and that's not yet adding hardware fpu compiled math lib functions) :lol:
but to leave something for the stm32 f1 users i'd suggest we have about 15-20secs for the f1 users
and we'd need to use micros() for timing, the ultimate would be when we've the loops complete in under 1usecs, we can then try to compete with the supercomputers :D

User avatar
Pito
Posts: 815
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: FPU on F407 - how to

Postby Pito » Fri Apr 21, 2017 5:23 pm

Ok I will change back to 10000 steps, and the measurement will be in usecs.
I only wanted to show to F1 users they system is really slow :lol:
Pukao Hats Cleaning Services Ltd.

ag123
Posts: 312
Joined: Thu Jul 21, 2016 4:24 pm

Re: FPU on F407 - how to

Postby ag123 » Fri Apr 21, 2017 5:28 pm

Rick Kimball wrote:
Unfortunately, calling it in init() doesn't guarantee that it will be called before any of the _pre_init constructors.


hi rick,
my thoughts are that calling it within init() is adequate for the purpose
in fact i'm somewhat worried if enabling the fpu may caused unexpected behaviours for sketches that after all do not use the fpu, e.g. unexpected hard faults for sketches which use little or no floating point (they might be embedded in libraries for all we know)

one of those things that's probably related to fpu is the interrupt hook __irq_FPU_IRQHandler
i noted that currently vector_symbols.inc did not declare an extern for EXTERN(__irq_FPU_IRQHandler)
but stm32_isrs.S has them and stm32_vector_table.S has them defined
i'm currently still not familiar with the interrupts / nvic etc and i'm not sure what else might be missing for the f4. i'd think for 'proper' usage of fpu, it may be necessary for the users to implement __irq_FPU_IRQHandler() as well as it seem that would be used to handle floating point errors

just 2 cents
Last edited by ag123 on Fri Apr 21, 2017 5:35 pm, edited 2 times in total.

edogaldo
Posts: 213
Joined: Fri Jun 03, 2016 8:19 am

Re: FPU on F407 - how to

Postby edogaldo » Fri Apr 21, 2017 5:29 pm

Pito wrote:Ok I will change back to 10000 steps, and the measurement will be in usecs.
I only wanted to show to F1 users they system is really slow :lol:

What should say Arduino 8-bit users?!


Return to “STM32F4 Boards”

Who is online

Users browsing this forum: No registered users and 1 guest