Skip to content

Commit bb540df

Browse files
deadprogramaykevl
authored andcommitted
flash: retry 3 times when attempting to reset the serial port
Signed-off-by: Ron Evans <ron@hybridgroup.com>
1 parent e181199 commit bb540df

File tree

1 file changed

+15
-9
lines changed

1 file changed

+15
-9
lines changed

main.go

+15-9
Original file line numberDiff line numberDiff line change
@@ -473,16 +473,22 @@ func Run(pkgName string, options *compileopts.Options) error {
473473
})
474474
}
475475

476-
func touchSerialPortAt1200bps(port string) error {
477-
// Open port
478-
p, err := serial.Open(port, &serial.Mode{BaudRate: 1200})
479-
if err != nil {
480-
return fmt.Errorf("opening port: %s", err)
476+
func touchSerialPortAt1200bps(port string) (err error) {
477+
retryCount := 3
478+
for i := 0; i < retryCount; i++ {
479+
// Open port
480+
p, e := serial.Open(port, &serial.Mode{BaudRate: 1200})
481+
if e != nil {
482+
time.Sleep(1 * time.Second)
483+
err = e
484+
continue
485+
}
486+
defer p.Close()
487+
488+
p.SetDTR(false)
489+
return nil
481490
}
482-
defer p.Close()
483-
484-
p.SetDTR(false)
485-
return nil
491+
return fmt.Errorf("opening port: %s", err)
486492
}
487493

488494
func flashUF2UsingMSD(volume, tmppath string) error {

0 commit comments

Comments
 (0)