-
Notifications
You must be signed in to change notification settings - Fork 6
/
ctspi.py
70 lines (58 loc) · 1.77 KB
/
ctspi.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
#!/usr/bin/env python
# encoding: utf-8
"""
Adapted from i2c-dump.py
"""
import sys
from pyBusPirateLite.SPI import *
import argparse
def read_list_data(size):
data = []
for i in range(size+1):
data.append(0)
return data
if __name__ == '__main__':
parser = argparse.ArgumentParser(sys.argv[0])
parser.add_argument("-o", "--output", dest="outfile", metavar="OUTFILE", type=argparse.FileType('wb'),
required=True)
parser.add_argument("-p", "--serial-port", dest="bp", default="/dev/ttyUSB0")
parser.add_argument("-s", "--size", dest="size", type=int, required=True)
parser.add_argument("-S", "--serial-speed", dest="speed", default=115200, type=int)
args = parser.parse_args(sys.argv[1:])
spi = SPI(args.bp, args.speed)
print "Entering binmode: ",
if spi.BBmode():
print "OK."
else:
print "failed."
sys.exit()
print "Entering raw SPI mode: ",
if spi.enter_SPI():
print "OK."
else:
print "failed."
sys.exit()
print "Configuring SPI."
if not spi.cfg_pins(PinCfg.POWER | PinCfg.CS | PinCfg.AUX):
print "Failed to set SPI peripherals."
sys.exit()
print "Configuring SPI configuration: ",
if spi.cfg_spi(SPICfg.CLK_EDGE | SPICfg.SAMPLE | SPICfg.OUT_TYPE):
print "OK."
else:
print "failed."
sys.exit()
spi.timeout(0.2)
print "Dumping %d bytes out of the EEPROM." % args.size
spi.CS_Low()
spi.bulk_trans(3, [0x3, 0, 0])
for i in range(args.size/16):
data = spi.bulk_trans(16, read_list_data(16))
args.outfile.write(data)
spi.CS_High()
print "Reset Bus Pirate to user terminal: "
if spi.resetBP():
print "OK."
else:
print "failed."
sys.exit()