@@ -177,14 +177,16 @@ def phase_setup(ser):
177
177
178
178
packet = wait_for_packet (ser )
179
179
if (packet ['timeout' ] or packet ['crc' ]):
180
- return 1
180
+ return False # failed to enter bootloader
181
181
182
182
twopartprint ('\t ' , 'Got SVL Bootloader Version: ' +
183
183
str (int .from_bytes (packet ['data' ], 'big' )))
184
184
verboseprint ('\t Sending \' enter bootloader\' command' )
185
185
186
186
send_packet (ser , SVL_CMD_BL , b'' )
187
187
188
+ return True
189
+
188
190
# Now enter the bootload phase
189
191
190
192
@@ -218,16 +220,16 @@ def phase_bootload(ser):
218
220
' bytes to send in ' + str (total_frames ) + ' frames' )
219
221
220
222
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 )):
223
225
224
226
# wait for indication by Artemis
225
227
packet = wait_for_packet (ser )
226
228
if (packet ['timeout' ] or packet ['crc' ]):
227
229
verboseprint ('\n \t Error receiving packet' )
228
230
verboseprint (packet )
229
231
verboseprint ('\n ' )
230
- bl_failed = True
232
+ bl_succeeded = False
231
233
bl_done = True
232
234
233
235
if (packet ['cmd' ] == SVL_CMD_NEXT ):
@@ -238,11 +240,11 @@ def phase_bootload(ser):
238
240
verboseprint ('\t \t Retrying...' )
239
241
resend_count += 1
240
242
if (resend_count >= resend_max ):
241
- bl_failed = True
243
+ bl_succeeded = False
242
244
bl_done = True
243
245
else :
244
246
print ('Timeout or unknown error' )
245
- bl_failed = True
247
+ bl_succeeded = False
246
248
bl_done = True
247
249
248
250
if (curr_frame <= total_frames ):
@@ -267,15 +269,15 @@ def phase_bootload(ser):
267
269
send_packet (ser , SVL_CMD_DONE , b'' )
268
270
bl_done = True
269
271
270
- if (bl_failed == False ):
272
+ if (bl_succeeded == True ):
271
273
twopartprint ('\n \t ' , 'Upload complete' )
272
274
endTime = time .time ()
273
275
bps = total_len / (endTime - startTime )
274
276
verboseprint ('\n \t Nominal bootload bps: ' + str (round (bps , 2 )))
275
277
else :
276
278
twopartprint ('\n \t ' , 'Upload failed' )
277
279
278
- return bl_failed
280
+ return bl_succeeded
279
281
280
282
281
283
# ***********************************************************************************
@@ -324,6 +326,9 @@ def main():
324
326
print ("Bin file {} does not exits." .format (args .binfile ))
325
327
exit ()
326
328
329
+ bl_success = False
330
+ entered_bootloader = False
331
+
327
332
for _ in range (num_tries ):
328
333
329
334
with serial .Serial (args .port , args .baud , timeout = args .timeout ) as ser :
@@ -332,13 +337,25 @@ def main():
332
337
t_su = 0.15
333
338
334
339
time .sleep (t_su ) # Allow Artemis to come out of reset
335
- phase_setup (ser ) # Perform baud rate negotiation
336
340
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" )
338
351
339
- if (bl_failed == False ):
352
+ if (bl_success == True ):
340
353
break
341
354
355
+ if (entered_bootloader == False ):
356
+ print (
357
+ "Target failed to enter bootload mode. Verify the right COM port is selected." )
358
+
342
359
except serial .SerialException :
343
360
phase_serial_port_help ()
344
361
0 commit comments