From: travisutk Date: Sun, 19 Jul 2009 13:52:49 +0000 (+0000) Subject: SPI Flash writing is now performed in chunks, X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=c6e02600ef0e12eb9a7309755740a23b71a62205;hp=d0d48d9cdb77bee064236d148002f98f3c247121 SPI Flash writing is now performed in chunks, and a bug with the execution of the first command after powerup has been fixed. This client is now useful. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@70 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/client/GoodFET.py b/client/GoodFET.py index cbcf1c4..b87cee8 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -102,7 +102,7 @@ class GoodFET: def SPIsetup(self): """Moved the FET into the SPI application.""" self.writecmd(0x01,0x10,0,self.data); #SPI/SETUP - #self.readcmd(); + def SPItrans8(self,byte): """Read and write 8 bits by SPI.""" data=self.SPItrans([byte]); diff --git a/client/goodfet.spiflash b/client/goodfet.spiflash index a04ed19..354d502 100755 --- a/client/goodfet.spiflash +++ b/client/goodfet.spiflash @@ -28,8 +28,13 @@ if(len(sys.argv)==1): client=GoodFET(); client.serInit("/dev/ttyUSB0") + client.SPIsetup(); +#Dummy read. +#Might read as all ones if chip has a startup delay. +client.SPIjedec(); + if(sys.argv[1]=="test"): result=""; dropped=0; @@ -93,11 +98,17 @@ if(sys.argv[1]=="flash"): file = open(f, mode='rb') i=start; - bytes=file.read(); + chars=list(file.read()); + chunksize=0x80; + while i<=stop: - client.SPIpokebyte(i,ord(bytes[i])); + bytes=range(0,chunksize); + for j in range(0,chunksize): + bytes[j]=ord(chars[i+j]); + #client.SPIpokebyte(i,ord(chars[i])); + client.SPIpokebytes(i,bytes); - i+=1; + i+=chunksize; if(i%0x100==0): print "Flashed %06x."%i; file.close() diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index e00d2aa..c70cdb4 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -35,6 +35,10 @@ void spisetup(){ P5OUT|=SS; P5DIR|=MOSI+SCK+SS; P5DIR&=~MISO; + + //Begin a new transaction. + P5OUT&=~SS; + P5OUT|=SS; } //! Read and write an SPI bit.