@@ -172,7 +172,7 @@ def phase_setup(ser):
172
172
if (packet ['timeout' ] or packet ['crc' ]):
173
173
return 1
174
174
175
- verboseprint ('\t Got SVL Bootloader Version: ' +
175
+ twopartprint ('\t ' , 'Got SVL Bootloader Version: ' +
176
176
str (int .from_bytes (packet ['data' ], 'big' )))
177
177
verboseprint ('\t Sending \' enter bootloader\' command' )
178
178
@@ -194,6 +194,9 @@ def phase_bootload(ser):
194
194
195
195
frame_size = 512 * 4
196
196
197
+ resend_max = 64
198
+ resend_count = 0
199
+
197
200
verboseprint ('\n phase:\t bootload' )
198
201
199
202
with open (args .binfile , mode = 'rb' ) as binfile :
@@ -206,23 +209,31 @@ def phase_bootload(ser):
206
209
verboseprint ('\t have ' + str (total_len ) + ' bytes to send in ' + str (total_frames ) + ' frames' )
207
210
208
211
bl_done = False
209
- while (not bl_done ):
212
+ bl_failed = False
213
+ while ((not bl_done ) and (not bl_failed )):
210
214
211
215
packet = wait_for_packet (ser ) # wait for indication by Artemis
212
216
if (packet ['timeout' ] or packet ['crc' ]):
213
217
print ('\n \t error receiving packet' )
214
218
print (packet )
215
219
print ('\n ' )
216
- return 1
220
+ bl_failed = True
221
+ bl_done = True
217
222
218
223
if ( packet ['cmd' ] == SVL_CMD_NEXT ):
219
224
# verboseprint('\tgot frame request')
220
225
curr_frame += 1
226
+ resend_count = 0
221
227
elif ( packet ['cmd' ] == SVL_CMD_RETRY ):
222
228
verboseprint ('\t \t retrying...' )
229
+ resend_count += 1
230
+ if ( resend_count >= resend_max ):
231
+ bl_failed = True
232
+ bl_done = True
223
233
else :
224
234
print ('unknown error' )
225
- return 1
235
+ bl_failed = True
236
+ bl_done = True
226
237
227
238
if ( curr_frame <= total_frames ):
228
239
frame_data = application [((curr_frame - 1 )* frame_size ):((curr_frame - 1 + 1 )* frame_size )]
@@ -234,8 +245,12 @@ def phase_bootload(ser):
234
245
send_packet (ser , SVL_CMD_DONE , b'' )
235
246
bl_done = True
236
247
237
- verboseprint ('\n \t ' )
238
- print ('Upload complete' )
248
+ if ( bl_failed == False ):
249
+ twopartprint ('\n \t ' , 'Upload complete' )
250
+ else :
251
+ twopartprint ('\n \t ' , 'Upload failed' )
252
+
253
+ return bl_failed
239
254
240
255
241
256
@@ -281,16 +296,23 @@ def phase_serial_port_help():
281
296
# ***********************************************************************************
282
297
def main ():
283
298
try :
284
- with serial . Serial ( args . port , args . baud , timeout = args . timeout ) as ser :
299
+ num_tries = 3
285
300
286
- t_su = 0.15 # startup time for Artemis bootloader (experimentally determined - 0.095 sec min delay )
301
+ print ( ' \n \n Artemis SVL Bootloader' )
287
302
288
- print ( ' \n \n Artemis SVL Bootloader' )
303
+ for _ in range ( num_tries ):
289
304
290
- time .sleep (t_su ) # Allow Artemis to come out of reset
291
- phase_setup (ser ) # Perform baud rate negotiation
305
+ with serial .Serial (args .port , args .baud , timeout = args .timeout ) as ser :
292
306
293
- phase_bootload (ser ) # Bootload
307
+ t_su = 0.15 # startup time for Artemis bootloader (experimentally determined - 0.095 sec min delay)
308
+
309
+ time .sleep (t_su ) # Allow Artemis to come out of reset
310
+ phase_setup (ser ) # Perform baud rate negotiation
311
+
312
+ bl_failed = phase_bootload (ser ) # Bootload
313
+
314
+ if ( bl_failed == False ):
315
+ break
294
316
295
317
except :
296
318
phase_serial_port_help ()
@@ -341,4 +363,10 @@ def verboseprint(*args):
341
363
else :
342
364
verboseprint = lambda * a : None # do-nothing function
343
365
366
+ def twopartprint (verbosestr , printstr ):
367
+ if args .verbose :
368
+ print (verbosestr , end = '' )
369
+
370
+ print (printstr )
371
+
344
372
main ()
0 commit comments