Hi,
I use KDS3.2 with SDK2.0 for my Bareboard project.
I use printf() with my own _write() functin to print on my TFT display.
The printf() function puts the characters into internal buffer and call _write() on end of the line, or when the buffer is full.
How can I dissable this buffer witch disrupts synchronization (SetXY.. and ? so on)?
I need the printf() to use _write() function for every single character.
My _write() function use its own buffer.
Thank You
Jaroslav
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/
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:
1 2 | int _write ( 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 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.
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
Hello Jaroslav,
In KDSK v2.0 , we can use PRINTF() to print characters , also can print one character ,
you can check the hello_world demo under ksdk .
If i misunderstand your meaning, could you please with screenshot to describe your demand .
Hope it helps
Alice
Hi Alice, thank for Your response,
I know this possibility, PRINTF() is defined as DbgConsole_Printf() (if SDK_DEBUGCONSOLE)
or as printf().
I 'm using printf, with my own functin _write() witch puts the charakters on the TFT.
printf() is putting charakters into buffer (on the heap) untill
"\n" is present. It works as in your example.
But
a) I have a lot of code (written fo CodeWarrior and MQX) where I use something as:
the printXY() is my functin for printing unformated string directly to the position X,Y on the TFT.
Problem in this case is, that there are no "\n" in printf() functions and the strings from all printf() functions
is outputted when the internal buffer (0x400 long) is full (or on first "\n").
But the printXY() function outputs the string imediately.
I can solve this problem when i'll insert "\n" into every printf() (its plenty of code).
b) it occupies memory on heap, unnecessarily and needless
my _write() function puts the characters to its own buffer.
I know, that in SDK 1.3 is some option (I cant find that file just now) how to say to prinf() function to do not use the buffer.
Especially for processors with small memory.
I cant find similar optin in SDK 2.0.
And there is my question, exist some option in KDS3.2 /SDK2.0 how to say to printf() do not use the bufffer
and call _write() function for every character?
Thank You and have a great day,
Jaroslav
Hello Jaroslav,
Sorry i may misunderstand your meaning.
In the PRINTF(), the"\n" is not the end mark , it is indicate change to the next line.
while the PRINTF() is send one character after one , not after the buffer is full .
So i think you can directly use the PRINTF function.
Or if you want write by yourself , i think you can copy one _writhe() code , there is a sample about this "
https://mcuoneclipse.com/2013/02/07/tutorial-printf-with-and-without-processor-expert/
Or you can directly use the device to send, for example , if you use UART, you can directly use UART_putc ()
Hope it helps
Alice