Serial not working in its simplest form

Hello,
Just fired up my Nucleo-F303K8 and tried to use “Serial” in mbed studio. Plain old printf works fine but thats obviously only one of the serial periphals on the board. When trying to use the other the “Serial” command isnt working at all.
My code is as follows. In my compiler (mbed studio) the word serial is underlined and therefore wont compile.

#include “mbed.h”

Serial device(PB_6, PB_7); // tx, rx

int main() {

device.printf("Hello World\n");

}

Any help would be great im really stumped.
Ed

Hello,

it depends on what version of the MbedOS you have in your project.
The Serial API is deprecated and can be used only in MbedOS < 6 for MbedOS =>6 there are new APIs BufferedSerial and UnbufferedSerial . On APIs pages you will also find a basic examples. With these new APIs you also can not use printf function. But you can still use it for a debugging .

BR, Jan

Note that if you want to get the old behavior back, I wrote a small adapter library to do that: https://os.mbed.com/users/MultipleMonomials/code/SerialStream/

1 Like