Repair of 16-bit MSP430 JTAG nearly complete, dump works well.
[goodfet] / firmware / apps / jtag / jtag430.c
index d518ca1..9260b0c 100644 (file)
@@ -1,3 +1,7 @@
+/*! \file jtag430.c
+  \author Travis Goodspeed <travis at radiantmachines.com>
+  \brief MSP430 JTAG (16-bit)
+*/
 
 #include "platform.h"
 #include "command.h"
@@ -51,6 +55,7 @@ unsigned int jtag430_readmem(unsigned int adr){
   
   CLRTCLK;
   jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
+  
   if(adr>0xFF)
     jtag_dr_shift16(0x2409);//word read
   else
@@ -81,7 +86,6 @@ void jtag430_writemem(unsigned int adr, unsigned int data){
   SETTCLK;
 }
 
-
 //! Write data to flash memory.  Must be preconfigured.
 void jtag430_writeflashword(unsigned int adr, unsigned int data){
   /*
@@ -191,8 +195,9 @@ void jtag430_eraseflash(unsigned int mode, unsigned int adr, unsigned int count)
 void jtag430_resettap(){
   int i;
   // Settle output
+  SETTDI; //430X2
   SETTMS;
-  SETTDI;
+  //SETTDI; //classic
   SETTCK;
 
   // Navigate to reset state.
@@ -211,7 +216,7 @@ void jtag430_resettap(){
 
     
   /* sacred, by spec.
-     Sometimes this isn't necessary. */
+     Sometimes this isn't necessary.  */
   // fuse check
   CLRTMS;
   delay(50);
@@ -235,11 +240,11 @@ void jtag430_start(){
   
   //Entry sequence from Page 67 of SLAU265A for 4-wire MSP430 JTAG
   CLRRST;
-  delay(100);
+  delay(100); //100
   CLRTST;
-  delay(50);
+  delay(50);  //50
   SETTST;
-  delay(50);
+  delay(50);  //50
   SETRST;
   P5DIR&=~RST;
   delay(0xFFFF);
@@ -266,6 +271,9 @@ void jtag430_setinstrfetch(){
 void oldjtag430handle(unsigned char app,
                   unsigned char verb,
                   unsigned char len){
+  register char blocks;
+  unsigned long at;
+  unsigned int i, val;
   
   switch(verb){
   case START:
@@ -273,6 +281,7 @@ void oldjtag430handle(unsigned char app,
     jtag430_start();
     //TAP setup, fuse check
     jtag430_resettap();
+    
     txdata(app,verb,0);
     break;
   case JTAG430_HALTCPU:
@@ -287,17 +296,41 @@ void oldjtag430handle(unsigned char app,
     jtag430_setinstrfetch();
     txdata(app,verb,0);
     break;
-
     
   case JTAG430_READMEM:
   case PEEK:
+    /*
     cmddataword[0]=jtag430_readmem(cmddataword[0]);
     txdata(app,verb,2);
+    */
+    blocks=(len>4?cmddata[4]:1);
+    at=cmddatalong[0];
+    
+    len=0x80;
+    serial_tx(app);
+    serial_tx(verb);
+    serial_tx(len);
+    
+    while(blocks--){
+      for(i=0;i<len;i+=2){
+       jtag430_resettap();
+       delay(10);
+       
+       val=jtag430_readmem(at);
+               
+       at+=2;
+       serial_tx(val&0xFF);
+       serial_tx((val&0xFF00)>>8);
+      }
+    }
+    
+    
+    
     break;
   case JTAG430_WRITEMEM:
   case POKE:
-    jtag430_writemem(cmddataword[0],cmddataword[1]);
-    cmddataword[0]=jtag430_readmem(cmddataword[0]);
+    jtag430_writemem(cmddatalong[0],cmddataword[2]);
+    cmddataword[0]=jtag430_readmem(cmddatalong[0]);
     txdata(app,verb,2);
     break;
   case JTAG430_WRITEFLASH:
@@ -315,6 +348,14 @@ void oldjtag430handle(unsigned char app,
     jtag430_setpc(cmddataword[0]);
     txdata(app,verb,0);
     break;
+    
+  case JTAG430_COREIP_ID:
+  case JTAG430_DEVICE_ID:
+    cmddataword[0]=0;
+    cmddataword[1]=0;
+    txdata(app,verb,4);
+    break;
+    
   default:
     jtaghandle(app,verb,len);
   }