Skip to content

Commit 180d538

Browse files
committed
Added Mbed 2 to Mbed OS bare metal porting guide
1 parent 69a4e99 commit 180d538

File tree

1 file changed

+125
-0
lines changed

1 file changed

+125
-0
lines changed
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Porting an Mbed OS 2 target to Mbed OS 6 bare metal
2+
3+
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.
4+
5+
## Configuring your target
6+
7+
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.
8+
9+
The main steps are:
10+
1. Clone [mbed-os-example-blinky-baremetal](https://github.com/ARMmbed/mbed-os-example-blinky-baremetal).
11+
1. Edit `targets.json`. In this step, you will configure your target to support Mbed OS 6 and add bare metal configuration parameters.
12+
1. Build and run mbed-os-example-blinky-baremetal. In this step, you will validate the configuration and troubleshoot any issue.
13+
14+
### Clone mbed-os-example-blinky-baremetal
15+
16+
Run the following command:
17+
- `git clone https://github.com/ARMmbed/mbed-os-example-blinky-baremetal`
18+
19+
And then change directory:
20+
- `cd mbed-os-example-blinky-baremetal`
21+
22+
### Edit targets.json
23+
24+
Find your target in `mbed-os/targets/targets.json` and update its configuration as described below.
25+
26+
Configure your target to support Mbed OS 6:
27+
- Remove the `release_versions` property as it is no longer required.
28+
```
29+
"release_versions": ["2"]
30+
```
31+
32+
- Add the `supported_application_profiles` property to indicate that the application profile supported by this target is bare metal.
33+
```
34+
"supported_application_profiles" : ["bare-metal"]
35+
```
36+
37+
- Override `supported_c_libs` property to link with the smaller C libraries. The default for all targets is defined as follows:
38+
```
39+
"supported_c_libs": {
40+
"arm": ["std"],
41+
"gcc_arm": ["std", "small"],
42+
"iar": ["std"]
43+
}
44+
```
45+
46+
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:
47+
```
48+
"supported_c_libs": {
49+
"arm": ["small"],
50+
"gcc_arm": ["small"]
51+
}
52+
```
53+
54+
For each toolchain, if there is enough memory to link with the standard library, add the corresponding "std" library to the list. For example:
55+
```
56+
"supported_c_libs": {
57+
"arm": ["std", "small"],
58+
"gcc_arm": ["std", "small"],
59+
"iar": ["std"]
60+
}
61+
```
62+
<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>
63+
64+
<span class="notes">**Note:** The IAR toolchain does not have a small C library.</span>
65+
66+
- 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.
67+
68+
<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>
69+
70+
- 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.
71+
72+
<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>
73+
74+
- If your board does not have a low power ticker, ensure that tickless is enabled using the microsecond ticker as follows:
75+
```
76+
"overrides": {
77+
"tickless-from-us-ticker": true
78+
}
79+
```
80+
81+
- 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.
82+
```
83+
"overrides": {
84+
"boot-stack-size": "0x400"
85+
}
86+
```
87+
88+
### Build and run mbed-os-example-blinky-baremetal
89+
90+
Build the application and program your target: `mbed compile -m <YOUR_TARGET> -t <TOOLCHAIN> --flash --sterm`.
91+
92+
The application running on the target should print a text on the console. Repeat for all supported toolchains.
93+
94+
Troubleshoot any issue.
95+
96+
## Validating the port
97+
98+
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.
99+
100+
- First, change directory.
101+
```
102+
cd mbed-os
103+
```
104+
- Then execute the greentea test suite with the bare metal configuration for the supported toolchains.
105+
```
106+
mbed test -m <YOUR_TARGET> -t <TOOLCHAIN> --app-config TESTS/configs/baremetal.json
107+
```
108+
It can be useful to append `--compile` and fix build issues first before running tests with `--run`.
109+
110+
All tests should pass (or be automatically skipped).
111+
112+
Further optimisations for targets with small flash memories:
113+
- Append `--profile release` to the command above. Use of the release profile helps keep some tests within the size limit.
114+
- 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.
115+
116+
Modify `TESTS/configs/baremetal.json` for your target:
117+
```
118+
{
119+
"target_overrides": {
120+
"YOUR_TARGET": {
121+
"platform.stdio-minimal-console-only": true
122+
}
123+
}
124+
}
125+
```

0 commit comments

Comments
 (0)