Mistake on this page? Email us

Using the Mbed OS bare metal profile

The Mbed OS bare metal profile is for ultraconstrained hardware. It is compact - including only a minimal set of APIs - and without an RTX (so is not an RTOS). It is suitable for applications that do not require complex thread management and advanced connectivity features. Instead of the RTOS's scheduler, all activities are polled or interrupt-driven. This simplifies application code and allows using APIs that are not thread safe. Just as important, you can use the code-optimized versions of the C standard libraries, microlib and newlib-nano, which are much smaller than the thread safe equivalents the full profile requires.

The Mbed OS bare metal profile on the Mbed OS documentation goes into more detail, and lists all the supported APIs.

When creating or importing a program in Mbed Studio, you always get the full Mbed OS library. To build your program as a bare metal program, you need to enable the bare metal profile in mbed_app.json in your program's root directory:

{
    "requires": ["bare-metal"]
}

To see an example, create a new program based on mbed-os-example-blinky-baremetal. This example shows both the correct way to set up mbed_app.json and a basic Blinky example that doesn't rely on RTOS.

/* mbed Microcontroller Library
 * Copyright (c) 2019 ARM Limited
 * SPDX-License-Identifier: Apache-2.0
 */

#include "mbed.h"

#define WAIT_TIME_MS 500 
DigitalOut led1(LED1);

int main()
{
    printf("This is the bare metal blinky example running on Mbed OS %d.%d.%d.\n", MBED_MAJOR_VERSION, MBED_MINOR_VERSION, MBED_PATCH_VERSION);

    while (true)
    {
        led1 = !led1;
        thread_sleep_for(WAIT_TIME_MS);
    }
}

Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.