Sane SPI Flash addressing for poke date, will later convert all functions.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Mon, 5 Oct 2009 14:30:51 +0000 (14:30 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Mon, 5 Oct 2009 14:30:51 +0000 (14:30 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@184 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFET.py
client/GoodFETSPI.py
client/goodfet.spiflash
firmware/Makefile
firmware/apps/spi/spi.c
firmware/include/command.h

index 18a3eb1..7497497 100755 (executable)
@@ -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();
         
index 044aea2..021c7e6 100644 (file)
@@ -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);
         
index 55a7b12..b7cec4b 100755 (executable)
@@ -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()
 
 
index f6a221b..d701b74 100644 (file)
@@ -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?=
index ce21cb8..f02d402 100644 (file)
@@ -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(off<len){
+    //calculate block length
+    blen=(len-off>0x100?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<len;i++)
-      spitrans8(cmddata[i]);
-    P5OUT|=SS;          //Raise !SS to end transaction.
-    
-    
-    while(spiflash_status()&0x01)
-      P1OUT^=1;
-    
-    P1OUT&=~1;
+    spiflash_pokeblocks(cmddatalong[0],//adr
+                       cmddata+4,//buf
+                       len-4);//len    
     
     txdata(app,verb,len);
     break;
index 9f6c0f4..8c7f72b 100644 (file)
@@ -6,7 +6,7 @@
 //! Global data buffer.
 
 #ifndef CMDDATALEN
-#define CMDDATALEN 0x200
+#define CMDDATALEN 0x0x204
 #endif
 
 extern unsigned char cmddata[CMDDATALEN];