cancel
Showing results for 
Search instead for 
Did you mean: 

full printf redirection

pcu
Associate II
Posted on March 05, 2013 at 10:29

Hello,

I work with Atollic and STM3220 kit. I use the console with SWV. When I use printf with ''tiny_printf.c'' I have no problem.

This is the method:

in syscalls.c

_write int (int file, char * ptr, int len)

{

/ * Implement write your code here, this is used by printf and puts for example * /

myprintf (file, ptr, len);

return len;

}

myprintf void (int file, char * ptr, int len)

{

int i = 0;

for (i = 0; i <len; i + +)

ITM_SendChar ((* ptr + +));

}

But tiny printf is not always enough I would use FULL printf and full printf is not redirected to _write.

The workaround is to go through (a) sprintf:

if (i == 10000000ul)

{

i = 0;

asprintf (& buf, ''var =% 02i'', i);

printf (''% s'', buf);

free (buf);

}

But how to redirect full printf to _write. Someone has already been doing that?

thank you
2 REPLIES 2
pcu
Associate II
Posted on March 05, 2013 at 10:47

It seems that full printf is redirect to _write when the len is equal to 1024 bytes. Each new string is concatenated with teh previous...

In stdio.h there is one #define

#ifdef __BUFSIZ__

#define BUFSIZ __BUFSIZ__

#else

#define BUFSIZ 1024

#endif

I don't know if there is a link???

Pierre

pcu
Associate II
Posted on March 05, 2013 at 12:12

Finally I found one solution somewhere :

''The

stdout

stream is buffered, so will only display what's in the buffer after it reaches a newline ''

then should beprintf (''var = %02i '',i); instead ofprintf (''var = %02i'',i); Otherwise nothing is sent until the buffer is full.