16-bit MSP430 support working well from 1612.
authortravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 4 Oct 2009 07:40:00 +0000 (07:40 +0000)
committertravisutk <travisutk@12e2690d-a6be-4b82-a7b7-67c4a43b65c8>
Sun, 4 Oct 2009 07:40:00 +0000 (07:40 +0000)
git-svn-id: https://svn.code.sf.net/p/goodfet/code/trunk@167 12e2690d-a6be-4b82-a7b7-67c4a43b65c8

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

index af24201..a31676c 100755 (executable)
@@ -60,11 +60,13 @@ class GoodFET:
             for d in data:
                 self.serialport.write(chr(d));
         
             for d in data:
                 self.serialport.write(chr(d));
         
+        #self.serialport.flushOutput();
+        #self.serialport.flushInput();
+        
+        
         if not self.besilent:
         if not self.besilent:
-            #print "Reading reply to %02x/%02x." % (app,verb);
             self.readcmd(blocks);
             self.readcmd(blocks);
-            #print "Read reply."
-    
+        
     besilent=0;
     app=0;
     verb=0;
     besilent=0;
     app=0;
     verb=0;
@@ -74,16 +76,21 @@ class GoodFET:
     def readcmd(self,blocks=1):
         """Read a reply from the GoodFET."""
         while 1:
     def readcmd(self,blocks=1):
         """Read a reply from the GoodFET."""
         while 1:
+            #print "Reading...";
             self.app=ord(self.serialport.read(1));
             self.app=ord(self.serialport.read(1));
+            #print "APP=%2x" % self.app;
             self.verb=ord(self.serialport.read(1));
             self.verb=ord(self.serialport.read(1));
+            #print "VERB=%02x" % self.verb;
             self.count=ord(self.serialport.read(1));
             self.count=ord(self.serialport.read(1));
-            self.data=self.serialport.read(self.count*blocks);
+            #print "Waiting for %i bytes." % self.count;
+            
             #print "READ %02x %02x %02x " % (self.app, self.verb, self.count);
             
             #Debugging string; print, but wait.
             if self.app==0xFF and self.verb==0xFF:
             #print "READ %02x %02x %02x " % (self.app, self.verb, self.count);
             
             #Debugging string; print, but wait.
             if self.app==0xFF and self.verb==0xFF:
-                print "DEBUG %s" % self.data;
+                print "DEBUG %s" % self.serialport.read(self.count);
             else:
             else:
+                self.data=self.serialport.read(self.count*blocks);
                 return self.data;
     
     #Monitor stuff
                 return self.data;
     
     #Monitor stuff
index 884a47a..7ad26d2 100644 (file)
@@ -45,8 +45,8 @@ class GoodFETMSP430(GoodFET):
     def MSP430peekblock(self,adr,blocks=1):
         """Grab a few block from an SPI Flash ROM.  Block size is unknown"""
         data=[adr&0xff, (adr&0xff00)>>8,
     def MSP430peekblock(self,adr,blocks=1):
         """Grab a few block from an SPI Flash ROM.  Block size is unknown"""
         data=[adr&0xff, (adr&0xff00)>>8,
-                   (adr&0xff0000)>>16,(adr&0xff000000)>>24,
-                   blocks];
+              (adr&0xff0000)>>16,(adr&0xff000000)>>24,
+              blocks];
         
         self.writecmd(self.MSP430APP,0x02,5,data,blocks);
         return self.data;
         
         self.writecmd(self.MSP430APP,0x02,5,data,blocks);
         return self.data;
@@ -162,16 +162,7 @@ class GoodFETMSP430(GoodFET):
     def MSP430masserase(self):
         """Erase MSP430 flash memory."""
         self.writecmd(self.MSP430APP,0xE3,0,None);
     def MSP430masserase(self):
         """Erase MSP430 flash memory."""
         self.writecmd(self.MSP430APP,0xE3,0,None);
-    def MSP430writeflash(self,adr,val):
-        """Write a word of flash memory."""
-        if(self.MSP430peek(adr)!=0xFFFF):
-            print "FLASH ERROR: %04x not clear." % adr;
-        data=[adr&0xFF,(adr&0xFF00)>>8,val&0xFF,(val&0xFF00)>>8];
-        self.writecmd(self.MSP430APP,0xE1,4,data);
-        rval=ord(self.data[0])+(ord(self.data[1])<<8);
-        if(val!=rval):
-            print "FLASH WRITE ERROR AT %04x.  Found %04x, wrote %04x." % (adr,rval,val);
-        
+    
     def MSP430dumpbsl(self):
         self.MSP430dumpmem(0xC00,0xfff);
     def MSP430dumpallmem(self):
     def MSP430dumpbsl(self):
         self.MSP430dumpmem(0xC00,0xfff);
     def MSP430dumpallmem(self):
index 9745a5a..3140e13 100755 (executable)
@@ -27,6 +27,7 @@ client.MSP430setup();
 
 #Identify model number.
 client.MSP430start();
 
 #Identify model number.
 client.MSP430start();
+client.MSP430haltcpu();
 #print "started"
 
 if(sys.argv[1]=="info"):
 #print "started"
 
 if(sys.argv[1]=="info"):
@@ -77,7 +78,7 @@ if(sys.argv[1]=="flash"):
     for i in h._buf.keys():
         #print "%04x: %04x"%(i,h[i>>1]);
         if(i>=start and i<stop  and i&1==0):
     for i in h._buf.keys():
         #print "%04x: %04x"%(i,h[i>>1]);
         if(i>=start and i<stop  and i&1==0):
