forked from mtirado1/at89s8252-arduino
-
Notifications
You must be signed in to change notification settings - Fork 0
/
verifyprogram3.py
81 lines (72 loc) · 2.39 KB
/
verifyprogram3.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
import serial
import time
from intelhex import IntelHex
from config import *
# Path to hex file
f = code_targetFile
print('Reading file: ' + f)
# Serial port name
p = serialPort
print('Programmer port = ' + p)
# Read hex file
ih = IntelHex()
ih.fromfile(f, format='hex')
if ih.addresses()[len(ih.addresses()) - 1] >= at89s8253_max_program:
print('The file is too large ' + hex(ih.addresses()[len(ih.addresses()) - 1]) + '!')
print('Max space is ' + hex(at89s8253_max_program) + ' bytes, extra data will be ignored!')
a = input( 'Continue? y/n: ')
if a != 'Y' and a != 'y':
quit()
with serial.Serial(p, 9600) as ser:
time.sleep(2)
print(ser.readline().decode('utf-8'))
ser.write(b'\x60') # Enable programming
ih.dump()
# print('Programming...')
print(ser.readline().decode('utf-8'))
# conta = 0
# for i in range(0, len(ih.addresses())):
# addr = ih.addresses()[i]
# if conta == 256:
# conta = 0
# print(hex(addr))
# conta += 1
# ser.write(b'\x51')
# ser.write(bytes([addr//256])) # high address byte
# ser.write(bytes([addr%256])) # low address byte
# ser.write(bytes([ih[addr]])) # data byte
# #time.sleep(0.05)
# ser.readline()
# a = input('Programming done. Do you wish to verify? y/n: ')
conta = 0
#if a == 'Y' or a == 'y':
print('Verifying...')
err = False
for i in range(0, len(ih.addresses())):
addr = ih.addresses()[i]
if addr < at89s8253_max_program:
if conta == 0:
print()
print(hex(i) + ' ', end='')
if conta == 63:
conta = -1
conta += 1
ser.write(b'\x62')
ser.write(bytes([addr//256])) # high address byte
ser.write(bytes([addr%256])) # low address byte
k = int(ser.readline().decode('utf-8'), 16)
if k != ih[addr]:
#print('Error at address' + hex(addr))
#print('Got %d, was %d' % (k, ih[addr]))
print('E', end = '')
err = True
else:
print('.', end = '')
print()
if not err:
print('Program verification complete.')
else:
print('Error during program verification')
ser.write(b'\x40') # End programming
print(ser.readline().decode('utf-8'))
print('Done.')