Skip to content

Commit 80927dc

Browse files
author
Amanda Butler
authored
Merge pull request #1178 from ARMmbed/ed-microlib
Documentation on using small C libraries in Mbed OS bare metal
2 parents c449701 + 246c0cb commit 80927dc

File tree

1 file changed

+62
-0
lines changed

1 file changed

+62
-0
lines changed
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
<h1 id="using-small-c-libraries">Using small C libraries in Mbed OS bare metal</h1>
2+
3+
If your application does not use an RTOS, build it in the bare metal mode to achieve memory savings. Both the `ARM` and `GCC_ARM` toolchains support code optimized versions of their C standard libraries, `microlib` and `newlib-nano`. It is safe to use these smaller C libraries in bare metal mode, and we recommend using them.
4+
5+
You can build with the smaller C libraries by creating an `mbed_app.json` with the following contents:
6+
7+
```
8+
{
9+
"requires": ["bare-metal"],
10+
"target_overrides": {
11+
"*": {
12+
"target.default_lib": "small"
13+
}
14+
}
15+
}
16+
```
17+
18+
This links your application with `microlib` for the `ARM` toolchain and `newlib-nano` for the `GCC_ARM` toolchain.
19+
20+
## Newlib-nano
21+
22+
[Newlib-nano](https://community.arm.com/developer/ip-products/system/b/embedded-blog/posts/shrink-your-mcu-code-size-with-gcc-arm-embedded-4-7) is an open source C library targeting embedded microcontrollers. It is based on newlib but is much smaller. One restriction is that newlib-nano is not thread-safe, so an application that uses the RTOS should not use it.
23+
24+
## Arm microlib
25+
26+
Microlib is an alternative library to the default C library. It is intended for deeply embedded applications that must fit into extremely small memory footprints.
27+
28+
These applications do not run under an operating system. You can find more information at the [Arm developer documentation](https://developer.arm.com/docs/100073/0613/the-arm-c-micro-library).
29+
30+
### Differences between Arm C standard library and microlib
31+
32+
To see a complete list of the differences between microlib and the default C library, please see the [Arm developer documentation](https://developer.arm.com/docs/100073/0613/the-arm-c-micro-library/differences-between-microlib-and-the-default-c-library).
33+
34+
In particular:
35+
36+
- Microlib has no re-entrant variant. Microlib does not provide mutex locks to guard against code that is not thread-safe.
37+
- Microlib does not support selectable one- or two-region memory models as the standard library does. Microlib provides only the two-region memory model with separate stack and heap regions.
38+
39+
Mbed OS supports a two-region memory model for heap and stack. This means you can use the same scatter file with both the Arm C standard library and microlib.
40+
41+
### Scatter file for Arm toolchain
42+
43+
By default, only a few targets have been tested with microlib. If your target has not been tested, the build system will throw an error. In that case, you need to check if the Arm scatter file for your target supports the two-region memory model. In other words, are the `ARM_LIB_HEAP` and `ARM_LIB_STACK` regions defined? This file is located in `targets/.../device/TOOLCHAIN_ARM_STD/your_target_scatter_file.sct`):
44+
45+
- If yes, you can use the scatter file unmodified for microlib.
46+
- If no, check if your target was ported to uARM:
47+
- If yes, replace the `TOOLCHAIN_ARM_STD` scatter file with `../TOOLCHAIN_ARM_MICRO/microlib_scatter_file.sct`.
48+
- If no, you need to update the scatter file to use the two-region memory model. You can find more information on the two-region memory model in the [design document](https://github.com/ARMmbed/mbed-os/blob/master/docs/design-documents/platform/memory-model/ram_memory_model.md#proposed-ram-memory-model). For more details, see this example of a [scatter file updated for the two-region memory model](https://github.com/ARMmbed/mbed-os/pull/9571/files?file-filters%5B%5D=.sct#diff-0ce0bec61a6d5ac63ab5ae3afcfe7119).
49+
50+
After you have completed the steps above, add `small` to the `supported_c_libs` parameter for your target in `targets.json`:
51+
52+
```
53+
"supported_c_libs": {
54+
"arm": ["std", "small"],
55+
"gcc_arm": ["std", "small"],
56+
"iar": ["std"]
57+
}
58+
```
59+
60+
### Note on uARM toolchain
61+
62+
The uARM toolchain is the ARMC6 toolchain with the Arm microlib, the C micro-library. This toolchain will be deprecated after 5.15.

0 commit comments

Comments
 (0)