Blinky sample project freezes on sleep with optimization -O0


OS: mbed-os 6.17.0
Target: STM32 DISCO_L475VG_IOT01A

I was having issues with optimization level 0 in my personal project. So i decided to test it on one of the sample projects, blinky in this case. And doesn’t seem to work correctly there either.

The first test went as following:
Created sample project without linking to existing OS.
Changed from -O1 to -O0 for ARMC6 in debug.json
Debugging or regular run of debug build resulted in hard fault:

++ MbedOS Error Info ++
Error Status: 0x80040124 Code: 292 Module: 4
Error Message: DeepSleepLock underflow (< 0)
Location: 0x800E459
Error Value: 0xFFFF
Current Thread: rtx_idle Id: 0x2000028C Entry: 0x800C2C5 StackSize: 0x380 StackMem: 0x100018F8 SP: 0x20017C68
For more info, visit: mbedos-error

I tried increased stack size as following: “rtos.main-thread-stack-size”: 4096, but didn’t have any effect.

For some reason, allocating a static integer in main and doing some arithmetic on it in the while loop prevents hard fault and instead causes a freeze at: ThisThread::sleep_for(BLINKING_RATE);

When debugging, it indicates that rtx_idle is ‘PAUSED ON SIGINT’. If i manually step into the sleep function and keep doing it, it eventually returns. But stepping over, continuing etc… causes freeze.

Any insight what going on here?