cancel
Showing results for 
Search instead for 
Did you mean: 

Double Calculations causing hard fault

pisaacs9
Associate II
Posted on March 07, 2013 at 07:23

Hi,

Im trying to do some calculations on a STM32F4 discovery board and I keep getting hard faults when I try to run the code. The is being ported over from a PC application but the lines that are causing the issues are simple multiplications.

One of the lines

double phi = aircraftRotation[0] * PI/180.0;

aircraftRotation[0] = 0.0

PI = 3.141592654;

I have stepped through the assembly for this line of code and the assembly that its crashing on is the multiplcation

BL __aeabi_dul 

Im using IAR and the code is C++, is there anything I can do to fix this?

Thanks

Phil
3 REPLIES 3
frankmeyer9
Associate II
Posted on March 07, 2013 at 09:04

I assume you want to use the FPU, and trying to compile your code for FPU usage.

Note that by default, the FPU, as any coprocessor, is not enabled. It needs to be enabled explicitly in the code. In other IDE's, that part is located in the startup code, and is usually only included when defining a macro like _USE_FPU.

I don't know IAR in this regard, you might need to check yourself

Posted on March 07, 2013 at 16:26

The FPU doesn't support doubles

A Hard Fault handler should be able to determine the instructions causing the fault. Look at the stacked context, and registers, then look at the surrounding instructions against that context.

If the FPU and instructions are used the FPU *MUST* be enabled, this is typically done in the SystemInit() function or ResetHandler. Failure to do so will cause a Hard Fault as soon as those instructions are encountered.

Other frequent causes of Hard Fault are touching memory inappropriately, or attempting to run ARM 32-bit code, often in external libraries.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
pisaacs9
Associate II
Posted on March 08, 2013 at 02:19

Thanks guys, I wasnt explicitly trying to use the FPU, the compiler decided I wanted to use it.

I have changed all the doubles to floats and enabled the FPU and now everything works, thanks.