-
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
Changes from 8 commits
6b8490e
6528b3c
6c3372d
cec980c
910e020
53ac4ba
9776dfd
f28a40d
841ebce
f207742
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
This file was deleted.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,90 @@ | ||
# 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. | ||
|
||
## Creating a bare metal application | ||
|
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I need to double-check that this transcluded correctly. |
||
|
||
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
|
||
|
||
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). | ||
|
||
iriark01 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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). | ||
|
||
1. 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" | ||
} | ||
} | ||
} | ||
``` | ||
|
||
1. 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`). You should get the following output: | ||
``` | ||
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 Ctrl + C. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What if I don't get that output? What does it mean and what should I do? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There can be different causes of not getting the expected output - issues with serial communication, target drivers, the application itself, etc. In my opinion it may not be feasible to have a troubleshooting guide wherever some output is quoted. In https://os.mbed.com/docs/mbed-os/v5.15/tutorials/the-eventqueue-api.html for example, it just says "This is the output of the above program on an FRDM-K64F board." So I'll replace "You should get the following output" which seems to hint users they may or may not get it. |
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.
What does "for now" mean? Until later in the document? Later in the year?
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'll remove "for now" to avoid confusion.
(If we have worked around those errors sometime in the future, we will then remove this line in my opinion.)