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,18 +214,27 @@ 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(
|
||||||
|
"=" * (20*position//length),
|
||||||
|
" " * (20-20*position//length),
|
||||||
100*position//length))
|
100*position//length))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
# Send frame if max outstanding not reached.
|
||||||
|
if outstanding <= sfl_outstanding:
|
||||||
|
# Prepare frame.
|
||||||
frame = SFLFrame()
|
frame = SFLFrame()
|
||||||
frame_data = f.read(min(remaining, sfl_payload_length-4))
|
frame_data = f.read(min(remaining, sfl_payload_length-4))
|
||||||
if self.flash:
|
if self.flash:
|
||||||
|
@ -233,21 +243,33 @@ class LiteXTerm:
|
||||||
frame.cmd = sfl_cmd_load
|
frame.cmd = sfl_cmd_load
|
||||||
frame.payload = current_address.to_bytes(4, "big")
|
frame.payload = current_address.to_bytes(4, "big")
|
||||||
frame.payload += frame_data
|
frame.payload += frame_data
|
||||||
|
|
||||||
|
# Encode frame and send it.
|
||||||
self.port.write(frame.encode())
|
self.port.write(frame.encode())
|
||||||
outstanding += 1
|
|
||||||
if self.port.in_waiting:
|
# Update parameters
|
||||||
self.receive_upload_response()
|
|
||||||
outstanding -= 1
|
|
||||||
current_address += len(frame_data)
|
current_address += len(frame_data)
|
||||||
position += len(frame_data)
|
position += len(frame_data)
|
||||||
remaining -= len(frame_data)
|
remaining -= len(frame_data)
|
||||||
time.sleep(1e-5) # Inter-frame delay for fast UARTs (ex: FT245).
|
outstanding += 1
|
||||||
|
|
||||||
|
# Inter-frame delay for fast UARTs (ex: FT245).
|
||||||
|
time.sleep(1e-4)
|
||||||
|
|
||||||
|
# Read response if availables.
|
||||||
|
if self.port.in_waiting:
|
||||||
|
self.receive_upload_response()
|
||||||
|
outstanding -= 1
|
||||||
|
|
||||||
|
# Get remaining responses.
|
||||||
for _ in range(outstanding):
|
for _ in range(outstanding):
|
||||||
self.receive_upload_response()
|
self.receive_upload_response()
|
||||||
|
|
||||||
|
# Compute speed.
|
||||||
end = time.time()
|
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