|
| 1 | +# Using bare metal profile |
| 2 | + |
| 3 | +## Creating a bare metal application |
| 4 | + |
| 5 | +First, clone Mbed OS into the directory where we want to create an application |
| 6 | +``` |
| 7 | +mkdir my_mbed_app && cd my_mbed_app |
| 8 | +git clone https://github.com/ARMmbed/mbed-os.git |
| 9 | +``` |
| 10 | + |
| 11 | +To enable Mbed OS bare metal, create an `mbed_app.json` with the following contents: |
| 12 | +``` |
| 13 | +{ |
| 14 | + "requires": ["bare-metal"] |
| 15 | +} |
| 16 | +``` |
| 17 | + |
| 18 | +On bare metal, features are enabled with a bottom-up approach - those listed in [Bare metal APIs](bare_metal_api.md#bare-metal-apis) are now ready for use (but not other features) in our application. See [Bare metal example](bare_metal_example.md). |
| 19 | + |
| 20 | +To pull in additional features (take filesystem for example) |
| 21 | + |
| 22 | +1. Locate the libraries we want to use in `mbed-os/` and find their names in their respective `mbed_lib.json`, e.g. `features/storage/filesystem/mbed_lib.json`: |
| 23 | + ```json |
| 24 | + { |
| 25 | + "name": "filesystem", |
| 26 | + "config": { |
| 27 | + "present": 1 |
| 28 | + } |
| 29 | + } |
| 30 | + ``` |
| 31 | +1. Add the libraries to `"requires"` in our application's `mbed_app.json`, for example: |
| 32 | + ```json |
| 33 | + { |
| 34 | + "requires": [ |
| 35 | + "bare-metal", |
| 36 | + "filesystem" |
| 37 | + ] |
| 38 | + } |
| 39 | + ``` |
| 40 | +1. Write the application to use bare metal APIs and libraries added in 2. |
| 41 | +1. Try to compile: |
| 42 | + ``` |
| 43 | + mbed compile -t <TOOLCHAIN> -m <TARGET> |
| 44 | + ``` |
| 45 | + Compilation may fail if any libaries added in 2 depend on other libraries. Use error messages to locate dependent libraries (like we did in 1.) and add them to `mbed_lib.json` too, for example `"filesystem"` depends on `"fat_chan"`: |
| 46 | + ``` |
| 47 | + { |
| 48 | + "requires": [ |
| 49 | + "bare-metal", |
| 50 | + "filesystem", |
| 51 | + "fat_chan" |
| 52 | + ] |
| 53 | + } |
| 54 | + ``` |
| 55 | + Repeat this step until compilation succeeds, i.e. we have added all dependencies. |
| 56 | + |
| 57 | +## Running Greentea tests for bare metal profile |
| 58 | + |
| 59 | +(If you have not used Greentea before, [you can learn more in our documentation](../tools/greentea-testing-applications.html).) |
| 60 | + |
| 61 | +To run Greentea tests for bare metal profile, simply use `baremetal.json`. The full commands are as follows: |
| 62 | + |
| 63 | +1. Change directory: |
| 64 | + |
| 65 | + ``` |
| 66 | + cd mbed-os |
| 67 | + ``` |
| 68 | + |
| 69 | +1. Execute the Greentea test suite with the bare metal configuration for the supported toolchains: |
| 70 | + |
| 71 | + ``` |
| 72 | + mbed test -m <YOUR_TARGET> -t <TOOLCHAIN> --app-config TESTS/configs/baremetal.json |
| 73 | + ``` |
| 74 | + |
| 75 | + <span class="tips">**Tip:** You can append `--compile` and fix build issues before running tests with `--run`.</span> |
0 commit comments