Arm Mbed OS support forum

ThisThread::sleep_for not returning in Mbed OS 6 with HSE XTAL

Mbed OS version: 6.3.0
build profile: release
GCC version: 10.2.0
Target: NUCLEO_L476RG with external 8MHz crystal

Hello,
with an example program I observed, that ThisThread::sleep_for does not return when using an external high speed crystal. This only appears in Mbed OS 6, in Mbed OS 5 (5.15.5) the same program with the same configuration works fine.

When compiling with the debug profile, the program is working as intended, except the deep sleep mode is not entered, because it is disabled in debug mode, which is fine.

The example program:

#include "mbed.h"
#include "mbed_stats.h"

static DigitalOut led(LED1);

int main() {
  while (1) {
    led = !led;
    printf("Wait for 2 seconds\n");
    ThisThread::sleep_for(2000);
    
    mbed_stats_cpu_t stats;
    mbed_stats_cpu_get(&stats);
    printf("Uptime: %llu ", stats.uptime / 1000);
    printf("Sleep time: %llu ", stats.sleep_time / 1000);
    printf("Deep Sleep: %llu\n", stats.deep_sleep_time / 1000);
  }
}

The used mbed_app.json configuration:

{
    "target_overrides": {
        "NUCLEO_L476RG": {
            "target.clock_source": "USE_PLL_HSE_XTAL",
            "platform.stdio-baud-rate": 115200,
            "platform.cpu-stats-enabled": true
        }
    }
}

When using "target.clock_source": "USE_PLL_MSI" instead, everything works fine.

I think this topic addresses a similar problem.

Am I missing any configuration or what changed with Mbed OS 6 that ThisThread::sleep_for does not return any more when using a HSE crystal? Or is it a bug in Mbed OS 6?

Hi

Could you try


?

Thx

1 Like

Hi,

yes, this fixes the problem, everything is now working as it should.

Thanks a lot! :slight_smile:

Best Regards,
Stefan