@@ -361,11 +361,24 @@ func runProgramAction(pme *packagemanager.Explorer,
361
361
uploadProperties .Set ("build.project_name" , sketchName )
362
362
}
363
363
364
+ // Force port wait to make easier to unbrick boards like the Arduino Leonardo, or similar with native USB,
365
+ // when a sketch causes a crash and the native USB serial port is lost.
366
+ // See https://github.com/arduino/arduino-cli/issues/1943 for the details.
367
+ //
368
+ // In order to trigger the forced serial-port-wait the following conditions must be met:
369
+ // - No upload port specified (protocol == "default")
370
+ // - "upload.wait_for_upload_port" == true (developers requested the touch + port wait)
371
+ // - "upload.tool.serial" not defained, or
372
+ // "upload.tool.serial" is the same as "upload.tool.default"
373
+ forcedSerialPortWait := port .Protocol == "default" && // this is the value when no port is specified
374
+ uploadProperties .GetBoolean ("upload.wait_for_upload_port" ) &&
375
+ (! uploadProperties .ContainsKey ("upload.tool.serial" ) ||
376
+ uploadProperties .Get ("upload.tool.serial" ) == uploadProperties .Get ("upload.tool.default" ))
377
+
364
378
// If not using programmer perform some action required
365
379
// to set the board in bootloader mode
366
380
actualPort := port
367
- if programmer == nil && ! burnBootloader && port .Protocol == "serial" {
368
-
381
+ if programmer == nil && ! burnBootloader && (port .Protocol == "serial" || forcedSerialPortWait ) {
369
382
// Perform reset via 1200bps touch if requested and wait for upload port also if requested.
370
383
touch := uploadProperties .GetBoolean ("upload.use_1200bps_touch" )
371
384
wait := false
@@ -425,7 +438,7 @@ func runProgramAction(pme *packagemanager.Explorer,
425
438
if actualPort .Address != "" {
426
439
// Set serial port property
427
440
uploadProperties .Set ("serial.port" , actualPort .Address )
428
- if actualPort .Protocol == "serial" {
441
+ if actualPort .Protocol == "serial" || actualPort . Protocol == "default" {
429
442
// This must be done only for serial ports
430
443
portFile := strings .TrimPrefix (actualPort .Address , "/dev/" )
431
444
uploadProperties .Set ("serial.port.file" , portFile )
0 commit comments