Fast MSP430 Flash writes.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 22 Nov 2009 20:56:44 +0000 (20:56 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 22 Nov 2009 20:56:44 +0000 (20:56 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@232 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

client/GoodFETMSP430.py
client/goodfet.msp430
firmware/apps/jtag/jtag430.c

index 4ee6e4f..d5e5f8f 100644 (file)
@@ -65,7 +65,14 @@ class GoodFETMSP430(GoodFET):
                    val&0xff, (val&0xff00)>>8];
         self.writecmd(self.MSP430APP,0xE1,6,self.data);
         return ord(self.data[0])+(ord(self.data[1])<<8);
                    val&0xff, (val&0xff00)>>8];
         self.writecmd(self.MSP430APP,0xE1,6,self.data);
         return ord(self.data[0])+(ord(self.data[1])<<8);
-    
+    def MSP430pokeflashblock(self,adr,data):
+        """Write many words to flash memory at an address."""
+        self.data=[adr&0xff, (adr&0xff00)>>8,
+                   (adr&0xff0000)>>16,(adr&0xff000000)>>24]+data;
+        #print "Writing %i bytes to %x" % (len(data),adr);
+        #print "%2x %2x %2x %2x ..." % (data[0], data[1], data[2], data[3]);
+        self.writecmd(self.MSP430APP,0xE1,len(self.data),self.data);
+        return ord(self.data[0])+(ord(self.data[1])<<8);
     def MSP430start(self):
         """Start debugging."""
         self.writecmd(self.MSP430APP,0x20,0,self.data);
     def MSP430start(self):
         """Start debugging."""
         self.writecmd(self.MSP430APP,0x20,0,self.data);
index d012728..9fcb68f 100755 (executable)
@@ -77,17 +77,37 @@ if(sys.argv[1]=="flash"):
     
     h = IntelHex16bit(f);
     
     
     h = IntelHex16bit(f);
     
+    #Should this be default?
+    #Makes flashing multiple images inconvenient.
     client.MSP430masserase();
     client.MSP430masserase();
+    
+    count=0; #Bytes in commit.
+    first=0;
+    vals=[];
+    last=0;  #Last address committed.
     for i in h._buf.keys():
     for i in h._buf.keys():
-        #print "%04x: %04x"%(i,h[i>>1]);
+        if((count>0x40 or last+2!=i) and count>0 and i&1==0):
+            #print "%i, %x, %x" % (len(vals), last, i);
+            client.MSP430pokeflashblock(first,vals);
+            count=0;
+            first=0;
+            last=0;
+            vals=[];
         if(i>=start and i<stop  and i&1==0):
             val=h[i>>1];
         if(i>=start and i<stop  and i&1==0):
             val=h[i>>1];
-            val2=client.MSP430pokeflash(i,val);
-            if(val!=val2):
-                print "Write error at %04x, %04x!=%04x." %(
-                    i, val, val2);
+            if(count==0):
+                first=i;
+            last=i;
+            count+=2;
+            #val2=client.MSP430pokeflash(i,val);
+            #if(val!=val2):
+            #    print "Write error at %04x, %04x!=%04x." %(
+            #        i, val, val2);
+            vals+=[val&0xff,(val&0xff00)>>8];
             if(i%0x100==0):
                 print "%04x" % i;
             if(i%0x100==0):
                 print "%04x" % i;
+    if count>0: #last commit, ivt
+        client.MSP430pokeflashblock(first,vals);
 if(sys.argv[1]=="verify"):
     f=sys.argv[2];
     start=0;
 if(sys.argv[1]=="verify"):
     f=sys.argv[2];
     start=0;
index 18a7c38..50fc70d 100644 (file)
@@ -363,13 +363,14 @@ void jtag430handle(unsigned char app,
   case JTAG430_WRITEFLASH:
     at=cmddataword[0];
     
   case JTAG430_WRITEFLASH:
     at=cmddataword[0];
     
-    for(i=2;i<(len>>1);i++){
+    for(i=0;i<(len>>1)-2;i++){
       //debugstr("Poking flash memory.");
       //debugstr("Poking flash memory.");
-      jtag430_writeflash(at,cmddataword[i]);
+      jtag430_writeflash(at+(i<<1),cmddataword[i+2]);
+      //Reflash if needed.  Try this twice to save grace?
       if(cmddataword[i]!=jtag430_readmem(at))
       if(cmddataword[i]!=jtag430_readmem(at))
-       jtag430_writeflash(at,cmddataword[i]);
+       jtag430_writeflash(at+(i<<1),cmddataword[i+2]);
     }
     }
-
+    
     //Return result of first write as a word.
     cmddataword[0]=jtag430_readmem(cmddataword[0]);
     
     //Return result of first write as a word.
     cmddataword[0]=jtag430_readmem(cmddataword[0]);