-            client.MSP430writeflash(i,h[i>>1]);
+            client.MSP430pokeflash(i,h[i>>1]);
             if(i%0x100==0):
                 print "%04x" % i;
 if(sys.argv[1]=="flashtest"):
             if(i%0x100==0):
                 print "%04x" % i;
 if(sys.argv[1]=="flashtest"):
index 66adb11..ce4e7b6 100644 (file)
@@ -52,6 +52,8 @@ void jtag430_releasecpu(){
 //! Read data from address
 unsigned int jtag430_readmem(unsigned int adr){
   unsigned int toret;
 //! Read data from address
 unsigned int jtag430_readmem(unsigned int adr){
   unsigned int toret;
+  jtag430_haltcpu();
+  
   
   CLRTCLK;
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
   
   CLRTCLK;
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
@@ -132,7 +134,7 @@ void jtag430_writeflash(unsigned int adr, unsigned int data){
   //FCTL1=0xA500, disabling flash write
   jtag430_writemem(0x0128, 0xA500);
   
   //FCTL1=0xA500, disabling flash write
   jtag430_writemem(0x0128, 0xA500);
   
-  jtag430_releasecpu();
+  //jtag430_releasecpu();
 }
 
 
 }
 
 
@@ -188,7 +190,7 @@ void jtag430_eraseflash(unsigned int mode, unsigned int adr, unsigned int count)
   //FCTL1=0xA500, disabling flash write
   jtag430_writemem(0x0128, 0xA500);
   
   //FCTL1=0xA500, disabling flash write
   jtag430_writemem(0x0128, 0xA500);
   
-  jtag430_releasecpu();
+  //jtag430_releasecpu();
 }
 
 
 }
 
 
@@ -252,10 +254,14 @@ void jtag430_start(){
   
   //Perform a reset and disable watchdog.
   jtag430_por();
   
   //Perform a reset and disable watchdog.
   jtag430_por();
+  jtag430_writemem(0x120,0x5a80);//disable watchdog
+  
+  jtag430_haltcpu();
 }
 
 //! Set CPU to Instruction Fetch
 void jtag430_setinstrfetch(){
 }
 
 //! Set CPU to Instruction Fetch
 void jtag430_setinstrfetch(){
+  
   jtag_ir_shift8(IR_CNTRL_SIG_CAPTURE);
 
   // Wait until instruction fetch state.
   jtag_ir_shift8(IR_CNTRL_SIG_CAPTURE);
 
   // Wait until instruction fetch state.
@@ -276,6 +282,8 @@ void jtag430handle(unsigned char app,
   unsigned long at;
   unsigned int i, val;
   
   unsigned long at;
   unsigned int i, val;
   
+  //debugstr("Classic MSP430 handler.");
+  
   switch(verb){
   case START:
     //Enter JTAG mode.
   switch(verb){
   case START:
     //Enter JTAG mode.
@@ -307,7 +315,11 @@ void jtag430handle(unsigned char app,
     blocks=(len>4?cmddata[4]:1);
     at=cmddatalong[0];
     
     blocks=(len>4?cmddata[4]:1);
     at=cmddatalong[0];
     
-    len=0x80;
+    //Fetch large blocks for bulk fetches,
+    //small blocks for individual peeks.
+    if(blocks>1)
+      len=0x80;
+    
     serial_tx(app);
     serial_tx(verb);
     serial_tx(len);
     serial_tx(app);
     serial_tx(verb);
     serial_tx(len);
@@ -315,18 +327,15 @@ void jtag430handle(unsigned char app,
     while(blocks--){
       for(i=0;i<len;i+=2){
        jtag430_resettap();
     while(blocks--){
       for(i=0;i<len;i+=2){
        jtag430_resettap();
-       delay(10);
+       //delay(10);
        
        val=jtag430_readmem(at);
        
        val=jtag430_readmem(at);
-               
+       
        at+=2;
        serial_tx(val&0xFF);
        serial_tx((val&0xFF00)>>8);
       }
     }
        at+=2;
        serial_tx(val&0xFF);
        serial_tx((val&0xFF00)>>8);
       }
     }
-    
-    
-    
     break;
   case JTAG430_WRITEMEM:
   case POKE:
     break;
   case JTAG430_WRITEMEM:
   case POKE:
@@ -335,7 +344,7 @@ void jtag430handle(unsigned char app,
     txdata(app,verb,2);
     break;
   case JTAG430_WRITEFLASH:
     txdata(app,verb,2);
     break;
   case JTAG430_WRITEFLASH:
-    debugstr("Poking flash memory.");
+    //debugstr("Poking flash memory.");
     jtag430_writeflash(cmddataword[0],cmddataword[2]);
     cmddataword[0]=jtag430_readmem(cmddataword[0]);
     txdata(app,verb,2);
     jtag430_writeflash(cmddataword[0],cmddataword[2]);
     cmddataword[0]=jtag430_readmem(cmddataword[0]);
     txdata(app,verb,2);
index d09683c..c310c0c 100644 (file)
@@ -36,6 +36,7 @@ void init(){
 void handle(unsigned char app,\r
            unsigned char verb,\r
            unsigned char len){\r
 void handle(unsigned char app,\r
            unsigned char verb,\r
            unsigned char len){\r
+  //debugstr("GoodFET");\r
   switch(app){\r
   case MONITOR:\r
     monitorhandle(app,verb,len);\r
   switch(app){\r
   case MONITOR:\r
     monitorhandle(app,verb,len);\r