@@ -121,19 +121,8 @@ func run(cmd *cobra.Command, args []string) {
121121
122122 loaderSketch := strings .ReplaceAll (loaderSketchPath .String (), loaderSketchPath .Ext (), "" )
123123
124- uploaderCommand := board .GetUploaderCommand ()
125- uploaderCommand = strings .ReplaceAll (uploaderCommand , "{tool_dir}" , filepath .FromSlash (uploadToolDir .String ()))
126- uploaderCommand = strings .ReplaceAll (uploaderCommand , "{serial.port.file}" , address )
127- uploaderCommand = strings .ReplaceAll (uploaderCommand , "{loader.sketch}" , loaderSketch )
128-
129- commandLine , err := properties .SplitQuotedString (uploaderCommand , "\" " , false )
130- if err != nil {
131- feedback .Errorf (`Error splitting command line "%s": %s` , uploaderCommand , err )
132- os .Exit (errorcodes .ErrGeneric )
133- }
134-
135124 // Check if board needs a 1200bps touch for upload
136- uploadPort := address
125+ bootloaderPort := address
137126 if board .UploadTouch {
138127 logrus .Info ("Putting board into bootloader mode" )
139128 newUploadPort , err := serialutils .Reset (address , board .UploadWait , nil )
@@ -143,10 +132,21 @@ func run(cmd *cobra.Command, args []string) {
143132 }
144133 if newUploadPort != "" {
145134 logrus .Infof ("Found port to upload Loader: %s" , newUploadPort )
146- uploadPort = newUploadPort
135+ bootloaderPort = newUploadPort
147136 }
148137 }
149138
139+ uploaderCommand := board .GetUploaderCommand ()
140+ uploaderCommand = strings .ReplaceAll (uploaderCommand , "{tool_dir}" , filepath .FromSlash (uploadToolDir .String ()))
141+ uploaderCommand = strings .ReplaceAll (uploaderCommand , "{serial.port.file}" , bootloaderPort )
142+ uploaderCommand = strings .ReplaceAll (uploaderCommand , "{loader.sketch}" , loaderSketch )
143+
144+ commandLine , err := properties .SplitQuotedString (uploaderCommand , "\" " , false )
145+ if err != nil {
146+ feedback .Errorf (`Error splitting command line "%s": %s` , uploaderCommand , err )
147+ os .Exit (errorcodes .ErrGeneric )
148+ }
149+
150150 // Flash loader Sketch
151151 programmerOut := new (bytes.Buffer )
152152 programmerErr := new (bytes.Buffer )
@@ -162,16 +162,17 @@ func run(cmd *cobra.Command, args []string) {
162162
163163 // Wait a bit after flashing the loader sketch for the board to become
164164 // available again.
165- time .Sleep (2 * time .Second )
165+ time .Sleep (3 * time .Second )
166166
167167 // Get flasher depending on which module to use
168168 var f flasher.Flasher
169169 moduleName := board .Module
170170 switch moduleName {
171171 case "NINA" :
172- f , err = flasher .NewNinaFlasher (uploadPort )
172+ // we use address and not bootloaderPort because the board should not be in bootloader mode
173+ f , err = flasher .NewNinaFlasher (address )
173174 case "WINC1500" :
174- f , err = flasher .NewWincFlasher (uploadPort )
175+ f , err = flasher .NewWincFlasher (address )
175176 default :
176177 err = fmt .Errorf ("unknown module: %s" , moduleName )
177178 }
0 commit comments