tools/litex_term: add sfl_outstanding parameter (set to 4), cleanup code and increase inter-frame delay.
This fixes upload on OrangeCrab with USB-ACM, but we still need to understand why sfl_payload_length can't be set to 255 with USB-FIFO.
This commit is contained in:
parent
5e10552f3f
commit
894802d131
|
@ -58,7 +58,8 @@ sfl_prompt_ack = b"\x06"
|
||||||
sfl_magic_req = b"sL5DdSMmkekro\n"
|
sfl_magic_req = b"sL5DdSMmkekro\n"
|
||||||
sfl_magic_ack = b"z6IHG7cYDID6o\n"
|
sfl_magic_ack = b"z6IHG7cYDID6o\n"
|
||||||
|
|
||||||
sfl_payload_length = 64 # FIXME: understand why 255 failing with USB-FIFO.
|
sfl_payload_length = 64 # FIXME: Understand why 255 failing with USB-FIFO.
|
||||||
|
sfl_outstanding = 4
|
||||||
|
|
||||||
# General commands
|
# General commands
|
||||||
sfl_cmd_abort = b"\x00"
|
sfl_cmd_abort = b"\x00"
|
||||||
|
@ -213,41 +214,62 @@ class LiteXTerm:
|
||||||
f.seek(0, 2)
|
f.seek(0, 2)
|
||||||
length = f.tell()
|
length = f.tell()
|
||||||
f.seek(0, 0)
|
f.seek(0, 0)
|
||||||
print("[LXTERM] {} {} to 0x{:08x} ({} bytes)...".format(
|
|
||||||
"Flashing" if self.flash else "Uploading", filename, address, length))
|
action = "Flashing" if self.flash else "Uploading"
|
||||||
|
print(f"[LXTERM] {action} {filename} to 0x{address:08x} ({length} bytes)...")
|
||||||
|
|
||||||
|
# Prepare parameters
|
||||||
current_address = address
|
current_address = address
|
||||||
position = 0
|
position = 0
|
||||||
start = time.time()
|
start = time.time()
|
||||||
remaining = length
|
remaining = length
|
||||||
outstanding = 0
|
outstanding = 0
|
||||||
while remaining:
|
while remaining:
|
||||||
sys.stdout.write("|{}>{}| {}%\r".format('=' * (20*position//length),
|
# Show progress
|
||||||
' ' * (20-20*position//length),
|
sys.stdout.write("|{}>{}| {}%\r".format(
|
||||||
100*position//length))
|
"=" * (20*position//length),
|
||||||
|
" " * (20-20*position//length),
|
||||||
|
100*position//length))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
frame = SFLFrame()
|
|
||||||
frame_data = f.read(min(remaining, sfl_payload_length-4))
|
# Send frame if max outstanding not reached.
|
||||||
if self.flash:
|
if outstanding <= sfl_outstanding:
|
||||||
frame.cmd = sfl_cmd_flash
|
# Prepare frame.
|
||||||
else:
|
frame = SFLFrame()
|
||||||
frame.cmd = sfl_cmd_load
|
frame_data = f.read(min(remaining, sfl_payload_length-4))
|
||||||
frame.payload = current_address.to_bytes(4, "big")
|
if self.flash:
|
||||||
frame.payload += frame_data
|
frame.cmd = sfl_cmd_flash
|
||||||
self.port.write(frame.encode())
|
else:
|
||||||
outstanding += 1
|
frame.cmd = sfl_cmd_load
|
||||||
|
frame.payload = current_address.to_bytes(4, "big")
|
||||||
|
frame.payload += frame_data
|
||||||
|
|
||||||
|
# Encode frame and send it.
|
||||||
|
self.port.write(frame.encode())
|
||||||
|
|
||||||
|
# Update parameters
|
||||||
|
current_address += len(frame_data)
|
||||||
|
position += len(frame_data)
|
||||||
|
remaining -= len(frame_data)
|
||||||
|
outstanding += 1
|
||||||
|
|
||||||
|
# Inter-frame delay for fast UARTs (ex: FT245).
|
||||||
|
time.sleep(1e-4)
|
||||||
|
|
||||||
|
# Read response if availables.
|
||||||
if self.port.in_waiting:
|
if self.port.in_waiting:
|
||||||
self.receive_upload_response()
|
self.receive_upload_response()
|
||||||
outstanding -= 1
|
outstanding -= 1
|
||||||
current_address += len(frame_data)
|
|
||||||
position += len(frame_data)
|
# Get remaining responses.
|
||||||
remaining -= len(frame_data)
|
|
||||||
time.sleep(1e-5) # Inter-frame delay for fast UARTs (ex: FT245).
|
|
||||||
for _ in range(outstanding):
|
for _ in range(outstanding):
|
||||||
self.receive_upload_response()
|
self.receive_upload_response()
|
||||||
end = time.time()
|
|
||||||
|
# Compute speed.
|
||||||
|
end = time.time()
|
||||||
elapsed = end - start
|
elapsed = end - start
|
||||||
f.close()
|
|
||||||
print("[LXTERM] Upload complete ({0:.1f}KB/s).".format(length/(elapsed*1024)))
|
print("[LXTERM] Upload complete ({0:.1f}KB/s).".format(length/(elapsed*1024)))
|
||||||
|
f.close()
|
||||||
return length
|
return length
|
||||||
|
|
||||||
def boot(self):
|
def boot(self):
|
||||||
|
|
Loading…
Reference in New Issue