Arm Mbed OS support forum

MbedOS Error after disabling compiler optimization, increasing stack size


I am working on a larger project where I want to disable compiler optimization for proper debugging.
But to trigger my problem this little program is sufficient:

#include “mbed.h”


static BufferedSerial SerialPort(USBTX, USBRX);

int main() {
SerialPort.set_format(8, BufferedSerial::None, 1);

char buf[MAXIMUM_BUFFER_SIZE] = {0};

while (true) {
    printf("Before Reading\n");
    int num =, sizeof(buf));
    printf("Reading ended, num = %d\n", num);



(Sorry for the format, for some reason I cannot format it the way I want.)

Using the unmodified debug.json file it works as expected.
But I need to disable compiler optimization so I change “-Og” to “-O0” in the GCC_ARM toolchain of debug.json profile.

When I build and run it like this, I receive this:

When I build and start debugging, the process hangs at ThisThread::sleep_for(1s);

Is there any way to make this work by increasing the stack size or something?
I already looked for this but I only find solutions for deprecated mbed 5 and I use mbed 6.

Thank you for any help!