Skip to content

Commit 885f1eb

Browse files
hugueskambaevedon
authored andcommitted
Simplify application (#192)
The example project has been re-written to be simplified. It uses a delay within a loop. Runtime statistics has been removed and is only mentioned in the README. The reader is invited to find out more. Runtime statistics is a topic on its own and should not be implemented here.
1 parent d0e1f47 commit 885f1eb

File tree

8 files changed

+55
-338
lines changed

8 files changed

+55
-338
lines changed

README.md

Lines changed: 46 additions & 134 deletions
Original file line numberDiff line numberDiff line change
@@ -1,149 +1,61 @@
1-
# Getting started example for Mbed OS
1+
![](./resources/official_armmbed_example_badge.png)
2+
# Blinky Mbed OS example
23

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/).
45

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).)
68

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).
810

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:
1012

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+
```
1516

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:
13718

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`.
13936

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
14050
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.
14151

14252
## Related Links
14353

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/).
14759

14860
### License and contributions
14961

main.cpp

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,23 @@
11
/* mbed Microcontroller Library
2-
* Copyright (c) 2018 ARM Limited
2+
* Copyright (c) 2019 ARM Limited
33
* SPDX-License-Identifier: Apache-2.0
44
*/
55

66
#include "mbed.h"
77
#include "platform/mbed_thread.h"
8-
#include "stats_report.h"
98

10-
DigitalOut led1(LED1);
119

12-
#define SLEEP_TIME 500 // (msec)
13-
#define PRINT_AFTER_N_LOOPS 20
10+
// Blinking rate in milliseconds
11+
#define BLINKING_RATE_MS 500
12+
1413

15-
// main() runs in its own thread in the OS
1614
int main()
1715
{
18-
SystemReport sys_state( SLEEP_TIME * PRINT_AFTER_N_LOOPS /* Loop delay time in ms */);
16+
// Initialise the digital pin LED1 as an output
17+
DigitalOut led(LED1);
1918

20-
int count = 0;
2119
while (true) {
22-
// Blink LED and wait 0.5 seconds
23-
led1 = !led1;
24-
thread_sleep_for(SLEEP_TIME);
25-
26-
if ((0 == count) || (PRINT_AFTER_N_LOOPS == count)) {
27-
// Following the main thread wait, report on the current system status
28-
sys_state.report_state();
29-
count = 0;
30-
}
31-
++count;
20+
led = !led;
21+
thread_sleep_for(BLINKING_RATE_MS);
3222
}
3323
}

mbed-os.lib

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
https://github.com/ARMmbed/mbed-os/#679d24833acf0a0b5b0d528576bb37c70863bc4e
1+
https://github.com/ARMmbed/mbed-os/#679d24833acf0a0b5b0d528576bb37c70863bc4e

mbed_app.json

Lines changed: 0 additions & 11 deletions
This file was deleted.
3.67 KB
Loading

stats_report.h

Lines changed: 0 additions & 133 deletions
This file was deleted.

tests/README.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

0 commit comments

Comments
 (0)