heinbali01 wrote on Sunday, July 02, 2017:
Hi Dave, thanks a lot for all these insights!
I just want to confirm that the [v][s][n]printf()
implementation in the FreeRTOS Labs TCP/IP ( attached below ) is quite complete and well tested. Unfortunately is misses the floating point formats ( %f
, %e
, %g
, %E
, %G
).
These printf()
functions only use stack ( about 70 bytes ) and they don’t use the heap.
They are thread- and even interrupt-safe.
I added two formats, to print IPv4 and IPv6 addresses :
/* Dot notation for IP addresses: */
printf( "IP = %xip\n", 0xC0A80164 );
/* will produce "IP = 192.168.1.100\n" */
printf( "IP = %pip\n", pxIPv6_Address );
/* 'pxIPv6_Address' is a pointer to a 16-byte array.
It could produce "IP = fe80::1\n" */
Memory protection:
Printing a string with %s
may lead to a crash in case you make a mistake with the parameters.
The functions in printf-stdarg.c
will check the validity of the pointer by calling :
/*
* Return 1 for readable, 2 for writeable, 3 for both.
* Function must be provided by the application.
*/
extern BaseType_t xApplicationMemoryPermissions( uint32_t aAddress );
Another habit of printf-stdarg.c
is to use an external function to actually write the character to a peripheral.
The function below is called in case sprintf(NULL, xxx)
is called. We kept it for backward compatibility.
void vOutputChar( const char cChar, const TickType_t xTicksToWait )
{
/* Eg. send a byte to the UART. */
}