I was not able to reproduce the reported runtime error when running the code below (built wit Mbed OS 6.4.0) on a NUCLEO_F446RE:
#include "mbed.h"
DigitalOut led(LED1);
BufferedSerial serial(USBTX, USBRX);
char buf[64];
Thread t;
EventQueue eventQueue;
void onSerialReceived(void)
{
char* p_buf = buf;
memset(buf, 0, sizeof(buf));
while (serial.readable()) {
p_buf += serial.read(p_buf, sizeof(buf) - (p_buf - buf));
}
if (p_buf > buf) {
printf("Received: %s\r\n", buf);
}
}
void onSigio(void)
{
eventQueue.call(onSerialReceived);
}
int main()
{
printf("Starting...\r\n");
t.start(callback(&eventQueue, &EventQueue::dispatch_forever));
serial.sigio(callback(onSigio));
}
Maybe you have a mbed_app.json
configuration file in your project affecting the build?