-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrissy.py
More file actions
executable file
·62 lines (48 loc) · 1.52 KB
/
crissy.py
File metadata and controls
executable file
·62 lines (48 loc) · 1.52 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/usr/bin/env python
"""
Crissy Programmer, An AT89S52 command-line programmer.
Usage:
crissy.py [options] <hex_file>
crissy.py -h | --help
crissy.py --version
Options:
-h, --help Show this help message.
--version Show programmer version.
-p <port>, --port <port> The serial port of the programmer hardware [default: /dev/ttyACM0].
-b <baudrate> The baudrate [default: 9600].
"""
from intelhex import IntelHex
from docopt import docopt
import mcu
import time
SERIAL_PORT = "--port"
HEX_FILE = "<hex_file>"
BAUDRATE = "-b"
if __name__ == "__main__":
arguments = docopt(__doc__, version="0.0.1")
print(arguments)
hexfile = IntelHex(arguments[HEX_FILE]).todict()
port_name = arguments[SERIAL_PORT]
baudrate = arguments[BAUDRATE]
print("Porta serial: %s, baudrate: %s", port_name, baudrate)
mcu.open(port_name, int(baudrate))
print("Habilitar programacao...")
mcu.prog_enable()
ack = mcu.ser.readline()
print("--> %s" % ack)
print("Apagar o chip...")
mcu.erase_chip()
ack = mcu.ser.readline()
time.sleep(0.5)
print("--> %s" % ack)
print("Lendo o arquivo .hex, e carregando no micro.");
for addr, code in hexfile.items():
print("%x : %x" %(addr, code))
mcu.write_progmem(addr, code)
ack = mcu.ser.readline()
print("--> %s" % ack)
print("Finalizar a gravacao...")
mcu.finalize()
ack = mcu.ser.readline()
print("--> %s" % ack)
mcu.close()