Two issues with snprintf and floats

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
lock attach
Attachments are accessible only for community members.
Anonymous
Not applicable

I was attempting to use snprintf to format floats into strings to print over UART and I ran into two issues.

   
   

Issue 1: "Use newlib-nano Float Formatting" doesn't work.

   

With the default settings it works perfectly for integers but attempting to use it with floats doesn't work even with the "Use newlib-nano Float Formatting" set to true it does not print the float.

   

Example:

   

Value of pi is:  to 2dp

   

In order to get it to include support for floating point printing I had to follow the instructions from http://www.cypress.com/?id=4&rID=87354 and add -u _printf_float to the command line manually and set "Use newlib-nano Float Formatting" to false.

   

 

   

Issue 2: Using snprintf with floats causes the PSoC  4 to hang unless the heap is increased to at least 256B

   

If you attempt to use snprintf (or sprintf) with floats the processor will jump to IntDefaultHandler and hang. In PSoC Creator 3.1 the default heap size was decreased to 128B from 256B which likely caused this issue.

   
   

I have attached a project that should reproduce these issues.

0 Likes
2 Replies
Bob_Marlowe
Level 10
Level 10
First like given 50 questions asked 10 questions asked

Thank you very much sharing your experiences with us! That took you some time, I presume.

   

 

   

Bob

0 Likes
Anonymous
Not applicable

I think Issue 1 is caused by quotes around "-u _printf_float".

0 Likes