Using the Online Compiler
Setting up
-
If you have an Mbed Board:
- Plug your Mbed board into your computer, and open its USB device folder.
- Double click on the
MBED.HTML
file. This adds your Mbed board to the Online Compiler as a compilation target.
-
If you don't have a board but still want to follow the quick start:
- Go to os.mbed.com/platforms.
- Select a board.
- On the board page, click Add to your Mbed Compiler.
Importing the code
Click the button below to automatically import the example into the Online Compiler.
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*/
#include "mbed.h"
// Blinking rate in milliseconds
#define BLINKING_RATE 500ms
int main()
{
// Initialise the digital pin LED1 as an output
DigitalOut led(LED1);
while (true) {
led = !led;
ThisThread::sleep_for(BLINKING_RATE);
}
}
Alternatively, you may select the import button on the top left hand side of the Online Compiler screen and copy the example link into the prompt.
Compiling and flashing (programming)
-
Click Compile.
Note: To build with the Mbed OS bare metal profile, add
"requires": ["bare-metal"]
to thembed_app.json
file:{ "requires": ["bare-metal"], "target_overrides": { "*": {
The Online Compiler compiles the code into an executable file, which your browser downloads.
-
Open the folder where the executable file was downloaded, and then click and drag (or copy and paste) the file to your Mbed board's USB device folder.
-
Press the board's reset button.
Example walkthrough
The quick start example blinks the LED on your board on and off. The main thread also takes a snapshot of the device's runtime statistics and displays them over a serial connection to your PC.
Viewing the output
To view the serial output use any terminal client, such as PuTTY or CoolTerm.
The default baud rate, or speed, for this application is set to 9600
. You can modify it in the mbed_app.json
file. To configure your terminal client to this baud rate, change the speed option when selecting the port.
Tip: You can find more information on the Mbed OS configuration tools and serial communication in Mbed OS in the related links section.
The output transmits the system, CPU, heap and thread information.
Note: If you are building with the Mbed OS bare metal profile, you will not get thread information.
Understanding the output
System information
Mbed OS version: Tip of master is represented by 999999. If you are using a tagged release of Mbed OS, the version will be configured by the OS. For custom releases, you can modify the version manually in platform/mbed_version.h
.
CPUID register information:
Bit Field | Field Description | Values |
---|---|---|
[31:24] | Implementer | 0x41 = ARM |
[23:20] | Variant | Major revision 0x0 = Revision 0 |
[19:16] | Architecture | 0xC = Baseline Architecture |
0xF = Constant (Mainline Architecture) | ||
[15:4] | Part Number | 0xC20 = Cortex-M0 |
0xC60 = Cortex-M0+ | ||
0xC23 = Cortex-M3 | ||
0xC24 = Cortex-M4 | ||
0xC27 = Cortex-M7 | ||
0xD20 = Cortex-M23 | ||
0xD21 = Cortex-M33 | ||
[3:0] | Revision | Minor revision: 0x1 = Patch 1 |
Compiler ID and version:
Compiler | Version tag | Version layout |
---|---|---|
ARM | 1 | PVVbbbb (P = Major; VV = Minor; bbbb = build number) |
GCC_ARM | 2 | VVRRPP (VV = Version; RR = Revision; PP = Patch) |
IAR | 3 | VRRRPPP (V = Version; RRR = Revision; PPP = Patch) |
CPU statistics
Percentage of runtime the device has spent awake.
Heap statistics
- Current heap size.
- Maximum size the heap has ever reached (not the maximum size it can reach).
Thread statistics
Provides information on all running threads in the OS:
- ID.
- Name.
- State.
- Priority.
- Stack size.
- Stack space.