Am using Atmel Studio 7 to program my Atmel SAM E70 Xplained Development board.
Am unable to print floating point numbers.
printf("Float : %f",11.11);
Its output will be
Float : f
Don't know why.
Please Help.
Am using Atmel Studio 7 to program my Atmel SAM E70 Xplained Development board.
Am unable to print floating point numbers.
printf("Float : %f",11.11);
Its output will be
Float : f
Don't know why.
Please Help.
It also gives strange results while multiplying a floating point number.
11*2
gives
22
And
11.0*2
gives
13
I wonder what is happening.
Have you selected print with floating point options? You get a choice as to what features you want with printf to optimise size.
How to do that?
Hi, Please tell me how to get those floating point variable working.
Hi, Please let me know how to enable this option.
10 seconds of googling:
http://community.atmel.com/forum/samc21-printf-not-printing-float-values
I'm staggered that you waited over a week for me to google the answer for you! The keywords were: atmel studio printf float
I have already done these stuffs before.
But t didn't work for me.
"didn't work" - it's hard to move forward with that response. What precisely did you do and what "didn't work".
So far, this is what I have come to know.
Someone from Atmel asked me to following steps in my project to get floating point working.
1. Include
#include "arm_math.h"
in ‘main.c’ file.
2.Enable FPU unit -> call
fpu_enable()
function in main() in main.c
3. In Atmel Studio
Project -> ProjectName Properties … -> Toolchain -> ARM/GNU C Compiler -> Symbols
Please ensure that the following symbol has been added.
ARM_MATH_CM7 = true
4. Add the following two flags in compiler settings
Project -> ProjectName Properties … -> Toolchain -> ARM/GNU C Compiler -> Miscellaneous -> Other Flags ->
-mfloat-abi=hard -mfpu=fpv5-d16
5. Add the following two flags in linker settings
Project -> ProjectName Properties … -> Toolchain -> ARM/GNU Linker->
Miscellaneous -> Linker Flags -> -mfloat-abi=hard -mfpu=fpv5-d16
6. Change the optimization to ‘O0’
Project -> ProjectName Properties … -> Toolchain -> ARM/GNU C Compiler-> Optimization -> Optimization Level -> None(-O0)
I modified my project properties as per their suggestion.
Then I included below mentioned strand in my project.
float x =3.2,y=7.1,z=0;
z= x+y;
But it seems like the code is not working even though it got compiled & uploaded successfully.
I did add a few more line to the code to check its working.
Firstly, I enabled serial communication & the then did give a printf command.
printf("z=%f",z)
What I saw in the serial terminal was
z=f
Since x=3.2 & y=7.1
expected value of z is 10.3
Assuming something went wrong with printf, I did add a few more lines like
if(z==10.3)
ioport_set_pin_level(LED0_GPIO,LOW);
else
ioport_set_pin_level(LED0_GPIO,HIGH);
But that too failed to respond.
So, what is happening?
Any Idea?
Since floats may not be exactly represented, try something like:
if (fabsf(10.3 - z) < 0.001) {
Edit: abs to fabsf
Came to know about few more details.
To print floating point numbers, we are supposed to remove two lines from the project properties toolchain.
Project -> ProjectName Properties … -> Toolchain -> ARM/GNU C Compiler -> Symbols
(Remove)
scanf=iscanf
printf=iprintf
With this symbol,printf() uses only iprintf (integer printf() version - reduced version) by default from library.
This is the reason why I used to get
z=f
Other modifications are just like the ones mentioned above.
Project -> ProjectName Properties … -> Toolchain -> ARM/GNU C Compiler -> Miscellaneous -> Other Flags ->
-mfloat-abi=softfp -mfpu=fpv5-sp-d16
Do not simply paste it in there, to the end of all the flags, you need to make sure that these flags are defined properly.
Again, make sure that
Project -> ProjectName Properties … -> Toolchain -> ARM/GNU Linker-> Libraries->
contain the following line.
libarm_cortexM7lfsp_math_softfp
Thank you for the help guys.
Thanks to guys in Atmel Support Team as well.
The critical thing for me, using V71, is to remove
printf=iprintf
in ARM/GNU Compiler, Symbols options
Fast foward to January 2020 ->
still float math does not work after all those recommendations found here.
No symbols are there to compiler other than DEBUG.
This library libarm_cortexM7lfsp_math_softfp is not found in the current START generated project.
Included flags -mfloat-abi=softfp -mfpu=fpv5-sp-d16 to the Compiler and linker options . The only library explicitly included to the linker is libm (math).
Why float type doesn't work?
Please help
Vlad
referring to this, i got the hint to untick the optimize library box in the linker/General TAB. float works without optimize.
https://www.avrfreaks.net/forum/...
try it out
please see my reply