Writing of SPI Flash is more reliable.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 19 Jul 2009 13:14:52 +0000 (13:14 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 19 Jul 2009 13:14:52 +0000 (13:14 +0000)
I forgot to raise !CS.

git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@69 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/goodfet.spiflash
firmware/apps/spi/spi.c

index 5c73eda..a04ed19 100755 (executable)
@@ -8,6 +8,7 @@
 
 import sys;
 import binascii;
+import array;
 
 from GoodFET import GoodFET;
 from intelhex import IntelHex;
@@ -65,8 +66,6 @@ if(sys.argv[1]=="dump"):
     if(len(sys.argv)>4):
         stop=int(sys.argv[4],16);
     
-    
-
     print "Dumping code from %06x to %06x as %s." % (start,stop,f);
     file = open(f, mode='wb')
 
@@ -81,6 +80,29 @@ if(sys.argv[1]=="dump"):
             file.write(j);
             i+=1;
     file.close()
+if(sys.argv[1]=="flash"):
+    f = sys.argv[2];
+    start=0x0000;
+    stop=0x100000; #TODO, adjust this by the JEDEC size parameter.
+    if(len(sys.argv)>3):
+        start=int(sys.argv[3],16);
+    if(len(sys.argv)>4):
+        stop=int(sys.argv[4],16);
+    
+    print "Flashing code from %06x to %06x with %s." % (start,stop,f);
+    file = open(f, mode='rb')
+
+    i=start;
+    bytes=file.read();
+    while i<=stop:
+        client.SPIpokebyte(i,ord(bytes[i]));
+        
+        i+=1;
+        if(i%0x100==0):
+            print "Flashed %06x."%i;
+    file.close()
+
+
 if(sys.argv[1]=="erase"):
   client.SPIchiperase();
 
@@ -104,6 +126,8 @@ if(sys.argv[1]=="poke"):
     if(len(sys.argv)>3):
         val=int(sys.argv[3],16);
     print "Poking %06x to become %02x." % (start,val);
-    client.SPIpokebyte(start,val);
-
+    
+    while client.SPIpeek(start)!=val:
+        client.SPIpokebyte(start,val);
+        print "Poked to %02x" % client.SPIpeek(start);
 
index c58b4bc..e00d2aa 100644 (file)
@@ -79,6 +79,7 @@ void spiflash_wrten(){
 //! Grab the SPI flash status byte.
 unsigned char spiflash_status(){
   unsigned char c;
+  P5OUT|=SS;  //Raise !SS to end transaction.
   P5OUT&=~SS; //Drop !SS to begin transaction.
   spitrans8(0x05);//GET STATUS
   c=spitrans8(0xFF);
@@ -99,6 +100,11 @@ void spihandle(unsigned char app,
               unsigned char verb,
               unsigned char len){
   unsigned char i;
+  
+  
+  //Raise !SS to end transaction, just in case we forgot.
+  P5OUT|=SS;  
+  
   switch(verb){
     //PEEK and POKE might come later.
   case READ:
@@ -127,8 +133,8 @@ void spihandle(unsigned char app,
     len=0x80;//128 byte chunk
     for(i=0;i<len;i++)
       cmddata[i]=spitrans8(0);
-    txdata(app,verb,len);
     P5OUT|=SS;  //Raise !SS to end transaction.
+    txdata(app,verb,len);
     break;
   case POKE://Poke up bytes from an SPI Flash ROM.
     spiflash_setstatus(0x02);
@@ -140,9 +146,8 @@ void spihandle(unsigned char app,
     //First three bytes are address, then data.
     for(i=0;i<len;i++)
       spitrans8(cmddata[i]);
-    P5OUT&=~SS; //Drop !SS to begin transaction.
+    P5OUT|=SS;  //Raise !SS to end transaction.
     while(spiflash_status()&0x01);//while busy
-    spiflash_wrten();
     txdata(app,verb,len);
     break;
   case SPI_ERASE://Erase the SPI Flash ROM.
@@ -157,4 +162,5 @@ void spihandle(unsigned char app,
     txdata(app,verb,0);
     break;
   }
+  
 }