Mistake on this page?
Report an issue in GitHub or email us

Blinky on Arm Mbed CLI

This tutorial builds Blinky using the Arm Mbed CLI, which allows you to build Mbed OS applications on your own machine. You will need to install Mbed CLI and a toolchain before you can work with Blinky.

Please create a developer account. It's free, and we don't spam.

Blinky's code

Blinky's code is a simple while loop inside the main() function:

#include "mbed.h"
#include "rtos.h"

DigitalOut led1(LED1);

// main() runs in its own thread in the OS
// (note the calls to wait below for delays)
int main() {
    while (true) {
        led1 = !led1;

Quick start video

This video shows how to use Mbed CLI to import and build Blinky. Note that it assumes you have already installed Mbed CLI (see next section):

Video tutorialWatch how to create your first application on Arm Mbed CLI

Installing Mbed CLI and a toolchain

Mbed CLI is an offline tool, meaning you'll have to install it before you can work. You will also need to install a toolchain. Please follow the installation instructions on the Mbed CLI setup page, and come back here when you're done.

Setting context

Whenever you work with Mbed CLI, you need to navigate your command-line terminal to the directory in which you want to work. For example, if your program is in a folder called my_program:

cd my_program

You can then start running Mbed CLI commands, and they will run in the correct context.

Getting Blinky

Mbed CLI can import Blinky, along with the Arm Mbed OS codebase. The import process creates a new directory as a subdirectory of your current context (as explained above).

To import Blinky, from the command-line:

  1. Navigate to a directory of your choice. We're navigating to our development directory:
cd dev_directory
  1. Import the example:
mbed import mbed-os-example-blinky
cd mbed-os-example-blinky

Tip: import requires a full URL to Mercurial or GitHub. If you don't enter a full URL, Mbed CLI prefixes your snippet with https://github.com/ARMmbed/. We took advantage of this feature in our example; import mbed-os-example-blinky is interpreted as https://github.com/ARMmbed/mbed-os-example-blinky.

Blinky is now under dev_directory > mbed-os-example-blinky. You can look at main.cpp to familiarize yourself with the code.


Invoke mbed compile, specifying:

  • Your board: -m <board_name>.
  • Your toolchain: -t <GCC_ARM, ARM, ARMC6 or IAR>.

For example, for the board K64F and the Arm Compiler 5:

mbed compile -m K64F -t ARM

If you don't know the name of your target board, there are several ways to tell.

  • Invoke mbed detect, and the Mbed CLI tool displays an output similar to below, where 'K64F' is the name of your target platform and COM3 is the name of the serial port that the platform connects to:
[mbed] Detected "K64F" connected to "D:" and using com port "COM3"
  • Check the board information page on the list of Mbed Enabled boards. The right side of each information page lists the name of the target.

  • If you only have one Mbed Enabled board connected, Mbed CLI can automatically detect the target by specifing -m detect.

Your PC may take a few minutes to compile your code. At the end you should get the following result:

| Module                     | .text | .data | .bss |
| Misc                       | 13939 |    24 | 1372 |
| core/hal                   | 16993 |    96 |  296 |
| core/rtos                  |  7384 |    92 | 4204 |
| features/FEATURE_IPV4      |    80 |     0 |  176 |
| frameworks/greentea-client |  1830 |    60 |   44 |
| frameworks/utest           |  2392 |   512 |  292 |
| Subtotals                  | 42618 |   784 | 6384 |
Allocated Heap: unknown
Allocated Stack: unknown
Total Static RAM memory (data + bss): 7168 bytes
Total RAM memory (data + bss + heap + stack): 7168 bytes
Total Flash memory (text + data + misc): 43402 bytes
Image: .\.build\K64F\ARM\mbed-os-example-blinky.bin             

The program file, mbed-os-example-blinky.bin, is under your mbed-os-example-blinky\build\K64F\ARM\ folder.

Programming your board

Arm Mbed Enabled boards are programmable by drag and drop over a USB connection:

  1. Connect your mbed board to the computer over USB.
  2. Copy the binary file to the board. In the example above, the file is mbed-os-example-blinky.bin, and it's under the mbed-os-example-blinky\build\K64F\ARM\ folder.
  3. Press the reset button to start the program.

You should see the LED of your board turning on and off.

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.