RawSerial is deprecated: The class has been deprecated and will be removed in the future

In Mbed_os 5, I have this warning:
int mbed::RawSerial::printf is deprecated: The class has been deprecated and will be removed in the future.

reason, why I use RawSerial is due to interrupt when Serial Rx occur. If I change RawSerial to Serial, Mbed_OS crash.
It will be removed Just printf? or whole RawSerial?

how to fix this code to avoid a warning?:
/* example how I handle interuupt on SerialRX */

indent preformatted text by 4 spaces
#include "mbed.h"
#include "platform/mbed_thread.h"
#define STRING_SIZE                                                         20
RawSerial pc(USBTX,USBRX, 9600);
DigitalOut led(LED2);
char message[STRING_SIZE];
bool flag_serial_catch = false;

void read_serial()
{   
int string_possition = 0;
char chr;
flag_serial_catch = true;
do
{
    chr = pc.getc();
    pc.putc(chr);       // it should be for clear Serrial::Irq
    message[string_possition] = chr;
    string_possition++;
}
while (chr != '\n');    // end of line character
}

int main()
{
    pc.attach(&read_serial, Serial::RxIrq);
    pc.printf("start\r\n");
    while(1)
    {
        wait(5);
        led = !led;
        if (flag_serial_catch)
        {
                pc.printf("caught message is : %s\r\n", message);
                flag_serial_catch = false;
        }
        else
                pc.printf("Noting on serial port. \r\n");
     }
}

Hi there,

that is a part of preparing to migrate to the MbedOS6 and when you visit the documentation page of the RawSerial you can see a Note

Note: This API has been deprecated in favor of UnbufferedSerial.

So the right way will be UnbufferedSerial probably.
These informations are according to documentation, I have not tested yet.

BR, Jan

1 Like