![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
00
README.md@0:69db88456c7f, 2019-10-17 (annotated)
- Committer:
- peng103617
- Date:
- Thu Oct 17 03:27:19 2019 +0000
- Revision:
- 0:69db88456c7f
916
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
peng103617 | 0:69db88456c7f | 1 | # Getting started example for Mbed OS |
peng103617 | 0:69db88456c7f | 2 | |
peng103617 | 0:69db88456c7f | 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).) |
peng103617 | 0:69db88456c7f | 4 | |
peng103617 | 0:69db88456c7f | 5 | Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). |
peng103617 | 0:69db88456c7f | 6 | |
peng103617 | 0:69db88456c7f | 7 | ## Import the example application |
peng103617 | 0:69db88456c7f | 8 | |
peng103617 | 0:69db88456c7f | 9 | From the command-line, import the example: |
peng103617 | 0:69db88456c7f | 10 | |
peng103617 | 0:69db88456c7f | 11 | ``` |
peng103617 | 0:69db88456c7f | 12 | mbed import mbed-os-example-blinky |
peng103617 | 0:69db88456c7f | 13 | cd mbed-os-example-blinky |
peng103617 | 0:69db88456c7f | 14 | ``` |
peng103617 | 0:69db88456c7f | 15 | |
peng103617 | 0:69db88456c7f | 16 | ### Now compile |
peng103617 | 0:69db88456c7f | 17 | |
peng103617 | 0:69db88456c7f | 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: |
peng103617 | 0:69db88456c7f | 19 | |
peng103617 | 0:69db88456c7f | 20 | ``` |
peng103617 | 0:69db88456c7f | 21 | mbed compile -m K64F -t ARM |
peng103617 | 0:69db88456c7f | 22 | ``` |
peng103617 | 0:69db88456c7f | 23 | |
peng103617 | 0:69db88456c7f | 24 | Your PC may take a few minutes to compile your code. At the end, you see the following result: |
peng103617 | 0:69db88456c7f | 25 | |
peng103617 | 0:69db88456c7f | 26 | ``` |
peng103617 | 0:69db88456c7f | 27 | [snip] |
peng103617 | 0:69db88456c7f | 28 | |
peng103617 | 0:69db88456c7f | 29 | Image: ./BUILD/K64F/GCC_ARM/mbed-os-example-blinky.bin |
peng103617 | 0:69db88456c7f | 30 | ``` |
peng103617 | 0:69db88456c7f | 31 | |
peng103617 | 0:69db88456c7f | 32 | ### Program your board |
peng103617 | 0:69db88456c7f | 33 | |
peng103617 | 0:69db88456c7f | 34 | 1. Connect your Mbed device to the computer over USB. |
peng103617 | 0:69db88456c7f | 35 | 1. Copy the binary file to the Mbed device. |
peng103617 | 0:69db88456c7f | 36 | 1. Press the reset button to start the program. |
peng103617 | 0:69db88456c7f | 37 | |
peng103617 | 0:69db88456c7f | 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: |
peng103617 | 0:69db88456c7f | 39 | |
peng103617 | 0:69db88456c7f | 40 | * System Information: |
peng103617 | 0:69db88456c7f | 41 | * Mbed OS Version: Will currently default to 999999 |
peng103617 | 0:69db88456c7f | 42 | * Compiler ID |
peng103617 | 0:69db88456c7f | 43 | * ARM = 1 |
peng103617 | 0:69db88456c7f | 44 | * GCC_ARM = 2 |
peng103617 | 0:69db88456c7f | 45 | * IAR = 3 |
peng103617 | 0:69db88456c7f | 46 | * [CPUID Register Information](#cpuid-register-information) |
peng103617 | 0:69db88456c7f | 47 | * [Compiler Version](#compiler-version) |
peng103617 | 0:69db88456c7f | 48 | * CPU Statistics |
peng103617 | 0:69db88456c7f | 49 | * Percentage of runtime that the device has spent awake versus in sleep |
peng103617 | 0:69db88456c7f | 50 | * Heap Statistics |
peng103617 | 0:69db88456c7f | 51 | * Current heap size |
peng103617 | 0:69db88456c7f | 52 | * Max heap size which refers to the largest the heap has grown to |
peng103617 | 0:69db88456c7f | 53 | * Thread Statistics |
peng103617 | 0:69db88456c7f | 54 | * Provides information on all running threads in the OS including |
peng103617 | 0:69db88456c7f | 55 | * Thread ID |
peng103617 | 0:69db88456c7f | 56 | * Thread Name |
peng103617 | 0:69db88456c7f | 57 | * Thread State |
peng103617 | 0:69db88456c7f | 58 | * Thread Priority |
peng103617 | 0:69db88456c7f | 59 | * Thread Stack Size |
peng103617 | 0:69db88456c7f | 60 | * Thread Stack Space |
peng103617 | 0:69db88456c7f | 61 | |
peng103617 | 0:69db88456c7f | 62 | #### Compiler Version |
peng103617 | 0:69db88456c7f | 63 | |
peng103617 | 0:69db88456c7f | 64 | | Compiler | Version Layout | |
peng103617 | 0:69db88456c7f | 65 | | -------- | -------------- | |
peng103617 | 0:69db88456c7f | 66 | | ARM | PVVbbbb (P = Major; VV = Minor; bbbb = build number) | |
peng103617 | 0:69db88456c7f | 67 | | GCC | VVRRPP (VV = Version; RR = Revision; PP = Patch) | |
peng103617 | 0:69db88456c7f | 68 | | IAR | VRRRPPP (V = Version; RRR = Revision; PPP = Patch) | |
peng103617 | 0:69db88456c7f | 69 | |
peng103617 | 0:69db88456c7f | 70 | #### CPUID Register Information |
peng103617 | 0:69db88456c7f | 71 | |
peng103617 | 0:69db88456c7f | 72 | | Bit Field | Field Description | Values | |
peng103617 | 0:69db88456c7f | 73 | | --------- | ----------------- | ------ | |
peng103617 | 0:69db88456c7f | 74 | |[31:24] | Implementer | 0x41 = ARM | |
peng103617 | 0:69db88456c7f | 75 | |[23:20] | Variant | Major revision 0x0 = Revision 0 | |
peng103617 | 0:69db88456c7f | 76 | |[19:16] | Architecture | 0xC = Baseline Architecture | |
peng103617 | 0:69db88456c7f | 77 | | | | 0xF = Constant (Mainline Architecture) | |
peng103617 | 0:69db88456c7f | 78 | |[15:4] | Part Number | 0xC20 = Cortex-M0 | |
peng103617 | 0:69db88456c7f | 79 | | | | 0xC60 = Cortex-M0+ | |
peng103617 | 0:69db88456c7f | 80 | | | | 0xC23 = Cortex-M3 | |
peng103617 | 0:69db88456c7f | 81 | | | | 0xC24 = Cortex-M4 | |
peng103617 | 0:69db88456c7f | 82 | | | | 0xC27 = Cortex-M7 | |
peng103617 | 0:69db88456c7f | 83 | | | | 0xD20 = Cortex-M23 | |
peng103617 | 0:69db88456c7f | 84 | | | | 0xD21 = Cortex-M33 | |
peng103617 | 0:69db88456c7f | 85 | |[3:0] | Revision | Minor revision: 0x1 = Patch 1 | |
peng103617 | 0:69db88456c7f | 86 | |
peng103617 | 0:69db88456c7f | 87 | |
peng103617 | 0:69db88456c7f | 88 | |
peng103617 | 0:69db88456c7f | 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). |
peng103617 | 0:69db88456c7f | 90 | |
peng103617 | 0:69db88456c7f | 91 | |
peng103617 | 0:69db88456c7f | 92 | ### Output |
peng103617 | 0:69db88456c7f | 93 | |
peng103617 | 0:69db88456c7f | 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. |
peng103617 | 0:69db88456c7f | 95 | |
peng103617 | 0:69db88456c7f | 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). |
peng103617 | 0:69db88456c7f | 97 | |
peng103617 | 0:69db88456c7f | 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): |
peng103617 | 0:69db88456c7f | 99 | |
peng103617 | 0:69db88456c7f | 100 | ``` |
peng103617 | 0:69db88456c7f | 101 | =============================== SYSTEM INFO ================================ |
peng103617 | 0:69db88456c7f | 102 | Mbed OS Version: 999999 |
peng103617 | 0:69db88456c7f | 103 | CPU ID: 0x410fc241 |
peng103617 | 0:69db88456c7f | 104 | Compiler ID: 2 |
peng103617 | 0:69db88456c7f | 105 | Compiler Version: 60300 |
peng103617 | 0:69db88456c7f | 106 | RAM0: Start 0x20000000 Size: 0x30000 |
peng103617 | 0:69db88456c7f | 107 | RAM1: Start 0x1fff0000 Size: 0x10000 |
peng103617 | 0:69db88456c7f | 108 | ROM0: Start 0x0 Size: 0x100000 |
peng103617 | 0:69db88456c7f | 109 | ================= CPU STATS ================= |
peng103617 | 0:69db88456c7f | 110 | Idle: 98% Usage: 2% |
peng103617 | 0:69db88456c7f | 111 | ================ HEAP STATS ================= |
peng103617 | 0:69db88456c7f | 112 | Current heap: 1096 |
peng103617 | 0:69db88456c7f | 113 | Max heap size: 1096 |
peng103617 | 0:69db88456c7f | 114 | ================ THREAD STATS =============== |
peng103617 | 0:69db88456c7f | 115 | ID: 0x20001eac |
peng103617 | 0:69db88456c7f | 116 | Name: main_thread |
peng103617 | 0:69db88456c7f | 117 | State: 2 |
peng103617 | 0:69db88456c7f | 118 | Priority: 24 |
peng103617 | 0:69db88456c7f | 119 | Stack Size: 4096 |
peng103617 | 0:69db88456c7f | 120 | Stack Space: 3296 |
peng103617 | 0:69db88456c7f | 121 | |
peng103617 | 0:69db88456c7f | 122 | ID: 0x20000f5c |
peng103617 | 0:69db88456c7f | 123 | Name: idle_thread |
peng103617 | 0:69db88456c7f | 124 | State: 1 |
peng103617 | 0:69db88456c7f | 125 | Priority: 1 |
peng103617 | 0:69db88456c7f | 126 | Stack Size: 512 |
peng103617 | 0:69db88456c7f | 127 | Stack Space: 352 |
peng103617 | 0:69db88456c7f | 128 | |
peng103617 | 0:69db88456c7f | 129 | ID: 0x20000f18 |
peng103617 | 0:69db88456c7f | 130 | Name: timer_thread |
peng103617 | 0:69db88456c7f | 131 | State: 3 |
peng103617 | 0:69db88456c7f | 132 | Priority: 40 |
peng103617 | 0:69db88456c7f | 133 | Stack Size: 768 |
peng103617 | 0:69db88456c7f | 134 | Stack Space: 664 |
peng103617 | 0:69db88456c7f | 135 | |
peng103617 | 0:69db88456c7f | 136 | ``` |
peng103617 | 0:69db88456c7f | 137 | |
peng103617 | 0:69db88456c7f | 138 | ## Troubleshooting |
peng103617 | 0:69db88456c7f | 139 | |
peng103617 | 0:69db88456c7f | 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. |
peng103617 | 0:69db88456c7f | 141 | |
peng103617 | 0:69db88456c7f | 142 | ## Related Links |
peng103617 | 0:69db88456c7f | 143 | |
peng103617 | 0:69db88456c7f | 144 | * [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html) |
peng103617 | 0:69db88456c7f | 145 | * [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html) |
peng103617 | 0:69db88456c7f | 146 | * [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html) |
peng103617 | 0:69db88456c7f | 147 | |
peng103617 | 0:69db88456c7f | 148 | ### License and contributions |
peng103617 | 0:69db88456c7f | 149 | |
peng103617 | 0:69db88456c7f | 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. |
peng103617 | 0:69db88456c7f | 151 | |
peng103617 | 0:69db88456c7f | 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. |