AnsweredAssumed Answered

printf(), double and unsigned long int support

Question asked by J Stark on Jun 24, 2019
Latest reply on Jun 27, 2019 by Erich Styger

I'm encountering difficulties printing both 64-bit integers and double precision floating point values in the same application. Some background. MCU is MK22DX128VLF5 on a board of my own design. I'm using MCUXpresso 10.3.1 in a no-host configuration. I've written my own _read() and _write() functions to interface to a UART which communicates to the outside world at 1 Mb/s through an external serial/USB translator. Both I/O support functions are re-used from a similar design and have been thoroughly proven in use. Code size is not an issue as my application code is approximately 90% complete and, with Newlib selected only about 60% of available flash is needed and much less than 50% of available RAM.

 

Using the Quick Settings link, I've first selected SoftABI floating point since the MCU has no hardware floating point unit. If I then select NewlibNano (nohost) in the Library/Header category, the following statement executes as expected:

printf("x = %f\n", x);

where x is a declared as a double precision value equal to 2.71828. On the other hand, the statement

printf("i = %lu\n", i);

where i is declared as uint64_t cast as an unsigned long int equal to 0x100000001 displays as "i = lu".

 

If instead I select Newlib  (nohost) in the Library/Header category, the second printf() call shown above will render the expected value, however when the first printf() shown is encountered the hard fault handler is inevitably invoked.

 

I've spent a number of hours reading through the MCUXpresso IDE User's Guide to be sure I understand what libraries are available and how they are intended to be used, inspecting library paths and compiler options, etc., but so far have been unable to find a way to build an applications which can render both data types correctly using printf(). It's understandable to me that NewlibNano doesn't support 64-bit integers, but I don't understand why it's not working with double precision floats. My code is needed to control an instrument which needs to go into service soon, and this is the final hurdle to leap before that can happen. Any suggestions are appreciated.

Outcomes