Serial class in Mbed OS 6?


In Mbed 5, i use:
Serial vcom(USBTX, USBRX);
vcom.printf(“Output serial”);

In Mbed 6, it is not working anymore.

I find Serialbase but i don’t see the parameters for it.
Any replacement for Serial with example please ?


Hello Da Dude,

In Mbed OS 6 you can use either BufferedSerial or UnbufferedSerial.

You can also use the “serial console” to communicate with the PC over a virtual USB serial port associated with the USBTX, USBRX pins . It uses the STDIO device. Simply call the global printf function:

printf("Prints to the virtual serial port\r\n");

I works at 9600 bit/s.

For debug messages you can also call the global debug function. It works like the global printfbut it is automatically optimized away (no debug messages are printed) if you build the project using the release profile:

debug("This message is optimized away (not printed) in release build");

It is also possible to remap the “serial console” to other than the USBTX, USBRX pins.

Best regards, Zoltan

Note: If you need to be able to call pc.printf(), then my SerialStream library might be able to help since this function doesn’t exist for serial ports in vanilla Mbed.