cancel
Showing results for 
Search instead for 
Did you mean: 

Using "double" on STM32F407 make it crach

ANauz.1
Senior II

Hello,

I just created a new project on CubeMX for a STM32F407G-Disc1. I'm working with last version of MX, firmware.

The project is configured to build with Makefile.

Have a double variable modification causes a MCU HardFault_Handler to trigger.

Any idea why the default project do not allow to use double?

Thank you

6 REPLIES 6
ANauz.1
Senior II

When MX is configured for STM32CubeIDE compilation, it is working.

I will have a look at configuration, but if you have any idea...

Thank you

Pavel A.
Evangelist III

Have you modified the generated makefile ?

Watch for unaligned pointers or structures, say files, or data on a comms link.

The LDRD / STRD will fault on unaligned addresses.

Look at the instructions/code that's actually faulting

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

Do you really need "double" vs "float" which maybe HW float co-pro ?

Otherwise, maybe the double math library is conflict with float ?

Danish1
Lead II

Double uses twice as much memory as float. It could be that you’ve run out of memory, perhaps on the stack, particularly if you’re using an array of what are now doubles.

Ghofrane GSOURI
ST Employee

Hello @ANauz.1​ 

First let me thank you for posting.

If modifying a double variable causes a HardFault_Handler to trigger in your STM32F407G-Disc1 MCU, it's possible that there is an issue with how the double variable is being used or accessed in your code. Here are some possible causes of this issue:

  1. Invalid memory access: Modifying a double variable may require accessing a memory location that is not valid or is outside the bounds of the allocated memory space. This can cause a Hard Fault. Make sure that your code is properly allocating and accessing memory.
  2. Alignment issues: The ARM Cortex-M4 processor used in the STM32F407G-Disc1 requires 32-bit aligned memory access for double precision floating-point values. If your code tries to access a double variable with an unaligned memory address, a Hard Fault can occur. Make sure that your double variables are properly aligned.
  3. Compiler options: The Hard Fault may also be caused by incorrect compiler settings or options. Make sure that your project settings are configured correctly to support the use of doubles.
  4. Insufficient memory: If the MCU is running low on memory, it may cause a Hard Fault when trying to modify a double variable. Make sure that your code is not consuming too much memory and that there is enough memory available for the MCU to operate properly.

Thx

Ghofrane