Skip to content

Commit d4c7b34

Browse files
harden the flashing process (#58)
* enhance reset logic (port could change after reset) * increment wait time: the board could still be unavailable after 1 sec * Remove useless comment * Update cli/certificates/flash.go Co-authored-by: Silvano Cerza <[email protected]> Co-authored-by: Silvano Cerza <[email protected]>
1 parent e5f422a commit d4c7b34

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

Diff for: cli/certificates/flash.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,18 @@ func run(cmd *cobra.Command, args []string) {
133133
}
134134

135135
// Check if board needs a 1200bps touch for upload
136+
uploadPort := address
136137
if board.UploadTouch {
137138
logrus.Info("Putting board into bootloader mode")
138-
_, err := serialutils.Reset(address, board.UploadWait, nil)
139+
newUploadPort, err := serialutils.Reset(address, board.UploadWait, nil)
139140
if err != nil {
140141
feedback.Errorf("Error during certificates flashing: missing board address")
141142
os.Exit(errorcodes.ErrGeneric)
142143
}
144+
if newUploadPort != "" {
145+
logrus.Infof("Found port to upload Loader: %s", newUploadPort)
146+
uploadPort = newUploadPort
147+
}
143148
}
144149

145150
// Flash loader Sketch
@@ -157,18 +162,18 @@ func run(cmd *cobra.Command, args []string) {
157162

158163
// Wait a bit after flashing the loader sketch for the board to become
159164
// available again.
160-
time.Sleep(1 * time.Second)
165+
time.Sleep(2 * time.Second)
161166

162167
// Get flasher depending on which module to use
163168
var f flasher.Flasher
164169
moduleName := board.Module
165170
switch moduleName {
166171
case "NINA":
167-
f, err = flasher.NewNinaFlasher(address)
172+
f, err = flasher.NewNinaFlasher(uploadPort)
168173
case "SARA":
169-
f, err = flasher.NewSaraFlasher(address)
174+
f, err = flasher.NewSaraFlasher(uploadPort)
170175
case "WINC1500":
171-
f, err = flasher.NewWincFlasher(address)
176+
f, err = flasher.NewWincFlasher(uploadPort)
172177
default:
173178
err = fmt.Errorf("unknown module: %s", moduleName)
174179
}

Diff for: cli/firmware/flash.go

+10-5
Original file line numberDiff line numberDiff line change
@@ -160,13 +160,18 @@ func run(cmd *cobra.Command, args []string) {
160160
}
161161

162162
// Check if board needs a 1200bps touch for upload
163+
uploadPort := address
163164
if board.UploadTouch {
164165
logrus.Info("Putting board into bootloader mode")
165-
_, err := serialutils.Reset(address, board.UploadWait, nil)
166+
newUploadPort, err := serialutils.Reset(address, board.UploadWait, nil)
166167
if err != nil {
167168
feedback.Errorf("Error during firmware flashing: missing board address")
168169
os.Exit(errorcodes.ErrGeneric)
169170
}
171+
if newUploadPort != "" {
172+
logrus.Infof("Found port to upload Loader: %s", newUploadPort)
173+
uploadPort = newUploadPort
174+
}
170175
}
171176

172177
// Flash loader Sketch
@@ -184,17 +189,17 @@ func run(cmd *cobra.Command, args []string) {
184189

185190
// Wait a bit after flashing the loader sketch for the board to become
186191
// available again.
187-
time.Sleep(1 * time.Second)
192+
time.Sleep(2 * time.Second)
188193

189194
// Get flasher depending on which module to use
190195
var f flasher.Flasher
191196
switch moduleName {
192197
case "NINA":
193-
f, err = flasher.NewNinaFlasher(address)
198+
f, err = flasher.NewNinaFlasher(uploadPort)
194199
case "SARA":
195-
f, err = flasher.NewSaraFlasher(address)
200+
f, err = flasher.NewSaraFlasher(uploadPort)
196201
case "WINC1500":
197-
f, err = flasher.NewWincFlasher(address)
202+
f, err = flasher.NewWincFlasher(uploadPort)
198203
default:
199204
err = fmt.Errorf("unknown module: %s", moduleName)
200205
}

0 commit comments

Comments
 (0)