This is a very simple guide, reviewing the steps required to get Blinky working on an Mbed OS platform.
Mbed OS Blinky
This example shows the use of a DigitalOut object to represent an LED and use of the nonblocking Thread::wait()
call. Using nonblocking calls is good practice because Mbed OS can schedule and run other threads while the first thread is waiting.
Building this example
Building with Arm Mbed CLI
To use Mbed CLI to build this example, follow the instructions in the documentation. The instructions here relate to using the Arm Online Compiler.
To use the Online Compiler, import this code into the Online Compiler, and select your platform from the top right. Compile the code using the compile button, load it onto your board and press the reset button on the board. The code will run on the board, and you will see the LED blink.
You can find more instructions for using the Mbed Online Compiler in the documentation.
README.md@95:bb79be6644fe, 2019-05-15 (annotated)
- Committer:
- mbed_official
- Date:
- Wed May 15 10:00:04 2019 +0100
- Revision:
- 95:bb79be6644fe
- Parent:
- 93:4b44c2502b00
- Child:
- 102:6979ad8bc0bc
Merge pull request #173 from jamesbeyond/test
add log compare test for blinky example
.
Commit copied from https://github.com/ARMmbed/mbed-os-example-blinky
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 82:abf1b1785bd7 | 1 | # Getting started example for Mbed OS |
Jonathan Austin |
0:2757d7abb7d9 | 2 | |
mbed_official | 91:3a205782066a | 3 | This guide reviews the steps required to get Blinky with the addition of dynamic OS statistics working on an Mbed OS platform. (Note: To see a rendered example you can import into the Arm Online Compiler, please see our [quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).) |
Jonathan Austin |
0:2757d7abb7d9 | 4 | |
mbed_official | 91:3a205782066a | 5 | Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). |
Jonathan Austin |
0:2757d7abb7d9 | 6 | |
mbed_official | 27:e64a31d541da | 7 | ## Import the example application |
Jonathan Austin |
0:2757d7abb7d9 | 8 | |
mbed_official | 27:e64a31d541da | 9 | From the command-line, import the example: |
Jonathan Austin |
0:2757d7abb7d9 | 10 | |
Jonathan Austin |
0:2757d7abb7d9 | 11 | ``` |
Jonathan Austin |
0:2757d7abb7d9 | 12 | mbed import mbed-os-example-blinky |
Jonathan Austin |
0:2757d7abb7d9 | 13 | cd mbed-os-example-blinky |
Jonathan Austin |
0:2757d7abb7d9 | 14 | ``` |
Jonathan Austin |
0:2757d7abb7d9 | 15 | |
Jonathan Austin |
0:2757d7abb7d9 | 16 | ### Now compile |
Jonathan Austin |
0:2757d7abb7d9 | 17 | |
mbed_official | 93:4b44c2502b00 | 18 | Invoke `mbed compile`, and specify the name of your platform and your favorite toolchain (`GCC_ARM`, `ARM`, `IAR`). For example, for the Arm Compiler: |
Jonathan Austin |
0:2757d7abb7d9 | 19 | |
Jonathan Austin |
0:2757d7abb7d9 | 20 | ``` |
Jonathan Austin |
0:2757d7abb7d9 | 21 | mbed compile -m K64F -t ARM |
Jonathan Austin |
0:2757d7abb7d9 | 22 | ``` |
Jonathan Austin |
0:2757d7abb7d9 | 23 | |
mbed_official | 27:e64a31d541da | 24 | Your PC may take a few minutes to compile your code. At the end, you see the following result: |
Jonathan Austin |
0:2757d7abb7d9 | 25 | |
Jonathan Austin |
0:2757d7abb7d9 | 26 | ``` |
Jonathan Austin |
0:2757d7abb7d9 | 27 | [snip] |
mbed_official | 82:abf1b1785bd7 | 28 | |
mbed_official | 82:abf1b1785bd7 | 29 | Image: ./BUILD/K64F/GCC_ARM/mbed-os-example-blinky.bin |
Jonathan Austin |
0:2757d7abb7d9 | 30 | ``` |
Jonathan Austin |
0:2757d7abb7d9 | 31 | |
Jonathan Austin |
0:2757d7abb7d9 | 32 | ### Program your board |
Jonathan Austin |
0:2757d7abb7d9 | 33 | |
mbed_official | 91:3a205782066a | 34 | 1. Connect your Mbed device to the computer over USB. |
mbed_official | 91:3a205782066a | 35 | 1. Copy the binary file to the Mbed device. |
Jonathan Austin |
0:2757d7abb7d9 | 36 | 1. Press the reset button to start the program. |
Jonathan Austin |
0:2757d7abb7d9 | 37 | |
mbed_official | 82:abf1b1785bd7 | 38 | The LED on your platform turns on and off. The main thread will additionally take a snapshot of the device's runtime statistics and display it over serial to your PC. The snapshot includes: |
mbed_official | 82:abf1b1785bd7 | 39 | |
mbed_official | 82:abf1b1785bd7 | 40 | * System Information: |
mbed_official | 82:abf1b1785bd7 | 41 | * Mbed OS Version: Will currently default to 999999 |
mbed_official | 82:abf1b1785bd7 | 42 | * Compiler ID |
mbed_official | 82:abf1b1785bd7 | 43 | * ARM = 1 |
mbed_official | 82:abf1b1785bd7 | 44 | * GCC_ARM = 2 |
mbed_official | 82:abf1b1785bd7 | 45 | * IAR = 3 |
mbed_official | 82:abf1b1785bd7 | 46 | * [CPUID Register Information](#cpuid-register-information) |
mbed_official | 82:abf1b1785bd7 | 47 | * [Compiler Version](#compiler-version) |
mbed_official | 82:abf1b1785bd7 | 48 | * CPU Statistics |
mbed_official | 82:abf1b1785bd7 | 49 | * Percentage of runtime that the device has spent awake versus in sleep |
mbed_official | 82:abf1b1785bd7 | 50 | * Heap Statistics |
mbed_official | 82:abf1b1785bd7 | 51 | * Current heap size |
mbed_official | 82:abf1b1785bd7 | 52 | * Max heap size which refers to the largest the heap has grown to |
mbed_official | 82:abf1b1785bd7 | 53 | * Thread Statistics |
mbed_official | 82:abf1b1785bd7 | 54 | * Provides information on all running threads in the OS including |
mbed_official | 82:abf1b1785bd7 | 55 | * Thread ID |
mbed_official | 82:abf1b1785bd7 | 56 | * Thread Name |
mbed_official | 82:abf1b1785bd7 | 57 | * Thread State |
mbed_official | 82:abf1b1785bd7 | 58 | * Thread Priority |
mbed_official | 82:abf1b1785bd7 | 59 | * Thread Stack Size |
mbed_official | 82:abf1b1785bd7 | 60 | * Thread Stack Space |
mbed_official | 82:abf1b1785bd7 | 61 | |
mbed_official | 82:abf1b1785bd7 | 62 | #### Compiler Version |
mbed_official | 82:abf1b1785bd7 | 63 | |
mbed_official | 82:abf1b1785bd7 | 64 | | Compiler | Version Layout | |
mbed_official | 82:abf1b1785bd7 | 65 | | -------- | -------------- | |
mbed_official | 82:abf1b1785bd7 | 66 | | ARM | PVVbbbb (P = Major; VV = Minor; bbbb = build number) | |
mbed_official | 82:abf1b1785bd7 | 67 | | GCC | VVRRPP (VV = Version; RR = Revision; PP = Patch) | |
mbed_official | 82:abf1b1785bd7 | 68 | | IAR | VRRRPPP (V = Version; RRR = Revision; PPP = Patch) | |
mbed_official | 82:abf1b1785bd7 | 69 | |
mbed_official | 82:abf1b1785bd7 | 70 | #### CPUID Register Information |
mbed_official | 82:abf1b1785bd7 | 71 | |
mbed_official | 82:abf1b1785bd7 | 72 | | Bit Field | Field Description | Values | |
mbed_official | 82:abf1b1785bd7 | 73 | | --------- | ----------------- | ------ | |
mbed_official | 82:abf1b1785bd7 | 74 | |[31:24] | Implementer | 0x41 = ARM | |
mbed_official | 82:abf1b1785bd7 | 75 | |[23:20] | Variant | Major revision 0x0 = Revision 0 | |
mbed_official | 82:abf1b1785bd7 | 76 | |[19:16] | Architecture | 0xC = Baseline Architecture | |
mbed_official | 82:abf1b1785bd7 | 77 | | | | 0xF = Constant (Mainline Architecture) | |
mbed_official | 82:abf1b1785bd7 | 78 | |[15:4] | Part Number | 0xC20 = Cortex-M0 | |
mbed_official | 82:abf1b1785bd7 | 79 | | | | 0xC60 = Cortex-M0+ | |
mbed_official | 82:abf1b1785bd7 | 80 | | | | 0xC23 = Cortex-M3 | |
mbed_official | 82:abf1b1785bd7 | 81 | | | | 0xC24 = Cortex-M4 | |
mbed_official | 82:abf1b1785bd7 | 82 | | | | 0xC27 = Cortex-M7 | |
mbed_official | 82:abf1b1785bd7 | 83 | | | | 0xD20 = Cortex-M23 | |
mbed_official | 82:abf1b1785bd7 | 84 | | | | 0xD21 = Cortex-M33 | |
mbed_official | 82:abf1b1785bd7 | 85 | |[3:0] | Revision | Minor revision: 0x1 = Patch 1 | |
mbed_official | 82:abf1b1785bd7 | 86 | |
mbed_official | 82:abf1b1785bd7 | 87 | |
mbed_official | 82:abf1b1785bd7 | 88 | |
mbed_official | 82:abf1b1785bd7 | 89 | You can view individual examples and additional API information of the statistics collection tools at the bottom of the page in the [related links section](#related-links). |
mbed_official | 82:abf1b1785bd7 | 90 | |
mbed_official | 82:abf1b1785bd7 | 91 | |
mbed_official | 82:abf1b1785bd7 | 92 | ### Output |
mbed_official | 82:abf1b1785bd7 | 93 | |
mbed_official | 88:bea4f2daa48c | 94 | To view the serial output you can use any terminal client of your choosing such as [PuTTY](http://www.putty.org/) or [CoolTerm](http://freeware.the-meiers.org/). Unless otherwise specified, printf defaults to a baud rate of 9600 on Mbed OS. |
mbed_official | 82:abf1b1785bd7 | 95 | |
mbed_official | 84:9b22d3bf66f7 | 96 | You can find more information on the Mbed OS configuration tools and serial communication in Mbed OS in the related [related links section](#related-links). |
mbed_official | 82:abf1b1785bd7 | 97 | |
mbed_official | 82:abf1b1785bd7 | 98 | The output should contain the following block transmitted at the blinking LED frequency (actual values may vary depending on your target, build profile, and toolchain): |
mbed_official | 82:abf1b1785bd7 | 99 | |
mbed_official | 82:abf1b1785bd7 | 100 | ``` |
mbed_official | 82:abf1b1785bd7 | 101 | =============================== SYSTEM INFO ================================ |
mbed_official | 82:abf1b1785bd7 | 102 | Mbed OS Version: 999999 |
mbed_official | 82:abf1b1785bd7 | 103 | CPU ID: 0x410fc241 |
mbed_official | 82:abf1b1785bd7 | 104 | Compiler ID: 2 |
mbed_official | 82:abf1b1785bd7 | 105 | Compiler Version: 60300 |
mbed_official | 89:448e37ce650a | 106 | RAM0: Start 0x20000000 Size: 0x30000 |
mbed_official | 89:448e37ce650a | 107 | RAM1: Start 0x1fff0000 Size: 0x10000 |
mbed_official | 89:448e37ce650a | 108 | ROM0: Start 0x0 Size: 0x100000 |
mbed_official | 82:abf1b1785bd7 | 109 | ================= CPU STATS ================= |
mbed_official | 82:abf1b1785bd7 | 110 | Idle: 98% Usage: 2% |
mbed_official | 82:abf1b1785bd7 | 111 | ================ HEAP STATS ================= |
mbed_official | 82:abf1b1785bd7 | 112 | Current heap: 1096 |
mbed_official | 82:abf1b1785bd7 | 113 | Max heap size: 1096 |
mbed_official | 82:abf1b1785bd7 | 114 | ================ THREAD STATS =============== |
mbed_official | 82:abf1b1785bd7 | 115 | ID: 0x20001eac |
mbed_official | 82:abf1b1785bd7 | 116 | Name: main_thread |
mbed_official | 82:abf1b1785bd7 | 117 | State: 2 |
mbed_official | 82:abf1b1785bd7 | 118 | Priority: 24 |
mbed_official | 82:abf1b1785bd7 | 119 | Stack Size: 4096 |
mbed_official | 82:abf1b1785bd7 | 120 | Stack Space: 3296 |
mbed_official | 82:abf1b1785bd7 | 121 | |
mbed_official | 82:abf1b1785bd7 | 122 | ID: 0x20000f5c |
mbed_official | 82:abf1b1785bd7 | 123 | Name: idle_thread |
mbed_official | 82:abf1b1785bd7 | 124 | State: 1 |
mbed_official | 82:abf1b1785bd7 | 125 | Priority: 1 |
mbed_official | 82:abf1b1785bd7 | 126 | Stack Size: 512 |
mbed_official | 82:abf1b1785bd7 | 127 | Stack Space: 352 |
mbed_official | 82:abf1b1785bd7 | 128 | |
mbed_official | 82:abf1b1785bd7 | 129 | ID: 0x20000f18 |
mbed_official | 82:abf1b1785bd7 | 130 | Name: timer_thread |
mbed_official | 82:abf1b1785bd7 | 131 | State: 3 |
mbed_official | 82:abf1b1785bd7 | 132 | Priority: 40 |
mbed_official | 82:abf1b1785bd7 | 133 | Stack Size: 768 |
mbed_official | 82:abf1b1785bd7 | 134 | Stack Space: 664 |
mbed_official | 82:abf1b1785bd7 | 135 | |
mbed_official | 82:abf1b1785bd7 | 136 | ``` |
Jonathan Austin |
0:2757d7abb7d9 | 137 | |
Jonathan Austin |
0:2757d7abb7d9 | 138 | ## Troubleshooting |
Jonathan Austin |
0:2757d7abb7d9 | 139 | |
mbed_official | 54:64a293b4da54 | 140 | If you have problems, you can review the [documentation](https://os.mbed.com/docs/latest/tutorials/debugging.html) for suggestions on what could be wrong and how to fix it. |
mbed_official | 82:abf1b1785bd7 | 141 | |
mbed_official | 82:abf1b1785bd7 | 142 | ## Related Links |
mbed_official | 82:abf1b1785bd7 | 143 | |
mbed_official | 82:abf1b1785bd7 | 144 | * [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html) |
mbed_official | 82:abf1b1785bd7 | 145 | * [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html) |
mbed_official | 82:abf1b1785bd7 | 146 | * [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html) |
mbed_official | 85:b4c5dbbf74e3 | 147 | |
mbed_official | 85:b4c5dbbf74e3 | 148 | ### License and contributions |
mbed_official | 85:b4c5dbbf74e3 | 149 | |
mbed_official | 85:b4c5dbbf74e3 | 150 | The software is provided under Apache-2.0 license. Contributions to this project are accepted under the same license. Please see contributing.md for more info. |
mbed_official | 85:b4c5dbbf74e3 | 151 | |
mbed_official | 85:b4c5dbbf74e3 | 152 | This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide. |