@@ -378,6 +378,7 @@ def upload(args, verboseprint):
378378 connection_timeout = 5
379379
380380 print ('Connecting over serial port {}...' .format (args .port ), flush = True )
381+ print ('Baud rate:' ,args .baud )
381382
382383 #Check to see if the com port is available
383384 try :
@@ -412,13 +413,15 @@ def upload(args, verboseprint):
412413 #fails to correctly catch the BOOT signal about 1 out of ten times.
413414 #Auto-retry this number of times before we give up.
414415
416+ loadTries = 0
417+
415418 while loadTries < 3 :
416419 loadSuccess = False
417420
418421 with serial .Serial (args .port , args .baud , timeout = connection_timeout ) as ser :
419422 #DTR is driven low when serial port open. DTR has now pulled RST low.
420423
421- time .sleep (0.005 ) #3ms and 10ms work well. Not 50, and not 0.
424+ time .sleep (0.008 ) #3ms and 10ms work well. Not 50, and not 0.
422425
423426 #Setting RTS/DTR high causes the bootload pin to go high, then fall across 100ms
424427 ser .setDTR (0 ) #Set DTR high
@@ -431,15 +434,15 @@ def upload(args, verboseprint):
431434
432435 connect_device (ser , args , verboseprint )
433436
437+ loadTries = loadTries + 1
438+
434439 if (loadSuccess == True ):
435440 print ("Tries =" , loadTries )
436- print ('Upload complete! ' )
441+ print ('Upload complete' )
437442 exit ()
438443 else :
439444 print ("Fail" )
440445
441- loadTries = loadTries + 1
442-
443446 print ("Tries =" , loadTries )
444447 print ("Upload failed" )
445448 exit ()
@@ -462,10 +465,10 @@ def connect_device(ser, args, verboseprint):
462465 hello = bytearray ([0x00 ]* 4 )
463466 fill_word (hello , 0 , ((8 << 16 ) | AM_SECBOOT_WIRED_MSGTYPE_HELLO ))
464467 verboseprint ('Sending Hello.' )
465- response = send_command (hello , 88 , ser , verboseprint )
468+ response , success = send_command (hello , 88 , ser , verboseprint )
466469
467470 #Check if response failed
468- if response == False :
471+ if success == False :
469472 verboseprint ("Failed to respond" )
470473 return
471474
@@ -492,7 +495,8 @@ def connect_device(ser, args, verboseprint):
492495 abortMsg = bytearray ([0x00 ]* 8 );
493496 fill_word (abortMsg , 0 , ((12 << 16 ) | AM_SECBOOT_WIRED_MSGTYPE_ABORT ))
494497 fill_word (abortMsg , 4 , abort )
495- if send_ackd_command (abortMsg , ser , verboseprint ) == False :
498+ response , success = send_ackd_command (abortMsg , ser , verboseprint )
499+ if success == False :
496500 verboseprint ("Failed to ack command" )
497501 return
498502
@@ -504,7 +508,8 @@ def connect_device(ser, args, verboseprint):
504508 otaDesc = bytearray ([0x00 ]* 8 );
505509 fill_word (otaDesc , 0 , ((12 << 16 ) | AM_SECBOOT_WIRED_MSGTYPE_OTADESC ))
506510 fill_word (otaDesc , 4 , otadescaddr )
507- if send_ackd_command (otaDesc , ser , verboseprint ) == False :
511+ response , success = send_ackd_command (otaDesc , ser , verboseprint )
512+ if success == False :
508513 verboseprint ("Failed to ack command" )
509514 return
510515
@@ -545,8 +550,8 @@ def connect_device(ser, args, verboseprint):
545550 fill_word (update , 8 , crc )
546551 # Size = 0 => We're not piggybacking any data to IMAGE command
547552 fill_word (update , 12 , 0 )
548-
549- if send_ackd_command ( update , ser , verboseprint ) == False :
553+ response , success = send_ackd_command ( update , ser , verboseprint )
554+ if success == False :
550555 verboseprint ("Failed to ack command" )
551556 return
552557
@@ -574,7 +579,8 @@ def connect_device(ser, args, verboseprint):
574579 fill_word (dataMsg , 4 , x )
575580
576581 verboseprint ("Sending Data Packet of length " , chunklen )
577- if send_ackd_command (dataMsg + chunk , ser , verboseprint ) == False :
582+ response , success = send_ackd_command (dataMsg + chunk , ser , verboseprint )
583+ if success == False :
578584 verboseprint ("Failed to ack command" )
579585 return
580586
@@ -594,7 +600,9 @@ def connect_device(ser, args, verboseprint):
594600 fill_word (resetmsg , 0 , ((12 << 16 ) | AM_SECBOOT_WIRED_MSGTYPE_RESET ))
595601 # options
596602 fill_word (resetmsg , 4 , args .reset )
597- if send_ackd_command (resetmsg , ser , verboseprint ) == False :
603+
604+ response , success = send_ackd_command (resetmsg , ser , verboseprint )
605+ if success == False :
598606 verboseprint ("Failed to ack command" )
599607 return
600608
@@ -621,10 +629,10 @@ def connect_device(ser, args, verboseprint):
621629#******************************************************************************
622630def send_ackd_command (command , ser , verboseprint ):
623631
624- response = send_command (command , 20 , ser , verboseprint )
632+ response , success = send_command (command , 20 , ser , verboseprint )
625633
626634 #Check if response failed
627- if response == False :
635+ if success == False :
628636 verboseprint ("Response not valid" )
629637 return False #Return error
630638
@@ -639,9 +647,9 @@ def send_ackd_command(command, ser, verboseprint):
639647 #print("!!!Wired Upgrade Unsuccessful!!!....Terminating the script")
640648 verboseprint ("Upload failed: No ack to command" )
641649
642- return False #Return error
650+ return ( b'' , False ) #Return error
643651
644- return response
652+ return ( response , True )
645653
646654#******************************************************************************
647655#
@@ -672,9 +680,9 @@ def send_command(params, response_len, ser, verboseprint):
672680 if (n != 0 ):
673681 verboseprint ("received bytes " , len (response ))
674682 verboseprint ([hex (n ) for n in response ])
675- return False
683+ return ( b'' , False )
676684
677- return response
685+ return ( response , True )
678686
679687#******************************************************************************
680688#
0 commit comments