-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreprogram
More file actions
executable file
·45 lines (36 loc) · 1.05 KB
/
reprogram
File metadata and controls
executable file
·45 lines (36 loc) · 1.05 KB
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
#!/usr/bin/python3
import serial
import binascii
# import sys
import argparse
parser = argparse.ArgumentParser()
parser.add_argument('hexfile', nargs='?', help='hex file to program board')
parser.add_argument('-p', '--port', type=str, default='/dev/ttyUSB1', help='serial port')
args = parser.parse_args()
# port = '/dev/ttyUSB1'
baudrate = 115200
ser = serial.Serial(args.port, baudrate)
ser.bytesize = serial.EIGHTBITS
ser.timeout = 2;
# raw_input("Make sure that the PROG switch is set before programming!")
input("Make sure that the PROG switch is set before programming!")
print(args.hexfile)
f = open(args.hexfile, 'r')
ins = f.readlines()
deadbeef = 'deadbeef'
baddab99 = 'baddab99'
for i in range(len(deadbeef)-1, -1, -2):
tx = deadbeef[i-1:i+1]
tx = binascii.unhexlify(tx)
ser.write(bytes(tx));
for l in ins:
l = l[:-1]
print(l)
for i in range(len(l)-1, -1, -2):
tx = l[i-1:i+1]
tx = binascii.unhexlify(tx)
ser.write(bytes(tx));
for i in range(len(baddab99)-1, -1, -2):
tx = baddab99[i-1:i+1]
tx = binascii.unhexlify(tx)
ser.write(bytes(tx));