KDS printf issues with -nanolibc

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

KDS printf issues with -nanolibc

Jump to solution
4,231 Views
dereksnell
NXP Employee
NXP Employee

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

 

12041_12041.jpgKDS-Debug.jpg

12040_12040.jpgKDS-Linker.jpg

Original Attachment has been moved to: K64_MQXL_Printf.zip

Labels (1)
1 Solution
1,636 Views
BlackNight
NXP Employee
NXP Employee

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

View solution in original post

0 Kudos
Reply
7 Replies
1,636 Views
BlackNight
NXP Employee
NXP Employee

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

0 Kudos
Reply
1,636 Views
BlackNight
NXP Employee
NXP Employee

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?

0 Kudos
Reply
1,636 Views
dereksnell
NXP Employee
NXP Employee

Thanks, Erich.

I bumped up the task stack size to 4KB, and still have the issue.

0 Kudos
Reply
1,637 Views
BlackNight
NXP Employee
NXP Employee

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

0 Kudos
Reply
1,636 Views
dereksnell
NXP Employee
NXP Employee

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:

Assembler.jpg

For the PEx project, the stack and heap sizes are set in the Build Options properties of the CPU component.

PEx Heap.jpg

0 Kudos
Reply
1,636 Views
BlackNight
NXP Employee
NXP Employee

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.

1,636 Views
DavidS
NXP Employee
NXP Employee

Hi Derek,

My workaround is using AS1:Serial_LDD component.  Not sure if it helps size wise though.

Regards,

David

0 Kudos
Reply