From 0f74d1543b9f5588ab56da571b8686b4d045be01 Mon Sep 17 00:00:00 2001 From: Yannis Chatzikonstantinou Date: Sun, 4 Feb 2024 16:59:30 +0200 Subject: [PATCH] update DFU script to support DFU fw 1.1.x --- studio/Python/tinymovr/dfu.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/studio/Python/tinymovr/dfu.py b/studio/Python/tinymovr/dfu.py index 4b1c8d3e..1b33542e 100644 --- a/studio/Python/tinymovr/dfu.py +++ b/studio/Python/tinymovr/dfu.py @@ -15,6 +15,7 @@ import sys import os import time +import inspect from pathlib import Path import can import yaml @@ -88,12 +89,22 @@ def upload_bin(device, bin_path): """ total_size = os.path.getsize(bin_path) # Get the total size of .bin file uploaded_size = 0 + print("\nErasing flash...") - result = device.erase_all() + + # Check if the erase_all function supports hash_validation parameter + if 'hash_validation' in inspect.signature(device.erase_all).parameters: + # Call erase_all with hash_validation, using the device's specified hash + result = device.erase_all(device.hash_uint32) + else: + # If not, call erase_all without hash_validation + result = device.erase_all() + if result != 0: print("\nError while erasing!") return print("Done.") + with Progress() as progress: task2 = progress.add_task("[orange]Flashing...", total=total_size) with open(bin_path, "rb") as bin_file: @@ -110,7 +121,13 @@ def upload_bin(device, bin_path): time.sleep(1e-5) # Commit the data in scratchpad to flash memory and get checksum - device_checksum = device.commit(flash_addr) + # Check if the commit function supports hash_validation parameter + if 'hash_validation' in inspect.signature(device.commit).parameters: + # Call commit with hash_validation, using the device's specified hash + device_checksum = device.commit(flash_addr, device.hash_uint32) + else: + # If not, call commit without hash_validation + device_checksum = device.commit(flash_addr) local_checksum = calculate_local_checksum(chunk)