mbv: now with functioning timer interrupts!
And a few other nice things. The bootloader now has an embedded wozmon! If you know its offset, you can jump to it from the app.
This commit is contained in:
44
mbv/prog.py
44
mbv/prog.py
@@ -1,6 +1,8 @@
|
||||
import argparse
|
||||
import serial
|
||||
import struct
|
||||
import sys
|
||||
import threading
|
||||
import time
|
||||
|
||||
offset = 0x80000000
|
||||
@@ -29,28 +31,46 @@ def write(s, offset, dat):
|
||||
|
||||
def jump(s, offset):
|
||||
cmd = struct.pack('<cI', b'j', offset)
|
||||
print(f'Jumping to 0x{offset:04x}')
|
||||
s.write(cmd)
|
||||
|
||||
|
||||
def stream_logs(s):
|
||||
while True:
|
||||
dat = s.read()
|
||||
if not dat:
|
||||
continue
|
||||
sys.stdout.buffer.write(dat.replace(b'\r', b''))
|
||||
sys.stdout.buffer.flush()
|
||||
|
||||
|
||||
def parse_args():
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("binary")
|
||||
parser.add_argument("--monitor", action="store_true",
|
||||
help="wait for and display program serial output")
|
||||
return parser.parse_args()
|
||||
|
||||
def main():
|
||||
binfile = sys.argv[1]
|
||||
with open(binfile, 'rb') as f:
|
||||
args = parse_args()
|
||||
|
||||
with open(args.binary, 'rb') as f:
|
||||
dat = f.read()
|
||||
|
||||
s = serial.Serial(tty, baud, timeout=1)
|
||||
write(s, offset, dat)
|
||||
jump(s, offset)
|
||||
last_dat = time.time()
|
||||
|
||||
while True:
|
||||
dat = s.read()
|
||||
if not dat:
|
||||
if time.time() - last_dat > 1.0:
|
||||
print('Data timeout')
|
||||
break
|
||||
continue
|
||||
last_dat = time.time()
|
||||
sys.stdout.buffer.write(dat)
|
||||
if args.monitor:
|
||||
t = threading.Thread(target=lambda: stream_logs(s), daemon=True)
|
||||
t.start()
|
||||
|
||||
try:
|
||||
while True:
|
||||
dat = input("") + '\r'
|
||||
s.write(dat.encode())
|
||||
except KeyboardInterrupt:
|
||||
print("Bye.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user