Mbed 6 how to use printf on multiple serial ports

Mbed os 5 can use printf in the following ways:

Serial pc(PA_9, PA_10); // TX, RX
Serial pc2(PA_2, PA_3); // TX, RX
pc.printf("%f\r\n", 0.12);
pc2.printf("%f\r\n", 0.12);

I want to know, in Mbed os 6, if I have multiple serial ports and want to use printf, how should I set it up?

I had the same problem, so I wrote this tiny library: https://os.mbed.com/users/MultipleMonomials/code/SerialStream/

1 Like