|
| 1 | +# Using the bare metal profile |
| 2 | + |
| 3 | +This guide shows how to create a bare metal profile application: |
| 4 | +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. |
| 5 | +1. Bare metal has a [minimal set of APIs](bare_metal_api.md). You can add additional ones [from the list of supported API](../../api/api.md). |
| 6 | + |
| 7 | +## Creating a bare metal application |
| 8 | + |
| 9 | +1. Create a new Mbed application and enter its directory: |
| 10 | + |
| 11 | + ``` |
| 12 | + mbed new example_app && cd example_app |
| 13 | + ``` |
| 14 | +
|
| 15 | + This contains an empty application with Mbed OS (`mbed-os/`) pre-fetched. |
| 16 | +
|
| 17 | +1. Open `mbed_app.json` and replace it with the following content: |
| 18 | +
|
| 19 | + ```json |
| 20 | + { |
| 21 | + "requires": ["bare-metal"], |
| 22 | + "target_overrides": { |
| 23 | + "*": { |
| 24 | + "target.c_lib": "small" |
| 25 | + } |
| 26 | + } |
| 27 | + } |
| 28 | + ``` |
| 29 | + <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>. |
| 30 | +
|
| 31 | + 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. |
| 32 | +
|
| 33 | + For a list of default and supported APIs, [please see our full API list](../../api/api.md). |
| 34 | +
|
| 35 | +1. To add an API - in this example, the `EventQueue` class: |
| 36 | +
|
| 37 | + 1. Locate the library you want to use in `mbed-os/`. |
| 38 | + 1. In the library folder, find the library's name in `mbed_lib.json`. You will need it for the next step. |
| 39 | +
|
| 40 | + For example: `events/mbed_lib.json`: |
| 41 | + ```json |
| 42 | + { |
| 43 | + "name": "events", |
| 44 | + "config": { |
| 45 | + "present": 1, |
| 46 | + ... |
| 47 | + } |
| 48 | + } |
| 49 | + ``` |
| 50 | + To continue, go back to the application's root directory. |
| 51 | +
|
| 52 | + 1. Open `mbed_app.json` again, and add the library to the `"requires"` field: |
| 53 | +
|
| 54 | + ```json |
| 55 | + { |
| 56 | + "requires": [ |
| 57 | + "bare-metal", |
| 58 | + "events" |
| 59 | + ] |
| 60 | + } |
| 61 | + ``` |
| 62 | +
|
| 63 | +1. Write the application using the libraries you added. |
| 64 | +
|
| 65 | + [](https://github.com/ARMmbed/mbed-os-example-baremetal-eventqueue-blinky/blob/master/main.cpp) |
| 66 | +
|
| 67 | +1. With a supported board connected to your computer, compile and flash your application: |
| 68 | + ``` |
| 69 | + mbed compile -t <TOOLCHAIN> -m <TARGET> --flash |
| 70 | + ``` |
| 71 | +
|
| 72 | + In the example above, the on-board LED keeps blinking. |
0 commit comments