-
Notifications
You must be signed in to change notification settings - Fork 178
Added Mbed 2 to Mbed OS bare metal porting guide #1293
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
# Porting an Mbed OS 2 target to Mbed OS 6 bare metal | ||
|
||
The Mbed OS bare metal profile removes the RTOS and provides fewer features compared to Mbed OS 6. This profile offers the same functionality as Mbed OS 2 and allows targets to access features that we have added to more recent versions of Mbed OS. This document describes how to configure an Mbed OS 2 target for bare metal and validate the port. | ||
hugueskamba marked this conversation as resolved.
Show resolved
Hide resolved
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Configuring your target | ||
|
||
You will use the blinky bare metal Mbed OS example and make it run on your target. The configuration will be validated upon successful run of the example. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The main steps are: | ||
1. Clone [mbed-os-example-blinky-baremetal](https://github.com/ARMmbed/mbed-os-example-blinky-baremetal). | ||
1. Edit `targets.json`. In this step, you will configure your target to support Mbed OS 6 and add bare metal configuration parameters. | ||
1. Build and run mbed-os-example-blinky-baremetal. In this step, you will validate the configuration and troubleshoot any issue. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Clone mbed-os-example-blinky-baremetal | ||
|
||
Run the following command: | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `git clone https://github.com/ARMmbed/mbed-os-example-blinky-baremetal` | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
And then change directory: | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
- `cd mbed-os-example-blinky-baremetal` | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
### Edit targets.json | ||
|
||
Find your target in `mbed-os/targets/targets.json` and update its configuration as described below. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Configure your target to support Mbed OS 6: | ||
- Remove the `release_versions` property as it is no longer required. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
"release_versions": ["2"] | ||
``` | ||
|
||
- Add the `supported_application_profiles` property to indicate that the application profile supported by this target is bare metal. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
"supported_application_profiles" : ["bare-metal"] | ||
``` | ||
|
||
- Override `supported_c_libs` property to link with the smaller C libraries. The default for all targets is defined as follows: | ||
``` | ||
"supported_c_libs": { | ||
"arm": ["std"], | ||
"gcc_arm": ["std", "small"], | ||
"iar": ["std"] | ||
} | ||
``` | ||
|
||
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 to achieve lower memory footprints. Ultra constrained targets should override `supported_c_libs` as follows: | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
"supported_c_libs": { | ||
"arm": ["small"], | ||
"gcc_arm": ["small"] | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
``` | ||
|
||
For each toolchain, if there is enough memory to link with the standard library, add the corresponding "std" library to the list. For example: | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
"supported_c_libs": { | ||
"arm": ["std", "small"], | ||
"gcc_arm": ["std", "small"], | ||
"iar": ["std"] | ||
} | ||
``` | ||
<span class="notes">**Note:** For ARM, your target scatter file needs to have a two-region memory model. If the build system throws an error (presence of undefined symbols `Image$$ARM_LIB_HEAP$$ZI$$Base`, `Image$$ARM_LIB_HEAP$$ZI$$Length`, `Image$$ARM_LIB_HEAP$$ZI$$Limit`) when compiling with microlib, you can find more information [here](https://os.mbed.com/docs/mbed-os/v6.0-preview/reference/using-small-c-libraries.html).</span> | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<span class="notes">**Note:** The IAR toolchain does not have a small C library.</span> | ||
iriark01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- Set the `c_lib` property to indicate which C library should be used by the build tools. If your target has `"default_lib": "small"` defined, then replace it with `"c_lib" : "small"`. Otherwise add `"c_lib" : "small"`. We recommend that ultra constrained devices running bare metal applications link with the small C libraries by default. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<span class="notes">**Note:** If a toolchain does not support a small C library and `c_lib` is set to `small`, the build tools will revert to linking with the standard C library, provided that it is listed in `supported_c_libs` for the given toolchain.</span> | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- If `default_toolchain` is set to `uARM`, then replace it with `ARM` and remove `uARM` from `supported_toolchains`. Support for the uARM toolchain, which is the ARM toolchain with microlib, has been removed. Setting `c_lib` to `small` ensures that microlib is used when the ARM toolchain is selected. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
<span class="notes">**Note:** As mentioned above, to successfully build with microlib, the target must define a two-region memory model. You might need to replace the content of the TOOLCHAIN_ARM_STD linker file with that of TOOLCHAIN_ARM_MICRO which includes a two-region memory model linker file.</span> | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- If your board does not have a low power ticker, ensure that tickless is enabled using the microsecond ticker as follows: | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
"overrides": { | ||
"tickless-from-us-ticker": true | ||
} | ||
``` | ||
|
||
- It might be necessary to reduce the stack size allocated for your target if it does not have enough RAM. 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. By default all targets are configured to have a boot stack size of 0x1000 (4096 bytes) in bare metal. However, this must be overridden if inadequate for your target. We recommend to reduce the boot stack size to 0x400 (1024 bytes) if your target has 8KB of RAM and to 0x300 (768 bytes) if your target has 4KB of RAM. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
"overrides": { | ||
"boot-stack-size": "0x400" | ||
} | ||
``` | ||
|
||
### Build and run mbed-os-example-blinky-baremetal | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
Build the application and program your target: `mbed compile -m <YOUR_TARGET> -t <TOOLCHAIN> --flash --sterm`. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
The application running on the target should print a text on the console. Repeat for all supported toolchains. | ||
|
||
Troubleshoot any issue. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
## Validating the port | ||
|
||
To validate the bare metal target configuration, you will execute the Mbed OS greentea test suite with the bare metal configuration. A subset of the tests are automatically skipped by the framework 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. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
iriark01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
- First, change directory. | ||
iriark01 marked this conversation as resolved.
Show resolved
Hide resolved
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
cd mbed-os | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
- Then execute the greentea test suite with the bare metal configuration for the supported toolchains. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
``` | ||
mbed test -m <YOUR_TARGET> -t <TOOLCHAIN> --app-config TESTS/configs/baremetal.json | ||
``` | ||
It can be useful to append `--compile` and fix build issues first before running tests with `--run`. | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
All tests should pass (or be automatically skipped). | ||
evedon marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
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: | ||
``` | ||
{ | ||
"target_overrides": { | ||
"YOUR_TARGET": { | ||
"platform.stdio-minimal-console-only": true | ||
} | ||
} | ||
} | ||
``` |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.