-
Notifications
You must be signed in to change notification settings - Fork 0
/
prog2.py
45 lines (37 loc) · 820 Bytes
/
prog2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import sys
import serial
with open(sys.argv[2], 'rb') as f:
data = f.read()
s = serial.Serial(sys.argv[1], 921600)
def wait_for(str):
buf = b''
str = str.encode('ascii')
while True:
buf += s.read()
if str in buf:
return
s.write(b'bus acq ')
buf = b''
wait_for('acquired')
s.write(b'max init ')
with open(sys.argv[2], 'rb') as f:
data = f.read()
for i, byte in enumerate(data):
s.write(b'write addr ' + (hex(i)[2:]).encode('ascii') + b' ')
wait_for('ok')
s.write(b'write data ' + (hex(byte)[2:]).encode('ascii') + b' ')
wait_for('ok')
s.write(b'mq ')
wait_for('ok')
s.write(b'wr ')
wait_for('ok')
s.write(b'wr ')
wait_for('ok')
s.write(b'mq ')
wait_for('ok')
s.write(b'max off ')
wait_for('ok')
s.write(b'bus rel ')
wait_for('ok')
s.write(b'reset ')
wait_for('ok')