You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tutorial on creating a bare metal application (#1305)
* Add guide for using bare metal profile
* Bare metal porting: stress that compatible Greentea tests are all enabled
* mbed2_porting: explain Greentea errors due to small memory size
* mbed2_porting: JSON syntax highlighting
* Remove baremetal_example.md whose purpose duplicates using_bare_metal.md
* Bare metal guide improved
* Bare metal guide: events library path relative to application root
* Apply suggestions from @iriark01
Co-authored-by: Irit Arkin <[email protected]>
* Incorporate the latest review comments
* Fomatting
Co-authored-by: Irit Arkin <[email protected]>
Copy file name to clipboardExpand all lines: docs/bare_metal/mbed2_porting.md
+22-10Lines changed: 22 additions & 10 deletions
Original file line number
Diff line number
Diff line change
@@ -34,19 +34,19 @@ Configure your target to support Mbed OS 6:
34
34
35
35
1. Remove the `release_versions` property; it is no longer required:
36
36
37
-
```
37
+
```json
38
38
"release_versions": ["2"]
39
39
```
40
40
41
41
1. To indicate that the application profile supported by this target is bare metal, add the `supported_application_profiles` property:
42
42
43
-
```
43
+
```json
44
44
"supported_application_profiles" : ["bare-metal"]
45
45
```
46
46
47
47
1. Override `supported_c_libs` property to link with the smaller C libraries. The default for all targets is defined as follows:
48
48
49
-
```
49
+
```json
50
50
"supported_c_libs": {
51
51
"arm": ["std"],
52
52
"gcc_arm": ["std", "small"],
@@ -56,7 +56,7 @@ Configure your target to support Mbed OS 6:
56
56
57
57
Both the ARM and GCC_ARM toolchains support optimized versions of the C standard libraries - microlib and newlib-nano, respectively. We recommend using them with the bare metal profile for lower memory footprints. Ultraconstrained targets should override `supported_c_libs`:
58
58
59
-
```
59
+
```json
60
60
"supported_c_libs": {
61
61
"arm": ["small"],
62
62
"gcc_arm": ["small"]
@@ -67,7 +67,7 @@ Configure your target to support Mbed OS 6:
67
67
68
68
For each toolchain, if there is enough memory to link with the standard library, add the corresponding `std` library to the list. For example:
69
69
70
-
```
70
+
```json
71
71
"supported_c_libs": {
72
72
"arm": ["std", "small"],
73
73
"gcc_arm": ["std", "small"],
@@ -92,7 +92,7 @@ Configure your target to support Mbed OS 6:
92
92
93
93
1. If your board does not have a low power ticker, ensure that tickless is enabled using the microsecond ticker:
94
94
95
-
```
95
+
```json
96
96
"overrides": {
97
97
"tickless-from-us-ticker": true
98
98
}
@@ -102,7 +102,7 @@ Configure your target to support Mbed OS 6:
102
102
103
103
The stack size is configured by setting a value for the `boot-stack-size` attribute; this value must be a multiple of 8 for alignment purposes. We recommend that you reduce the boot stack size to 0x400 (1,024 bytes) if your target has 8KB of RAM and to 0x300 (768 bytes) if your target has 4KB of RAM.
104
104
105
-
```
105
+
```json
106
106
"overrides": {
107
107
"boot-stack-size": "0x400"
108
108
}
@@ -122,7 +122,7 @@ Troubleshoot any issue.
122
122
123
123
## Validating the port
124
124
125
-
To validate the bare metal target configuration, execute the Mbed OS Greentea test suite with the bare metal profile. This profile causes Greentea to skip a subset of the tests, either because the underlying functionality has not been ported to bare metal or because some tests require RTOS features (for examples, more complex tests based on multi-threading).
125
+
To validate the bare metal target configuration, execute the Mbed OS Greentea test suite with the bare metal profile. This profile causes Greentea to skip a subset of the tests, either because the underlying functionality has not been ported to bare metal or because some tests require RTOS features (for examples, more complex tests based on multi-threading). It performs all the tests compatible with bare metal.
126
126
127
127
If you haven't used Greentea before, [you can learn more in our documentation](../tools/greentea-testing-applications.html).
128
128
@@ -140,15 +140,27 @@ If you haven't used Greentea before, [you can learn more in our documentation](.
140
140
141
141
<span class="tips">**Tip:** You can append `--compile` and fix build issues before running tests with `--run`.</span>
142
142
143
-
1. All tests should pass (or be automatically skipped).
143
+
1. All tests should pass (or be automatically skipped), unless the target being ported is ultraconstrained (with 32KB or less of flash memory) - in which case linking may fail for _a few_ tests. For example:
144
+
145
+
ARM toolchain:
146
+
```
147
+
Error: L6407E: Sections of aggregate size 0x318 bytes could not fit into .ANY selector(s).
148
+
```
149
+
150
+
GCC_ARM toolchain:
151
+
```
152
+
region `FLASH' overflowed by 792 bytes
153
+
```
154
+
155
+
Please ignore tests with similar errors.
144
156
145
157
Further optimisations for targets with small flash memories:
146
158
- Append `--profile release` to the command above. Use of the release profile helps keep some tests within the size limit.
147
159
- Save additional memory by using a [minimal console](https://github.com/ARMmbed/mbed-os-example-blinky-baremetal#using-a-minimal-console) to remove file handling functionality from the system I/O retarget code.
148
160
149
161
Modify `TESTS/configs/baremetal.json` for your target:
This guide shows how to create a bare metal profile application:
4
+
5
+
1. Set the profile: By default, the build tool uses the full profile for all application builds. To use the bare metal profile, set up your application to override this default behaviour.
6
+
1. By default, the bare metal profile uses a minimal set of APIs. You can add additional ones [from the list of supported APIs](../bare-metal/index.html#features) if your application needs them.
7
+
8
+
To demonstrate how to create a bare metal application, here is an example that prints text at regular intervals using the `EventQueue` class:
1. Create a new Mbed OS application and navigate to its directory:
17
+
18
+
```
19
+
mbed new example_app && cd example_app
20
+
```
21
+
22
+
The directory contains the full Mbed OS library (`mbed-os/`) and no application files.
23
+
24
+
1. Create a `main.cpp` file containing the `EventQueue` code snippet above.
25
+
26
+
1. Open `mbed_app.json` (in the root of the application) and replace it with the following content:
27
+
28
+
```json
29
+
{
30
+
"requires": ["bare-metal"],
31
+
"target_overrides": {
32
+
"*": {
33
+
"target.c_lib": "small"
34
+
}
35
+
}
36
+
}
37
+
```
38
+
39
+
The file specifies which profile to use (`"requires": ["bare-metal"]`) and which C library to use (`"target.c_lib": "small"`).
40
+
41
+
In this example, we're using `"target.c_lib": "small"` (small C library). This means your application will use an optimised version of the C library with lower memory footprint. For more details, see [Using small C libraries in Mbed OS bare metal](../bare-metal/using-small-c-libraries.html).
42
+
43
+
You now have application code and a bare metal profile with the default APIs. However, this example uses APIs that are not part of the default bare metal profile - you need to manually add support for those APIs to the application.
44
+
45
+
## Adding APIs
46
+
47
+
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.
48
+
49
+
For a list of default and supported APIs, [please see our full API list](../apis/index.html).
50
+
51
+
This example depends on the `EventQueue` class, so you need to add the library that contains that class:
52
+
53
+
1. In `mbed-os/`, locate the API and the library in which it is declared.
54
+
1. In the library folder, open `mbed_lib.json` and find the library's name. You will need it for the next step.
55
+
56
+
For example: `mbed-os/events/mbed_lib.json`:
57
+
```json
58
+
{
59
+
"name": "events",
60
+
"config": {
61
+
"present": 1,
62
+
...
63
+
}
64
+
}
65
+
```
66
+
To continue, go back to the application's root directory.
67
+
68
+
1. Open `mbed_app.json` again, and add the library to the `"requires"` field:
69
+
70
+
```json
71
+
{
72
+
"requires": ["bare-metal", "events"],
73
+
"target_overrides": {
74
+
"*": {
75
+
"target.c_lib": "small"
76
+
}
77
+
}
78
+
}
79
+
```
80
+
81
+
## Compiling and Running the Application
82
+
83
+
Connect a supported board to your computer, and compile and run your application:
0 commit comments