using (s)printf with float / double

Discuss how to use the features of Atollic TrueSTUDIO, including the editor, assembler, C/C++ compiler, linker, debugger, static code analysis and team collaboration tools.

Moderators: Markus Girdland, Mattias Norlander

Mr_M_from_G
Posts: 5
Joined: Wed Jul 06, 2016 6:16 am

using (s)printf with float / double

Postby Mr_M_from_G » Mon Aug 01, 2016 6:00 am

Hello,
it seems I need some assistance with using (s)printf from the lib. I want to use a simple sprintf functionality just to load a string, no streaming or so and first of all no dynamic memory.
I read in other threads that I should not check "using tiny_printf.c" when creating a project. I am not sure if I did that, where can I find it in the project settings and can I change it there?
I chose newlib-nano to avoid dynamic memory (does newlib-standard use dynamic memory?) but it seems double is not supported (?)
What can I expect? Will these work:
sprintf (Buf, "Text %.3f more Text", 123.45678); => Text 123.456 moreText
sprintf (Buf, "Text %.3E more Text", 123.45678E34); => Text 1.234E34 moreText
sprintf (Buf, "Text %.3G more Text", 123.45678); => Text 123.456 moreText or Text 1.234E2 moreText

How many arguments are allowed?

Thanks a lot

Martin

Mr_M_from_G
Posts: 5
Joined: Wed Jul 06, 2016 6:16 am

just pushing this up again I

Postby Mr_M_from_G » Wed Aug 17, 2016 7:56 am

just pushing this up again
I am still interested in some help

Thanks

Martin

Lawrence
Posts: 44
Joined: Mon Nov 09, 2015 5:13 pm

I believe you must use

Postby Lawrence » Wed Aug 17, 2016 2:42 pm

I believe you must use newlib standard, and perhaps ( not sure) the debug build configuration, optimized to send more debugging info.

I learned this from youtube videos that Atollic made, webinars.


Lawrence
Posts: 44
Joined: Mon Nov 09, 2015 5:13 pm

build config zero optimization newlib

Postby Lawrence » Tue Aug 23, 2016 1:58 am

build config zero optimization newlib standard.

as per video webinars.

theXant
Posts: 0
Joined: Thu Aug 25, 2016 7:46 am

Look if you have a

Postby theXant » Thu Aug 25, 2016 8:52 am

Look if you have a c-file called tiny_printf.c.
If you want to switch to normal printf delete the tiny_printf.c file.
Because the printf function in the file overrides the printf function of newlib.

For printf with floating points i have "Newlib standard" in use.

Go to:
Project Properties -> C/C++ Build --> Tool Settings --> C Linker --> General
Now you see the configuration for "Runtime Library" and there you can select Newlib standard.

Edit:
If you want the tiny_printf.c file back:
Rightclick on the project -> New -> Other -> Library functions
And there is "Tiny printf implementation"

msimunic
Posts: 1
Joined: Mon Dec 17, 2018 9:24 am

Re: I believe you must use

Postby msimunic » Mon Dec 17, 2018 9:27 am

Lawrence wrote:/cut
I learned this from youtube videos that Atollic made, webinars.

Please, do you have a link to those webinars?

ak_embedded
Posts: 1
Joined: Mon Dec 31, 2018 5:59 am

Re: using (s)printf with float / double

Postby ak_embedded » Mon Dec 31, 2018 9:14 am

Hello Everyone,

I’m unable to use float in printf & sprintf on STM32F103CB & STM32 VL discovery.

The output (over UART-Teraterm) of printf(" %f \r\n", 1.2345); is 0.000000 .

There are lot many post related to printf & floating point support on this forum. I have gone through all of the related posts and configured my project as below:
1. I have tried using both Newlib-nano & Newlib-standard
2. Added compiler flag -mfloat-abi=soft
3. Added linker flag -u _printf_float
4. The tiny_printf.c doesn't seem to have floating point implementation. Moreover, with tiny_printf.c, I do not even get the zeros in output.

I’m using arm-atollic-eabi-gcc -std=gnu11 compiler.

Even, I have tried all permutation & combinations of above settings and none of these have worked.

Please let me know if I'm missing anything here.

Thanks,
Ak_embedded

DD4DA
Posts: 40
Joined: Thu Jan 11, 2018 10:06 pm

Re: using (s)printf with float / double

Postby DD4DA » Mon Jan 14, 2019 1:02 am

the linker should inludes the flag -lm

didier9
Posts: 8
Joined: Sat Jan 05, 2019 1:48 am

Re: using (s)printf with float / double

Postby didier9 » Mon Jan 14, 2019 1:39 am

Have you debugged your code through the call (using the ST-LINK debug head) to make sure it is fed the right value?
If you get 0.0000 that means the library includes the code (unlike the nano library which returns an empty string), so it should work if it is fed the right values.


Return to “Atollic TrueSTUDIO tool discussions”

Who is online

Users browsing this forum: No registered users and 1 guest