@@ -177,14 +177,16 @@ def phase_setup(ser):
177177
178178 packet = wait_for_packet (ser )
179179 if (packet ['timeout' ] or packet ['crc' ]):
180- return 1
180+ return False # failed to enter bootloader
181181
182182 twopartprint ('\t ' , 'Got SVL Bootloader Version: ' +
183183 str (int .from_bytes (packet ['data' ], 'big' )))
184184 verboseprint ('\t Sending \' enter bootloader\' command' )
185185
186186 send_packet (ser , SVL_CMD_BL , b'' )
187187
188+ return True
189+
188190 # Now enter the bootload phase
189191
190192
@@ -218,16 +220,16 @@ def phase_bootload(ser):
218220 ' bytes to send in ' + str (total_frames ) + ' frames' )
219221
220222 bl_done = False
221- bl_failed = False
222- while ((not bl_done ) and (not bl_failed )):
223+ bl_succeeded = True
224+ while ((bl_done == False ) and (bl_succeeded == True )):
223225
224226 # wait for indication by Artemis
225227 packet = wait_for_packet (ser )
226228 if (packet ['timeout' ] or packet ['crc' ]):
227229 verboseprint ('\n \t Error receiving packet' )
228230 verboseprint (packet )
229231 verboseprint ('\n ' )
230- bl_failed = True
232+ bl_succeeded = False
231233 bl_done = True
232234
233235 if (packet ['cmd' ] == SVL_CMD_NEXT ):
@@ -238,11 +240,11 @@ def phase_bootload(ser):
238240 verboseprint ('\t \t Retrying...' )
239241 resend_count += 1
240242 if (resend_count >= resend_max ):
241- bl_failed = True
243+ bl_succeeded = False
242244 bl_done = True
243245 else :
244246 print ('Timeout or unknown error' )
245- bl_failed = True
247+ bl_succeeded = False
246248 bl_done = True
247249
248250 if (curr_frame <= total_frames ):
@@ -267,15 +269,15 @@ def phase_bootload(ser):
267269 send_packet (ser , SVL_CMD_DONE , b'' )
268270 bl_done = True
269271
270- if (bl_failed == False ):
272+ if (bl_succeeded == True ):
271273 twopartprint ('\n \t ' , 'Upload complete' )
272274 endTime = time .time ()
273275 bps = total_len / (endTime - startTime )
274276 verboseprint ('\n \t Nominal bootload bps: ' + str (round (bps , 2 )))
275277 else :
276278 twopartprint ('\n \t ' , 'Upload failed' )
277279
278- return bl_failed
280+ return bl_succeeded
279281
280282
281283# ***********************************************************************************
@@ -324,6 +326,9 @@ def main():
324326 print ("Bin file {} does not exits." .format (args .binfile ))
325327 exit ()
326328
329+ bl_success = False
330+ entered_bootloader = False
331+
327332 for _ in range (num_tries ):
328333
329334 with serial .Serial (args .port , args .baud , timeout = args .timeout ) as ser :
@@ -332,13 +337,25 @@ def main():
332337 t_su = 0.15
333338
334339 time .sleep (t_su ) # Allow Artemis to come out of reset
335- phase_setup (ser ) # Perform baud rate negotiation
336340
337- bl_failed = phase_bootload (ser ) # Bootload
341+ # Perform baud rate negotiation
342+ entered_bootloader = phase_setup (ser )
343+
344+ if (entered_bootloader == True ):
345+ bl_success = phase_bootload (ser )
346+ if (bl_success == True ): # Bootload
347+ #print("Bootload complete!")
348+ break
349+ else :
350+ verboseprint ("Failed to enter bootload phase" )
338351
339- if (bl_failed == False ):
352+ if (bl_success == True ):
340353 break
341354
355+ if (entered_bootloader == False ):
356+ print (
357+ "Target failed to enter bootload mode. Verify the right COM port is selected." )
358+
342359 except serial .SerialException :
343360 phase_serial_port_help ()
344361
0 commit comments