- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Thanks,
Nick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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 ?
#include <device.h>
#include <stdio.h>
void testSprintf(void)
{
char strMsg1[21];
sprintf(strMsg1,"Testing:%f",(float)12.35);
}
int main()
{
testSprintf();
for(;;)
{ }
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
For info with Creator 2.2 I use ARM_GCC_441 and
with Creator 3 I use ARM_GCC_473.
Thank for you help
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Should there be whitespace after the ":"
Should
sprintf(strMsg1,"Testing:%f",(float)12.35);
be changed to
sprintf(strMsg1,"Testing: %f",(float)12.35);
Regards, Dana.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
Best regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Did you try the suggestion in the second link (adding the linker parameter to link in the FP stuff for printf)?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Thanks,
Nick
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello,
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,
-Robyn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Checked, tested and confirmed. Works like a charm.
Are there any more secret documents we ought to read for the new release?
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Bob
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!
-Robyn
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi everybody,
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.
binary_combf=binary_comb/32;
sprintf(TransmitBuffer,"temp_result_float: %f", binary_combf);
UART_1_PutString(TransmitBuffer);
"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
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It is me again,
sorry, I found a related topic called "Defect report: sprintf() with floats just prints 0x00 with no error." And there i found the solution.
My problem was solved by adjusting the heap size to 0x0200!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Fine that it works. But I still suggest you to upgrade to 3.3.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have already used creator version 3.3, increased the heap size to 0x0200, Used newlib nano and newlib nano float formatting in project build settings -> Linker, but the float number still doesn't appear on my LCD. this is my example code:
#include <project.h>
#include <stdio.h>
int main()
{
char teststring[16];
float test = -1.2345;
LCD_Start();
LCD_Position(0,0);
sprintf(teststring, "%.2f", test );
LCD_PrintString(teststring);
for(;;)
{
}
}
sorry i am real beginner at this.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum!
The code looks ok at first sight. Can you post your complete project, so that we all can have a look at all of your settings? To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file. Tell us please, which board you use, CY8C-042, -044, -049, -030, -050 etc.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello Bob.
Can you help me solve the problem with float values. I use creator 3.3 version, I've enabled newlib-nano, newlib-nano Floating formatting, but my values still doesn't appear, my code is correct, I've checked it in Debug state.
Maybe increasing of heap will help me, but I have no idea how to do that. Help me pls...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
You do need to increase the heap or the program might crash.
Open the .cydwr-file (where you assign the pins), select the "System" tab at the bottom and in the list you find the settings for the heap which you should increase to 0x200
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks a lot, that helped me.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have German Shepherd of common size, but with broken ears, so they are not straight-up
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I am using PSoC Creator 3.3. When I step through the following program using the debugger
<code>
int main()
{
int j;
int n;
double x;
char float_value[16];
x = 0.0;
j = 0;
n = 0;
j = sprintf(float_value,"%5.2lf",45.);
n = sscanf(float_value,"%lf",&x);
CyGlobalIntEnable; /* Enable global interrupts. */
for(;;)
{
asm("NOP");
}
}
</code>
with "use newlib-nano" set to FALSE, and a heap size of 0x0800 bytes, both the sprintf() and the sscanf() work properly.
With "use newlib-nano" set to FALSE, and a heap size of 0x0200 bytes, the program gets trapped in IntDefaultHandler() when it tries to execute the sprintf().
With "use newlib-nano" and "use newlib-nano Float Formatting" set to TRUE and a heap size of 0x0800, the sprintf() works properly but the sscanf() does not.
With "use newlib-nano" and "use newlib-nano Float Formatting" set to TRUE and a heap size of 0x0200, the sprintf() works properly but the sscanf() does not.
I conclude that the support for floating point formats in newlib-nano is still dodgy.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Timothy, thank you so much for this post!
I was struggling all day trying to find what's wrong with my code because I couldn't print floats to my LCD. I increased the heap size and set newlib-nano to false as you said and then I was able to see float values to my LCD!
I am using a CY8CKIT - 042- BLE by the way.
Kind regards,
Nikos
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Be great if there was a pull-down menu option in IDE to use the FloatF library. Maybe a button hooked to a script that make the appropriate nano library setting and adjusts the memory to suit.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I do not have had any problems printing floats, although I do not use an LCD but using the UART-USB bridge and PuTTY.
My settings are:
Heap 0x200
Use newlib-nano
use newlib-nano float formatting
Only restriction I found so far is that the float formatting is not reentrant
Advantage is that the nano library is considerably smaller!
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
As noted above, the sprintf() function seems to work in the newlib-nano while sscanf() does not.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I make all the step on Psoc Creator 3.3 project setting, change link value and thats not work, any can helpme resolve that?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
@Fernandov
Can you please post your complete project, so that we all can have a look at all of your settings. To do so, use
Creator->File->Create Workspace Bundle (minimal)
and attach the resulting file.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for the helpful responses. I set the newlib-nano float formatting = true and heap size 0x200 and sprintf with %f worked!
As a beginner I've found this forum (and Cypress' documentation and videos in general) very helpful compared to some other manufacturers.
Now if I would stop trying to use ports with bypass caps, or ports allocated to kitprog on my CYC8KIT-059...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Welcome in the forum, david.
The schematic for your -059 kit is already installed on your PC. Look at ..\Program Files (x86)\Cypress\CY8CKIT-059\1.0\Hardware\
You will see in the .pdf which pins are already in use.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The information in this thread do not seem to work with PsOC Creator 4. I've gone round and round and cannot get it to display. I am using the uart and sprintf on my pioneer BLE board.
This causes a hang:
char str[10];
float tempVal = 175.72;
sprintf(str, "New Temp = %+5.1f", tempVal);
UART_UartPutString(str);
UART_UartPutCRLF(0);
Banging my head against the wall, here.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Stop banging!!! I couldn't sleep a wink!!! Set the heap space (in System view) to 0x0200 and in project build settings -> linker set "use newlib nano float formatting" to true.
Bob
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The %f descriptor in sscanf is not working in the newlib-nano version of lib.c. Turn off newlib-nano and use the standard lib.c. It works. Sad part is the the standard lib.c is much larger than the nano version.
"Engineering is an Art. The Art of Compromise."