//! Read data from address
unsigned int jtag430_readmem(unsigned int adr){
unsigned int toret;
+ jtag430_haltcpu();
+
CLRTCLK;
jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
//! Write data to flash memory. Must be preconfigured.
void jtag430_writeflashword(unsigned int adr, unsigned int data){
- /*
+
CLRTCLK;
jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
jtag_dr_shift16(0x2408);//word write
CLRTCLK;
jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
jtag_dr_shift16(0x2409);
- */
+ /*
jtag430_writemem(adr,data);
CLRTCLK;
jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
jtag_dr_shift16(0x2409);
+ */
//Pulse TCLK
jtag430_tclk_flashpulses(35); //35 standard
//FCTL2=0xA540, selecting MCLK as source, DIV=1
jtag430_writemem(0x012A, 0xA540);
//FCTL3=0xA500, should be 0xA540 for Info Seg A on 2xx chips.
- jtag430_writemem(0x012C, 0xA500);
+ jtag430_writemem(0x012C, 0xA500); //all but info flash.
//Write the word itself.
jtag430_writeflashword(adr,data);
//FCTL1=0xA500, disabling flash write
jtag430_writemem(0x0128, 0xA500);
- jtag430_releasecpu();
+ //jtag430_releasecpu();
}
//FCTL1=0xA500, disabling flash write
jtag430_writemem(0x0128, 0xA500);
- jtag430_releasecpu();
+ //jtag430_releasecpu();
}
//Perform a reset and disable watchdog.
jtag430_por();
+ jtag430_writemem(0x120,0x5a80);//disable watchdog
+
+ jtag430_haltcpu();
}
//! Set CPU to Instruction Fetch
void jtag430_setinstrfetch(){
+
jtag_ir_shift8(IR_CNTRL_SIG_CAPTURE);
// Wait until instruction fetch state.
//! Handles classic MSP430 JTAG commands. Forwards others to JTAG.
-void oldjtag430handle(unsigned char app,
+void jtag430handle(unsigned char app,
unsigned char verb,
unsigned char len){
register char blocks;
unsigned long at;
unsigned int i, val;
+ //debugstr("Classic MSP430 handler.");
+
switch(verb){
case START:
//Enter JTAG mode.
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);
while(blocks--){
for(i=0;i<len;i+=2){
jtag430_resettap();
- delay(10);
+ //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(cmddatalong[0],cmddataword[2]);
- cmddataword[0]=jtag430_readmem(cmddatalong[0]);
+ jtag430_writemem(cmddataword[0],cmddataword[2]);
+ cmddataword[0]=jtag430_readmem(cmddataword[0]);
txdata(app,verb,2);
break;
case JTAG430_WRITEFLASH:
- jtag430_writeflash(cmddataword[0],cmddataword[1]);
+ //debugstr("Poking flash memory.");
+ jtag430_writeflash(cmddataword[0],cmddataword[2]);
cmddataword[0]=jtag430_readmem(cmddataword[0]);
txdata(app,verb,2);
break;
}
jtag430_resettap();
}
-
-//! Handles unique MSP430 JTAG commands. Forwards others to JTAG.
-void jtag430handle(unsigned char app,
- unsigned char verb,
- unsigned char len){
- switch(jtag430mode){
- case MSP430MODE:
- return oldjtag430handle(app,verb,len);
- case MSP430X2MODE:
- return jtag430x2handle(app,verb,len);
- default:
- txdata(app,NOK,0);
- }
-}