Skip to content

Commit

Permalink
update DFU script to support DFU fw 1.1.x
Browse files Browse the repository at this point in the history
  • Loading branch information
yconst committed Feb 4, 2024
1 parent 542c0f1 commit 0f74d15
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions studio/Python/tinymovr/dfu.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import sys
import os
import time
import inspect
from pathlib import Path
import can
import yaml
Expand Down Expand Up @@ -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:
Expand All @@ -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)

Expand Down

0 comments on commit 0f74d15

Please sign in to comment.