From 5cf168b303d062af61b7f6b9e2a7bc09ca2738fe Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 17 Mar 2017 17:37:25 +0100 Subject: [PATCH 1/3] Some debug messages set to info level Otherwise they won't appear in console Signed-off-by: Cristian Maglie --- upload/upload.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/upload/upload.go b/upload/upload.go index 6417f91fa..7f8b9b65c 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -143,11 +143,11 @@ func reset(port string, wait bool, l Logger) (string, error) { // Get port list before reset ports, err := serial.GetPortsList() - debug(l, "Get port list before reset") + info(l, "Get port list before reset") if err != nil { return "", errors.Wrapf(err, "Get port list before reset") } else { - debug(l, ports) + info(l, ports) } // Open port @@ -155,14 +155,14 @@ func reset(port string, wait bool, l Logger) (string, error) { BaudRate: 1200, } p, err := serial.Open(port, mode) - debug(l, "Open port", port) + info(l, "Open port", port) if err != nil { return "", errors.Wrapf(err, "Open port %s", port) } // Set DTR err = p.SetDTR(false) - debug(l, "Set DTR") + info(l, "Set DTR off") if err != nil { return "", errors.Wrapf(err, "Can't set DTR") } From 7bccd71cb495175b73c13cfdab4142975a46ed54 Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 17 Mar 2017 17:39:37 +0100 Subject: [PATCH 2/3] uploader: factored method to touch port at 1200bps This allows the use of defer-close that doesn't leak a file handle if something goes wrong. Signed-off-by: Cristian Maglie --- upload/upload.go | 37 ++++++++++++++++++++++--------------- 1 file changed, 22 insertions(+), 15 deletions(-) diff --git a/upload/upload.go b/upload/upload.go index 7f8b9b65c..608b8c912 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -150,24 +150,12 @@ func reset(port string, wait bool, l Logger) (string, error) { info(l, ports) } - // Open port - mode := &serial.Mode{ - BaudRate: 1200, - } - p, err := serial.Open(port, mode) - info(l, "Open port", port) + // Touch port at 1200bps + err = touchSerialPortAt1200bps(port, l) if err != nil { - return "", errors.Wrapf(err, "Open port %s", port) + return "", errors.Wrapf(err, "1200bps Touch") } - // Set DTR - err = p.SetDTR(false) - info(l, "Set DTR off") - if err != nil { - return "", errors.Wrapf(err, "Can't set DTR") - } - p.Close() - // Wait for port to disappear and reappear if wait { port = waitReset(ports, l) @@ -176,6 +164,25 @@ func reset(port string, wait bool, l Logger) (string, error) { return port, nil } +func touchSerialPortAt1200bps(port string, l Logger) error { + info(l, "Touching port ", port, " at 1200bps") + + // Open port + p, err := serial.Open(port, &serial.Mode{BaudRate: 1200}) + if err != nil { + return errors.Wrapf(err, "Open port %s", port) + } + defer p.Close() + + // Set DTR + err = p.SetDTR(false) + info(l, "Set DTR off") + if err != nil { + return errors.Wrapf(err, "Can't set DTR") + } + return nil +} + // waitReset is meant to be called just after a reset. It watches the ports connected // to the machine until a port disappears and reappears. The port name could be different // so it returns the name of the new port. From 18e794c9d6d81ba953e8c9c3b0000fdc2dacd71e Mon Sep 17 00:00:00 2001 From: Cristian Maglie Date: Fri, 17 Mar 2017 17:42:16 +0100 Subject: [PATCH 3/3] uploader: added a small sleep to allow board reset Signed-off-by: Cristian Maglie --- upload/upload.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/upload/upload.go b/upload/upload.go index 608b8c912..14a4c1055 100644 --- a/upload/upload.go +++ b/upload/upload.go @@ -180,6 +180,10 @@ func touchSerialPortAt1200bps(port string, l Logger) error { if err != nil { return errors.Wrapf(err, "Can't set DTR") } + + // Wait a bit to allow restart of the board + time.Sleep(200 * time.Millisecond) + return nil }