rtos::ThisThread::sleep_for(mbed::chrono::microseconds_u32(100)); - does not compile for Artemis

rtos::ThisThread::sleep_for(mbed::chrono::milliseconds_u32(100));

rtos::ThisThread::sleep_for(mbed::chrono::microseconds_u32(100));

Is there any reason that the microseconds sleep_for does not work, but the milliseconds one does?

There is no sleep_for() with microseconds, only sleep_for () milliseconds defined in ThisThread.h. BUt there is a function wait_us(int us), defined in mbed-os/platform/mbed_wait_api.h)

You get closest to calculating the time needed in microseconds first and then see whether that is more than milliseconds

like :

uint32_t wait_time_us;  

// calculate time in micro_seconds

// calculate milliseconds
uint32_t sleep_time_ms = sleep_time_us / 1000;

// calculate microseconds left over
sleep_time_us = sleept_time_us % 1000;

// if any millisecond needed
if (sleep_time_ms)  rtos::ThisThread::sleep_for(mbed::chrono::milliseconds_u32(sleep_time_ms));

// if any microseconds left over
if (sleep_time_us)  wait_us(sleep_time_us);