Skip to content

Commit 581b5fd

Browse files
author
Amanda Butler
authored
Update mbed_targets.md
Update with content from PR #157
1 parent 2750775 commit 581b5fd

File tree

1 file changed

+146
-0
lines changed

1 file changed

+146
-0
lines changed

docs/porting/mbed_targets.md

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,149 @@ The `release_versions` property is a list of major versions of mbed OS that the
212212
#### `supported_form_factors`
213213

214214
The `supported_form_factors` property is an optional list of form factors that a development board supports. You can use this property in C, C++ and assembly language by passing a macro prefixed with `TARGET_FF_` to the compiler. The accepted values for `supported_form_factors` are `ARDUINO`, which indicates compatibility with Arduino headers, and `MORPHO`, which indicates compatibility with ST Morpho headers.
215+
216+
### Style guide
217+
218+
A linting script for `targets.json` is available as `tools/targets/lint.py` in mbed OS. This script is a utility for avoiding common errors when defining targets and detecting style inconsistencies between targets. This linting script displays style errors based on a few rules outlined below.
219+
220+
#### Rules enforced
221+
222+
There are two sets of rules: rules that affect how you must structure target inheritance and rules that govern what each role within the inheritance hierarchy can do.
223+
224+
##### Inheritance rules
225+
226+
A target's inheritance must look like one of these:
227+
228+
```
229+
MCU -> Board
230+
MCU -> Module -> Board
231+
Family -> MCU -> Board
232+
Family -> MCU -> Module -> Board
233+
Family -> Subfamily -> MCU -> Board
234+
Family -> Subfamily -> MCU -> Module -> Board
235+
```
236+
237+
The linting script guesses where the Boards and Modules stop and the MCUs, Families and Subfamilies begin. An MCU, Family or Subfamily must have at least one Board or Module above it in any hierarchy.
238+
239+
##### Role rules
240+
241+
For each of these target roles, some restrictions are in place:
242+
- Families, MCUs and Subfamilies may contain the following keys:
243+
- `core`.
244+
- `extra_labels`.
245+
- `features`.
246+
- `bootloader_supported`.
247+
- `device_name`.
248+
- `post_binary_hook`.
249+
- `default_tool chain`.
250+
- `config`.
251+
- `target_overrides`.
252+
- MCUs are required to have, and Families and Subfamilies may have:
253+
- `release_versions`.
254+
- `supported_toolchains`.
255+
- `default_lib`.
256+
- `public`.
257+
- `device_has`.
258+
- Modules and Boards may have the following keys:
259+
- `supported_form_factors`.
260+
- `is_disk_virtual`.
261+
- `detect_code`.
262+
- `extra_labels`.
263+
- `public`.
264+
- `config`.
265+
- `forced_reset_timeout`.
266+
- `target_overrides`
267+
- `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.
268+
- `extra_labels` may not contain any target names
269+
- `device_has` may only contain values from the following list:
270+
- `ANALOGIN`.
271+
- `ANALOGOUT`.
272+
- `CAN`.
273+
- `ETHERNET`.
274+
- `EMAC`.
275+
- `FLASH`.
276+
- `I2C`.
277+
- `I2CSLAVE`.
278+
- `I2C_ASYNCH`.
279+
- `INTERRUPTIN`.
280+
- `LOWPOWERTIMER`.
281+
- `PORTIN`.
282+
- `PORTINOUT`.
283+
- `PORTOUT`.
284+
- `PWMOUT`.
285+
- `RTC`.
286+
- `TRNG`.
287+
- `SERIAL`.
288+
- `SERIAL_ASYNCH`.
289+
- `SERIAL_FC`.
290+
- `SLEEP`.
291+
- `SPI`.
292+
- `SPI_ASYNCH`.
293+
- `SPISLAVE`.
294+
- If `release_versions` contains 5, then `supported_toolchains` must contain all of `GCC_ARM`, `ARM` and `IAR`
295+
- MCUs, Families and SubFamilies must set `public` to `false`
296+
297+
#### Sample output
298+
299+
The linting script takes three subcommands: `targets`, `all-targets` and `orphans`.
300+
301+
##### `targets` and `all-targets` commands
302+
303+
The `targets` and `all-targets` commands both show errors within public inheritance hierarchies. For example:
304+
305+
`python tools/targets/lint.py targets EFM32GG_STK3700 EFM32WG_STK3800 LPC11U24_301`
306+
307+
Could produce this output
308+
309+
```yaml
310+
hierarchy: Family (EFM32) -> MCU (EFM32GG990F1024) -> Board (EFM32GG_STK3700)
311+
target errors:
312+
EFM32:
313+
- EFM32 is not allowed in extra_labels
314+
EFM32GG990F1024:
315+
- macros found, and is not allowed
316+
- default_lib not found, and is required
317+
- device_has not found, and is required
318+
EFM32GG_STK3700:
319+
- progen found, and is not allowed
320+
- device_has found, and is not allowed
321+
---
322+
hierarchy: Family (EFM32) -> MCU (EFM32WG990F256) -> Board (EFM32WG_STK3800)
323+
target errors:
324+
EFM32:
325+
- EFM32 is not allowed in extra_labels
326+
EFM32WG990F256:
327+
- macros found, and is not allowed
328+
- default_lib not found, and is required
329+
- device_has not found, and is required
330+
EFM32WG_STK3800:
331+
- progen found, and is not allowed
332+
- device_has found, and is not allowed
333+
---
334+
hierarchy: Family (LPCTarget) -> MCU (LPC11U24_301) -> ???
335+
hierarchy errors:
336+
- no boards found in heirarchy
337+
target errors:
338+
LPC11U24_301:
339+
- release_versions not found, and is required
340+
- default_lib not found, and is required
341+
- public not found, and is required
342+
```
343+
344+
The `all-targets` command is very verbose, with output that matches the format above but is too long to reproduce here.
345+
346+
##### `orphans` command
347+
348+
The `orphans` command shows all targets that you cannot reach from a public target.
349+
350+
`python tools/targets/lint.py orphans`
351+
352+
```yaml
353+
- CM4_UARM
354+
- CM4_ARM
355+
- CM4F_UARM
356+
- CM4F_ARM
357+
- LPC1800
358+
- EFR32MG1P132F256GM48
359+
- EFR32MG1_BRD4150
360+
```

0 commit comments

Comments
 (0)