Hi Alice,
I understand how I can use printf() with overwriten function _write()
as in https://mcuoneclipse.com/2014/07/11/printf-and-scanf-with-gnu-arm-libraries/
Printf() with GNU Libraries
By default, the GNU newlib and newlib-nano libraries in KDS have semihosting included (at least in V1.0.1 beta which has been released in May 2014). So when I do a printf() or one of its family members, it tries to communicate with the debugger. In order to use my communication channel for input and output, I need to overwrite the following methods of the GNU library:
| int _write (int fd, const void *buf, size_t count);int _read (int fd, const void *buf, size_t count);
|
So if I use printf() in my code, it actually will end up at the _write() function to write the characters. In a similar way, if I call scanf(), it will use _read() to get the data from the input stream.
I took an example code : usb_device_msc_sdcard,
I wrote my own _write() function for putting characters onto TFT display.
The PRINTF() function is defined in fsl_debug_debugconsole.h as:

I do not want to use SDK_DEBUGCONSOLE, so I want (for text formating)use printf() function as I mentioned above.
It works when I use printf() function with "thisstring_with_newline \n", but not for
printf("stringwithout_newline").
The printf function is line oriented, put all characters into heap buffer and send it to output (to _write() function in my case) only when it find "\n" (new line) in the string or when the heap buffer is full (0x400 in this sample code).

I know that I can insert "\n" into the end of all strings in printf() functions, but it is used on lot of places
and there is 0x400 heap buffer that I need not.
I found
KDS printf issues with -nanolibc
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
But the optin nanolib :

has no affect on printf() function.
I know that there is some optin CR_PRINTF_CHAR in Using printf() for Redlib:
Redlib printf variants
Redlib provides the following two variants of printf. Some of the LPCXpresso project wizards provide options to select which of these to use when you create a new project.
Character vs String output
By default printf() and puts() functions will output the generated string at once, so that a single semihosted operation can output the string to the console of the debugger. Note that these versions of printf() /puts() make use of malloc() to provide a temporary buffer on the heap in order to generate the string to be displayed.
It is possible to switch to using "character-by-character" versions of these functions (which do not require additional heap space) by specifying the build define "CR_PRINTF_CHAR" (which should be set at the project level). This can be useful, for example, if you are retargeting printf() to write out over a UART (as detailed below)- as in this case it is pointless creating a temporary buffer to store the whole string, only to then print it out over the UART one character at a time.
My question is,
Exist something similar as CR_PRINTF_CHAR for libreries in KDS 3.2 ?
Best regards
Jaroslav