-
Notifications
You must be signed in to change notification settings - Fork 178
Tutorial on creating a bare metal application #1305
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
6b8490e
6528b3c
6c3372d
cec980c
910e020
53ac4ba
9776dfd
f28a40d
841ebce
f207742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,19 +34,19 @@ Configure your target to support Mbed OS 6: | |
|
||
1. Remove the `release_versions` property; it is no longer required: | ||
|
||
``` | ||
```json | ||
"release_versions": ["2"] | ||
``` | ||
|
||
1. To indicate that the application profile supported by this target is bare metal, add the `supported_application_profiles` property: | ||
|
||
``` | ||
```json | ||
"supported_application_profiles" : ["bare-metal"] | ||
``` | ||
|
||
1. Override `supported_c_libs` property to link with the smaller C libraries. The default for all targets is defined as follows: | ||
|
||
``` | ||
```json | ||
"supported_c_libs": { | ||
"arm": ["std"], | ||
"gcc_arm": ["std", "small"], | ||
|
@@ -56,7 +56,7 @@ Configure your target to support Mbed OS 6: | |
|
||
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`: | ||
|
||
``` | ||
```json | ||
"supported_c_libs": { | ||
"arm": ["small"], | ||
"gcc_arm": ["small"] | ||
|
@@ -67,7 +67,7 @@ Configure your target to support Mbed OS 6: | |
|
||
For each toolchain, if there is enough memory to link with the standard library, add the corresponding `std` library to the list. For example: | ||
|
||
``` | ||
```json | ||
"supported_c_libs": { | ||
"arm": ["std", "small"], | ||
"gcc_arm": ["std", "small"], | ||
|
@@ -92,7 +92,7 @@ Configure your target to support Mbed OS 6: | |
|
||
1. If your board does not have a low power ticker, ensure that tickless is enabled using the microsecond ticker: | ||
|
||
``` | ||
```json | ||
"overrides": { | ||
"tickless-from-us-ticker": true | ||
} | ||
|
@@ -102,7 +102,7 @@ Configure your target to support Mbed OS 6: | |
|
||
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. | ||
|
||
``` | ||
```json | ||
"overrides": { | ||
"boot-stack-size": "0x400" | ||
} | ||
|
@@ -122,7 +122,7 @@ Troubleshoot any issue. | |
|
||
## Validating the port | ||
|
||
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). | ||
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). All tests compatible with bare metal are enabled. | ||
|
||
If you haven't used Greentea before, [you can learn more in our documentation](../tools/greentea-testing-applications.html). | ||
|
||
|
@@ -140,15 +140,27 @@ If you haven't used Greentea before, [you can learn more in our documentation](. | |
|
||
<span class="tips">**Tip:** You can append `--compile` and fix build issues before running tests with `--run`.</span> | ||
|
||
1. All tests should pass (or be automatically skipped). | ||
1. All tests should pass (or be automatically skipped), with exceptions when the target being ported is ultra-constrained (with 32KB of flash memory or less) in which case linking may fail for only _a few_ tests. For example, | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
ARM toolchain: | ||
``` | ||
Error: L6407E: Sections of aggregate size 0x318 bytes could not fit into .ANY selector(s). | ||
``` | ||
|
||
GCC_ARM toolchain: | ||
``` | ||
region `FLASH' overflowed by 792 bytes | ||
``` | ||
|
||
Please ignore tests with similar errors for now. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What does "for now" mean? Until later in the document? Later in the year? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'll remove "for now" to avoid confusion. |
||
|
||
Further optimisations for targets with small flash memories: | ||
- Append `--profile release` to the command above. Use of the release profile helps keep some tests within the size limit. | ||
- 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. | ||
|
||
Modify `TESTS/configs/baremetal.json` for your target: | ||
|
||
``` | ||
```json | ||
{ | ||
"target_overrides": { | ||
"YOUR_TARGET": { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,72 @@ | ||
# Using the bare metal profile | ||
|
||
Content still in PR | ||
This guide shows how to create a bare metal profile application: | ||
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. | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. Bare metal has a minimal set of APIs. You can add additional ones [from the list of supported API](bare_metal.md#features). | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Creating a bare metal application | ||
|
||
1. Create a new Mbed application and enter its directory: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
``` | ||
mbed new example_app && cd example_app | ||
``` | ||
|
||
This contains an empty application with Mbed OS (`mbed-os/`) pre-fetched. | ||
|
||
1. Open `mbed_app.json` and replace it with the following content: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
```json | ||
{ | ||
"requires": ["bare-metal"], | ||
"target_overrides": { | ||
"*": { | ||
"target.c_lib": "small" | ||
} | ||
} | ||
} | ||
``` | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<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>. | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
iriark01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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. | ||
|
||
For a list of default and supported APIs, [please see our full API list](bare_metal.md#features). | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. To add an API - in this example, the `EventQueue` class: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. Locate the library you want to use in `mbed-os/`. | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
1. In the library folder, find the library's name in `mbed_lib.json`. You will need it for the next step. | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
For example: `events/mbed_lib.json`: | ||
```json | ||
{ | ||
"name": "events", | ||
"config": { | ||
"present": 1, | ||
... | ||
} | ||
} | ||
``` | ||
To continue, go back to the application's root directory. | ||
|
||
1. Open `mbed_app.json` again, and add the library to the `"requires"` field: | ||
|
||
```json | ||
{ | ||
"requires": [ | ||
"bare-metal", | ||
"events" | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
} | ||
``` | ||
|
||
1. Write the application using the libraries you added. | ||
|
||
[](https://github.com/ARMmbed/mbed-os-example-baremetal-eventqueue-blinky/blob/master/main.cpp) | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. With a supported board connected to your computer, compile and flash your application: | ||
``` | ||
mbed compile -t <TOOLCHAIN> -m <TARGET> --flash | ||
``` | ||
|
||
In the example above, the on-board LED keeps blinking. |
Uh oh!
There was an error while loading. Please reload this page.