cancel
Showing results for 
Search instead for 
Did you mean: 

Float value gives hard fault in STMCubeIDE

赵静.1
Associate

Dear All:

I want to use the FPU module in STM32F407,But how can i use it in STM32Cubeide?

and i use UCOS_III.

If I define a floating point data,when i use this data,it will be case HardFault.

add the lib

0693W000001sIopQAE.png

open the FPU0693W000001sIpJQAU.png

define __VFP_FP__0693W000001sIpTQAU.png

but in SystemInit FPU Settings cannot be performed

0693W000001sIr0QAE.png

because in core_cm4.h, __SOFTFP__ is defined ,but i can't find where __SOFTFP__defined

0693W000001sIsYQAU.png

and another question,in startup_stm32f407xx.s file,

 .syntax unified

 .cpu cortex-m4

 .fpu softvfp

 .thumb

i set the Floating-point ABI Hardware ,why .fpu=softvfp?

1 REPLY 1
KnarfB
Principal III

I have a STMF446, not exactly the same as you. Few comments:

.syntax unified
 .cpu cortex-m4
 .fpu softvfp
 .thumb

This is only valid for assembler code withtin startup_stm32f407xx.s - no problem.

> but in SystemInit FPU Settings cannot be performed

Are you sure? Set a breakpoint and try it out. The code lines are grayed out, but this is because the IDE cannot deduce the correct settings because __VFP_FP__ and __SOFTFP__ are predefined by gcc (depending on settings).

For me, if I write some test code in main:

#if __FPU_USED==1
	volatile float a = 1.0;
	volatile float b = a*a;
	volatile float c = asin(b);
#endif

the test code is executed (despite being grayed out by the IDE) and works.

Build log (compile step):

...

arm-none-eabi-gcc "../Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.c" -mcpu=cortex-m4 -std=gnu11 -g3 -DUSE_HAL_DRIVER -DSTM32F446xx -DDEBUG -c -I../Drivers/CMSIS/Include -I../Drivers/STM32F4xx_HAL_Driver/Inc -I../Core/Inc -I../Drivers/CMSIS/Device/ST/STM32F4xx/Include -I../Drivers/STM32F4xx_HAL_Driver/Inc/Legacy -O0 -ffunction-sections -fdata-sections -Wall -fstack-usage -MMD -MP -MF"Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.d" -MT"Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.o" --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -o "Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.o"

...

Build log (link step):

arm-none-eabi-gcc -o "STM32F446RE_float.elf" @"objects.list"  -mcpu=cortex-m4 -T"...\STM32F042K6\projects\STM32F446RE_float\STM32F446RETX_FLASH.ld" --specs=nosys.specs -Wl,-Map="STM32F446RE_float.map" -Wl,--gc-sections -static --specs=nano.specs -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mthumb -u _printf_float -u _scanf_float -Wl,--start-group -lc -lm -Wl,--end-group

Everything seems okay.