I'm writing a serial interface for an MCU, and I want to know how one would create a printf
-like function to write to the serial UART. I can write to the UART, but to save memory and stack space, and avoid temp string buffers, I would prefer to do that write directly instead of doing sprintf()
to a string and then writing the string via serial. There is no kernel and no file handling, so FILE*
writes like those from fprintf()
won't work (but sprintf()
does).
Is there something that processes formatted strings for each char, so I can print char-by-char as it parses the format string, and applies the related arguments?
We are using newlib as part of the efm32-base project.
I would like to note that ultimately we implemented the _write() function because thats all newlib needs to light up printf.
depending on your standard library implementation you need to write your own versions of fputc
or _write
functions.