Thursday, 28 January 2016

Useful tiny printf library

I have come across this very tiny implementation of printf for embedded applications

https://github.com/cjlano/tinyprintf

It takes about 2.6K of memory footprint on a FT900 family(FT32 core) . The library has only two files tinyprint.h and tinyprintf.

The library is under BSD new licence or the LGPL licence. 

Initialise the tinyprintf library by passing a function to write a character to UART or to stdout
void init_printf(void *putp, putcf putf)

e.g:
#include "tinyprintf.h"

static void my_putc(void *unused, char c)
{
  putchar(c);  // Change to UART write a char function
}

int main ()
{
...
...
init_printf(NULL, my_putc);
tfp_printf("Hello World ! \n");
...
}