Fixed python client buffering issues, minor changes to SPI app.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 8 Oct 2009 00:10:41 +0000 (00:10 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Thu, 8 Oct 2009 00:10:41 +0000 (00:10 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@194 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

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

index 7497497..ec65900 100755 (executable)
@@ -63,9 +63,13 @@ class GoodFET:
         self.serialport.write(chr(count>>8));
         
         #print "count=%02x, len(data)=%04x" % (count,len(data));
+        
         if count!=0:
-            for d in data:
-                self.serialport.write(chr(d));
+            for i in range(0,count):
+                #print "Converting %02x at %i" % (data[i],i)
+                data[i]=chr(data[i]);
+            outstr=''.join(data);
+            self.serialport.write(outstr);
         if not self.besilent:
             self.readcmd();
         
index 021c7e6..bd28019 100644 (file)
@@ -93,16 +93,12 @@ class GoodFETSPIFlash(GoodFETSPI):
         self.SPIpokebytes(adr,[val]);
     def SPIpokebytes(self,adr,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;
-        
+        #print "%06x: poking %i bytes" % (adr,len(data));
         self.writecmd(0x01,0x03,
                       len(adranddata),adranddata);
         
index b7cec4b..d4450c2 100755 (executable)
@@ -111,16 +111,21 @@ if(sys.argv[1]=="verify"):
     file = open(f, mode='rb')
     
     i=start;
-    bits=0;
+    bytes=0;
     while i<=stop:
-        data=client.SPIpeekblock(i,255);
+        data=client.SPIpeekblock(i);
         print "Verified %06x." % i;
         for j in data:
             if i<stop:
-                bits|=ord(file.read(1))^ord(j);
+                #bits|=ord(file.read(1))^ord(j);
+                a=ord(file.read(1));
+                b=ord(j);
+                if a!=b:
+                    print "%06x: %02x/%02x" % (i,a,b);
+                    bytes+=1;
             i+=1;
-        if bits!=0:
-            print "Bits don't match."
+        if bytes!=0:
+            print "%i bytes don't match." % bytes
 
     file.close()
 
@@ -142,7 +147,8 @@ if(sys.argv[1]=="flash"):
     
     #N.B., chunksize must be an even fraction of 0x100.
     #Increasing above 0x200 doesn't help, 0x100 might be good enough.
-    chunksize=0x200;
+    chunksize=0x100;
+    #chunksize=0x1000;
     
     while i<=stop:
         bytes=range(0,chunksize);
index 0985340..6e008a1 100644 (file)
@@ -123,7 +123,13 @@ void spiflash_pokeblock(unsigned long adr,
   
   SETSS;
   
-  //while(spiflash_status()&0x01);//minor performance impact
+  //if(len!=0x100)
+  //  debugstr("Non-standard block size.");
+  
+  while(spiflash_status()&0x01);//minor performance impact
+  
+  spiflash_setstatus(0x02);
+  spiflash_wrten();
   
   //Are these necessary?
   //spiflash_setstatus(0x02);
@@ -153,8 +159,6 @@ void spiflash_pokeblocks(unsigned long adr,
   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
@@ -191,6 +195,30 @@ void spiflash_peek(unsigned char app,
   P5OUT|=SS;  //Raise !SS to end transaction.
 }
 
+
+//! Erase a sector.
+void spiflash_erasesector(unsigned long adr){
+  //debugstr("Erasing a 4kB sector.");
+
+  //Write enable.
+  spiflash_wrten();
+
+  //Begin
+  CLRSS;
+
+  //Second command.
+  spitrans8(0x20);
+  //Send address
+  spitrans8((adr&0xFF0000)>>16);
+  spitrans8((adr&0xFF00)>>8);
+  spitrans8(adr&0xFF);
+
+  SETSS;
+  while(spiflash_status()&0x01);//while busy
+  //debugstr("Erased.");
+}
+
+
 //! Handles a monitor command.
 void spihandle(unsigned char app,
               unsigned char verb,
@@ -234,7 +262,7 @@ void spihandle(unsigned char app,
                        cmddata+4,//buf
                        len-4);//len    
     
-    txdata(app,verb,len);
+    txdata(app,verb,0);
     break;
 
 
index 4eda217..569dab2 100644 (file)
@@ -9,9 +9,11 @@
 #define u16 unsigned int
 #define u32 unsigned long
 
-
 #ifndef CMDDATALEN
+//512 bytes
 #define CMDDATALEN 0x204
+//4k
+//#define CMDDATALEN 0x1004
 #endif
 
 //! Global data buffer.
index f5c0d8e..e96bef3 100644 (file)
@@ -35,3 +35,14 @@ void spiflash_peekblock(unsigned long adr,
 void spiflash_pokeblocks(unsigned long adr,
                         unsigned char *buf,
                         unsigned int len);
+
+
+//! Enable SPI writing
+void spiflash_wrten();
+
+//! Read and write an SPI byte.
+unsigned char spitrans8(unsigned char byte);
+//! Grab the SPI flash status byte.
+unsigned char spiflash_status();
+//! Erase a sector.
+void spiflash_erasesector(unsigned long adr);