Skip to content

Commit

Permalink
Clean output flashing script
Browse files Browse the repository at this point in the history
  • Loading branch information
rafal-gorecki committed May 23, 2024
1 parent 0548f01 commit ac7aabc
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions flash-firmware.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ def __init__(self, binary_file):
self.binary_file = binary_file
sys_arch = str(sh.uname("-m")).strip()

self.max_approach_no = 3

print(f"System architecture: {sys_arch}")

if sys_arch == "armv7l":
Expand Down Expand Up @@ -71,20 +73,24 @@ def exit_bootloader_mode(self):

def try_flash_operation(self, operation_name, flash_args):
self.enter_bootloader_mode()

try:
if operation_name == "Flashing":
sh.stm32flash(self.port, *flash_args, _out=sys.stdout)
time.sleep(0.2)
print("Success! The robot firmware has been uploaded.")
else:
sh.stm32flash(self.port, *flash_args)
time.sleep(0.2)
except Exception as e:
stderr = e.stderr.decode('utf-8')
if stderr:
print(f"ERROR {operation_name} went wrong: {stderr}")


print(f"{operation_name} operation started.")
for i in range(self.max_approach_no):
try:
if operation_name == "Flashing":
sh.stm32flash(self.port, *flash_args, _out=sys.stdout)
print("Success! The robot firmware has been uploaded.")
else:
sh.stm32flash(self.port, *flash_args)
break
except Exception as e:
stderr = e.stderr.decode('utf-8')
if stderr:
print(f"[ERROR] [{operation_name}]: \n\t{stderr}.")
else:
break
time.sleep(0.2) # Delay between attempts

self.exit_bootloader_mode()


Expand Down

0 comments on commit ac7aabc

Please sign in to comment.