From: travisutk Date: Mon, 5 Oct 2009 14:30:51 +0000 (+0000) Subject: Sane SPI Flash addressing for poke date, will later convert all functions. X-Git-Url: http://git.rot13.org/?p=goodfet;a=commitdiff_plain;h=78f4f21969789bec27a8e2957eb00a87d8756041 Sane SPI Flash addressing for poke date, will later convert all functions. git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@184 12e2690d-a6be-4b82-a7b7-67c4a43b65c8 --- diff --git a/client/GoodFET.py b/client/GoodFET.py index 18a3eb1..7497497 100755 --- a/client/GoodFET.py +++ b/client/GoodFET.py @@ -55,7 +55,9 @@ class GoodFET: self.serialport.write(chr(app)); self.serialport.write(chr(verb)); - + + #print "TX %02x %02x" % (app,verb); + #little endian 16-bit length self.serialport.write(chr(count&0xFF)); self.serialport.write(chr(count>>8)); @@ -64,11 +66,6 @@ class GoodFET: if count!=0: for d in data: self.serialport.write(chr(d)); - - #self.serialport.flushOutput(); - #self.serialport.flushInput(); - - if not self.besilent: self.readcmd(); diff --git a/client/GoodFETSPI.py b/client/GoodFETSPI.py index 044aea2..021c7e6 100644 --- a/client/GoodFETSPI.py +++ b/client/GoodFETSPI.py @@ -62,6 +62,7 @@ class GoodFETSPIFlash(GoodFETSPI): """Grab an SPI Flash ROM's JEDEC bytes.""" data=[0x9f, 0, 0, 0]; data=self.SPItrans(data); + self.JEDECmanufacturer=ord(data[1]); self.JEDECtype=ord(data[2]); self.JEDECcapacity=ord(data[3]); @@ -91,11 +92,17 @@ class GoodFETSPIFlash(GoodFETSPI): def SPIpokebyte(self,adr,val): self.SPIpokebytes(adr,[val]); def SPIpokebytes(self,adr,data): - #self.SPIwriteenable(); - adranddata=[(adr&0xFF0000)>>16, - (adr&0xFF00)>>8, - adr&0xFF - ]+data; + #Used to be 24 bits, BE, not 32 bits, LE. +# adranddata=[(adr&0xFF0000)>>16, +# (adr&0xFF00)>>8, +# adr&0xFF +# ]+data; + adranddata=[adr&0xFF, + (adr&0xFF00)>>8, + (adr&0xFF0000)>>16, + 0, #MSB + ]+data; + self.writecmd(0x01,0x03, len(adranddata),adranddata); diff --git a/client/goodfet.spiflash b/client/goodfet.spiflash index 55a7b12..b7cec4b 100755 --- a/client/goodfet.spiflash +++ b/client/goodfet.spiflash @@ -141,9 +141,9 @@ if(sys.argv[1]=="flash"): chars=list(file.read()); #N.B., chunksize must be an even fraction of 0x100. - chunksize=0x100; + #Increasing above 0x200 doesn't help, 0x100 might be good enough. + chunksize=0x200; - #client.silent(1); while i<=stop: bytes=range(0,chunksize); for j in range(0,chunksize): @@ -153,8 +153,8 @@ if(sys.argv[1]=="flash"): i+=chunksize; if(i%0x1000==0): print "Flashed %06x."%i; - print "Done, ending silence."; - #client.silent(0); + + file.close() diff --git a/firmware/Makefile b/firmware/Makefile index f6a221b..d701b74 100644 --- a/firmware/Makefile +++ b/firmware/Makefile @@ -1,6 +1,5 @@ #include `uname`.mak - GOODFET?=/dev/ttyUSB0 @@ -17,7 +16,7 @@ mcu?=msp430x1612 GCCINC=-T ldscripts/$(mcu).x CCEXTRA?= -CC=msp430-gcc -Wall -g -mmcu=$(mcu) -DGCC $(GCCINC) -I include $(CCEXTRA) +CC=msp430-gcc -Wall -Os -g -mmcu=$(mcu) -DGCC $(GCCINC) -I include $(CCEXTRA) #Define extra modules here. moreapps?= diff --git a/firmware/apps/spi/spi.c b/firmware/apps/spi/spi.c index ce21cb8..f02d402 100644 --- a/firmware/apps/spi/spi.c +++ b/firmware/apps/spi/spi.c @@ -35,7 +35,7 @@ void spisetup(){ //! Read and write an SPI byte. unsigned char spitrans8(unsigned char byte){ - unsigned int bit; + register unsigned int bit; //This function came from the SPI Wikipedia article. //Minor alterations. @@ -47,13 +47,8 @@ unsigned char spitrans8(unsigned char byte){ CLRMOSI; byte <<= 1; - /* half a clock cycle before leading/rising edge */ - SPIDELAY(SPISPEED/2); SETCLK; - - /* half a clock cycle before trailing/falling edge */ - SPIDELAY(SPISPEED/2); - + /* read MISO on trailing edge */ byte |= READMISO; CLRCLK; @@ -120,17 +115,41 @@ void spiflash_peekblock(unsigned long adr, SETSS; //Raise !SS to end transaction. } +//! Write many blocks to the SPI Flash. +void spiflash_pokeblocks(unsigned long adr, + unsigned char *buf, + unsigned int len){ + long off=0;//offset of this block + int blen;//length of this block + SETSS; + spiflash_setstatus(0x02); + spiflash_wrten(); + + while(off0x100?0x100:len-off); + //write the block + spiflash_pokeblock(adr+off, + buf+off, + blen); + //add offset + off+=blen; + } +} //! Read a block to a buffer. void spiflash_pokeblock(unsigned long adr, unsigned char *buf, unsigned int len){ - unsigned char i; + unsigned int i; SETSS; - spiflash_setstatus(0x02); - spiflash_wrten(); + //while(spiflash_status()&0x01);//minor performance impact + + //Are these necessary? + //spiflash_setstatus(0x02); + //spiflash_wrten(); CLRSS; //Drop !SS to begin transaction. spitrans8(0x02); //Poke command. @@ -144,8 +163,7 @@ void spiflash_pokeblock(unsigned long adr, spitrans8(buf[i]); SETSS; //Raise !SS to end transaction. - while(spiflash_status()&0x01); - + while(spiflash_status()&0x01);//minor performance impact return; } @@ -210,22 +228,9 @@ void spihandle(unsigned char app, case POKE://Poke up bytes from an SPI Flash ROM. - spiflash_setstatus(0x02); - spiflash_wrten(); - - P5OUT&=~SS; //Drop !SS to begin transaction. - spitrans8(0x02); //Poke command. - - //First three bytes are address, then data. - for(i=0;i