I'm struggling to properly implement printf from newlib into my esp32, using GCC.
I've gone through the newlib documentation and it gives me general information about how printf is called, but doesn't explain the back end implementation to me.
Based on my current research I have determined that printf outputs a formatted string to the STDOUT. On a PC this was simpler for me to understand because there's a console window that would display the formatted output from printf, however on an embedded system I understand that you have to tell the library where to redirect the formatted output of printf to and that's what I'm trying to figure out.
Again, based off of my research I have come to understand that some functions are required to accomplish this, specifically the function _write
.
I'm finding it very difficult on how to bridge the gap between printf and utilizing the _write
function. I'm hoping someone here can help me understand how to properly implement printf.
And if I missed some documentation that clearly explains this, then please redirect me to that. I tried reading the newlib documentation, as well as GCC related documentation, but nothing really mentions how to use printf, but there is plenty of documentation on how to call printf and format the string, but that part is easy. I need to know how to get the formatted string from the STDOUT of the MCU.
Thanks to all!
printf()
and its relatives of greater or lesser complexity on the web. If you findint printf(const char * restrict fmt, ...) { va_list args; va_start(args, fmt); int rc = vfprintf(stdout, fmt, args); va_end(args); return rc; }
then you've got a relay function and you need to find the implementation ofvfprintf()
instead. But that too is available… – Jonathan Lefflerprintf()
implementation. The question I think should be about how to retarget Newlib so that itsprintf()
works rather then how to implementprintf
– Clifford