-
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
6b8490e
Add guide for using bare metal profile
LDong-Arm 6528b3c
Bare metal porting: stress that compatible Greentea tests are all ena…
LDong-Arm 6c3372d
mbed2_porting: explain Greentea errors due to small memory size
LDong-Arm cec980c
mbed2_porting: JSON syntax highlighting
LDong-Arm 910e020
Remove baremetal_example.md whose purpose duplicates using_bare_metal.md
LDong-Arm 53ac4ba
Bare metal guide improved
LDong-Arm 9776dfd
Bare metal guide: events library path relative to application root
LDong-Arm f28a40d
Apply suggestions from @iriark01
LDong-Arm 841ebce
Incorporate the latest review comments
LDong-Arm f207742
Fomatting
iriark01 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
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -1,3 +1,100 @@ | ||
# Using the bare metal profile | ||
|
||
Content still in PR | ||
This guide shows how to create a bare metal profile application: | ||
|
||
1. Set the profile: By default, the build tool uses the full profile for all application builds. To use the bare metal profile, set up your application to override this default behaviour. | ||
1. By default, the bare metal profile uses a minimal set of APIs. You can add additional ones [from the list of supported APIs](../bare-metal/index.html#features) if your application needs them. | ||
|
||
To demonstrate how to create a bare metal application, here is an example that prints text at regular intervals using the `EventQueue` class: | ||
|
||
[](https://github.com/ARMmbed/mbed-os-examples-docs_only/blob/master/APIs_RTOS/EventQueue_ex_2/main.cpp) | ||
|
||
## Creating a bare metal application | ||
|
||
To create the application: | ||
|
||
1. Create a new Mbed OS application and navigate to its directory: | ||
|
||
``` | ||
mbed new example_app && cd example_app | ||
``` | ||
|
||
The directory contains the full Mbed OS library (`mbed-os/`) and no application files. | ||
|
||
1. Create a `main.cpp` file containing the `EventQueue` code snippet above. | ||
|
||
1. Open `mbed_app.json` (in the root of the application) and replace it with the following content: | ||
|
||
```json | ||
{ | ||
"requires": ["bare-metal"], | ||
"target_overrides": { | ||
"*": { | ||
"target.c_lib": "small" | ||
} | ||
} | ||
} | ||
``` | ||
LDong-Arm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
iriark01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
The file specifies which profile to use (`"requires": ["bare-metal"]`) and which C library to use (`"target.c_lib": "small"`). | ||
|
||
In this example, we're using `"target.c_lib": "small"` (small C library). This means your application will use an optimised version of the C library with lower memory footprint. For more details, see [Using small C libraries in Mbed OS bare metal](../bare-metal/using-small-c-libraries.html). | ||
|
||
You now have application code and a bare metal profile with the default APIs. However, this example uses APIs that are not part of the default bare metal profile - you need to manually add support for those APIs to the application. | ||
|
||
## Adding APIs | ||
|
||
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](../apis/index.html). | ||
|
||
This example depends on the `EventQueue` class, so you need to add the library that contains that class: | ||
|
||
1. In `mbed-os/`, locate the API and the library in which it is declared. | ||
1. In the library folder, open `mbed_lib.json` and find the library's name. You will need it for the next step. | ||
|
||
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" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
## Compiling and Running the Application | ||
|
||
Connect a supported board to your computer, and compile and run your application: | ||
|
||
``` | ||
mbed compile -t <TOOLCHAIN> -m <TARGET> --flash --sterm | ||
``` | ||
|
||
When the example is flashed, a serial terminal opens (because of `--sterm`). The outputis: | ||
|
||
``` | ||
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 <kbd>Ctrl</kbd> + <kbd>C</kbd>. |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I need to double-check that this transcluded correctly.