Enabling floating point printf/scanf in Atmel Studio 7

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

It seems like I have lost the ability to use printf with floating point values (I could have sworn it was working before).  I read in other posts that compiler optimizations causes printf to only support integers by default. 

In the output, any floating point values are replaced by the character 'f'.

 

float pi = 3.14;

printf("pi = %f", pi);

 

results in the output:

pi = f

 

 

In Toolchain -> ARM/GNU Linker -> General:

  • Use size optimized library (--specs=nano.specs) is not selected.

 

In Toolchain -> ARM/GNU C Compiler -> Symbols:

  • "printf=iprintf" is present
  • "scanf=iscanf" is present

 

 

What are the correct options to enable floats?   There are multiple forum posts here with different recommendations.  It would seem this should be a common issue with an Atmel App Note standard solution. 

 

 

Regards

 

 

 

 

 

 

 

 

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

In properties, toolchain linker, deselect "use size optimized libraries" (--specs=nano.specs)

 

jeff

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

I do not have optimized libraries selected.  And removing the symbol "printf=iprintf" did not appear to make a difference.

Here are my linker options:

 

 

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

same as mine... that solved it for me.  

jeff

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

A SAMD21 XPlained Pro ASF example that uses printf with %f has "-u _printf_float" added for the ARM/GNU Linker Miscellaneous Linker Flags. This is how to enable float printf with the nano library apparently ("Use size optimized library" is selected).

It's the ADC Configurations example.

/Lars

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

Actually in latest AS7 you just have to go to Project-Settings-Compiler-Symbols and remove the assignments for scanf =iscanf and printf =iprintf, at least for the S71

Best,
Andrew

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

Thanks Andrew ,it is worked for me 

Atmel studio 7 ,Ardunio serial MOniter

Attachment(s): 

pinindu