Skip to content

Commit 8d389c4

Browse files
committed
Add documentation
1 parent 23dac7f commit 8d389c4

4 files changed

+604
-13
lines changed

docs/package_index_json-specification.md

+10-1
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ Each tool describes a binary distribution of a command line tool. A tool can be:
8080
- a file preprocessor
8181
- a debugger
8282
- a program that performs a firmware upgrade
83+
- a [Pluggable Discovery](pluggable-discovery-specification.md)
8384

8485
basically anything that can run on the user's host PC and do something useful.
8586

@@ -215,7 +216,11 @@ Finally, let's see how `PLATFORMS` are made.
215216
"toolsDependencies": [
216217
{ "packager": "arduino", "name": "avr-gcc", "version": "4.8.1-arduino5" },
217218
{ "packager": "arduino", "name": "avrdude", "version": "6.0.1-arduino5" }
218-
]
219+
],
220+
"discoveryDependencies": [
221+
{ "packager": "arduino", "name": "serial-discovery" },
222+
{ "packager": "arduino", "name": "mdns-discovery" }
223+
]
219224
},
220225
```
221226

@@ -234,6 +239,10 @@ Each PLATFORM describes a core for a specific architecture. The fields needed ar
234239
- `toolsDependencies`: the tools needed by this core. They will be installed by Boards Manager along with the platform.
235240
Each tool is referenced by the triple (`packager`, `name`, `version`) as previously said. Note that you can reference
236241
tools available in other packages as well, even if no platform of that package is installed.
242+
- `discoveryDependencies`: the Pluggable Discoveries needed by this core. Each discovery is referenced by `packager` and
243+
`name`, the `version` is not specified because the latest installed discovery tool will always be used. Like
244+
`toolsDependencies` they will be installed by Boards Manager along with the platform and can reference tools available
245+
in other packages as well, even if no platform of that package is installed.
237246

238247
The `version` field is validated by both Arduino IDE and [JSemVer](https://github.com/zafarkhaja/jsemver). Here are the
239248
rules Arduino IDE follows for parsing versions

docs/platform-specification.md

+224-12
Original file line numberDiff line numberDiff line change
@@ -615,7 +615,7 @@ A tool may have some actions not defined (it's not mandatory to define all four
615615
tools.avrdude.cmd.path={path}/bin/avrdude
616616
tools.avrdude.config.path={path}/etc/avrdude.conf
617617

618-
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"
618+
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" -p{build.mcu} -c{upload.port.protocol} -P{upload.port.address} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"
619619

620620
A **{runtime.tools.TOOL_NAME.path}** and **{runtime.tools.TOOL_NAME-TOOL_VERSION.path}** property is generated for the
621621
tools of Arduino AVR Boards and any other platform installed via Boards Manager. **{runtime.tools.TOOL_NAME.path}**
@@ -625,6 +625,64 @@ The tool configuration properties are available globally without the prefix. For
625625
property can be used as **{cmd.path}** inside the recipe, and the same happens for all the other avrdude configuration
626626
variables.
627627

628+
#### Pluggable Discovery
629+
630+
Discovery tools are a special kind of tools that are used to find supported boards, a platform must declare one or more
631+
Pluggable Discoveries in its `platform.txt`. It's ok to use another platform discovery or the builtin ones if necessary.
632+
633+
There are two different syntaxes to declare discoveries, if the platform uses just one discovery:
634+
635+
```
636+
discovery.required=PLATFORM:DISCOVERY_NAME
637+
```
638+
639+
instead if it needs multiple discoveries:
640+
641+
```
642+
discovery.required.0=PLATFORM:DISCOVERY_ID_1
643+
discovery.required.1=PLATFORM:DISCOVERY_ID_2
644+
```
645+
646+
A platform that supports only boards connected to the serial can easily use the builtin `serial-discovery` without
647+
creating a custom Pluggable Discovery:
648+
649+
```
650+
discovery.required=builtin:serial-discovery
651+
```
652+
653+
if it supports also boards connected to the network it can use the builtin `mdns-discovery`:
654+
655+
```
656+
discovery.required.0=builtin:serial-discovery
657+
discovery.required.1=builtin:mdns-discovery
658+
```
659+
660+
Since the above syntax requires adding a discovery in the `discoveryDependencies` field in the platform
661+
`package_index.json` it might be cumbersome to do it before releasing it so we also provide another syntax to ease
662+
development:
663+
664+
```
665+
discovery.DISCOVERY_ID.pattern=DISCOVERY_RECIPE
666+
```
667+
668+
`DISCOVERY_ID` must be replaced by a unique identifier for the particular discovery and `DISCOVERY_RECIPE` must be
669+
replaced by the command line to launch the discovery. An example could be:
670+
671+
```
672+
## Teensy Ports Discovery
673+
discovery.teensy.pattern="{runtime.tools.teensy_ports.path}/hardware/tools/teensy_ports" -J2
674+
```
675+
676+
We strongly recommend not using this syntax on released platforms but only for development purposes.
677+
678+
For backward compatibility, if a platform does not declare any discovery (using the `discovery.*` properties in
679+
`platform.txt`) it will automatically inherits `builtin:serial-discovery` and `builtin:mdns-discovery` (but not other
680+
builtin discoveries that may be possibly added in the future). This will allow all legacy non-pluggable platforms to
681+
migrate to pluggable discovery without disruption.
682+
683+
For detailed information see the [Pluggable Discovery specification](pluggable-discovery-specification.md)
684+
documentation.
685+
628686
#### Verbose parameter
629687

630688
It is possible for the user to enable verbosity from the Preferences panel of the IDEs or Arduino CLI's `--verbose`
@@ -651,26 +709,48 @@ The Upload action is triggered when the user clicks on the "Upload" button on th
651709
[`arduino-cli upload`](commands/arduino-cli_upload.md). Arduino uses the term "upload" for the process of transferring a
652710
program to the Arduino board.
653711

654-
The **upload.tool** property determines the tool to be used for upload. A specific **upload.tool** property should be
655-
defined for every board in boards.txt:
712+
The **upload.tool.<protocol_name\>** property determines the tool to be used for upload. A specific
713+
**upload.tool.<protocol_name\>** property should be defined for every board in boards.txt:
656714

657715
[......]
658-
uno.upload.tool=avrdude
716+
uno.upload.tool.serial=avrdude
659717
[......]
660-
leonardo.upload.tool=avrdude
718+
leonardo.upload.tool.serial=avrdude
719+
leonardo.upload.tool.network=arduino_ota
661720
[......]
662721

722+
When the user tries to upload using a certain protocol but the board doesn't support it it will fallback to `default` if
723+
specified. A board can always specify a `default` protocol even if others are defined:
724+
725+
[......]
726+
uno.upload.tool.default=avrdude
727+
[......]
728+
leonardo.upload.tool.default=avrdude
729+
leonardo.upload.tool.network=arduino_ota
730+
[......]
731+
732+
`default` is also used when no upload address is provided by the user, this can be done only for boards that use upload
733+
tools with builtin port detection like `openocd`.
734+
735+
For backward compatibility with IDE 1.8.15 and older the previous syntax is still supported:
736+
737+
uno.upload.tool=avrdude
738+
739+
The previous syntax is equivalent to:
740+
741+
uno.upload.tool.default=avrdude
742+
663743
Other upload parameters can also be defined for the board. For example, in the Arduino AVR Boards boards.txt we have:
664744

665745
[.....]
666746
uno.name=Arduino Uno
667-
uno.upload.tool=avrdude
747+
uno.upload.tool.serial=avrdude
668748
uno.upload.protocol=arduino
669749
uno.upload.maximum_size=32256
670750
uno.upload.speed=115200
671751
[.....]
672752
leonardo.name=Arduino Leonardo
673-
leonardo.upload.tool=avrdude
753+
leonardo.upload.tool.serial=avrdude
674754
leonardo.upload.protocol=avr109
675755
leonardo.upload.maximum_size=28672
676756
leonardo.upload.speed=57600
@@ -681,9 +761,112 @@ Other upload parameters can also be defined for the board. For example, in the A
681761
Most **{upload.XXXX}** variables are used later in the avrdude upload recipe in platform.txt:
682762

683763
[.....]
684-
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.protocol} -P{serial.port} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"
764+
tools.avrdude.upload.pattern="{cmd.path}" "-C{config.path}" {upload.verbose} -p{build.mcu} -c{upload.port.protocol} -P{upload.port.address} -b{upload.speed} -D "-Uflash:w:{build.path}/{build.project_name}.hex:i"
685765
[.....]
686766

767+
If necessary the same property can be defined multiple times for different protocols:
768+
769+
leonardo.upload.serial.maximum_size=28672
770+
leonardo.upload.network.maximum_size=256
771+
772+
The two above properties will be available as **{upload.serial.maximum_size}** and **{upload.network.maximum_size}**.
773+
774+
#### Properties from Pluggable Discovery
775+
776+
If a platform supports Pluggable Discovery it can also use the port's properties returned by a discovery. For example,
777+
the following port metadata coming from a pluggable discovery:
778+
779+
{
780+
"eventType": "add",
781+
"port": {
782+
"address": "/dev/ttyACM0",
783+
"label": "ttyACM0",
784+
"protocol": "serial",
785+
"protocolLabel": "Serial Port (USB)",
786+
"properties": {
787+
"pid": "0x804e",
788+
"vid": "0x2341",
789+
"serialNumber": "EBEABFD6514D32364E202020FF10181E",
790+
"name": "ttyACM0"
791+
}
792+
}
793+
}
794+
795+
will be available on the recipe as the variables:
796+
797+
{upload.port.address} = /dev/ttyACM0
798+
{upload.port.label} = ttyACM0
799+
{upload.port.protocol} = serial
800+
{upload.port.protocolLabel} = Serial Port (USB)
801+
{upload.port.properties.pid} = 0x8043
802+
{upload.port.properties.vid} = 0x2341
803+
{upload.port.properties.serialNumber} = EBEABFD6514D32364E202020FF10181E
804+
{upload.port.properties.name} = ttyACM0
805+
{serial.port} = /dev/ttyACM0 # for backward compatibility
806+
{serial.port.file} = ttyACM0 # only because protocol=serial
807+
808+
Here another example:
809+
810+
{
811+
"eventType": "add",
812+
"port": {
813+
"address": "192.168.1.232",
814+
"label": "SSH on my-board (192.168.1.232)",
815+
"protocol": "ssh",
816+
"protocolLabel": "SSH Network port",
817+
"properties": {
818+
"macprefix": "AA:BB:CC",
819+
"macaddress": "AA:BB:CC:DD:EE:FF"
820+
}
821+
}
822+
}
823+
824+
that is translated to:
825+
826+
{upload.port.address} = 192.168.1.232
827+
{upload.port.label} = SSH on my-board (192.168.1.232)
828+
{upload.port.protocol} = ssh
829+
{upload.port.protocolLabel} = SSH Network port
830+
{upload.port.properties.macprefix} = AA:BB:CC
831+
{upload.port.properties.macaddress} = AA:BB:CC:DD:EE:FF
832+
{serial.port} = 192.168.1.232 # for backward compatibility
833+
834+
This configuration, together with protocol selection, allows to remove the hardcoded `network_pattern`, now we can
835+
replace the legacy recipe (split into multiple lines for clarity):
836+
837+
tools.bossac.upload.network_pattern="{runtime.tools.arduinoOTA.path}/bin/arduinoOTA"
838+
-address {serial.port} -port 65280
839+
-sketch "{build.path}/{build.project_name}.bin"
840+
841+
with:
842+
843+
tools.arduino_ota.upload.pattern="{runtime.tools.arduinoOTA.path}/bin/arduinoOTA"
844+
-address {upload.port.address} -port 65280
845+
-sketch "{build.path}/{build.project_name}.bin"
846+
847+
#### User provided fields
848+
849+
Some upload recipes might require custom fields that must be provided by the user, like username and password to upload
850+
over the network. In this case the recipe must use the special placeholder {upload.field.FIELD_NAME} where FIELD_NAME
851+
must be declared separately in the recipe using the following format:
852+
853+
tools.UPLOAD_RECIPE_ID.upload.field.FIELD_NAME=FIELD_LABEL
854+
tools.UPLOAD_RECIPE_ID.upload.field.FIELD_NAME.secret=true
855+
856+
FIELD_LABEL is the label shown in the graphical prompt to ask the user to enter the value of the field. The secret
857+
property is optional and it should be set to true if the field is a secret (like passwords or token).
858+
859+
Let’s see how a complete example will look like:
860+
861+
tools.arduino_ota.upload.field.username=Username
862+
tools.arduino_ota.upload.field.password=Password
863+
tools.arduino_ota.upload.field.password.secret=true
864+
tools.arduino_ota.upload.pattern="{runtime.tools.arduinoOTA.path}/bin/arduinoOTA"
865+
-address {upload.port.address} -port 65280
866+
-username "{upload.field.username}
867+
-password "{upload.field.password}"
868+
-sketch "{build.path}/{build.project_name}.bin"
869+
687870
#### Upload verification
688871

689872
Upload verification can be enabled via the Arduino IDE's **File > Preferences > Verify code after upload** or
@@ -744,10 +927,14 @@ support uploading via programmer.
744927

745928
The full path (e.g., `/dev/ttyACM0`) of the port selected via the IDE or
746929
[`arduino-cli upload`](commands/arduino-cli_upload.md)'s `--port` option is available as a configuration property
747-
**{serial.port}**.
930+
**{upload.port.address}**.
748931

749932
The file component of the port's path (e.g., `ttyACM0`) is available as the configuration property
750-
**{serial.port.file}**.
933+
**{upload.port.label}**.
934+
935+
For backward compatibility with IDE 1.8.15 and older the old property **serial.port** is still available and is
936+
identical to **{upload.port.address}**. Instead **serial.port.file** is identical to **{upload.port.label}** and
937+
available only if protocol in use is **serial**.
751938

752939
### Upload using an external programmer
753940

@@ -756,7 +943,17 @@ The `program` action is triggered via the **Sketch > Upload Using Programmer** f
756943
compiled sketch to a board using an external programmer.
757944

758945
The **program.tool** property determines the tool to be used for this action. This property is typically defined for
759-
each programmer in [programmers.txt](#programmerstxt):
946+
each programmer in [programmers.txt](#programmerstxt) and uses the same syntax as `upload` action:
947+
948+
[......]
949+
usbasp.program.tool.serial=avrdude
950+
[......]
951+
arduinoasisp.program.tool.serial=avrdude
952+
[......]
953+
arduinoisp.program.tool.default=avrdude
954+
[......]
955+
956+
For backward compatibility with IDE 1.8.15 and older the previous syntax is still supported:
760957

761958
[......]
762959
usbasp.program.tool=avrdude
@@ -786,7 +983,18 @@ the board.
786983
1. `bootloader` is used to flash the bootloader to the board
787984

788985
The **bootloader.tool** property determines the tool to be used for the `erase` and `bootloader` actions both. This
789-
property is typically defined for each board in boards.txt:
986+
property is typically defined for each board in boards.txt and uses the same syntax as `upload` action:
987+
988+
[......]
989+
uno.bootloader.tool.serial=avrdude
990+
[......]
991+
leonardo.upload.tool.serial=avrdude
992+
leonardo.upload.tool.network=arduino_ota
993+
[......]
994+
duemilanove.upload.tool.default=avrdude
995+
[......]
996+
997+
For backward compatibility with IDE 1.8.15 and older the previous syntax is still supported:
790998

791999
[......]
7921000
uno.bootloader.tool=avrdude
@@ -1009,3 +1217,7 @@ software is in use:
10091217
This behavior
10101218
[can be configured](https://arduino.github.io/arduino-cli/latest/commands/arduino-cli_core_install/#options)
10111219
- **Arduino Pro IDE**: (since 0.1.0) runs the script for any installed platform.
1220+
1221+
```
1222+
1223+
```

0 commit comments

Comments
 (0)