Skip to content

Commit 3fd02d3

Browse files
committed
Add guide for using bare metal profile
1 parent 5b0b35f commit 3fd02d3

File tree

3 files changed

+77
-8
lines changed

3 files changed

+77
-8
lines changed

docs.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@
5050
{
5151
"path": "docs/program-setup/bare_metal/bare_metal_api.md"
5252
},
53+
{
54+
"path": "docs/program-setup/bare_metal/bare_metal_application.md"
55+
},
5356
{
5457
"path": "docs/program-setup/bare_metal/baremetal_example.md"
5558
},
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Using the bare metal profile
2+
3+
This guide shows how to create a bare metal profile application:
4+
1. By default, when you build an application binary, the build tool uses the full profile. To use the bare metal profile, you need to set up your application to override this default behaviour.
5+
1. Bare metal has a [minimal set of APIs](bare_metal_api.md). You can add additional ones [from the list of supported API](../../api/api.md).
6+
7+
## Creating a bare metal application
8+
9+
1. Create a new Mbed application and enter its directory:
10+
11+
```
12+
mbed new example_app && cd example_app
13+
```
14+
15+
This contains an empty application with Mbed OS (`mbed-os/`) pre-fetched.
16+
17+
1. Open `mbed_app.json` and replace it with the following content:
18+
19+
```json
20+
{
21+
"requires": ["bare-metal"],
22+
"target_overrides": {
23+
"*": {
24+
"target.c_lib": "small"
25+
}
26+
}
27+
}
28+
```
29+
<span class="tips">**Tip:** `"target.c_lib": "small"` enables an optimised version of the C library with lower memory footprint. For more details, see [Using small C libraries in Mbed OS bare metal](c_small_libs.md)</span>.
30+
31+
Bare metal has a minimal set of default APIs - those that are always available to a bare metal application. You can add other supported APIs if you need the features they enable.
32+
33+
For a list of default and supported APIs, [please see our full API list](../../api/api.md).
34+
35+
1. To add an API - in this example, the `EventQueue` class:
36+
37+
1. Locate the library you want to use in `mbed-os/`.
38+
1. In the library folder, find the library's name in `mbed_lib.json`. You will need it for the next step.
39+
40+
For example: `events/mbed_lib.json`:
41+
```json
42+
{
43+
"name": "events",
44+
"config": {
45+
"present": 1,
46+
...
47+
}
48+
}
49+
```
50+
To continue, go back to the application's root directory.
51+
52+
1. Open `mbed_app.json` again, and add the library to the `"requires"` field:
53+
54+
```json
55+
{
56+
"requires": [
57+
"bare-metal",
58+
"events"
59+
]
60+
}
61+
```
62+
63+
1. Write the application using the libraries you added.
64+
65+
[![View code](https://www.mbed.com/embed/?url=https://github.com/armmbed/mbed-os-example-baremetal-eventqueue-blinky/)](https://github.com/ARMmbed/mbed-os-example-baremetal-eventqueue-blinky/blob/master/main.cpp)
66+
67+
1. With a supported board connected to your computer, compile and flash your application:
68+
```
69+
mbed compile -t <TOOLCHAIN> -m <TARGET> --flash
70+
```
71+
72+
In the example above, the on-board LED keeps blinking.
Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,7 @@
11
# Bare metal example
22

3-
To enable Mbed OS bare metal, create an `mbed_app.json` with the following contents:
3+
For a guide on creating a bare metal application, see [Creating a bare metal application](baremetal_application.md#creating-a-bare-metal-application).
44

5-
```
6-
{
7-
"requires": ["bare-metal"]
8-
}
9-
```
10-
11-
To learn about using the bare metal profile, please see the Blinky bare metal example:
5+
The following Blinky bare metal example uses [Bare metal APIs](bare_metal_api.md#bare-metal-apis):
126

137
[![View code](https://www.mbed.com/embed/?url=https://github.com/armmbed/mbed-os-example-blinky-baremetal/)](https://github.com/armmbed/mbed-os-example-blinky-baremetal/blob/master/main.cpp)

0 commit comments

Comments
 (0)