This a fork of https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-blinky/

Committer:
c_jin
Date:
Mon Feb 18 05:30:47 2019 +0000
Revision:
0:8b84a0b4f817
Fork of https://developer.mbed.org/teams/mbed-os-examples/code/mbed-os-example-blinky/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
c_jin 0:8b84a0b4f817 1 # Getting started example for Mbed OS
c_jin 0:8b84a0b4f817 2
c_jin 0:8b84a0b4f817 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).)
c_jin 0:8b84a0b4f817 4
c_jin 0:8b84a0b4f817 5 Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli).
c_jin 0:8b84a0b4f817 6
c_jin 0:8b84a0b4f817 7 ## Import the example application
c_jin 0:8b84a0b4f817 8
c_jin 0:8b84a0b4f817 9 From the command-line, import the example:
c_jin 0:8b84a0b4f817 10
c_jin 0:8b84a0b4f817 11 ```
c_jin 0:8b84a0b4f817 12 mbed import mbed-os-example-blinky
c_jin 0:8b84a0b4f817 13 cd mbed-os-example-blinky
c_jin 0:8b84a0b4f817 14 ```
c_jin 0:8b84a0b4f817 15
c_jin 0:8b84a0b4f817 16 ### Now compile
c_jin 0:8b84a0b4f817 17
c_jin 0:8b84a0b4f817 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 5:
c_jin 0:8b84a0b4f817 19
c_jin 0:8b84a0b4f817 20 ```
c_jin 0:8b84a0b4f817 21 mbed compile -m K64F -t ARM
c_jin 0:8b84a0b4f817 22 ```
c_jin 0:8b84a0b4f817 23
c_jin 0:8b84a0b4f817 24 Your PC may take a few minutes to compile your code. At the end, you see the following result:
c_jin 0:8b84a0b4f817 25
c_jin 0:8b84a0b4f817 26 ```
c_jin 0:8b84a0b4f817 27 [snip]
c_jin 0:8b84a0b4f817 28 +----------------------------+-------+-------+------+
c_jin 0:8b84a0b4f817 29 | Module | .text | .data | .bss |
c_jin 0:8b84a0b4f817 30 |--------------------|-----------|----------|----------|
c_jin 0:8b84a0b4f817 31 | [fill] | 98(+0) | 0(+0) | 2211(+0) |
c_jin 0:8b84a0b4f817 32 | [lib]/c.a | 27835(+0) | 2472(+0) | 89(+0) |
c_jin 0:8b84a0b4f817 33 | [lib]/gcc.a | 3168(+0) | 0(+0) | 0(+0) |
c_jin 0:8b84a0b4f817 34 | [lib]/misc | 248(+0) | 8(+0) | 28(+0) |
c_jin 0:8b84a0b4f817 35 | [lib]/nosys.a | 32(+0) | 0(+0) | 0(+0) |
c_jin 0:8b84a0b4f817 36 | main.o | 924(+0) | 0(+0) | 12(+0) |
c_jin 0:8b84a0b4f817 37 | mbed-os/components | 134(+0) | 0(+0) | 0(+0) |
c_jin 0:8b84a0b4f817 38 | mbed-os/drivers | 56(+0) | 0(+0) | 0(+0) |
c_jin 0:8b84a0b4f817 39 | mbed-os/features | 42(+0) | 0(+0) | 184(+0) |
c_jin 0:8b84a0b4f817 40 | mbed-os/hal | 2087(+0) | 8(+0) | 152(+0) |
c_jin 0:8b84a0b4f817 41 | mbed-os/platform | 3633(+0) | 260(+0) | 209(+0) |
c_jin 0:8b84a0b4f817 42 | mbed-os/rtos | 9370(+0) | 168(+0) | 6053(+0) |
c_jin 0:8b84a0b4f817 43 | mbed-os/targets | 9536(+0) | 12(+0) | 382(+0) |
c_jin 0:8b84a0b4f817 44 | Subtotals | 57163(+0) | 2928(+0) | 9320(+0) |
c_jin 0:8b84a0b4f817 45 Total Static RAM memory (data + bss): 12248(+0) bytes
c_jin 0:8b84a0b4f817 46 Total Flash memory (text + data): 60091(+0) bytes
c_jin 0:8b84a0b4f817 47
c_jin 0:8b84a0b4f817 48 Image: ./BUILD/K64F/GCC_ARM/mbed-os-example-blinky.bin
c_jin 0:8b84a0b4f817 49 ```
c_jin 0:8b84a0b4f817 50
c_jin 0:8b84a0b4f817 51 ### Program your board
c_jin 0:8b84a0b4f817 52
c_jin 0:8b84a0b4f817 53 1. Connect your Mbed device to the computer over USB.
c_jin 0:8b84a0b4f817 54 1. Copy the binary file to the Mbed device.
c_jin 0:8b84a0b4f817 55 1. Press the reset button to start the program.
c_jin 0:8b84a0b4f817 56
c_jin 0:8b84a0b4f817 57 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:
c_jin 0:8b84a0b4f817 58
c_jin 0:8b84a0b4f817 59 * System Information:
c_jin 0:8b84a0b4f817 60 * Mbed OS Version: Will currently default to 999999
c_jin 0:8b84a0b4f817 61 * Compiler ID
c_jin 0:8b84a0b4f817 62 * ARM = 1
c_jin 0:8b84a0b4f817 63 * GCC_ARM = 2
c_jin 0:8b84a0b4f817 64 * IAR = 3
c_jin 0:8b84a0b4f817 65 * [CPUID Register Information](#cpuid-register-information)
c_jin 0:8b84a0b4f817 66 * [Compiler Version](#compiler-version)
c_jin 0:8b84a0b4f817 67 * CPU Statistics
c_jin 0:8b84a0b4f817 68 * Percentage of runtime that the device has spent awake versus in sleep
c_jin 0:8b84a0b4f817 69 * Heap Statistics
c_jin 0:8b84a0b4f817 70 * Current heap size
c_jin 0:8b84a0b4f817 71 * Max heap size which refers to the largest the heap has grown to
c_jin 0:8b84a0b4f817 72 * Thread Statistics
c_jin 0:8b84a0b4f817 73 * Provides information on all running threads in the OS including
c_jin 0:8b84a0b4f817 74 * Thread ID
c_jin 0:8b84a0b4f817 75 * Thread Name
c_jin 0:8b84a0b4f817 76 * Thread State
c_jin 0:8b84a0b4f817 77 * Thread Priority
c_jin 0:8b84a0b4f817 78 * Thread Stack Size
c_jin 0:8b84a0b4f817 79 * Thread Stack Space
c_jin 0:8b84a0b4f817 80
c_jin 0:8b84a0b4f817 81 #### Compiler Version
c_jin 0:8b84a0b4f817 82
c_jin 0:8b84a0b4f817 83 | Compiler | Version Layout |
c_jin 0:8b84a0b4f817 84 | -------- | -------------- |
c_jin 0:8b84a0b4f817 85 | ARM | PVVbbbb (P = Major; VV = Minor; bbbb = build number) |
c_jin 0:8b84a0b4f817 86 | GCC | VVRRPP (VV = Version; RR = Revision; PP = Patch) |
c_jin 0:8b84a0b4f817 87 | IAR | VRRRPPP (V = Version; RRR = Revision; PPP = Patch) |
c_jin 0:8b84a0b4f817 88
c_jin 0:8b84a0b4f817 89 #### CPUID Register Information
c_jin 0:8b84a0b4f817 90
c_jin 0:8b84a0b4f817 91 | Bit Field | Field Description | Values |
c_jin 0:8b84a0b4f817 92 | --------- | ----------------- | ------ |
c_jin 0:8b84a0b4f817 93 |[31:24] | Implementer | 0x41 = ARM |
c_jin 0:8b84a0b4f817 94 |[23:20] | Variant | Major revision 0x0 = Revision 0 |
c_jin 0:8b84a0b4f817 95 |[19:16] | Architecture | 0xC = Baseline Architecture |
c_jin 0:8b84a0b4f817 96 | | | 0xF = Constant (Mainline Architecture) |
c_jin 0:8b84a0b4f817 97 |[15:4] | Part Number | 0xC20 = Cortex-M0 |
c_jin 0:8b84a0b4f817 98 | | | 0xC60 = Cortex-M0+ |
c_jin 0:8b84a0b4f817 99 | | | 0xC23 = Cortex-M3 |
c_jin 0:8b84a0b4f817 100 | | | 0xC24 = Cortex-M4 |
c_jin 0:8b84a0b4f817 101 | | | 0xC27 = Cortex-M7 |
c_jin 0:8b84a0b4f817 102 | | | 0xD20 = Cortex-M23 |
c_jin 0:8b84a0b4f817 103 | | | 0xD21 = Cortex-M33 |
c_jin 0:8b84a0b4f817 104 |[3:0] | Revision | Minor revision: 0x1 = Patch 1 |
c_jin 0:8b84a0b4f817 105
c_jin 0:8b84a0b4f817 106
c_jin 0:8b84a0b4f817 107
c_jin 0:8b84a0b4f817 108 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).
c_jin 0:8b84a0b4f817 109
c_jin 0:8b84a0b4f817 110
c_jin 0:8b84a0b4f817 111 ### Output
c_jin 0:8b84a0b4f817 112
c_jin 0:8b84a0b4f817 113 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.
c_jin 0:8b84a0b4f817 114
c_jin 0:8b84a0b4f817 115 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).
c_jin 0:8b84a0b4f817 116
c_jin 0:8b84a0b4f817 117 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):
c_jin 0:8b84a0b4f817 118
c_jin 0:8b84a0b4f817 119 ```
c_jin 0:8b84a0b4f817 120 =============================== SYSTEM INFO ================================
c_jin 0:8b84a0b4f817 121 Mbed OS Version: 999999
c_jin 0:8b84a0b4f817 122 CPU ID: 0x410fc241
c_jin 0:8b84a0b4f817 123 Compiler ID: 2
c_jin 0:8b84a0b4f817 124 Compiler Version: 60300
c_jin 0:8b84a0b4f817 125 RAM0: Start 0x20000000 Size: 0x30000
c_jin 0:8b84a0b4f817 126 RAM1: Start 0x1fff0000 Size: 0x10000
c_jin 0:8b84a0b4f817 127 ROM0: Start 0x0 Size: 0x100000
c_jin 0:8b84a0b4f817 128 ================= CPU STATS =================
c_jin 0:8b84a0b4f817 129 Idle: 98% Usage: 2%
c_jin 0:8b84a0b4f817 130 ================ HEAP STATS =================
c_jin 0:8b84a0b4f817 131 Current heap: 1096
c_jin 0:8b84a0b4f817 132 Max heap size: 1096
c_jin 0:8b84a0b4f817 133 ================ THREAD STATS ===============
c_jin 0:8b84a0b4f817 134 ID: 0x20001eac
c_jin 0:8b84a0b4f817 135 Name: main_thread
c_jin 0:8b84a0b4f817 136 State: 2
c_jin 0:8b84a0b4f817 137 Priority: 24
c_jin 0:8b84a0b4f817 138 Stack Size: 4096
c_jin 0:8b84a0b4f817 139 Stack Space: 3296
c_jin 0:8b84a0b4f817 140
c_jin 0:8b84a0b4f817 141 ID: 0x20000f5c
c_jin 0:8b84a0b4f817 142 Name: idle_thread
c_jin 0:8b84a0b4f817 143 State: 1
c_jin 0:8b84a0b4f817 144 Priority: 1
c_jin 0:8b84a0b4f817 145 Stack Size: 512
c_jin 0:8b84a0b4f817 146 Stack Space: 352
c_jin 0:8b84a0b4f817 147
c_jin 0:8b84a0b4f817 148 ID: 0x20000f18
c_jin 0:8b84a0b4f817 149 Name: timer_thread
c_jin 0:8b84a0b4f817 150 State: 3
c_jin 0:8b84a0b4f817 151 Priority: 40
c_jin 0:8b84a0b4f817 152 Stack Size: 768
c_jin 0:8b84a0b4f817 153 Stack Space: 664
c_jin 0:8b84a0b4f817 154
c_jin 0:8b84a0b4f817 155 ```
c_jin 0:8b84a0b4f817 156
c_jin 0:8b84a0b4f817 157 ## Troubleshooting
c_jin 0:8b84a0b4f817 158
c_jin 0:8b84a0b4f817 159 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.
c_jin 0:8b84a0b4f817 160
c_jin 0:8b84a0b4f817 161 ## Related Links
c_jin 0:8b84a0b4f817 162
c_jin 0:8b84a0b4f817 163 * [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html)
c_jin 0:8b84a0b4f817 164 * [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html)
c_jin 0:8b84a0b4f817 165 * [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html)
c_jin 0:8b84a0b4f817 166
c_jin 0:8b84a0b4f817 167 ### License and contributions
c_jin 0:8b84a0b4f817 168
c_jin 0:8b84a0b4f817 169 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.
c_jin 0:8b84a0b4f817 170
c_jin 0:8b84a0b4f817 171 This project contains code from other projects. The original license text is included in those source files. They must comply with our license guide.