|
1 |
| -# Getting started example for Mbed OS |
| 1 | + |
| 2 | +# Blinky Mbed OS example |
2 | 3 |
|
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).) |
| 4 | +The example project is part of the [Arm Mbed OS Official Examples](https://os.mbed.com/code/) and is the [getting started example for Mbed OS](https://os.mbed.com/docs/mbed-os/v5.14/quick-start/index.html). It contains an application that repeatedly blinks an LED on supported [Mbed boards](https://os.mbed.com/platforms/). |
4 | 5 |
|
5 |
| -Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). |
| 6 | +You can build the project with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/latest/tools/index.html). However, this example project specifically refers to the command-line interface tool [Arm Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). |
| 7 | +(Note: To see a rendered example you can import into the Arm Online Compiler, please see our [import quick start](https://os.mbed.com/docs/mbed-os/latest/quick-start/online-with-the-online-compiler.html#importing-the-code).) |
6 | 8 |
|
7 |
| -## Import the example application |
| 9 | +1. [Install Mbed CLI](https://os.mbed.com/docs/mbed-os/latest/quick-start/offline-with-mbed-cli.html). |
8 | 10 |
|
9 |
| -From the command-line, import the example: |
| 11 | +1. Clone this repository on your system, and change the current directory to where the project was cloned: |
10 | 12 |
|
11 |
| -``` |
12 |
| -mbed import mbed-os-example-blinky |
13 |
| -cd mbed-os-example-blinky |
14 |
| -``` |
| 13 | + ```bash |
| 14 | + $ git clone [email protected]:armmbed/mbed-os-example-blinky && cd mbed-os-example-blinky |
| 15 | + ``` |
15 | 16 |
|
16 |
| -### Now compile |
17 |
| - |
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: |
19 |
| - |
20 |
| -``` |
21 |
| -mbed compile -m K64F -t ARM |
22 |
| -``` |
23 |
| - |
24 |
| -Your PC may take a few minutes to compile your code. At the end, you see the following result: |
25 |
| - |
26 |
| -``` |
27 |
| -[snip] |
28 |
| -
|
29 |
| -Image: ./BUILD/K64F/GCC_ARM/mbed-os-example-blinky.bin |
30 |
| -``` |
31 |
| - |
32 |
| -### Program your board |
33 |
| - |
34 |
| -1. Connect your Mbed device to the computer over USB. |
35 |
| -1. Copy the binary file to the Mbed device. |
36 |
| -1. Press the reset button to start the program. |
37 |
| - |
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: |
39 |
| - |
40 |
| -* System Information: |
41 |
| - * Mbed OS Version: Will currently default to 999999 |
42 |
| - * Compiler ID |
43 |
| - * ARM = 1 |
44 |
| - * GCC_ARM = 2 |
45 |
| - * IAR = 3 |
46 |
| - * [CPUID Register Information](#cpuid-register-information) |
47 |
| - * [Compiler Version](#compiler-version) |
48 |
| -* CPU Statistics |
49 |
| - * Percentage of runtime that the device has spent awake versus in sleep |
50 |
| -* Heap Statistics |
51 |
| - * Current heap size |
52 |
| - * Max heap size which refers to the largest the heap has grown to |
53 |
| -* Thread Statistics |
54 |
| - * Provides information on all running threads in the OS including |
55 |
| - * Thread ID |
56 |
| - * Thread Name |
57 |
| - * Thread State |
58 |
| - * Thread Priority |
59 |
| - * Thread Stack Size |
60 |
| - * Thread Stack Space |
61 |
| - |
62 |
| -#### Compiler Version |
63 |
| - |
64 |
| -| Compiler | Version Layout | |
65 |
| -| -------- | -------------- | |
66 |
| -| ARM | PVVbbbb (P = Major; VV = Minor; bbbb = build number) | |
67 |
| -| GCC | VVRRPP (VV = Version; RR = Revision; PP = Patch) | |
68 |
| -| IAR | VRRRPPP (V = Version; RRR = Revision; PPP = Patch) | |
69 |
| - |
70 |
| -#### CPUID Register Information |
71 |
| - |
72 |
| -| Bit Field | Field Description | Values | |
73 |
| -| --------- | ----------------- | ------ | |
74 |
| -|[31:24] | Implementer | 0x41 = ARM | |
75 |
| -|[23:20] | Variant | Major revision 0x0 = Revision 0 | |
76 |
| -|[19:16] | Architecture | 0xC = Baseline Architecture | |
77 |
| -| | | 0xF = Constant (Mainline Architecture) | |
78 |
| -|[15:4] | Part Number | 0xC20 = Cortex-M0 | |
79 |
| -| | | 0xC60 = Cortex-M0+ | |
80 |
| -| | | 0xC23 = Cortex-M3 | |
81 |
| -| | | 0xC24 = Cortex-M4 | |
82 |
| -| | | 0xC27 = Cortex-M7 | |
83 |
| -| | | 0xD20 = Cortex-M23 | |
84 |
| -| | | 0xD21 = Cortex-M33 | |
85 |
| -|[3:0] | Revision | Minor revision: 0x1 = Patch 1 | |
86 |
| - |
87 |
| - |
88 |
| - |
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). |
90 |
| - |
91 |
| - |
92 |
| -### Output |
93 |
| - |
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. |
95 |
| - |
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). |
97 |
| - |
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): |
99 |
| - |
100 |
| -``` |
101 |
| -=============================== SYSTEM INFO ================================ |
102 |
| -Mbed OS Version: 999999 |
103 |
| -CPU ID: 0x410fc241 |
104 |
| -Compiler ID: 2 |
105 |
| -Compiler Version: 60300 |
106 |
| -RAM0: Start 0x20000000 Size: 0x30000 |
107 |
| -RAM1: Start 0x1fff0000 Size: 0x10000 |
108 |
| -ROM0: Start 0x0 Size: 0x100000 |
109 |
| -================= CPU STATS ================= |
110 |
| -Idle: 98% Usage: 2% |
111 |
| -================ HEAP STATS ================= |
112 |
| -Current heap: 1096 |
113 |
| -Max heap size: 1096 |
114 |
| -================ THREAD STATS =============== |
115 |
| -ID: 0x20001eac |
116 |
| -Name: main_thread |
117 |
| -State: 2 |
118 |
| -Priority: 24 |
119 |
| -Stack Size: 4096 |
120 |
| -Stack Space: 3296 |
121 |
| -
|
122 |
| -ID: 0x20000f5c |
123 |
| -Name: idle_thread |
124 |
| -State: 1 |
125 |
| -Priority: 1 |
126 |
| -Stack Size: 512 |
127 |
| -Stack Space: 352 |
128 |
| -
|
129 |
| -ID: 0x20000f18 |
130 |
| -Name: timer_thread |
131 |
| -State: 3 |
132 |
| -Priority: 40 |
133 |
| -Stack Size: 768 |
134 |
| -Stack Space: 664 |
135 |
| -
|
136 |
| -``` |
| 17 | + Alternatively, you can download the example project with Arm Mbed CLI using the `import` subcommand: |
137 | 18 |
|
138 |
| -## Troubleshooting |
| 19 | + ```bash |
| 20 | + $ mbed import mbed-os-example-blinky && cd mbed-os-example-blinky |
| 21 | + ``` |
| 22 | + |
| 23 | + |
| 24 | +## Application functionality |
| 25 | + |
| 26 | +The `main()` function is the single thread in the application. It toggles the state of a digital output connected to an LED on the board. |
| 27 | +
|
| 28 | +## Building and running |
| 29 | +
|
| 30 | +1. Connect a USB cable between the USB port on the board and the host computer. |
| 31 | +2. <a name="build_cmd"></a> Run the following command to build the example project and program the microcontroller flash memory: |
| 32 | + ```bash |
| 33 | + $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash |
| 34 | + ``` |
| 35 | +The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin`. |
139 | 36 |
|
| 37 | +Alternatively, you can manually copy the binary to the board, which you mount on the host computer over USB. |
| 38 | + |
| 39 | +Depending on the target, you can build the example project with the `GCC_ARM`, `ARM` or `IAR` toolchain. After installing Arm Mbed CLI, run the command below to determine which toolchain supports your target: |
| 40 | + |
| 41 | + ```bash |
| 42 | + $ mbed compile -S |
| 43 | + ``` |
| 44 | + |
| 45 | +## Expected output |
| 46 | +The LED on your target turns on and off every 500 milliseconds. |
| 47 | + |
| 48 | + |
| 49 | +## Troubleshooting |
140 | 50 | 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.
|
141 | 51 |
|
142 | 52 | ## Related Links
|
143 | 53 |
|
144 |
| -* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html) |
145 |
| -* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html) |
146 |
| -* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html) |
| 54 | +* [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html). |
| 55 | +* [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html). |
| 56 | +* [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html). |
| 57 | +* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html). |
| 58 | +* [Mbed boards](https://os.mbed.com/platforms/). |
147 | 59 |
|
148 | 60 | ### License and contributions
|
149 | 61 |
|
|
0 commit comments