For what it’s worth, this is actually a good use case for the new Mbed 6 asynchronous buffered serial.
You can actually completely remove the attach() call and the callback, and replace your waiting loop with something like this:
while (chrono::duration_cast<chrono::milliseconds>(t.elapsed_time()).count() < 500) {
while (Oled.readable()){
// read a byte using Oled.read() and process it
}
}
You will also need to make sure Oled is a BufferedSerial and set it to nonblocking mode, e.g. by adding this to the constructor:
Oled.set_blocking(false);
There’s more info in my guide here: Hitchhiker's Guide to Printf in Mbed 6