|
1 |
| -# Getting started example for Mbed OS |
| 1 | +# Blinky Mbed OS Example |
2 | 2 |
|
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).) |
| 3 | +## Introduction |
| 4 | +The example shows Mbed OS features suchs as threads, thread delay, and inter-thread communication to blink an LED on supported [Mbed boards](https://os.mbed.com/platforms/). It also comes with configuration files to enable RTOS statistic and to build with [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/v5.14/reference/mbed-os-bare-metal.html) profile. |
4 | 5 |
|
5 |
| -Please install [Mbed CLI](https://github.com/ARMmbed/mbed-cli#installing-mbed-cli). |
| 6 | +The project can be built with all supported [Mbed OS build tools](https://os.mbed.com/docs/mbed-os/v5.14/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). |
6 | 7 |
|
7 |
| -## Import the example application |
| 8 | +Depending on the target, the example project can be built with GCC_ARM, ARM or IAR toolchain. Run the command below after installing ARM Mbed CLI to determine which toolchain support your target. |
8 | 9 |
|
9 |
| -From the command-line, import the example: |
10 |
| - |
11 |
| -``` |
12 |
| -mbed import mbed-os-example-blinky |
13 |
| -cd mbed-os-example-blinky |
| 10 | +```bash |
| 11 | +$ mbed compile -S |
14 | 12 | ```
|
15 | 13 |
|
16 |
| -### Now compile |
| 14 | +Clone this repository on your system and change the current directory to where the project was cloned. |
17 | 15 |
|
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: |
| 16 | +Select the section for the version of the application you wish to build: |
| 17 | +* [Building and Running the RTOS application](#blinky_rtos) |
| 18 | +* [Building and Running the bare metal application](#blinky_bare_metal) |
19 | 19 |
|
20 |
| -``` |
21 |
| -mbed compile -m K64F -t ARM |
22 |
| -``` |
| 20 | +## <a name="blinky_rtos"></a> Building and Running the RTOS application |
23 | 21 |
|
24 |
| -Your PC may take a few minutes to compile your code. At the end, you see the following result: |
| 22 | +1. Connect a USB cable between the USB port on the target and the host computer. |
| 23 | +2. Run the following command to build the example project and program the microcontroller flash memory: |
| 24 | + ```bash |
| 25 | + $ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash |
| 26 | + ``` |
| 27 | +The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin` and can alternatively be manually copied to the target which gets mounted on the host computer via USB. |
25 | 28 |
|
26 |
| -``` |
27 |
| -[snip] |
| 29 | +### Application functionality |
| 30 | + |
| 31 | +The `main()` function calls `blinky_rtos()`, as part of the main thread, which starts two threads: `thread_producer()` and `thread_consumer`. `thread_producer()` periodically send messages to `thread_consumer()` via an inter-thread queue. `thread_consumer()` verifies the message correctness and toggle the state of a digital output connected to an LED on the target. |
28 | 32 |
|
29 |
| -Image: ./BUILD/K64F/GCC_ARM/mbed-os-example-blinky.bin |
| 33 | +### Optional RTOS runtime statistics |
| 34 | +
|
| 35 | +`blinky_rtos()` can optionally take a snapshot of the device's runtime statistics and display it over serial to your PC. The example project has to be re-built with modified Mbed OS configuration parameters. Modifying default Mbed OS configuration parameters can be done at application level using an application configuration file. By default ARM Mbed CLI looks for `mbed_app.json`, however the configuration file can be named anything. It can be passed to ARM Mbed CLI using the optional argument `--app-config` of the `compile` sub-command. The application configuration file `config_rtos_stats.json` has been provided to enable runtime statistics to be printed. |
| 36 | +
|
| 37 | +Run the following command to build the example project with runtime statistics output: |
| 38 | +```bash |
| 39 | +$ mbed compile -m <TARGET> -t <TOOLCHAIN> --app-config=config_rtos_stats.json --flash |
30 | 40 | ```
|
31 | 41 |
|
32 |
| -### Program your board |
| 42 | +### View the serial output |
| 43 | +
|
| 44 | +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. |
33 | 45 |
|
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. |
| 46 | +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). |
37 | 47 |
|
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: |
| 48 | +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): |
39 | 49 |
|
| 50 | +```bash |
| 51 | +=============================== SYSTEM INFO ================================ |
| 52 | +Mbed OS Version: 999999 |
| 53 | +CPU ID: 0x410fc241 |
| 54 | +Compiler ID: 2 |
| 55 | +Compiler Version: 60300 |
| 56 | +RAM0: Start 0x20000000 Size: 0x30000 |
| 57 | +RAM1: Start 0x1fff0000 Size: 0x10000 |
| 58 | +ROM0: Start 0x0 Size: 0x100000 |
| 59 | +================= CPU STATS ================= |
| 60 | +Idle: 98% Usage: 2% |
| 61 | +================ HEAP STATS ================= |
| 62 | +Current heap: 1096 |
| 63 | +Max heap size: 1096 |
| 64 | +================ THREAD STATS =============== |
| 65 | +ID: 0x20001eac |
| 66 | +Name: main_thread |
| 67 | +State: 2 |
| 68 | +Priority: 24 |
| 69 | +Stack Size: 4096 |
| 70 | +Stack Space: 3296 |
| 71 | +
|
| 72 | +ID: 0x20000f5c |
| 73 | +Name: idle_thread |
| 74 | +State: 1 |
| 75 | +Priority: 1 |
| 76 | +Stack Size: 512 |
| 77 | +Stack Space: 352 |
| 78 | +
|
| 79 | +ID: 0x20000f18 |
| 80 | +Name: timer_thread |
| 81 | +State: 3 |
| 82 | +Priority: 40 |
| 83 | +Stack Size: 768 |
| 84 | +Stack Space: 664 |
| 85 | +``` |
| 86 | +
|
| 87 | +The snapshot includes: |
40 | 88 | * System Information:
|
41 | 89 | * Mbed OS Version: Will currently default to 999999
|
42 | 90 | * Compiler ID
|
@@ -84,66 +132,37 @@ The LED on your platform turns on and off. The main thread will additionally tak
|
84 | 132 | | | | 0xD21 = Cortex-M33 |
|
85 | 133 | |[3:0] | Revision | Minor revision: 0x1 = Patch 1 |
|
86 | 134 |
|
87 |
| - |
88 |
| - |
89 | 135 | 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 | 136 |
|
91 | 137 |
|
92 |
| -### Output |
| 138 | +## <a name="blinky_bare_metal"></a> Building and Running the bare metal application |
93 | 139 |
|
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. |
| 140 | +An application configuration file, `config_bare_metal.json` is provided to build a version that uses [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/v5.14/reference/mbed-os-bare-metal.html) profile to create a single threaded application. |
95 | 141 |
|
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): |
| 142 | +1. Connect a USB cable between the USB port on the target and the host computer. |
| 143 | +2. Run the following command to build the example project with runtime statistics output: |
| 144 | + ```bash |
| 145 | + $ mbed compile -m <TARGET> -t <TOOLCHAIN> --app-config=config_bare_metal.json --flash |
| 146 | + ``` |
| 147 | +The binary is located at `./BUILD/<TARGET>/<TOOLCHAIN>/mbed-os-example-blinky.bin` and can alternatively be manually copied to the target which gets mounted on the host computer via USB. |
99 | 148 |
|
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 |
| 149 | +`"target.default_lib" : "small"` tells the build tool to use a small version of the C standard library for the toolchain selected if available. That would be Newlib-nano and MicroLib for GCC_ARM and ARM toolchains respectively. |
121 | 150 |
|
122 |
| -ID: 0x20000f5c |
123 |
| -Name: idle_thread |
124 |
| -State: 1 |
125 |
| -Priority: 1 |
126 |
| -Stack Size: 512 |
127 |
| -Stack Space: 352 |
| 151 | +### Application functionality |
128 | 152 |
|
129 |
| -ID: 0x20000f18 |
130 |
| -Name: timer_thread |
131 |
| -State: 3 |
132 |
| -Priority: 40 |
133 |
| -Stack Size: 768 |
134 |
| -Stack Space: 664 |
| 153 | +The `main()` function calls `blinky_bare_metal()`, as part of the single thread, which toggles the state of a digital output connected to an LED on the target. |
135 | 154 |
|
136 |
| -``` |
137 | 155 |
|
138 | 156 | ## Troubleshooting
|
139 |
| - |
140 | 157 | 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 | 158 |
|
142 | 159 | ## Related Links
|
143 | 160 |
|
144 | 161 | * [Mbed OS Stats API](https://os.mbed.com/docs/latest/apis/mbed-statistics.html)
|
145 | 162 | * [Mbed OS Configuration](https://os.mbed.com/docs/latest/reference/configuration.html)
|
146 | 163 | * [Mbed OS Serial Communication](https://os.mbed.com/docs/latest/tutorials/serial-communication.html)
|
| 164 | +* [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/v5.14/reference/mbed-os-bare-metal.html) |
| 165 | +* [Mbed boards](https://os.mbed.com/platforms/) |
147 | 166 |
|
148 | 167 | ### License and contributions
|
149 | 168 |
|
|
0 commit comments