Very simple program to test sprintf with 5LP
This work wiith Creator 2.2 not in Creator 3 with %f as format.
Put a breakpoint after the line sprintf and look the string strMsg1.
You must see Testing: 12.35 and I see : Testing : then \0.
Where is the bug ?
}Sorry for the presentation of the first message.
For info with Creator 2.2 I use ARM_GCC_441 and
with Creator 3 I use ARM_GCC_473.
Thank for you help
Should there be whitespace after the ":"
be changed to
Sorry but obviusly that it's not the problem.
Try the program with the breakpoint on the line after sprintf(strMsg1,"Testing: %f",(float)12.35) and look strMsg1
sprintf(strMsg1,"Testing: %d",12); //is working
sprintf(strMsg1,"Testing: %f",12.35); // is not working with Creator 3.0 but ok in Creator 2.2
I think this is due to the usage of newlib-nano. According to blogs.arm.com/embedded/879-shrink-your-mcu-code-size-with-gcc-arm-embedded-47/ using floating point IO is now "weak" referenced (to reduce the library size for printf). This implies that one needs to manually add libary code for having FP IO. It might be sufficient to add the math libaries ( see www.cypress.com/ ), but maybe not. I see nothing mentioned in the Creator 3.0 release notes.
Maybe this helps: github.com/32bitmicro/newlib-nano-1.0/blob/master/newlib/README.nano
Thank for your help.
Finally your have reason for the newlib-nano. It 'is not Additional Libraries 'm'
For correct working you must go to the menu Build Stteing/Linker/General and : Use newlib-nano = FALSE
By defaut it is True ( bad idea ).
Now sprintf( %f,....) is working.
Thank for your help.
Capture Newlib-nano.JPG 67.7 K
Did you try the suggestion in the second link (adding the linker parameter to link in the FP stuff for printf)?
We default to newlib-nano in PSoC Creator 3.0 because it is leaner, which leaves more flash and memory) for your design. As hli observed, newlib-nano weak references the code that handles floating point as a part of stdio.
You can enable floating point support by going to: Build Settings -> ARM GCC 4.7.3 -> Linker -> Command Line -> Custom Flags. Set its value to "-u _printf_float" (without the quotes).
We already have a bug on file to make this the default behavior. Sorry this tripped you up.
stdio_printf.png 56.6 K
The Newlib-nano libraries do not include floating point support by default. You can either use the full Newlib libraries (which are bigger). You can add floating point to the Newlib-nano libraries which is a bit bigger than not using the libraries but stillsmaller than Newlib.
You have two choices for using floating point with Newlib-nano....
1) You can add "-u _printf_float" to the linker command line.
2) You can also put a reference to the support function into one of the object files with a statment like....
asm (".global _scanf_float");
Attaching the newlib-nano readme.
Hope that helps,
Readme nano1.txt.zip 2.3 K
Checked, tested and confirmed. Works like a charm.
Are there any more secret documents we ought to read for the new release?
I'd recommend reading the blog hli points to earlier in this post. I think it's a great high level description by Joey Ye on ARM's embedded open source toolchain team. ARM put a lot of thought into the new 4.7 compiler and the new Newlib-nano libraries. They are a lot more targeted for small memory devices and we wanted to let the PSoC Community take the best advantage of that.
We try to make sure all the docuemntation needed is readily available from within Creator. We do have some challenges when it's not our documentation though!
I have the same problem with float values and found this topic here during my search. I am using Creator 3.2 and ARM GCC 4.8.4
In the Linker options I changed "Use newlib-nano" to FALSE as recommended here. But the problem still exist in my case.
sprintf(TransmitBuffer,"temp_result_float: %f", binary_combf);
"binary_comb" is just in integer value, by dividing it with 32 there should be an float value (float binary_combf). But by showing
the result via UART there is just 0.
Am I doing anything wrong or is it some kind of unsolved bug?
Thank you in advance for your help
We are now at Creator version 3.3. I would suggest you to upgrade because that issue is cured.
Use newlib nano and newlib nano float formatting in project build settings -> Linker
Increase heap to 200 bytes.