Skip to main content
ANauz.1
Senior
April 7, 2023
Question

Using "double" on STM32F407 make it crach

  • April 7, 2023
  • 6 replies
  • 1634 views

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

This topic has been closed for replies.

6 replies

ANauz.1
ANauz.1Author
Senior
April 7, 2023

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.
Super User
April 7, 2023

Have you modified the generated makefile ?

Tesla DeLorean
Guru
April 8, 2023

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 VenmoUp vote any posts that you find helpful, it shows what's working..
S.Ma
Principal
April 8, 2023

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 III
April 9, 2023

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
Technical Moderator
April 10, 2023

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

To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.