//! Handles classic MSP430 JTAG commands. Forwards others to JTAG.
void jtag430_handle_fn(uint8_t const app,
- uint8_t const verb,
- uint32_t const len);
+ uint8_t const verb,
+ uint32_t const len);
// define the jtag430 app's app_t
app_t const jtag430_app = {
-
- /* app number */
- JTAG430,
-
- /* handle fn */
- jtag430_handle_fn,
-
- /* name */
- "JTAG430",
-
- /* desc */
- "\tThe JTAG430 app adds to the basic JTAG app\n"
- "\tsupport for JTAG'ing MSP430 devices.\n"
+ /* app number */
+ JTAG430,
+
+ /* handle fn */
+ jtag430_handle_fn,
+
+ /* name */
+ "JTAG430",
+
+ /* desc */
+ "\tThe JTAG430 app adds to the basic JTAG app\n"
+ "\tsupport for JTAG'ing MSP430 devices.\n"
};
unsigned int jtag430mode=MSP430X2MODE;
//! Power-On Reset
void jtag430_por(){
- unsigned int jtagid;
-
// Perform Reset
jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
jtag_dr_shift16(0x2C01); // apply
}
+
+//! Get the JTAG ID
+unsigned char jtag430x2_jtagid(){
+ jtag430_resettap();
+ jtagid=jtag_ir_shift8(IR_BYPASS);
+ if(jtagid!=0x89 && jtagid!=0x91){
+ debugstr("Unknown JTAG ID");
+ debughex(jtagid);
+ }
+ return jtagid;
+}
+//! Start JTAG, take pins
+unsigned char jtag430x2_start(){
+ jtagsetup();
+
+ //Known-good starting position.
+ //Might be unnecessary.
+ SETTST;
+ SETRST;
+
+ delay(0xFFFF);
+
+ //Entry sequence from Page 67 of SLAU265A for 4-wire MSP430 JTAG
+ CLRRST;
+ delay(20);//10
+ CLRTST;
+
+ delay(10);//5
+ SETTST;
+ msdelay(10);//5
+ SETRST;
+ P5DIR&=~RST;
+
+ delay(0xFFFF);
+
+ //Perform a reset and disable watchdog.
+ return jtag430x2_jtagid();
+}
+
+
//! Start JTAG, take pins
void jtag430_start(){
jtagsetup();
}
+
+
+
//! Handles classic MSP430 JTAG commands. Forwards others to JTAG.
void jtag430_handle_fn(uint8_t const app,
- uint8_t const verb,
- uint32_t const len)
+ uint8_t const verb,
+ uint32_t const len)
{
unsigned long at, l;
unsigned int i, val;
* chip ID cannot be read. Should print warning
* for testing server.
*/
- while((i=jtag430_readmem(0xff0))==0xFFFF){
- debugstr("Reconnecting to target MSP430.");
- jtag430_start();
- PLEDOUT^=PLEDPIN;
- }
+ if (jtagid!=0)
+ while((i=jtag430_readmem(0xff0))==0xFFFF){
+ debugstr("Reconnecting to target MSP430.");
+ jtag430x2_start();
+ PLEDOUT^=PLEDPIN;
+ }
PLEDOUT&=~PLEDPIN;
switch(verb){
case START:
- //Enter JTAG mode.
- jtag430_start();
- //TAP setup, fuse check
- jtag430_resettap();
+ debugstr("Using JTAG430 (instead of JTAG430X2)!");
+
+ jtag430x2_start();
+ cmddata[0]=jtagid;
+
+ jtag430mode=MSP430MODE;
+
+ /* So the way this works is that a width of 20 does some
+ backward-compatibility finagling, causing the correct value
+ to be exchanged for addresses on 16-bit chips as well as the
+ new MSP430X chips. (This has only been verified on the
+ MSP430F2xx family. TODO verify for others.)
+ */
+
+ drwidth=20;
+
+ //Perform a reset and disable watchdog.
+ jtag430_por();
+ jtag430_writemem(0x120,0x5a80);//disable watchdog
- cmddata[0]=jtag_ir_shift8(IR_BYPASS);
+ jtag430_haltcpu();
+
+ jtag430_resettap();
txdata(app,verb,1);
-
+
break;
case STOP:
jtag430_stop();
cmddataword[0]=jtag430_readmem(cmddataword[0]);
txdata(app,verb,2);
break;
- /*
- case JTAG430_WRITEFLASH:
-
- //debugstr("Poking flash memory.");
- jtag430_writeflash(cmddataword[0],cmddataword[2]);
-
- //Try again if failure.
- //if(cmddataword[2]!=jtag430_readmem(cmddataword[0]))
- // jtag430_writeflash(cmddataword[0],cmddataword[2]);
-
- //Return result.
- cmddataword[0]=jtag430_readmem(cmddataword[0]);
-
- txdata(app,verb,2);
- break; */
case JTAG430_WRITEFLASH:
at=cmddataword[0];
txdata(app,verb,2);
break;
case JTAG430_COREIP_ID:
+ //cmddataword[0]=jtag430_coreid();
+ cmddataword[0]=0xdead;
+ txdata(app,verb,2);
+ break;
case JTAG430_DEVICE_ID:
- cmddataword[0]=0;
- cmddataword[1]=0;
+ //cmddatalong[0]=jtag430_deviceid();
+ cmddataword[0]=0xdead;
+ cmddataword[1]=0xbeef;
txdata(app,verb,4);
break;
-
default:
(*(jtag_app.handle))(app,verb,len);
}