From 776c347efd99a89d6457b4988a4b201fbf17dae6 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Mon, 16 Feb 2015 00:47:42 +0100 Subject: [PATCH 01/17] Delete i2ceeprom.py --- src/examples/i2ceeprom.py | 40 --------------------------------------- 1 file changed, 40 deletions(-) delete mode 100644 src/examples/i2ceeprom.py diff --git a/src/examples/i2ceeprom.py b/src/examples/i2ceeprom.py deleted file mode 100644 index 2de2acf..0000000 --- a/src/examples/i2ceeprom.py +++ /dev/null @@ -1,40 +0,0 @@ -#!/usr/bin/env python - -from mpsse import * - -SIZE = 0x8000 # Size of EEPROM chip (32 KB) -WCMD = "\xA0\x00\x00" # Write start address command -RCMD = "\xA1" # Read command -FOUT = "eeprom.bin" # Output file - -try: - eeprom = MPSSE(I2C, FOUR_HUNDRED_KHZ) - - print "%s initialized at %dHz (I2C)" % (eeprom.GetDescription(), eeprom.GetClock()) - - eeprom.Start() - eeprom.Write(WCMD) - - if eeprom.GetAck() == ACK: - - eeprom.Start() - eeprom.Write(RCMD) - - if eeprom.GetAck() == ACK: - data = eeprom.Read(SIZE) - eeprom.SendNacks() - eeprom.Read(1) - else: - raise Exception("Received read command NACK!") - else: - raise Exception("Received write command NACK!") - - eeprom.Stop() - - open(FOUT, "wb").write(data) - print "Dumped %d bytes to %s" % (len(data), FOUT) - - eeprom.Close() -except Exception, e: - print "MPSSE failure:", e - From 14cad8b3116f12ec99262057be8a9c5bbbfc32ef Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Mon, 16 Feb 2015 00:48:59 +0100 Subject: [PATCH 02/17] First Commit More sophisticated example for I2C eeprom access via python mpsse --- src/examples/i2ceeprom.py | 193 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 193 insertions(+) create mode 100644 src/examples/i2ceeprom.py diff --git a/src/examples/i2ceeprom.py b/src/examples/i2ceeprom.py new file mode 100644 index 0000000..6fad968 --- /dev/null +++ b/src/examples/i2ceeprom.py @@ -0,0 +1,193 @@ +#!/usr/bin/env python + +import argparse, struct, sys, time +from fish import ProgressFish +from mpsse import * + +parser = argparse.ArgumentParser(prog="i2c-eeprom", description="i2c-eeprom utility based on python-mpsse") +parser.add_argument("-a", "--addressbits", help="addresstype (8 / 16), default to 8bits for <=16kbit size, 16bits for eeprom > 16kbit", type=int, required=0, metavar="<8 / 16>", action="store", dest="addressbits") +parser.add_argument("-s", "--size", help="eeprom size in bytes", type=int, metavar="", action="store", dest="eeprom_size", required=1) +parser.add_argument("-p", "--pagesize", help="count of bytes per page", type=int, metavar="", action="store", dest="page_size", required=1) +parser.add_argument("-e", "--erase", help="erase eeprom (to FFh Values)", action="store_true", dest="mode_erase") +parser.add_argument("-r", "--read", help="read eeprom to ", type=str, metavar="", action="store", dest="readfilename") +parser.add_argument("-w", "--write", help="write to eeprom", type=str, metavar="", action="store", dest="writefilename") +parser.add_argument("-d", "--eeprom-id", help="3bit device-address of eeprom, hardwired, default = 0", metavar="<0-7>", type=int, default=0, action="store", dest="devaddress") +parser.add_argument("-c", "--count", help="number of bytes to read in read-mode. default = full eeprom-size", metavar="<0-524288>", type=long, action="store", dest="bytecount") +parser.add_argument("-o", "--offset", help="bytenumber to start reading at. default = 0", metavar="<0-524287>", type=long, default=0, action="store", dest="offset") +parser.add_argument("-S", "--speed", help="I2C bus frequency. default = 100000KHz", metavar="", type=str, action="store", dest="speed") +parser.add_argument("-i", "--devicecode", help="Vendor_ID:Product_ID default = 0403:6010", metavar="", type=str, default="0403:6010", action="store", dest="devid") +parser.add_argument("-I", "--interface", help="Interface to use (if FTDI-device has multiple UART-interfaces). default = A", metavar="", type=str, default="A", action="store", dest="iface") +parser.add_argument("-v", "--verbose", help="increase output verbosity", action="store_true") + +args = parser.parse_args() + +if (args.devid != "0403:6010"): + vendor_id = int(args.devid.split(':')[0], 16) + product_id = int(args.devid.split(':')[1], 16) +else: + vendor_id = int("0403", 16) + product_id = int("6010", 16) + +if (args.iface == "A"): + IFACE=IFACE_A +elif (args.iface == "B"): + IFACE=IFACE_B +elif (args.iface == "C"): + IFACE=IFACE_C +elif (args.iface == "D"): + IFACE=IFACE_D +else: + parser.print_help() + print("This script supports interfaces A to D only !") + sys.exit(1) + +if ((args.mode_erase == False) and (args.readfilename == None) and (args.writefilename == None)): + parser.print_help() + print("\nYou need to specify either erase or read/write - mode!") + sys.exit(1) + +if (((args.mode_erase == True) and (args.readfilename != None)) or ((args.mode_erase == True) and (args.writefilename != None)) or ((args.writefilename != None) and (args.readfilename != None))): + parser.print_help() + print ("\nYou can only read OR write OR erase at a time ;) !") + sys.exit(1) + +if (args.addressbits != None): + addressbits = args.addressbits +elif ((args.addressbits == None) and (args.eeprom_size <= 2048)): + addressbits = 8 +else: + addressbits = 16 + +FLASHSIZE = args.eeprom_size +PAGESIZE = args.page_size +PAGECOUNT = FLASHSIZE / PAGESIZE +MODE = None +DATA = '' + +if (args.speed != None): + if (args.speed == "ONE_HUNDRED_KHZ"): + SPEED = ONE_HUNDRED_KHZ + elif (args.speed == "FOUR_HUNDRED_KHZ"): + SPEED = FOUR_HUNDRED_KHZ + elif (args.speed == "ONE_MHZ"): + SPEED = ONE_MHZ + else: + parser.print_help() + print('Speed must be set to "ONE_HUNDRED_KHZ" or "FOUR_HUNDRED_KHZ" or "ONE_MHZ" (Default : ONE_HUNDRED_KHZ)!') + sys.exit(1) +else: + SPEED=ONE_HUNDRED_KHZ + +if (args.devaddress <= 7): + DEVADDR = args.devaddress +else: + parser.print_help() + print("\nOnly 8 chained i2c-eeprom-devices on one i2c-bus possible !") + +if (args.mode_erase == True): + HEXDATA = chr(255)*PAGESIZE + MODE = "erase" + +if (args.writefilename != None): + HEXDATA = open(args.writefilename, 'rb').read() + PAGECOUNT = len(HEXDATA) / PAGESIZE + MODE = "write" + +if (args.readfilename != None): + readfilename = args.readfilename + MODE = "read" + +if (args.bytecount != None): + bytecount = args.bytecount +else: + bytecount = FLASHSIZE + +fish= ProgressFish(total=PAGECOUNT) + +try: + if (MODE == "read"): + eeprom = MPSSE(None) + eeprom.Open(vendor_id, product_id, I2C, SPEED, MSB, IFACE) + print "FTDI I2C initialized at %dHz" % (eeprom.GetClock()) + addressbyte = args.offset + addressbyte = 0 + if (addressbits == 8): + addr = divmod(addressbyte, 256) + byteaddress = struct.pack('BB', (160 + ((addr[0] + DEVADDR) * 2)), addr[1]) + else: + addr = divmod(addressbyte, 65536) + byteaddress = struct.pack('B', (160 + ((addr[0] + DEVADDR) * 2))) + struct.pack('>H', addr[1]) + eeprom.Start() + if (args.verbose == True): + print("Writing byteaddress %s" % byteaddress.encode('hex')) + eeprom.Write(byteaddress) + if eeprom.GetAck() != ACK: + print "Error writing byteaddress !" + else: + if (args.verbose == True): + print("Eeprom acknowledged byteaddress.") + eeprom.Start() + eeprom.Write(struct.pack('B', (161 + (DEVADDR * 2)))) + if eeprom.GetAck() != ACK: + print "Error writing readcommand!" + else: + if (args.verbose == True): + print("Eeprom acknowledged readcommand, start reading %d bytes from eeprom." % bytecount) + DATA = eeprom.Read(bytecount) + eeprom.SendNacks() + eeprom.Stop() + eeprom.Close() + open(readfilename, "wb").write(DATA) + print "Dumped %d bytes to %s" % (len(DATA), readfilename) + else: + eeprom = MPSSE(None) + eeprom.Open(vendor_id, product_id, I2C, SPEED, MSB, IFACE) + print "FTDI I2C initialized at %dHz" % (eeprom.GetClock()) + for PAGENUM in range(PAGECOUNT): + BYTENUM = PAGENUM * PAGESIZE + if (addressbits == 8): + address = divmod(BYTENUM, 256) + pageaddress = struct.pack('BB', (160 + ((DEVADDR + address[0]) * 2)), address[1]) + else: + address = divmod(BYTENUM, 65536) + pageaddress = struct.pack('B', (160 + ((DEVADDR + address[0]) * 2))) + struct.pack('>H', address[1]) + eeprom.Start() + eeprom.Write(pageaddress) + if eeprom.GetAck() != ACK: + print "Error writing pageaddress for page %d" % PAGENUM + break + else: + if (MODE == "write"): + data = HEXDATA[BYTENUM:(BYTENUM+PAGESIZE)] + if (args.verbose == True): + print("Eeprom acknowledged pageaddress %s, start writing data to eeprom.\nData = \n%s" % ('\\x' + '\\x'.join(x.encode('HEX') for x in pageaddress), data.encode('hex'))) + eeprom.Write(data) + if eeprom.GetAck() != ACK: + print "Error writing page %d" % PAGENUM + break + else: + if (args.verbose == True): + print("Eeprom acknowledged pagewrite for page %d" % PAGENUM) + elif (MODE == "erase"): + if (args.verbose == True): + print("Eeprom acknowledged pageaddress %s, start erasing page %d with \\xFF * %d" % ('\\x' + '\\x'.join(x.encode('HEX') for x in pageaddress), PAGENUM, PAGESIZE)) + eeprom.Write(HEXDATA) + if eeprom.GetAck() != ACK: + print "Error erasing page %d" % PAGENUM + break + else: + if (args.verbose == True): + print("Eeprom acknowledged erase of page %d" % PAGENUM) + eeprom.Stop() + time.sleep(1/1000.0 * 5) + if (args.verbose == False): + fish.animate(amount=(PAGENUM + 1)) + if (MODE == "write"): + print("Finished writing %s to eeprom !" % args.writefilename) + elif (MODE == "erase"): + print("Erase of flash finished !") + eeprom.Close() + +except Exception, e: + print "MPSSE failure:", e +sys.exit(0) From 4c92430759acba6030aac3718179c33c8d09e490 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 19:59:12 +0100 Subject: [PATCH 03/17] Update mpsse.c Add TIAO Multi-Protocol Adapter Lite --- src/mpsse.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/mpsse.c b/src/mpsse.c index b929b81..e3d9ed1 100644 --- a/src/mpsse.c +++ b/src/mpsse.c @@ -31,7 +31,8 @@ struct vid_pid supported_devices[] = { { 0x0403, 0x8879, "Bus Blaster v2 (channel B)" }, { 0x0403, 0xBDC8, "Turtelizer JTAG/RS232 Adapter A" }, { 0x0403, 0xCFF8, "Amontec JTAGkey" }, - { 0x0403, 0x8A98, "TIAO Multi Protocol Adapter"}, + { 0x0403, 0x8A98, "TIAO Multi Protocol Adapter"}, + { 0x0403, 0x8A99, "TIAO Multi Protocol Adapter Lite" { 0x15BA, 0x0003, "Olimex Ltd. OpenOCD JTAG" }, { 0x15BA, 0x0004, "Olimex Ltd. OpenOCD JTAG TINY" }, From 8fbe0b1a658f8239b572a9e884f07c68dc7493b2 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:00:52 +0100 Subject: [PATCH 04/17] Add TUMPA Lite Add TIAO Multi-Protocol Adapter Lite --- src/mpsse.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mpsse.c b/src/mpsse.c index e3d9ed1..8fb75c1 100644 --- a/src/mpsse.c +++ b/src/mpsse.c @@ -32,7 +32,7 @@ struct vid_pid supported_devices[] = { { 0x0403, 0xBDC8, "Turtelizer JTAG/RS232 Adapter A" }, { 0x0403, 0xCFF8, "Amontec JTAGkey" }, { 0x0403, 0x8A98, "TIAO Multi Protocol Adapter"}, - { 0x0403, 0x8A99, "TIAO Multi Protocol Adapter Lite" + { 0x0403, 0x8A99, "TIAO Multi Protocol Adapter Lite"}, { 0x15BA, 0x0003, "Olimex Ltd. OpenOCD JTAG" }, { 0x15BA, 0x0004, "Olimex Ltd. OpenOCD JTAG TINY" }, From 3b47a6d817579bbad4c22cf6ad730aa2e280f68b Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:15:39 +0100 Subject: [PATCH 05/17] Add BlockSize option Add Page/Block-Size option, e.g. for M25P05-A (which uses 128) --- src/examples/spiflash.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 5429d48..a21197e 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -13,15 +13,14 @@ class SPIFlash(object): ID_LENGTH = 3 # Normal SPI chip ID length, in bytes ADDRESS_LENGTH = 3 # Normal SPI flash address length (24 bits, aka, 3 bytes) - BLOCK_SIZE = 256 # SPI block size, writes must be done in multiples of this size PP_PERIOD = .025 # Page program time, in seconds - + def __init__(self, speed=FIFTEEN_MHZ): # Sanity check on the specified clock speed if not speed: speed = FIFTEEN_MHZ - + self.flash = MPSSE(SPI0, speed, MSB) self.chip = self.flash.GetDescription() self.speed = self.flash.GetClock() @@ -50,7 +49,7 @@ def Read(self, count, address=0): return data - def Write(self, data, address=0): + def Write(self, data, address=0, blocksize=256): count = 0 while count < len(data): @@ -60,12 +59,12 @@ def Write(self, data, address=0): self.flash.Stop() self.flash.Start() - self.flash.Write(self.WCMD + self._addr2str(address) + data[address:address+self.BLOCK_SIZE]) + self.flash.Write(self.WCMD + self._addr2str(address) + data[address:address+blocksize]) self.flash.Stop() sleep(self.PP_PERIOD) - address += self.BLOCK_SIZE - count += self.BLOCK_SIZE + address += blocksize + count += blocksize def Erase(self): self.flash.Start() @@ -117,6 +116,7 @@ def usage(): print "\t-r, --read= Read data from the chip to file" print "\t-w, --write= Write data from file to the chip" print "\t-s, --size= Set the size of data to read/write" + print "\t-b, --blocksize= Set the block/page - size of data to read/write" print "\t-a, --address= Set the starting address for the read/write operation [0]" print "\t-f, --frequency= Set the SPI clock frequency, in hertz [15,000,000]" print "\t-i, --id Read the chip ID" @@ -138,7 +138,7 @@ def main(): data = "" try: - opts, args = GetOpt(sys.argv[1:], "f:s:a:r:w:eipvh", ["frequency=", "size=", "address=", "read=", "write=", "id", "erase", "verify", "pin-mappings", "help"]) + opts, args = GetOpt(sys.argv[1:], "f:s:b:a:r:w:eipvh", ["frequency=", "size=", "blocksize=", "address=", "read=", "write=", "id", "erase", "verify", "pin-mappings", "help"]) except GetoptError, e: print e usage() @@ -148,6 +148,8 @@ def main(): freq = int(arg) elif opt in ('-s', '--size'): size = int(arg) + elif opt in ('-b', '--blocksize'): + blocksize = int(arg) elif opt in ('-a', '--address'): address = int(arg) elif opt in ('-r', '--read'): @@ -193,8 +195,9 @@ def main(): data = open(fname, 'rb').read() if not size: size = len(data) - - sys.stdout.write("Writing %d bytes from %s to the chip starting at address 0x%X..." % (size, fname, address)) + if not blocksize: + blocksize = 256 + sys.stdout.write("Writing %d bytes from %s to the chip starting at address 0x%X using a blocksize of %d" % (size, fname, address, blocksize)) sys.stdout.flush() spi.Write(data[0:size], address) print "done." From 42dd26fba406e528cc615775492c0bb2fa02d635 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:22:39 +0100 Subject: [PATCH 06/17] Modify ID option, now provide len of ID in bytes --- src/examples/spiflash.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index a21197e..ca2d650 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -11,7 +11,6 @@ class SPIFlash(object): CECMD = "\xc7" # Standard SPI flash chip erase command (0xC7) IDCMD = "\x9f" # Standard SPI flash chip ID command (0x9F) - ID_LENGTH = 3 # Normal SPI chip ID length, in bytes ADDRESS_LENGTH = 3 # Normal SPI flash address length (24 bits, aka, 3 bytes) PP_PERIOD = .025 # Page program time, in seconds @@ -75,10 +74,10 @@ def Erase(self): self.flash.Write(self.CECMD) self.flash.Stop() - def ChipID(self): + def ChipID(self, idlen): self.flash.Start() self.flash.Write(self.IDCMD) - chipid = self.flash.Read(self.IDLEN) + chipid = self.flash.Read(idlen) self.flash.Stop() return chipid @@ -119,7 +118,7 @@ def usage(): print "\t-b, --blocksize= Set the block/page - size of data to read/write" print "\t-a, --address= Set the starting address for the read/write operation [0]" print "\t-f, --frequency= Set the SPI clock frequency, in hertz [15,000,000]" - print "\t-i, --id Read the chip ID" + print "\t-i, --id= Read the chip ID, requires Length of ID in bytes" print "\t-v, --verify Verify data that has been read/written" print "\t-e, --erase Erase the entire chip" print "\t-p, --pin-mappings Display a table of SPI flash to FTDI pin mappings" @@ -138,7 +137,7 @@ def main(): data = "" try: - opts, args = GetOpt(sys.argv[1:], "f:s:b:a:r:w:eipvh", ["frequency=", "size=", "blocksize=", "address=", "read=", "write=", "id", "erase", "verify", "pin-mappings", "help"]) + opts, args = GetOpt(sys.argv[1:], "f:s:b:a:r:w:eipvh", ["frequency=", "size=", "blocksize=", "address=", "read=", "write=", "id=", "erase", "verify", "pin-mappings", "help"]) except GetoptError, e: print e usage() @@ -160,6 +159,7 @@ def main(): fname = arg elif opt in ('-i', '--id'): action = "id" + id_length = int(arg) elif opt in ('-e', '--erase'): action = "erase" elif opt in ('-v', '--verify'): @@ -203,8 +203,9 @@ def main(): print "done." elif action == "id": - - for byte in spi.ChipID(): + if not id_length: + id_length = 3 + for byte in spi.ChipID(id_length): print ("%.2X" % ord(byte)), print "" @@ -234,4 +235,3 @@ def main(): spi.Close() main() - From 6561d0db74d67aecb75074f588b81469ba85d2f2 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:26:32 +0100 Subject: [PATCH 07/17] Correct last commit --- src/examples/spiflash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index ca2d650..c73d3aa 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -137,7 +137,7 @@ def main(): data = "" try: - opts, args = GetOpt(sys.argv[1:], "f:s:b:a:r:w:eipvh", ["frequency=", "size=", "blocksize=", "address=", "read=", "write=", "id=", "erase", "verify", "pin-mappings", "help"]) + opts, args = GetOpt(sys.argv[1:], "f:s:b:i:a:r:w:epvh", ["frequency=", "size=", "blocksize=", "id_len=","address=", "read=", "write=", "erase", "verify", "pin-mappings", "help"]) except GetoptError, e: print e usage() @@ -159,7 +159,7 @@ def main(): fname = arg elif opt in ('-i', '--id'): action = "id" - id_length = int(arg) + id_len = int(arg) elif opt in ('-e', '--erase'): action = "erase" elif opt in ('-v', '--verify'): From ba39bbcd3c121fc7058319035c4ebeb812cb0c41 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:28:13 +0100 Subject: [PATCH 08/17] Update spiflash.py --- src/examples/spiflash.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index c73d3aa..12fb836 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -203,9 +203,9 @@ def main(): print "done." elif action == "id": - if not id_length: - id_length = 3 - for byte in spi.ChipID(id_length): + if not id_len: + id_len = 3 + for byte in spi.ChipID(id_len): print ("%.2X" % ord(byte)), print "" From e285556c0a47723dbc4769fa064f0191625ec61f Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:42:08 +0100 Subject: [PATCH 09/17] Update spiflash.py --- src/examples/spiflash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 12fb836..0c2f665 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -197,7 +197,7 @@ def main(): size = len(data) if not blocksize: blocksize = 256 - sys.stdout.write("Writing %d bytes from %s to the chip starting at address 0x%X using a blocksize of %d" % (size, fname, address, blocksize)) + sys.stdout.write("Writing %d bytes from %s to the chip starting at address 0x%X using a blocksize of %d ..." % (size, fname, address, blocksize)) sys.stdout.flush() spi.Write(data[0:size], address) print "done." From 0ce0e3b011da8b603ba5f6f208f47aa8c7960233 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:45:29 +0100 Subject: [PATCH 10/17] Update spiflash.py --- src/examples/spiflash.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 0c2f665..b9e8b38 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -115,10 +115,10 @@ def usage(): print "\t-r, --read= Read data from the chip to file" print "\t-w, --write= Write data from file to the chip" print "\t-s, --size= Set the size of data to read/write" - print "\t-b, --blocksize= Set the block/page - size of data to read/write" + print "\t-b, --blocksize= Set the block/page - size of data to read/write [256]" print "\t-a, --address= Set the starting address for the read/write operation [0]" print "\t-f, --frequency= Set the SPI clock frequency, in hertz [15,000,000]" - print "\t-i, --id= Read the chip ID, requires Length of ID in bytes" + print "\t-i, --id= Read the chip ID, requires Length of ID in bytes [3]" print "\t-v, --verify Verify data that has been read/written" print "\t-e, --erase Erase the entire chip" print "\t-p, --pin-mappings Display a table of SPI flash to FTDI pin mappings" From 3f83236513955e6b4b8c25d4db4948d22e3e35aa Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:47:50 +0100 Subject: [PATCH 11/17] Update spiflash.py --- src/examples/spiflash.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index b9e8b38..61be491 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -133,6 +133,8 @@ def main(): action = None verify = False address = 0 + blocksize = 256 + id_len = 3 size = 0 data = "" @@ -195,16 +197,12 @@ def main(): data = open(fname, 'rb').read() if not size: size = len(data) - if not blocksize: - blocksize = 256 sys.stdout.write("Writing %d bytes from %s to the chip starting at address 0x%X using a blocksize of %d ..." % (size, fname, address, blocksize)) sys.stdout.flush() spi.Write(data[0:size], address) print "done." elif action == "id": - if not id_len: - id_len = 3 for byte in spi.ChipID(id_len): print ("%.2X" % ord(byte)), print "" From 713209e626c0d031882847308f4868bd24e1ffc2 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:52:22 +0100 Subject: [PATCH 12/17] Update spiflash.py --- src/examples/spiflash.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 61be491..18f92e2 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -139,7 +139,7 @@ def main(): data = "" try: - opts, args = GetOpt(sys.argv[1:], "f:s:b:i:a:r:w:epvh", ["frequency=", "size=", "blocksize=", "id_len=","address=", "read=", "write=", "erase", "verify", "pin-mappings", "help"]) + opts, args = GetOpt(sys.argv[1:], "f:s:b:l:a:r:w:eipvh", ["frequency=", "size=", "blocksize=", "id_len=","address=", "read=", "write=", "erase", "id", "verify", "pin-mappings", "help"]) except GetoptError, e: print e usage() @@ -161,6 +161,7 @@ def main(): fname = arg elif opt in ('-i', '--id'): action = "id" + elif opt in ('-l', '--id_length'): id_len = int(arg) elif opt in ('-e', '--erase'): action = "erase" @@ -203,6 +204,8 @@ def main(): print "done." elif action == "id": + if not id_len: + id_len = 3 for byte in spi.ChipID(id_len): print ("%.2X" % ord(byte)), print "" From 8702092a7be369f6f7551716a472aab52d97e123 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:54:07 +0100 Subject: [PATCH 13/17] Update spiflash.py --- src/examples/spiflash.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 18f92e2..9746cbb 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -119,6 +119,7 @@ def usage(): print "\t-a, --address= Set the starting address for the read/write operation [0]" print "\t-f, --frequency= Set the SPI clock frequency, in hertz [15,000,000]" print "\t-i, --id= Read the chip ID, requires Length of ID in bytes [3]" + print "\t-l, --id_len= Length of chip ID in bytes [3]" print "\t-v, --verify Verify data that has been read/written" print "\t-e, --erase Erase the entire chip" print "\t-p, --pin-mappings Display a table of SPI flash to FTDI pin mappings" From 0590ce81ebf884443a08b78dce5d7e5389823481 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:55:05 +0100 Subject: [PATCH 14/17] Update spiflash.py --- src/examples/spiflash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 9746cbb..1c2d8a2 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -119,7 +119,7 @@ def usage(): print "\t-a, --address= Set the starting address for the read/write operation [0]" print "\t-f, --frequency= Set the SPI clock frequency, in hertz [15,000,000]" print "\t-i, --id= Read the chip ID, requires Length of ID in bytes [3]" - print "\t-l, --id_len= Length of chip ID in bytes [3]" + print "\t-l, --id_len= Length of chip ID in bytes [3]" print "\t-v, --verify Verify data that has been read/written" print "\t-e, --erase Erase the entire chip" print "\t-p, --pin-mappings Display a table of SPI flash to FTDI pin mappings" From 356acd24dfc3272f4d9d3e344d3d10e930e3b9f0 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:57:18 +0100 Subject: [PATCH 15/17] Update spiflash.py --- src/examples/spiflash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 1c2d8a2..57cce8f 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -118,7 +118,7 @@ def usage(): print "\t-b, --blocksize= Set the block/page - size of data to read/write [256]" print "\t-a, --address= Set the starting address for the read/write operation [0]" print "\t-f, --frequency= Set the SPI clock frequency, in hertz [15,000,000]" - print "\t-i, --id= Read the chip ID, requires Length of ID in bytes [3]" + print "\t-i, --id= Read the chip ID" print "\t-l, --id_len= Length of chip ID in bytes [3]" print "\t-v, --verify Verify data that has been read/written" print "\t-e, --erase Erase the entire chip" From 728629d1de3b9a78332522c436cf26ce864827b5 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Fri, 27 Feb 2015 20:58:09 +0100 Subject: [PATCH 16/17] Update spiflash.py --- src/examples/spiflash.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/examples/spiflash.py b/src/examples/spiflash.py index 57cce8f..e7ce1a0 100644 --- a/src/examples/spiflash.py +++ b/src/examples/spiflash.py @@ -118,7 +118,7 @@ def usage(): print "\t-b, --blocksize= Set the block/page - size of data to read/write [256]" print "\t-a, --address= Set the starting address for the read/write operation [0]" print "\t-f, --frequency= Set the SPI clock frequency, in hertz [15,000,000]" - print "\t-i, --id= Read the chip ID" + print "\t-i, --id Read the chip ID" print "\t-l, --id_len= Length of chip ID in bytes [3]" print "\t-v, --verify Verify data that has been read/written" print "\t-e, --erase Erase the entire chip" From d838d0038a4492860943373aa8e61762110fc0f5 Mon Sep 17 00:00:00 2001 From: Oliver Kleinecke Date: Thu, 19 Mar 2015 12:28:11 +0100 Subject: [PATCH 17/17] Update script to check for importable mpsse library --- src/examples/i2ceeprom.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/src/examples/i2ceeprom.py b/src/examples/i2ceeprom.py index 6fad968..e7e84f3 100644 --- a/src/examples/i2ceeprom.py +++ b/src/examples/i2ceeprom.py @@ -1,6 +1,32 @@ #!/usr/bin/env python -import argparse, struct, sys, time +import argparse, os, struct, sys, time + +# Check if were running on Python2.7 +if (sys.version[0:3] != "2.7"): + print("This script is meant to be run on python2.7.x ! Exiting") + exit(1) + +found=False +# Check if MPSSE lib can be found in pythons path first +for path in range(len(sys.path)): + if sys.path[path] != '' and os.path.exists(sys.path[path]) and os.path.isdir(sys.path[path]): + mpssename = "%s/mpsse.pyc" % sys.path[path] + if os.path.exists(mpssename) and os.path.isfile(mpssename): + found = True +# Try to locate mpsse in typical default dirs, if not found. +if found != True : + custom_paths = ['/usr/lib/python2.7/site-packages', '/usr/local/lib/python2.7/site-packages', '/usr/lib64/python2.7/site-packages', '/usr/local/lib64/python2.7/site-packages'] + for path in range(len(custom_paths)): + if custom_path[path] != '' and os.path.exists(custom_path[path]) and os.path.isdir(custom_path[path]): + mpssename = "%s/mpsse.pyc" % custom_path[path] + if os.path.exists(mpssename) and os.path.isfile(mpssename): + sys.path.append(custom_path[path]) + found = True +if found != True: + print("MPSSE Library could not be found. Exiting") + exit(1) + from fish import ProgressFish from mpsse import *