Skip to content

Commit 8a281b0

Browse files
author
Mattia Bertorello
committed
Change the serial BaudRate from 1000000 to 115200 that is support by osx
Otherwise when the serial will open it return invalid serial port
1 parent 7472ec2 commit 8a281b0

File tree

7 files changed

+33
-45
lines changed

7 files changed

+33
-45
lines changed

modules/nina/flasher.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package nina
2222
import (
2323
"crypto/md5"
2424
"encoding/binary"
25+
"github.com/arduino-libraries/FirmwareUpdater/utils"
2526
"log"
2627
"time"
2728

@@ -235,19 +236,9 @@ func (flasher *Flasher) Md5sum(data []byte) error {
235236
return nil
236237
}
237238

238-
func OpenSerial(portName string) (serial.Port, error) {
239-
mode := &serial.Mode{
240-
BaudRate: 115200,
241-
Vtimeout: 255,
242-
Vmin: 0,
243-
}
244-
245-
return serial.Open(portName, mode)
246-
}
247-
248239
func OpenFlasher(portName string) (*Flasher, error) {
249240

250-
port, err := OpenSerial(portName)
241+
port, err := utils.OpenSerial(portName)
251242

252243
if err != nil {
253244
return nil, &FlasherError{err: "Error opening serial port. " + err.Error()}

modules/nina/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ func Run(ctx context.Context) {
4949
}
5050

5151
if ctx.FWUploaderBinary != "" {
52-
log.Println("Flashing firmware uploader")
52+
log.Println("Flashing firmware uploader nina")
5353
if ctx.BinaryToRestore == "" {
5454
ctx.BinaryToRestore, err = programmer.DumpAndFlash(&ctx, ctx.FWUploaderBinary)
5555
} else {

modules/sara/flasher.go

Lines changed: 7 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,11 @@
2020
package sara
2121

2222
import (
23+
"github.com/arduino-libraries/FirmwareUpdater/utils"
2324
serial "github.com/facchinm/go-serial"
24-
"time"
25-
"strings"
2625
"log"
26+
"strings"
27+
"time"
2728
//"strconv"
2829
)
2930

@@ -44,7 +45,7 @@ func (flasher *Flasher) Hello() error {
4445
f.Expect("ATE0", "OK", 100)
4546
f.Expect("ATE0", "OK", 100)
4647
f.Expect("ATE0", "OK", 100)
47-
_, err := flasher.Expect("AT", "OK", 100);
48+
_, err := flasher.Expect("AT", "OK", 100)
4849
return err
4950
}
5051

@@ -65,7 +66,7 @@ func (flasher *Flasher) ExpectMinBytes(buffer string, response string, timeout i
6566

6667
start := time.Now()
6768

68-
for ((time.Since(start) < time.Duration(timeout) * time.Millisecond && !strings.Contains(string(res), response)) || (len(res) < min_bytes)) {
69+
for (time.Since(start) < time.Duration(timeout)*time.Millisecond && !strings.Contains(string(res), response)) || (len(res) < min_bytes) {
6970
data := 0
7071
partial := make([]byte, 65535)
7172
data, err = flasher.port.Read(partial)
@@ -79,7 +80,7 @@ func (flasher *Flasher) ExpectMinBytes(buffer string, response string, timeout i
7980
log.Println(string(res))
8081

8182
if !strings.Contains(string(res), response) {
82-
return string(res), &FlasherError{err: "Expected " + response + ", got " + string(res)}
83+
return string(res), &FlasherError{err: "Expected " + response + ", got " + string(res)}
8384
}
8485
return string(res), nil
8586
}
@@ -104,7 +105,6 @@ func (flasher *Flasher) Write(address uint32, buffer []byte) error {
104105
return nil
105106
}
106107

107-
108108
// Fill buffer with data coming from serial port.
109109
// Blocks until the buffer is full.
110110
func (flasher *Flasher) serialFillBuffer(buffer []byte) error {
@@ -131,19 +131,9 @@ func (flasher *Flasher) sendCommand(payload []byte) error {
131131
return nil
132132
}
133133

134-
func OpenSerial(portName string) (serial.Port, error) {
135-
mode := &serial.Mode{
136-
BaudRate: 1000000,
137-
Vtimeout: 100,
138-
Vmin: 0,
139-
}
140-
141-
return serial.Open(portName, mode)
142-
}
143-
144134
func OpenFlasher(portName string) (*Flasher, error) {
145135

146-
port, err := OpenSerial(portName)
136+
port, err := utils.OpenSerial(portName)
147137
if err != nil {
148138
return nil, &FlasherError{err: "Error opening serial port. " + err.Error()}
149139
}

modules/sara/main.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func Run(ctx context.Context) {
3939
programmer = &bossac.Bossac{}
4040

4141
if ctx.FWUploaderBinary != "" {
42-
log.Println("Flashing firmware uploader")
42+
log.Println("Flashing firmware uploader sara")
4343
if ctx.BinaryToRestore == "" {
4444
ctx.BinaryToRestore, err = programmer.DumpAndFlash(&ctx, ctx.FWUploaderBinary)
4545
} else {
@@ -118,7 +118,7 @@ func flashFirmware(ctx context.Context) error {
118118
return err
119119
}
120120

121-
_, err = f.Expect("AT+UDWNFILE=\"UPDATE.BIN\"," + strconv.Itoa(len(fwData)) + ",\"FOAT\"", ">", 20000)
121+
_, err = f.Expect("AT+UDWNFILE=\"UPDATE.BIN\","+strconv.Itoa(len(fwData))+",\"FOAT\"", ">", 20000)
122122
if err != nil {
123123
return err
124124
}
@@ -144,9 +144,9 @@ func flashFirmware(ctx context.Context) error {
144144

145145
// wait up to 20 minutes trying to ping the module. After 20 minutes signal the error
146146
start := time.Now()
147-
for (time.Since(start) < time.Minute * 20) {
147+
for time.Since(start) < time.Minute*20 {
148148
err = f.Hello()
149-
if (err == nil) {
149+
if err == nil {
150150
return nil
151151
}
152152
time.Sleep(1 * time.Second)

modules/winc/flasher.go

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ package winc
2121

2222
import (
2323
"encoding/binary"
24+
"github.com/arduino-libraries/FirmwareUpdater/utils"
2425
serial "github.com/facchinm/go-serial"
2526
"log"
2627
"time"
@@ -192,19 +193,9 @@ func (flasher *Flasher) sendCommand(command byte, address uint32, val uint32, pa
192193
return nil
193194
}
194195

195-
func OpenSerial(portName string) (serial.Port, error) {
196-
mode := &serial.Mode{
197-
BaudRate: 1000000,
198-
Vtimeout: 100,
199-
Vmin: 0,
200-
}
201-
202-
return serial.Open(portName, mode)
203-
}
204-
205196
func OpenFlasher(portName string) (*Flasher, error) {
206197

207-
port, err := OpenSerial(portName)
198+
port, err := utils.OpenSerial(portName)
208199
if err != nil {
209200
return nil, &FlasherError{err: "Error opening serial port. " + err.Error()}
210201
}

modules/winc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func Run(ctx context.Context) {
4141
programmer = &bossac.Bossac{}
4242

4343
if ctx.FWUploaderBinary != "" {
44-
log.Println("Flashing firmware uploader")
44+
log.Println("Flashing firmware uploader winc")
4545
if ctx.BinaryToRestore == "" {
4646
ctx.BinaryToRestore, err = programmer.DumpAndFlash(&ctx, ctx.FWUploaderBinary)
4747
} else {

utils/flasher.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package utils
2+
3+
import (
4+
"github.com/facchinm/go-serial"
5+
)
6+
7+
func OpenSerial(portName string) (serial.Port, error) {
8+
mode := &serial.Mode{
9+
// This bound rate works on osx 10.14
10+
BaudRate: 115200,
11+
Vtimeout: 255,
12+
Vmin: 0,
13+
}
14+
15+
return serial.Open(portName, mode)
16+
}

0 commit comments

Comments
 (0)