Hello,
I've run into an issue with KDS when using the nanolibc library and printf. With this library, the printf only prints the first character. If I remove the linker option -nanolibc, then printf works as expected.
I'm using the attached project for the FRDM-K64F Freedom board. I've used Processor Expert (PEx) to add MQX Lite and the ConsoleIO component. The attached project uses the option -nanolibc, and shows the issue. Debugging the issue, I put a breakpoint in the function _write() generated by the ConsoleIO component in CsIO1.c. The parameter count for the character count to send out the UART is set to 1 when -nanolibc, no matter what the length of the printf string is. If I remove the linker option -nanolibc and debug, the character count is passed correctly as expected.
I haven't figured out how to debug the library for why the count parameter is 1, since I haven't found the library source code yet.
I found this when trying to use a device with less RAM than the K64. In that device, using the default library didn't fit in the RAM, so I used the -nanolibc option for the smaller library. Now the application fits, but I can't get the printf statements to work.
Thanks for any guidance
Original Attachment has been moved to: K64_MQXL_Printf.zip
Solved! Go to Solution.
For Cortex-M4, somehow an additional hook routine is needed: _isatty().
see UART printf() for the FRDM-K64F Board and Kinetis Design Studio | MCU on Eclipse
Hi Derek,
>>The parameter count for the character count to send out the UART is set to 1 when -nanolibc, no matter what the length of the printf string is. If I remove the linker option -nanolibc and debug, the character count is passed correctly as expected.
The reason is that the newlib-nano is optimized for size/space to fit better smaller embedded devices. So the library implementation avoids buffering if possible. Instead, it writes characters by characters.
Erich
I'm able to use printf() with nanolib without any issues (see attached project), but I'm not using MQXlite. I only can guess that there is a problem in the context of MQXlite?
Apart of that: I know that the library needs a lot of stack (> 1 KByte) if using printf(), so increasing the stack size per task can help?
Thanks, Erich.
I bumped up the task stack size to 4KB, and still have the issue.
For Cortex-M4, somehow an additional hook routine is needed: _isatty().
see UART printf() for the FRDM-K64F Board and Kinetis Design Studio | MCU on Eclipse
Thanks for all your help with this, Erich.
Increasing the heap and replacing _isatty() fixed the issues for me.
Attached are two projects that both run on the FRDM-K64F board using KDS v1.0.1 and the -nanolibc linker option. One project is built with the Kinetis SDK and no Processor Expert (PEx). The other project uses PEx and no SDK.
For the SDK project, the stack and heap size are set in the Assembler settings:
For the PEx project, the stack and heap sizes are set in the Build Options properties of the CPU component.
What about HEAP size? I see in another thread that the GNU library in KDS needs at least 400 bytes or more of HEAP space allocated in the linker file.