Skip to content

Commit a084a49

Browse files
author
Amanda Butler
authored
Update mbed_targets.md
Make changes from PR #398 to new_engine, so they go to the test site for review.
1 parent 2064263 commit a084a49

File tree

1 file changed

+57
-11
lines changed

1 file changed

+57
-11
lines changed

docs/tools/mbed_targets.md

Lines changed: 57 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22

33
Arm Mbed uses JSON as a description language for its build targets. You can find the JSON description of Mbed targets in `targets/targets.json` and in `custom_targets.json` in the root of a project directory. When you add new targets with `custom_targets.json`, they are added to the list of available targets.
44

5-
<span class="notes">**Note:** The Online Compiler does not support this functionality. You need to use [Mbed CLI](/docs/development/tools/arm-mbed-cli.html) to take your code offline.</span>
5+
<span class="notes">**Note:** The Online Compiler does not support this functionality. You need to use [Mbed CLI](/docs/v5.7/tools/arm-mbed-cli.html) to take your code offline.</span>
66

77
You are not allowed to redefine existing targets in `custom_targets.json`. To better understand how a target is defined, we'll use this example (taken from `targets.json`):
88

9-
```
9+
```json
1010
"TEENSY3_1": {
1111
"inherits": ["Target"],
1212
"core": "Cortex-M4",
@@ -20,6 +20,7 @@ You are not allowed to redefine existing targets in `custom_targets.json`. To be
2020
},
2121
"device_name": "MK20DX256xxx7",
2222
"detect_code": ["0230"]
23+
}
2324
```
2425

2526
The style that we use for targets is:
@@ -37,7 +38,7 @@ This section lists all the properties the Mbed build system understands. Unless
3738

3839
The description of an Mbed target can "inherit" from one or more descriptions of other targets. When a target, called a _child_ inherits from another target, called its _parent_, the child automatically copies all the properties from the parent. After the child has copied the properties of the parent, it may then overwrite, add or remove from those properties. In our example above, `TEENSY3_1` inherits from `Target`. This is the definition of `Target`:
3940

40-
```
41+
```json
4142
"Target": {
4243
"core": null,
4344
"default_toolchain": "ARM",
@@ -59,7 +60,7 @@ A child target may add properties that don't exist in any of its parents. For ex
5960

6061
It's possible, but discouraged, to inherit from more than one target. For example:
6162

62-
```
63+
```json
6364
"ImaginaryTarget": {
6465
"inherits": ["Target", "TEENSY3_1"]
6566
}
@@ -103,7 +104,7 @@ When a target inherits, it's possible to alter the values of `macros` in the chi
103104

104105
For example:
105106

106-
```
107+
```json
107108
"TargetA": {
108109
"macros": ["PARENT_MACRO1", "PARENT_MACRO2"]
109110
},
@@ -148,6 +149,51 @@ The build system errors when you use features outside of this list.
148149

149150
When you use target inheritance, you may alter the values of `features` using `features_add` and `features_remove`. This is similar to the `macros_add` and `macros_remove` mechanism the previous section describes.
150151

152+
#### `config` and `overrides`
153+
154+
<span class="notes">**Note:** The [Arm Mbed configuration system](https://os.mbed.com/docs/v5.7/tools/configuring-tools.html) customizes the compile time configuration of various Mbed components (targets, libraries and applications). Each component can define a number of configuration parameters. The values of these configuration parameters can then be overridden in various ways.</span>
155+
156+
The list of _configs_ provide a way to modify the values of macros in child targets or in a project. Each configuration has a default value, as well as an optional macro name and help text. By default, the macro name is the name of the config. For example:
157+
158+
```json
159+
"config": {
160+
"clock_src": {
161+
"help": "Clock source to use, can be XTAL or RC",
162+
"value": "XTAL",
163+
},
164+
"clock_freq": {
165+
"help": "Clock frequency in Mhz",
166+
"value": "16",
167+
"macro_name": "CLOCK_FREQUENCY_MHZ"
168+
}
169+
}
170+
```
171+
172+
This case defines the config `clock_src` with the default value of `XTAL` for the macro `CLOCK_SRC`, and the config `clock_freq` with the default value of 16 for the macro `CLOCK_FREQUENCY_MHZ`.
173+
174+
_overrides_ allow a child target to change the value of a config. For example, if a child target uses the internal RC clock instead of the crystal, it can add an override:
175+
176+
```json
177+
"overrides": {
178+
"clock_src": "RC"
179+
}
180+
```
181+
182+
You can also modify config values for a project using the `target_overrides` key in the `mbed_app.json` file, either for specific targets or as a wildcard. For example:
183+
184+
```json
185+
"target_overrides": {
186+
"*": {
187+
"clock_src": "RC"
188+
},
189+
"NRF51_DK": {
190+
"clock_freq": "16"
191+
}
192+
}
193+
```
194+
195+
This section, in an `mbed_app.json` file, sets the clock source to `RC` on all targets and the clock frequency to 16Mhz on just the `NRF51_DK` target.
196+
151197
#### `device_has`
152198

153199
The list in `device_has` defines what hardware a device has.
@@ -166,7 +212,7 @@ The `default_toolchain` property names the toolchain that compiles code for this
166212

167213
Some targets require specific actions to generate a programmable binary image. Specify these actions using the `post_binary_hook` property and custom Python code. The value of `post_binary_hook` must be a JSON object with keys `function` and optionally `toolchain`. Within the `post_binary_hook` JSON object, the `function` key must contain a Python function that is accessible from the namespace of `tools/targets/__init__.py`, and the optional `toolchain` key must contain a list of toolchains that require processing from the `post_binary_hook`. When you do not specify the `toolchains` key for a `post_binary_hook`, you can assume the `post_binary_hook` applies to all toolchains. For the `TEENSY3_1` target above, the definition of `post_binary_hook` looks like this:
168214

169-
```
215+
```json
170216
"post_binary_hook": {
171217
"function": "TEENSY3_1Code.binary_hook",
172218
"toolchains": ["ARM_STD", "ARM_MICRO", "GCC_ARM"]
@@ -179,7 +225,7 @@ The build tools call `TEENSY3_1` `post_binary_hook` when they build using the `A
179225

