Page 1 of 1

printf float value

Posted: Thu Feb 04, 2016 2:38 am
by linuxjiahuo
hi,guys:
I find that the printf can not show the float value normally vis a COM port. Any one have a good suggestion?
Thanks

Re: printf float value

Posted: Thu Feb 04, 2016 9:01 pm
by jonavarque
void printfloat(float v)
{
float dec = (v - (int)v) * 100000; // depending on the number of digits in the decimal..
printf("%d.%05d",(int)v,(int)dec)
}

Re: printf float value

Posted: Mon Feb 15, 2016 2:57 am
by linuxjiahuo
hi,
I get it. I add -mfloat-abi=softfp -mfpu=fpv5-sp-d16 in the ARM/GNU C Compiler->Miscellanesous->other flags and it works now.
Thank you.

Re: printf float value

Posted: Fri May 13, 2016 7:27 am
by embeddedBee
Hi linuxjiahuo,
I have been fighting to display floating point values in the UART Console. This is also the post I have made in stackoverflow in search of the solution.
http://stackoverflow.com/questions/3718 ... rt-console

Added those compiler flags as you have instructed, but this too is not working. Compiler generates lots of warning of same type. It says :

Code: Select all

#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" [-Wcpp]	
I am using Atmel SAMB11 Xplained Pro board which is Cortex M0 processor and the IDE is Atmel Studio 7.

Re: printf float value

Posted: Fri May 13, 2016 11:20 am
by tsvoipio
embeddedBee wrote:Hi linuxjiahuo,
I have been fighting to display floating point values in the UART Console. This is also the post I have made in stackoverflow in search of the solution.
http://stackoverflow.com/questions/3718 ... rt-console

Added those compiler flags as you have instructed, but this too is not working. Compiler generates lots of warning of same type. It says :

Code: Select all

#warning "Compiler generates FPU instructions for a device without an FPU (check __FPU_PRESENT)" [-Wcpp]	
I am using Atmel SAMB11 Xplained Pro board which is Cortex M0 processor and the IDE is Atmel Studio 7.

Add only -mfloat-abi=soft

--

-TV

Re: printf float value

Posted: Thu Jun 23, 2016 7:33 pm
by Ragnar
Sorry, but printf() floating point output is not a matter of ABI, but of string formatting.
I have no experience with AtmelStudio, but with other IDEs, one chooses the proper library (clib implementation) - either with or without floating point support. Floats/doubles require the most code and stack space at runtime, which implementations on MCUs with just a few kByte cannot effort. AFAIK, nanolib does generally not support float printf.