Time functions confused student when learning Mbed

I was teaching IoT using Mbed for 3 semesters.
The Mbed is keep upgrading so I need to modify my lecture notes.
This semester I modify my lecture to Mbed 6.3.
I find the time function will confuse the student.

For example, the below code using different time functions.
The project can be compiled successfully.

Some student’s projects don’t work on a Chrono duration, ThisThread::sleep_for (3ms);
But can work on ThisThread::sleep_for (3000);

It is because of the Version of Mbed in their project?
Do you provide the latest Example project with the latest Mbed OS?
The example on your web seems not the latest OS?

#include "mbed.h"
PwmOut servo(PA_6);
int main() {
    servo.period_us(20000); //20ms period, typical for analog RC servo
    int servopulsewidth=1450;
    servo.pulsewidth_us(servopulsewidth); //centers the servo.  servos range is from 500 to 2400us.
    //ThisThread::sleep_for (3ms);
            servo.pulsewidth_us(500); //0deg
           ThisThread::sleep_for (3000);
            servo.pulsewidth_us(1450); //90deg
            ThisThread::sleep_for (3s);
            servo.pulsewidth_us(2400); //180deg
            ThisThread::sleep_for (3s);
            servo.pulsewidth_us(1450); //90deg

Hello there,

I think you use the Online Compiler. If yes, then you are right, it is wrong and it is caused by unfinished build system for online tools.

It mean when the compiler say something like BufferedSerial/UnbufferedSerial not exist or the compiler do not know ms

Error: No matching literal operator for call to ‘operator""ms’ with argument of type ‘unsigned long long’ or ‘const char *’, and no matching literal operator template in “main.cpp”, Line: 20, Col: 31

That is occurs when MbedOS 6+ is not MbedOS 6+ but Mbed OS 5.15 :slight_smile:

For verification what MbedOS version you use just place


or macro

# warning ("Warning : MbedOS is lover then 6!")

Latest working 6+ version is MbedOS 6.2.1. That issue is applies to the last two versions - MbedOS 6.3 and 6.4. That issue was already discussed, see below, but still no response from Mbed team but new version was released and still same issue…

BR, Jan

1 Like

Thank you Jan,

It is very strange when user followed the getting started example for Mbed OS then finding that the official example is wrong.
It is very bad for educating student mbed.

Even I follows https://os.mbed.com/docs/mbed-os/v6.3/build-tools/creating-a-new-program.html
The os is not mbed 6x but mbed 5.15.4.
I can use revision to change it to 6.2.1.
But how can I create a new empty program with Mbed 6x?

Yes, you are right, you can not create new MbedOS6+ program directly.
You have 3 options I think:

  1. Create your own Blinky and share the repository for others
  2. Normally create a new empty program according to the guide and then downgrade MbedOS to 6.2.1
  3. Normally create a new empty program according to the guide but instead of normal link to the Mbed master you can use link to specific commit (6.2.1), please see bellow.

BR, Jan


How do you know “Latest working 6+ version is MbedOS 6.2.1.” Where can user find this information?

“That issue was already discussed, see below, but still no response from Mbed team but new version was released and still same issue…”

That’s why many of my friends give up mbed and go back to Arduino.
If the Mbed Team don’t update their official examples with the latest os version, the new users will feel frustrated and leave.


I understand your frustrations. I am quite new with Mbed OS, working with it for about two months and there are a lot of problems, especially with build tools.

One of the major problems I raised attention to on this forum recently is that the official Code repository, where a lot of examples and libraries are held, does not indicate on which version of the OS they were written on.

But there is a lot of work being done. I don’t know if you have tried Mbed Studio, but it’s a much better experience, and apparently, they are working on replacing the current old online compiler with Mbed Studio from the browser.

Arduino code is fun, but I think you understand that Mbed OS offers an order of magnitude more functionality and reliability. As far as I know, the Arduino API never went through any major changes. The closest thing I know is the FreeRTOS, which has similar functionality as Mbed OS, without the focus on the connectivity.

FreeRTOS also almost never changes its API to keep it compatible. But if you want to add new features you have to break something. And that is the feeling I get from the Mbed OS 6 as a whole. A lot of things changed, especially in the background - for example, the way targets.json file is structured, which broke compatibility from 6.2 to 6.3 for custom targets.

I applaud your dedication to keeping your lectures up to date with the latest OS version, but I think you are adding yourself a lot of work. Version 5.15 is not obsolete, and I am quite sure that most people are using it now in the production code. A lot of 2nd party board examples like the u-blox C030 or even Nucleo boards haven’t been updated for OS 6.

I don’t think your students will miss out by you teaching OS 5 to them. When they move to the 6 in their own projects, the compiler for 6 will probably compile the 5 code but will put out a warning stating “this code is deprecated, will be removed in future iterations”.

Example is bool try_acquire_for in mutex library - states:


Pass a chrono duration, not an integer millisecond count. For example use  `5s`  rather than  `5000` .