mbv: black
This commit is contained in:
parent
7f1f924331
commit
e4936abb53
32
mbv/prog.py
32
mbv/prog.py
@ -6,7 +6,7 @@ import threading
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
offset = 0x80000000
|
offset = 0x80000000
|
||||||
tty = '/dev/ttyUSB1'
|
tty = "/dev/ttyUSB1"
|
||||||
baud = 115200
|
baud = 115200
|
||||||
chunksize = 1024
|
chunksize = 1024
|
||||||
|
|
||||||
@ -14,24 +14,24 @@ chunksize = 1024
|
|||||||
def write(s, offset, dat):
|
def write(s, offset, dat):
|
||||||
for i in range(0, len(dat), chunksize):
|
for i in range(0, len(dat), chunksize):
|
||||||
chunk = dat[i : i + chunksize]
|
chunk = dat[i : i + chunksize]
|
||||||
cmd = struct.pack('<cII', b'c', offset + i, len(chunk))
|
cmd = struct.pack("<cII", b"c", offset + i, len(chunk))
|
||||||
|
|
||||||
print(f'Sending {len(chunk)} bytes @0x{offset + i:04x}')
|
print(f"Sending {len(chunk)} bytes @0x{offset + i:04x}")
|
||||||
|
|
||||||
s.write(cmd)
|
s.write(cmd)
|
||||||
s.write(chunk)
|
s.write(chunk)
|
||||||
|
|
||||||
ack = s.read(2)
|
ack = s.read(2)
|
||||||
if len(ack) < 2:
|
if len(ack) < 2:
|
||||||
raise RuntimeError(f'timeout waiting for full ack. got {ack}')
|
raise RuntimeError(f"timeout waiting for full ack. got {ack}")
|
||||||
if ack[0] != b'a'[0]:
|
if ack[0] != b"a"[0]:
|
||||||
raise RuntimeError(f'expected ack, got this instead: {ack}')
|
raise RuntimeError(f"expected ack, got this instead: {ack}")
|
||||||
print(f'Ack! len={ack[1]}')
|
print(f"Ack! len={ack[1]}")
|
||||||
|
|
||||||
|
|
||||||
def jump(s, offset):
|
def jump(s, offset):
|
||||||
cmd = struct.pack('<cI', b'j', offset)
|
cmd = struct.pack("<cI", b"j", offset)
|
||||||
print(f'Jumping to 0x{offset:04x}')
|
print(f"Jumping to 0x{offset:04x}")
|
||||||
s.write(cmd)
|
s.write(cmd)
|
||||||
|
|
||||||
|
|
||||||
@ -40,21 +40,25 @@ def stream_logs(s):
|
|||||||
dat = s.read()
|
dat = s.read()
|
||||||
if not dat:
|
if not dat:
|
||||||
continue
|
continue
|
||||||
sys.stdout.buffer.write(dat.replace(b'\r', b''))
|
sys.stdout.buffer.write(dat.replace(b"\r", b""))
|
||||||
sys.stdout.buffer.flush()
|
sys.stdout.buffer.flush()
|
||||||
|
|
||||||
|
|
||||||
def parse_args():
|
def parse_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument("binary")
|
parser.add_argument("binary")
|
||||||
parser.add_argument("--monitor", action="store_true",
|
parser.add_argument(
|
||||||
help="wait for and display program serial output")
|
"--monitor",
|
||||||
|
action="store_true",
|
||||||
|
help="wait for and display program serial output",
|
||||||
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
args = parse_args()
|
args = parse_args()
|
||||||
|
|
||||||
with open(args.binary, 'rb') as f:
|
with open(args.binary, "rb") as f:
|
||||||
dat = f.read()
|
dat = f.read()
|
||||||
|
|
||||||
s = serial.Serial(tty, baud, timeout=1)
|
s = serial.Serial(tty, baud, timeout=1)
|
||||||
@ -67,7 +71,7 @@ def main():
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
dat = input("") + '\r'
|
dat = input("") + "\r"
|
||||||
s.write(dat.encode())
|
s.write(dat.encode())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("Bye.")
|
print("Bye.")
|
||||||
|
Loading…
Reference in New Issue
Block a user