cancel
Showing results for 
Search instead for 
Did you mean: 

Very odd FLOP issue

max239955
Associate II
Posted on July 25, 2016 at 23:00

So I'm currently working on two different STM32F4 boards for two different projects, which share some code between them. These are the F407 disco and F429disco.

I recently had to switch to the GCC compiler for both projects due to Keil uVision's code size limit. Using the same code on both devices (only changes being clock periods due to clock rate differences), I am getting very different results for the very simplest of operations:

t.durationSeconds = (
double
)t.duration / 1000000.0f;

duration is a uint32_t and is giving the correct value (just under 1,000,000 us for a 1 second test). durationSecondsis a double and gives either -2.0000 or -0.0000. This is only on the F407 - the F429 gives a fraction just below 1.0000 as the very basic maths suggests. I AM SO CONFUSED. All 'debugging' is done via UART since it's not possible to debug using the GCC compiler within Keil (I think?). Any ideas guys (clive)? 🙂 #flops-stm32f4-timing-discovery
4 REPLIES 4
Posted on July 26, 2016 at 00:47

The Keil debugger works with GNU/GCC objects in my experience, but will have size limits.

Don't use float constants to do double math. The FPU is only usable for 32-bit floats.

Create a minimal project that demonstrates the failure.

Review library and command line options that differ between the F407 vs F429 builds. Linking for a large memory foot-print, and using a fast PLL setting alone should not account for differences in floating point results.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
mark239955_stm1
Associate II
Posted on July 29, 2016 at 12:25

iirc Keil won't let you debug if you exceed their code size regardless of how you compiled the binary, so bypass Keil and use a more friendly free environment like

http://timor.atollic.com/resources/downloads/

, which is GCC-based anyway and lets you debug any code size in an M4.

troy1818
Senior
Posted on July 29, 2016 at 19:55

Dont know if it will make any difference at all but I would write something like this:

t.durationSeconds = (
double
)t.duration / (double)1000000;
Posted on July 29, 2016 at 22:24

It is hard to get much context from a single line of code.

1000000.0  would be encoded as a double

* 1e-6 might be more efficient.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..