+653
-339
lines changedFilter options
+653
-339
lines changed Original file line number Diff line number Diff line change
@@ -15,6 +15,7 @@ Each profile will define:
15
15
- A possible core platform name and version, that is a dependency of the target core platform (with the 3rd party
16
16
platform index URL if needed)
17
17
- The libraries used in the sketch (including their version)
18
+
- The port and protocol to upload the sketch and monitor the board
18
19
19
20
The format of the file is the following:
20
21
@@ -33,7 +34,11 @@ profiles:
33
34
- <LIB_NAME> (<LIB_VERSION>)
34
35
- <LIB_NAME> (<LIB_VERSION>)
35
36
- <LIB_NAME> (<LIB_VERSION>)
36
-
37
+
port: <PORT_NAME>
38
+
port_config:
39
+
<PORT_SETTING_NAME>: <PORT_SETTING_VALUE>
40
+
...
41
+
protocol: <PORT_PROTOCOL>
37
42
...more profiles here...
38
43
```
39
44
@@ -54,6 +59,15 @@ otherwise below). The available fields are:
54
59
- `<USER_NOTES>` is a free text string available to the developer to add comments. This field is optional.
55
60
- `<PROGRAMMER>` is the programmer that will be used. This field is optional.
56
61
62
+
The following fields are available since Arduino CLI 1.1.0:
63
+
64
+
- `<PORT_NAME>` is the port that will be used to upload and monitor the board (unless explicitly set otherwise). This
65
+
field is optional.
66
+
- `port_config` section with `<PORT_SETTING_NAME>` and `<PORT_SETTING_VALUE>` defines the port settings that will be
67
+
used in the `monitor` command. Typically is used to set the baudrate for the serial port (for example
68
+
`baudrate: 115200`) but any setting/value can be specified. Multiple settings can be set. These fields are optional.
69
+
- `<PORT_PROTOCOL>` is the protocol for the port used to upload and monitor the board. This field is optional.
70
+
57
71
A complete example of a sketch project file may be the following:
58
72
59
73
```
@@ -76,6 +90,9 @@ profiles:
76
90
- VitconMQTT (1.0.1)
77
91
- Arduino_ConnectionHandler (0.6.4)
78
92
- TinyDHT sensor library (1.1.0)
93
+
port: /dev/ttyACM0
94
+
port_config:
95
+
baudrate: 115200
79
96
80
97
tiny:
81
98
notes: testing the very limit of the AVR platform, it will be very unstable
@@ -139,6 +156,8 @@ particular:
139
156
- The `default_fqbn` key sets the default value for the `--fqbn` flag
140
157
- The `default_programmer` key sets the default value for the `--programmer` flag
141
158
- The `default_port` key sets the default value for the `--port` flag
159
+
- The `default_port_config` key sets the default values for the `--config` flag in the `monitor` command (available
160
+
since Arduino CLI 1.1.0)
142
161
- The `default_protocol` key sets the default value for the `--protocol` flag
143
162
- The `default_profile` key sets the default value for the `--profile` flag
144
163
@@ -148,11 +167,14 @@ For example:
148
167
default_fqbn: arduino:samd:mkr1000
149
168
default_programmer: atmel_ice
150
169
default_port: /dev/ttyACM0
170
+
default_port_config:
171
+
baudrate: 115200
151
172
default_protocol: serial
152
173
default_profile: myprofile
153
174
```
154
175
155
176
With this configuration set, it is not necessary to specify the `--fqbn`, `--programmer`, `--port`, `--protocol` or
156
177
`--profile` flags to the [`arduino-cli compile`](commands/arduino-cli_compile.md),
157
178
[`arduino-cli upload`](commands/arduino-cli_upload.md) or [`arduino-cli debug`](commands/arduino-cli_debug.md) commands
158
-
when compiling, uploading or debugging the sketch.
179
+
when compiling, uploading or debugging the sketch. Moreover in the `monitor` command it is not necessary to specify the
180
+
`--config baudrate=115200` to communicate with the monitor port of the board.
Original file line number Diff line number Diff line change
@@ -34,12 +34,13 @@ import (
34
34
35
35
// projectRaw is a support struct used only to unmarshal the yaml
36
36
type projectRaw struct {
37
-
ProfilesRaw yaml.Node `yaml:"profiles"`
38
-
DefaultProfile string `yaml:"default_profile"`
39
-
DefaultFqbn string `yaml:"default_fqbn"`
40
-
DefaultPort string `yaml:"default_port,omitempty"`
41
-
DefaultProtocol string `yaml:"default_protocol,omitempty"`
42
-
DefaultProgrammer string `yaml:"default_programmer,omitempty"`
37
+
ProfilesRaw yaml.Node `yaml:"profiles"`
38
+
DefaultProfile string `yaml:"default_profile"`
39
+
DefaultFqbn string `yaml:"default_fqbn"`
40
+
DefaultPort string `yaml:"default_port,omitempty"`
41
+
DefaultPortConfig map[string]string `yaml:"default_port_config,omitempty"`
42
+
DefaultProtocol string `yaml:"default_protocol,omitempty"`
43
+
DefaultProgrammer string `yaml:"default_programmer,omitempty"`
43
44
}
44
45
45
46
// Project represents the sketch project file
@@ -48,6 +49,7 @@ type Project struct {
48
49
DefaultProfile string
49
50
DefaultFqbn string
50
51
DefaultPort string
52
+
DefaultPortConfig map[string]string
51
53
DefaultProtocol string
52
54
DefaultProgrammer string
53
55
}
@@ -70,6 +72,12 @@ func (p *Project) AsYaml() string {
70
72
if p.DefaultPort != "" {
71
73
res += fmt.Sprintf("default_port: %s\n", p.DefaultPort)
72
74
}
75
+
if len(p.DefaultPortConfig) > 0 {
76
+
res += "default_port_config:\n"
77
+
for k, v := range p.DefaultPortConfig {
78
+
res += fmt.Sprintf(" %s: %s\n", k, v)
79
+
}
80
+
}
73
81
if p.DefaultProtocol != "" {
74
82
res += fmt.Sprintf("default_protocol: %s\n", p.DefaultProtocol)
75
83
}
@@ -103,17 +111,33 @@ type Profile struct {
103
111
Name string
104
112
Notes string `yaml:"notes"`
105
113
FQBN string `yaml:"fqbn"`
114
+
Port string `yaml:"port"`
115
+
PortConfig map[string]string `yaml:"port_config"`
116
+
Protocol string `yaml:"protocol"`
106
117
Programmer string `yaml:"programmer"`
107
118
Platforms ProfileRequiredPlatforms `yaml:"platforms"`
108
119
Libraries ProfileRequiredLibraries `yaml:"libraries"`
109
120
}
110
121
111
122
// ToRpc converts this Profile to an rpc.SketchProfile
112
123
func (p *Profile) ToRpc() *rpc.SketchProfile {
124
+
var portConfig *rpc.MonitorPortConfiguration
125
+
if len(p.PortConfig) > 0 {
126
+
portConfig = &rpc.MonitorPortConfiguration{}
127
+
for k, v := range p.PortConfig {
128
+
portConfig.Settings = append(portConfig.Settings, &rpc.MonitorPortSetting{
129
+
SettingId: k,
130
+
Value: v,
131
+
})
132
+
}
133
+
}
113
134
return &rpc.SketchProfile{
114
135
Name: p.Name,
115
136
Fqbn: p.FQBN,
116
137
Programmer: p.Programmer,
138
+
Port: p.Port,
139
+
PortConfig: portConfig,
140
+
Protocol: p.Protocol,
117
141
}
118
142
}
119
143
@@ -127,6 +151,18 @@ func (p *Profile) AsYaml() string {
127
151
if p.Programmer != "" {
128
152
res += fmt.Sprintf(" programmer: %s\n", p.Programmer)
129
153
}
154
+
if p.Port != "" {
155
+
res += fmt.Sprintf(" port: %s\n", p.Port)
156
+
}
157
+
if p.Protocol != "" {
158
+
res += fmt.Sprintf(" protocol: %s\n", p.Protocol)
159
+
}
160
+
if len(p.PortConfig) > 0 {
161
+
res += " port_config:\n"
162
+
for k, v := range p.PortConfig {
163
+
res += fmt.Sprintf(" %s: %s\n", k, v)
164
+
}
165
+
}
130
166
res += p.Platforms.AsYaml()
131
167
res += p.Libraries.AsYaml()
132
168
return res
@@ -291,6 +327,7 @@ func LoadProjectFile(file *paths.Path) (*Project, error) {
291
327
DefaultProfile: raw.DefaultProfile,
292
328
DefaultFqbn: raw.DefaultFqbn,
293
329
DefaultPort: raw.DefaultPort,
330
+
DefaultPortConfig: raw.DefaultPortConfig,
294
331
DefaultProtocol: raw.DefaultProtocol,
295
332
DefaultProgrammer: raw.DefaultProgrammer,
296
333
}, nil
Original file line number Diff line number Diff line change
@@ -289,6 +289,16 @@ func (s *Sketch) Hash() string {
289
289
// ToRpc converts this Sketch into a rpc.LoadSketchResponse
290
290
func (s *Sketch) ToRpc() *rpc.Sketch {
291
291
defaultPort, defaultProtocol := s.GetDefaultPortAddressAndProtocol()
292
+
var defaultPortConfig *rpc.MonitorPortConfiguration
293
+
if len(s.Project.DefaultPortConfig) > 0 {
294
+
defaultPortConfig = &rpc.MonitorPortConfiguration{}
295
+
for k, v := range s.Project.DefaultPortConfig {
296
+
defaultPortConfig.Settings = append(defaultPortConfig.Settings, &rpc.MonitorPortSetting{
297
+
SettingId: k,
298
+
Value: v,
299
+
})
300
+
}
301
+
}
292
302
res := &rpc.Sketch{
293
303
MainFile: s.MainFile.String(),
294
304
LocationPath: s.FullPath.String(),
@@ -297,6 +307,7 @@ func (s *Sketch) ToRpc() *rpc.Sketch {
297
307
RootFolderFiles: s.RootFolderFiles.AsStrings(),
298
308
DefaultFqbn: s.GetDefaultFQBN(),
299
309
DefaultPort: defaultPort,
310
+
DefaultPortConfig: defaultPortConfig,
300
311
DefaultProtocol: defaultProtocol,
301
312
DefaultProgrammer: s.GetDefaultProgrammer(),
302
313
Profiles: f.Map(s.Project.Profiles, (*Profile).ToRpc),
Original file line number Diff line number Diff line change
@@ -64,15 +64,19 @@ func (f *Fqbn) Set(fqbn string) {
64
64
// parameters provided by the user.
65
65
// This determine the FQBN based on:
66
66
// - the value of the FQBN flag if explicitly specified, otherwise
67
+
// - the FQBN of the selected profile if available, otherwise
67
68
// - the default FQBN value in sketch.yaml (`default_fqbn` key) if available, otherwise
68
69
// - it tries to autodetect the board connected to the given port flags
69
70
// If all above methods fails, it returns the empty string.
70
71
// The Port metadata are always returned except if:
71
72
// - the port is not found, in this case nil is returned
72
73
// - the FQBN autodetection fail, in this case the function prints an error and
73
74
// terminates the execution
74
-
func CalculateFQBNAndPort(ctx context.Context, portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultFQBN, defaultAddress, defaultProtocol string) (string, *rpc.Port) {
75
+
func CalculateFQBNAndPort(ctx context.Context, portArgs *Port, fqbnArg *Fqbn, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultFQBN, defaultAddress, defaultProtocol string, profile *rpc.SketchProfile) (string, *rpc.Port) {
75
76
fqbn := fqbnArg.String()
77
+
if fqbn == "" {
78
+
fqbn = profile.GetFqbn()
79
+
}
76
80
if fqbn == "" {
77
81
fqbn = defaultFQBN
78
82
}
@@ -87,7 +91,7 @@ func CalculateFQBNAndPort(ctx context.Context, portArgs *Port, fqbnArg *Fqbn, in
87
91
return fqbn, port
88
92
}
89
93
90
-
port, err := portArgs.GetPort(ctx, instance, srv, defaultAddress, defaultProtocol)
94
+
port, err := portArgs.GetPort(ctx, instance, srv, defaultAddress, defaultProtocol, profile)
91
95
if err != nil {
92
96
feedback.Fatal(i18n.Tr("Error getting port metadata: %v", err), feedback.ErrGeneric)
93
97
}
Original file line number Diff line number Diff line change
@@ -57,12 +57,12 @@ func (p *Port) AddToCommand(cmd *cobra.Command, srv rpc.ArduinoCoreServiceServer
57
57
// This method allows will bypass the discoveries if:
58
58
// - a nil instance is passed: in this case the plain port and protocol arguments are returned (even if empty)
59
59
// - a protocol is specified: in this case the discoveries are not needed to autodetect the protocol.
60
-
func (p *Port) GetPortAddressAndProtocol(ctx context.Context, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string) (string, string, error) {
60
+
func (p *Port) GetPortAddressAndProtocol(ctx context.Context, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string, profile *rpc.SketchProfile) (string, string, error) {
61
61
if p.protocol != "" || instance == nil {
62
62
return p.address, p.protocol, nil
63
63
}
64
64
65
-
port, err := p.GetPort(ctx, instance, srv, defaultAddress, defaultProtocol)
65
+
port, err := p.GetPort(ctx, instance, srv, defaultAddress, defaultProtocol, profile)
66
66
if err != nil {
67
67
return "", "", err
68
68
}
@@ -71,7 +71,13 @@ func (p *Port) GetPortAddressAndProtocol(ctx context.Context, instance *rpc.Inst
71
71
72
72
// GetPort returns the Port obtained by parsing command line arguments.
73
73
// The extra metadata for the ports is obtained using the pluggable discoveries.
74
-
func (p *Port) GetPort(ctx context.Context, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string) (*rpc.Port, error) {
74
+
func (p *Port) GetPort(ctx context.Context, instance *rpc.Instance, srv rpc.ArduinoCoreServiceServer, defaultAddress, defaultProtocol string, profile *rpc.SketchProfile) (*rpc.Port, error) {
75
+
if profile.GetPort() != "" {
76
+
defaultAddress = profile.GetPort()
77
+
}
78
+
if profile.GetProtocol() != "" {
79
+
defaultProtocol = profile.GetProtocol()
80
+
}
75
81
address := p.address
76
82
protocol := p.protocol
77
83
if address == "" && (defaultAddress != "" || defaultProtocol != "") {
Original file line number Diff line number Diff line change
@@ -59,7 +59,7 @@ func initAttachCommand(srv rpc.ArduinoCoreServiceServer) *cobra.Command {
59
59
func runAttachCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, path string, port *arguments.Port, fqbn string, programmer *arguments.Programmer) {
60
60
sketchPath := arguments.InitSketchPath(path)
61
61
62
-
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(ctx, nil, srv, "", "")
62
+
portAddress, portProtocol, _ := port.GetPortAddressAndProtocol(ctx, nil, srv, "", "", nil)
63
63
newDefaults, err := srv.SetSketchDefaults(ctx, &rpc.SetSketchDefaultsRequest{
64
64
SketchPath: sketchPath.String(),
65
65
DefaultFqbn: fqbn,
Original file line number Diff line number Diff line change
@@ -73,7 +73,7 @@ func runBootloaderCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer)
73
73
logrus.Info("Executing `arduino-cli burn-bootloader`")
74
74
75
75
// We don't need a Sketch to upload a board's bootloader
76
-
discoveryPort, err := port.GetPort(ctx, instance, srv, "", "")
76
+
discoveryPort, err := port.GetPort(ctx, instance, srv, "", "", nil)
77
77
if err != nil {
78
78
feedback.Fatal(i18n.Tr("Error during Upload: %v", err), feedback.ErrGeneric)
79
79
}
Original file line number Diff line number Diff line change
@@ -180,7 +180,7 @@ func runCompileCommand(cmd *cobra.Command, args []string, srv rpc.ArduinoCoreSer
180
180
fqbnArg.Set(profile.GetFqbn())
181
181
}
182
182
183
-
fqbn, port := arguments.CalculateFQBNAndPort(ctx, &portArgs, &fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
183
+
fqbn, port := arguments.CalculateFQBNAndPort(ctx, &portArgs, &fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol(), profile)
184
184
185
185
if keysKeychain != "" || signKey != "" || encryptKey != "" {
186
186
arguments.CheckFlagsMandatory(cmd, "keys-keychain", "sign-key", "encrypt-key")
Original file line number Diff line number Diff line change
@@ -108,7 +108,7 @@ func runDebugCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer, args
108
108
fqbnArg.Set(profile.GetFqbn())
109
109
}
110
110
111
-
fqbn, port := arguments.CalculateFQBNAndPort(ctx, portArgs, fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol())
111
+
fqbn, port := arguments.CalculateFQBNAndPort(ctx, portArgs, fqbnArg, inst, srv, sk.GetDefaultFqbn(), sk.GetDefaultPort(), sk.GetDefaultProtocol(), profile)
112
112
113
113
prog := profile.GetProgrammer()
114
114
if prog == "" || programmer.GetProgrammer() != "" {
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@ func runDebugCheckCommand(ctx context.Context, srv rpc.ArduinoCoreServiceServer,
60
60
instance := instance.CreateAndInit(ctx, srv)
61
61
logrus.Info("Executing `arduino-cli debug`")
62
62
63
-
port, err := portArgs.GetPort(ctx, instance, srv, "", "")
63
+
port, err := portArgs.GetPort(ctx, instance, srv, "", "", nil)
64
64
if err != nil {
65
65
feedback.FatalError(err, feedback.ErrBadArgument)
66
66
}
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4