180226
As for the `TEENSY3_1` code, this is how it looks in `tools/targets/__init__.py`:
181227

182-
```
228+
```python
183229
class TEENSY3_1Code:
184230
@staticmethod
185231
def binary_hook(t_self, resources, elf, binf):
@@ -199,7 +245,7 @@ Use this property to pass necessary data for exporting to various third party to
199245

200246
We use the tool [ArmPackManager](https://github.com/ARMmbed/mbed-os/tree/master/tools/arm_pack_manager) to parse CMSIS Packs for target information. [`index.json`](https://github.com/ARMmbed/mbed-os/blob/master/tools/arm_pack_manager/index.json) stores the parsed information from the [PDSC (Pack Description](http://www.keil.com/pack/doc/CMSIS/Pack/html/)</a> retrieved from each CMSIS Pack.
201247

202-
The [`"device_name"`](/docs/development/reference/contributing-target.html) attribute it `targets.json` maps from a target in Mbed OS to a device in a CMSIS Pack. To support IAR and uVision exports for your target, you must add a `"device_name"` field in `targets.json` containing this key.
248+
The [`"device_name"`](/docs/v5.7/reference/contributing-target.html) attribute it `targets.json` maps from a target in Mbed OS to a device in a CMSIS Pack. To support IAR and uVision exports for your target, you must add a `"device_name"` field in `targets.json` containing this key.
203249

204250
[http://www.keil.com/pack/Keil.Kinetis_K20_DFP.pdsc](http://www.keil.com/pack/Keil.Kinetis_K20_DFP.pdsc) is the PDSC that contains TEENSY_31 device (MK20DX256xxx7). ArmPackManager has parsed this PDSC, and `index.json` stores the device information. The device information begins on line 156 of the `.pdsc` file:
205251

@@ -290,9 +336,9 @@ For each of these target roles, some restrictions are in place:
290336
- `extra_labels`.
291337
- `public`.
292338
- `config`.
339+
- `overrides`.
293340
- `forced_reset_timeout`.
294-
- `target_overrides`
295-
- `macros` are not used. That is intentional: they do not provide any benefit over `config` and `target_overrides` but can be very difficult to use. In practice it is very difficult to override the value of a macro with a value. `config` and `target_overries`, on the other hand, are designed for this use case.
341+
- `macros` are not used. That is intentional: they do not provide any benefit over `config` and `overrides` but can be very difficult to use. In practice it is very difficult to override the value of a macro with a value. `config` and `overrides`, on the other hand, are designed for this use case.
296342
- `extra_labels` may not contain any target names
297343
- `device_has` may only contain values from the following list:
298344
- `ANALOGIN`.
@@ -361,7 +407,7 @@ target errors:
361407
---
362408
hierarchy: Family (LPCTarget) -> MCU (LPC11U24_301) -> ???
363409
hierarchy errors:
364-
- no boards found in heirarchy
410+
- no boards found in hierarchy
365411
target errors:
366412
LPC11U24_301:
367413
- release_versions not found, and is required

0 commit comments

Comments
 (0)