@@ -151,19 +151,8 @@ func run(cmd *cobra.Command, args []string) {
151
151
152
152
loaderSketch := strings .ReplaceAll (loaderSketchPath .String (), loaderSketchPath .Ext (), "" )
153
153
154
- uploaderCommand := board .GetUploaderCommand ()
155
- uploaderCommand = strings .ReplaceAll (uploaderCommand , "{tool_dir}" , filepath .FromSlash (uploadToolDir .String ()))
156
- uploaderCommand = strings .ReplaceAll (uploaderCommand , "{serial.port.file}" , address )
157
- uploaderCommand = strings .ReplaceAll (uploaderCommand , "{loader.sketch}" , loaderSketch )
158
-
159
- commandLine , err := properties .SplitQuotedString (uploaderCommand , "\" " , false )
160
- if err != nil {
161
- feedback .Errorf (`Error splitting command line "%s": %s` , uploaderCommand , err )
162
- os .Exit (errorcodes .ErrGeneric )
163
- }
164
-
165
154
for retry := 1 ; retry <= int (retries ); retry ++ {
166
- err = updateFirmware (board , commandLine , moduleName , firmwareFile )
155
+ err = updateFirmware (board , loaderSketch , moduleName , uploadToolDir , firmwareFile )
167
156
if err == nil {
168
157
logrus .Info ("Operation completed: success! :-)" )
169
158
break
@@ -178,10 +167,10 @@ func run(cmd *cobra.Command, args []string) {
178
167
}
179
168
}
180
169
181
- func updateFirmware (board * firmwareindex.IndexBoard , commandLine [] string , moduleName string , firmwareFile * paths.Path ) error {
170
+ func updateFirmware (board * firmwareindex.IndexBoard , loaderSketch , moduleName string , uploadToolDir , firmwareFile * paths.Path ) error {
182
171
var err error
183
172
// Check if board needs a 1200bps touch for upload
184
- uploadPort := address
173
+ bootloaderPort := address
185
174
if board .UploadTouch {
186
175
logrus .Info ("Putting board into bootloader mode" )
187
176
newUploadPort , err := serialutils .Reset (address , board .UploadWait , nil )
@@ -190,10 +179,21 @@ func updateFirmware(board *firmwareindex.IndexBoard, commandLine []string, modul
190
179
}
191
180
if newUploadPort != "" {
192
181
logrus .Infof ("Found port to upload Loader: %s" , newUploadPort )
193
- uploadPort = newUploadPort
182
+ bootloaderPort = newUploadPort
194
183
}
195
184
}
196
185
186
+ uploaderCommand := board .GetUploaderCommand ()
187
+ uploaderCommand = strings .ReplaceAll (uploaderCommand , "{tool_dir}" , filepath .FromSlash (uploadToolDir .String ()))
188
+ uploaderCommand = strings .ReplaceAll (uploaderCommand , "{serial.port.file}" , bootloaderPort )
189
+ uploaderCommand = strings .ReplaceAll (uploaderCommand , "{loader.sketch}" , loaderSketch )
190
+
191
+ commandLine , err := properties .SplitQuotedString (uploaderCommand , "\" " , false )
192
+ if err != nil {
193
+ feedback .Errorf (`Error splitting command line "%s": %s` , uploaderCommand , err )
194
+ os .Exit (errorcodes .ErrGeneric )
195
+ }
196
+
197
197
// Flash loader Sketch
198
198
programmerOut := new (bytes.Buffer )
199
199
programmerErr := new (bytes.Buffer )
@@ -208,15 +208,16 @@ func updateFirmware(board *firmwareindex.IndexBoard, commandLine []string, modul
208
208
209
209
// Wait a bit after flashing the loader sketch for the board to become
210
210
// available again.
211
- time .Sleep (2 * time .Second )
211
+ time .Sleep (3 * time .Second )
212
212
213
213
// Get flasher depending on which module to use
214
214
var f flasher.Flasher
215
215
switch moduleName {
216
216
case "NINA" :
217
- f , err = flasher .NewNinaFlasher (uploadPort )
217
+ // we use address and not bootloaderPort because the board should not be in bootloader mode
218
+ f , err = flasher .NewNinaFlasher (address )
218
219
case "WINC1500" :
219
- f , err = flasher .NewWincFlasher (uploadPort )
220
+ f , err = flasher .NewWincFlasher (address )
220
221
default :
221
222
err = fmt .Errorf ("unknown module: %s" , moduleName )
222
223
feedback .Errorf ("Error during firmware flashing: %s" , err )
0 commit comments