How does the global printf() know where to send the output?

I am interested in migrating my app to use the global printf(). I am currently using BufferedSerial on PA_9/PA_10. Will is just somehow magically know to send the output to PA_10? Or how do I initialize things so it knows where the output should be sent?

A link to an example program that uses the minimal printf() and outputs to PA_10 would be great. I am confident that such an example already exists, but am still trying to learn how to navigate the MBED documentation and find tutorials/examples.

FWIW, I’m very new to MBED, so please try to have some patience with my (clearly novice) questions.

Thanks, Chris

Hello,
I know about two options…

First:
Pins for default STDIO are defined here and can be overridden in mbed_app.json like this.

Second:

BR, Jan

Hi, I was looking for something similar. I needed to use different UART ports with printf, but mbed os 6 only provides a function to write a fixed buffer. I found this post, take a look at the second piece of code:

#include <mbed.h>
 
BufferedSerial serial(USBTX, USBRX, 115200);
FILE * pc;
 
int main() {
    pc = fdopen(&serial, "w");
 
    while(true)
    {
        fprintf(pc, "Hello world!\n");
        ThisThread::sleep_for(1s);
    }
}

It requires a few more steps but works as expected.

This should be helpful.