user3583807
user3583807

Reputation: 800

cortex-m3 fpu instruction hard fault

My firmware for stm32f103 results in hard fault. Here is the line of code that crash execution:

 float shuntResistance = p[SHUNT_RESISTANCE];

where p - is global array of floats:

float p[CONFIG_NUM_PARAMS];

There is dissaembly while debugging:

0800177c:   ldr r3, [pc, #332]      ; (0x80018cc <adcSetConstants+336>)
0800177e:   vldr s10, [r3, #48]     ; 0x30 ; on that instruction program results in hard fault

Here is compiler flags:

-c -fmessage-length=0 -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp -ffunction-sections -fdata-sections -fsingle-precision-constant

Linker flags:

-Wl,--static,--gc-sections,-Map=${ProjName}.map,-T../stm32_flash.ld -fmessage-length=0 -mthumb -mcpu=cortex-m3 -ffunction-sections -fdata-sections -fsingle-precision-constant -Dprintf=iprintf -u _printf_float -lc -lnosys -lc

Used compiler is launchpad's arm-none-eabi-gcc. Used IDE is eclipse. What is the cause?

Upvotes: 1

Views: 2151

Answers (1)

Turbo J
Turbo J

Reputation: 7711

Here is compiler flags:

-c -fmessage-length=0 -mthumb -mcpu=cortex-m3 -mfloat-abi=softfp

Your MCU is a Cortex M3, which has no FPU. You need to use -mfloat-abi=soft. The "softfp" option uses FPU instructions which will not work for you.

Upvotes: 2

Related Questions