-
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 7 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,88 @@ | ||
# 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 | ||
|
||
To demonstrate how to create a bare metal application, we use an example that prints text in regular intervals using the `EventQueue` class: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
[](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_RTOS/EventQueue_ex_2/main.cpp) | ||
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 need to double-check that this transcluded correctly. |
||
|
||
The steps are as follows: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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/`) fetched. | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. Create a `main.cpp` containing the `EventQueue` example code snippet above. | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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. Add dependencies - in this example, we need to add the library that contains the `EventQueue` class: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
1. Locate the API and the library where it is declared 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: `mbed-os/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"], | ||
"target_overrides": { | ||
"*": { | ||
"target.c_lib": "small" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
1. With a supported board connected to your computer, compile and run your application: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
mbed compile -t <TOOLCHAIN> -m <TARGET> --flash --sterm | ||
``` | ||
|
||
This opens a serial terminal once the example is compiled and flashed. The following output is expected: | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
called immediately | ||
called every 1 seconds | ||
called in 2 seconds | ||
called every 1 seconds | ||
called every 1 seconds | ||
called every 1 seconds | ||
``` | ||
|
||
To exit the serial terminal, press Ctrl + C. | ||
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 if I don't get that output? What does it mean and what should I do? 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. There can be different causes of not getting the expected output - issues with serial communication, target drivers, the application itself, etc. In my opinion it may not be feasible to have a troubleshooting guide wherever some output is quoted. In https://os.mbed.com/docs/mbed-os/v5.15/tutorials/the-eventqueue-api.html for example, it just says "This is the output of the above program on an FRDM-K64F board." So I'll replace "You should get the following output" which seems to hint users they may or may not get it. |
Uh oh!
There was an error while loading. Please reload this page.