Skip to content

Commit dd460e5

Browse files
committed
Remove multithreaded application
1 parent e069957 commit dd460e5

File tree

6 files changed

+24
-170
lines changed

6 files changed

+24
-170
lines changed

README.md

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Blinky Mbed OS Example
22

3-
The example project contains variants of an application to blink an LED on supported [Mbed boards](https://os.mbed.com/platforms/).
3+
The example project contains an application to blink an LED on supported [Mbed boards](https://os.mbed.com/platforms/).
44

55
The project can be built 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). Please install Arm Mbed CLI.
66

@@ -14,18 +14,11 @@ Clone this repository on your system and change the current directory to where t
1414

1515
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`](https://os.mbed.com/docs/mbed-os/latest/reference/configuration.html), 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. This project comes with configuration files for the different variants and configurations of the blinky application.
1616

17-
Select the section for the variant of the application you wish to build:
18-
* [Blinky Wait application](#blinky_wait)
19-
* [Bare metal](#blinky_wait_bare_metal)
20-
* [Blinky multi-threaded application](#blinky_multi_threaded)
17+
## Application functionality
2118

22-
## <a name="blinky_wait"></a> Blinky Wait application
19+
The `main()` function is the single thread in the application, it toggles the state of a digital output connected to an LED on the target.
2320

24-
### Application functionality
25-
26-
The `main()` function calls `blinky_wait()`, as part of the single thread, which toggles the state of a digital output connected to an LED on the target.
27-
28-
### <a name="build_blinky_wait_rtos"></a> Building and Running
21+
## Building and Running
2922

3023
1. Connect a USB cable between the USB port on the target and the host computer.
3124
2. Run the following command to build the example project and program the microcontroller flash memory:
@@ -34,38 +27,21 @@ The `main()` function calls `blinky_wait()`, as part of the single thread, which
3427
```
3528
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.
3629

37-
### <a name="blinky_wait_bare_metal"></a> Bare metal
38-
The variant of the application [above](#build_blinky_wait_rtos) is built with the full Mbed OS library including its RTOS components. However, for single-threaded applications running on targets with ultraconstrains, it is possible to obtain an application with an even smaller memory footprint using [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html) profile.
39-
An application configuration file, [`config_blinky_wait_bare_metal.json`](./blinky_wait/config_blinky_wait_bare_metal.json) is provided to build a binary with Mbed OS bare metal profile.
30+
## Bare metal
31+
The application above is built with the full Mbed OS library including its RTOS components. However, for single-threaded applications running on targets with ultraconstrains, it is possible to obtain an application with an even smaller memory footprint using [Mbed OS bare metal](https://os.mbed.com/docs/mbed-os/latest/reference/mbed-os-bare-metal.html) profile.
32+
An application configuration file, [`config_bare_metal.json`](./config_bare_metal.json) is provided to build a binary with Mbed OS bare metal profile.
4033

4134
1. Connect a USB cable between the USB port on the target and the host computer.
4235
2. Run the following command to build the example project with runtime statistics output:
4336
```bash
44-
$ mbed compile -m <TARGET> -t <TOOLCHAIN> --app-config=./blinky_wait/config_blinky_bare_metal.json --flash
37+
$ mbed compile -m <TARGET> -t <TOOLCHAIN> --app-config config_bare_metal.json --flash
4538
```
4639
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.
4740

4841
`"target.default_lib" : "small"` tells the build tool to use a small implementation 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.
4942

5043

51-
## <a name="blinky_multi_threaded"></a> Blinky multi-threaded application
52-
53-
This variant shows Mbed OS features suchs as threads, thread delay, and inter-thread communication to blink an LED.
54-
55-
### Application functionality
56-
57-
The `main()` function calls `blinky_multithreaded()`, 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 toggles the state of a digital output connected to an LED on the target.
58-
59-
### Building and Running
60-
61-
1. Connect a USB cable between the USB port on the target and the host computer.
62-
2. Run the following command to build the example project and program the microcontroller flash memory:
63-
```bash
64-
$ mbed compile -m <TARGET> -t <TOOLCHAIN> --flash --app-config=./blinky_multithreaded/config_blinky_multithreaded.json
65-
```
66-
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.
67-
68-
### Optional RTOS runtime statistics
44+
## Optional RTOS runtime statistics
6945

7046
It is possible to take a snapshot of the device's runtime statistics and display it over serial to your PC. See how [here](https://os.mbed.com/docs/latest/apis/mbed-statistics.html).
7147

blinky_multithreaded/blinky_multithreaded.cpp

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

blinky_multithreaded/config_blinky_multithreaded.json

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

blinky_wait/blinky_wait.cpp

Lines changed: 0 additions & 23 deletions
This file was deleted.
File renamed without changes.

main.cpp

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

6-
#ifdef BLINKY_MULTITHREADED
7-
extern void blinky_multithreaded();
8-
#else
9-
extern void blinky_wait();
10-
#endif
6+
#include "mbed.h"
7+
#include "platform/mbed_thread.h"
8+
9+
10+
// Blinking rate in milliseconds
11+
#define BLINKING_RATE_MS 500
12+
1113

1214
int main()
1315
{
14-
#ifdef BLINKY_MULTITHREADED
15-
blinky_multithreaded();
16-
#else
17-
blinky_wait();
18-
#endif
16+
// Initialise the digital pin LED1 as an output
17+
DigitalOut led(LED1);
18+
19+
while (true) {
20+
led = !led;
21+
thread_sleep_for(BLINKING_RATE_MS);
22+
}
1923
}

0 commit comments

Comments
 (0)