Stdio, printf, etc

An rp2040 compile seems to include printf() and related features. (in the Arduino core, it seems to use a printf() that is inherited from MBed. In Earle's core, it looks like it's using the RPi SDK implementation.)

MBed, in fact, seems to be pretty full of error messages sent out with printf(), so using it doesn't even increase sketch size!

However, I can't figure out where such printing GOES. It doesn't show up on the USB port (the most likely candidate?) It doesn't seem to go to either of the serial ports, either. I'm not familiar enough with either the SDK or MBed to know whether it needs some sort of initialization, or whether you need to somehow "connected" stdout to a particular place, or what. (I'm not sure whether the SDK implementation even allows run-time selection of where stdout goes - the documentation makes it sound like a compile-time option only.)

On a somewhat related note, it looks like the Arduino MBed implementation initializes and enables UART0 whether you use it or not - upload the BLINK example, and GP0 will go to a high output...

Ah. printf() output DOES seem to show up on GPIO0 at 115200bps, and you can change the speed with Serial1.begin(...)

1 Like

My solution to direct printf() to Serial Monitor:

#ifdef ARDUINO_ARCH_MBED
   REDIRECT_STDOUT_TO(Serial)  // MBED  printf(...) to console
#endif

Ah. This (from .../cores/arduino/macros.h) defines some override functions and has to be positioned in global scope (outside of any functions.) It is NOT a function...

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.