Skip to content

Commit 72183ac

Browse files
author
Amanda Butler
authored
Merge pull request #157 from theotherjimmy/targets-lint
Add documentation of the targets linter script
2 parents a30130b + 752da30 commit 72183ac

File tree

1 file changed

+143
-0
lines changed

1 file changed

+143
-0
lines changed

docs/advanced/mbed_targets.md

Lines changed: 143 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,3 +212,146 @@ 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+
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.
222+
223+
#### Inheritance rules
224+
A target's inheritance must look like one of these:
225+
226+
```
227+
MCU -> Board
228+
MCU -> Module -> Board
229+
Family -> MCU -> Board
230+
Family -> MCU -> Module -> Board
231+
Family -> Subfamily -> MCU -> Board
232+
Family -> Subfamily -> MCU -> Module -> Board
233+
```
234+
235+
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.
236+
237+
#### Role rules
238+
239+
For each of these target roles, some restrictions are in place:
240+
- Families, MCUs and Subfamilies may contain the following keys:
241+
- `core`.
242+
- `extra_labels`.
243+
- `features`.
244+
- `bootloader_supported`.
245+
- `device_name`.
246+
- `post_binary_hook`.
247+
- `default_tool chain`.
248+
- `config`.
249+
- `target_overrides`.
250+
- MCUs are required to have, and Families and Subfamilies may have:
251+
- `release_versions`.
252+
- `supported_toolchains`.
253+
- `default_lib`.
254+
- `public`.
255+
- `device_has`.
256+
- Modules and Boards may have the following keys:
257+
- `supported_form_factors`.
258+
- `is_disk_virtual`.
259+
- `detect_code`.
260+
- `extra_labels`.
261+
- `public`.
262+
- `config`.
263+
- `forced_reset_timeout`.
264+
- `target_overrides`
265+
- `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.
266+
- `extra_labels` may not contain any target names
267+
- `device_has` may only contain values from the following list:
268+
- `ANALOGIN`.
269+
- `ANALOGOUT`.
270+
- `CAN`.
271+
- `ETHERNET`.
272+
- `EMAC`.
273+
- `FLASH`.
274+
- `I2C`.
275+
- `I2CSLAVE`.
276+
- `I2C_ASYNCH`.
277+
- `INTERRUPTIN`.
278+
- `LOWPOWERTIMER`.
279+
- `PORTIN`.
280+
- `PORTINOUT`.
281+
- `PORTOUT`.
282+
- `PWMOUT`.
283+
- `RTC`.
284+
- `TRNG`.
285+
- `SERIAL`.
286+
- `SERIAL_ASYNCH`.
287+
- `SERIAL_FC`.
288+
- `SLEEP`.
289+
- `SPI`.
290+
- `SPI_ASYNCH`.
291+
- `SPISLAVE`.
292+
- if `release_versions` contains 5, then `supported_toolchains` must contain all of `GCC_ARM`, `ARM` and `IAR`
293+
- MCUs, Families and SubFamilies must set `public` to `false`
294+
295+
### Sample output
296+
The linting script takes three subcommands: `targets`, `all-targets` and `orphans`.
297+
298+
#### `targets` and `all-targets` commands
299+
300+
The `targets` and `all-targets` commands both show errors within public inheritance hierarchies. For example:
301+
302+
`python tools/targets/lint.py targets EFM32GG_STK3700 EFM32WG_STK3800 LPC11U24_301`
303+
304+
Could produce this output
305+
306+
```yaml
307+
hierarchy: Family (EFM32) -> MCU (EFM32GG990F1024) -> Board (EFM32GG_STK3700)
308+
target errors:
309+
EFM32:
310+
- EFM32 is not allowed in extra_labels
311+
EFM32GG990F1024:
312+
- macros found, and is not allowed
313+
- default_lib not found, and is required
314+
- device_has not found, and is required
315+
EFM32GG_STK3700:
316+
- progen found, and is not allowed
317+
- device_has found, and is not allowed
318+
---
319+
hierarchy: Family (EFM32) -> MCU (EFM32WG990F256) -> Board (EFM32WG_STK3800)
320+
target errors:
321+
EFM32:
322+
- EFM32 is not allowed in extra_labels
323+
EFM32WG990F256:
324+
- macros found, and is not allowed
325+
- default_lib not found, and is required
326+
- device_has not found, and is required
327+
EFM32WG_STK3800:
328+
- progen found, and is not allowed
329+
- device_has found, and is not allowed
330+
---
331+
hierarchy: Family (LPCTarget) -> MCU (LPC11U24_301) -> ???
332+
hierarchy errors:
333+
- no boards found in heirarchy
334+
target errors:
335+
LPC11U24_301:
336+
- release_versions not found, and is required
337+
- default_lib not found, and is required
338+
- public not found, and is required
339+
```
340+
341+
The `all-targets` command is very verbose, with output that matches the format above but is too long to reproduce here.
342+
343+
#### `orphans` command
344+
345+
The `orphans` command shows all targets that you cannot reach from a public target.
346+
347+
`python tools/targets/lint.py orphans`
348+
349+
```yaml
350+
- CM4_UARM
351+
- CM4_ARM
352+
- CM4F_UARM
353+
- CM4F_ARM
354+
- LPC1800
355+
- EFR32MG1P132F256GM48
356+
- EFR32MG1_BRD4150
357+
```

0 commit comments

Comments
 (0)