2016-07-25 02:00 PM
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
2016-07-25 03:47 PM
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.2016-07-29 03:25 AM
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
, which is GCC-based anyway and lets you debug any code size in an M4.2016-07-29 10:55 AM
Dont know if it will make any difference at all but I would write something like this:
t.durationSeconds = (
double
)t.duration / (double)1000000;
2016-07-29 01:24 PM
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.