Problem with float types math

Go To Last Post
4 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I am programming SAMS70 in Atmel Studio 7.0. I got stuck on a problem with float types math operation.
Simple operation like this 

float value = 0.0;
value = value + 1.0;

send me to the hard fault. Any math operation with float will do so.
I am using this math library: Toolchain->ARM/GNU Linker->Libraries->libarm_cortexM7lfsp_math_softfp
and this flags: Toolchain->ARM/GNU C Compiler->MIscellaneous->-mfloat-abi=softfp -mfpu=fpv5-sp-d16

I have no idea why this simple operation send me to the hard fault.
Have you also encountered this problem too?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I ran into this as too and struggled for an embarrassingly long time.  The solution is to send the floating point unit flags to both the compiler and linker.  In your case add "-mfloat-abi=softfp -mfpu=fpv5-sp-d16" under ARM/GNU Linker->Miscellaneous->Linker Flags.

 

And if you want to enable floating point support via printf/scanf while still using the size optimized library (--specs=nano.specs), add "-u _printf_float -u _scanf_float" to the linker flags as well.  Otherwise when using the nano-lib a printf call with "%f" will be ignored (nothing is sent to stdout).

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I tried to add these flags to ARM/GNU Linker->Miscellaneous->Linker Flags, but the result is still the same (hard fault).

Math operations with double types work well and math operations with float types causes hard fault.

I can not understand that. Any other advice?

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Try dropping the explicitly specified library libarm_cortexM7lfsp_math_softfp.  The compiler/linker flags for -mfloat-abi= and -mfpu= should tell the toolchain to pull in the correct libraries.  I'm also using the nano.spec option.