You are here

Two issues with snprintf and floats | Cypress Semiconductor

Two issues with snprintf and floats

Summary: 2 Replies, Latest post by Aaron McLean on 06 Jan 2015 02:03 AM PST
Verified Answers: 0
Last post
Log in to post new comments.
Aaron McLean's picture
2 posts

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.


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 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.

user_1377889's picture
9284 posts

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




Aaron McLean's picture
2 posts

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

Log in to post new comments.