X-Git-Url: http://git.rot13.org/?p=goodfet;a=blobdiff_plain;f=firmware%2Fapps%2Fjtag%2Fjtag430.c;h=d937b4d42bba208e2c79be59bd42c63b3dc84955;hp=081fb52427368ba49aa95e39d7d24850c8bb5dca;hb=ae09939eb8c62c83f244527e7916cee5f9145e6c;hpb=7487b2cd89324081ccfc195d49f4158f10ec534f diff --git a/firmware/apps/jtag/jtag430.c b/firmware/apps/jtag/jtag430.c index 081fb52..d937b4d 100644 --- a/firmware/apps/jtag/jtag430.c +++ b/firmware/apps/jtag/jtag430.c @@ -1,9 +1,15 @@ +/*! \file jtag430.c + \author Travis Goodspeed + \brief MSP430 JTAG (16-bit) +*/ #include "platform.h" #include "command.h" #include "jtag.h" +unsigned int jtag430mode=MSP430X2MODE; + //! Set the program counter. void jtag430_setpc(unsigned int adr){ jtag_ir_shift8(IR_CNTRL_SIG_16BIT); @@ -49,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 @@ -79,28 +86,6 @@ void jtag430_writemem(unsigned int adr, unsigned int data){ SETTCLK; } -//! Defined in jtag430asm.S -void jtag430_tclk_flashpulses(int); -/* //! Pulse TCLK at 350kHz +/- 100kHz */ -/* void jtag430_tclk_flashpulses(register i){ */ -/* //TODO check this on a scope. */ -/* register j=0; */ - -/* //At 2MHz, 350kHz is obtained with 5 clocks of delay */ - -/* /\** Pondering: */ -/* What happens if the frequency is too low or to high? */ -/* Is there any risk of damaging the chip, or only of a poor write? */ -/* *\/ */ -/* while(j++!=i){ */ -/* SETTCLK; */ -/* _NOP(); */ -/* _NOP(); */ -/* _NOP(); */ -/* CLRTCLK; */ -/* } */ -/* } */ - //! Write data to flash memory. Must be preconfigured. void jtag430_writeflashword(unsigned int adr, unsigned int data){ /* @@ -151,6 +136,27 @@ void jtag430_writeflash(unsigned int adr, unsigned int data){ +//! Power-On Reset +void jtag430_por(){ + unsigned int jtagid; + + // Perform Reset + jtag_ir_shift8(IR_CNTRL_SIG_16BIT); + jtag_dr_shift16(0x2C01); // apply + jtag_dr_shift16(0x2401); // remove + CLRTCLK; + SETTCLK; + CLRTCLK; + SETTCLK; + CLRTCLK; + jtagid = jtag_ir_shift8(IR_ADDR_CAPTURE); // get JTAG identifier + SETTCLK; + + jtag430_writemem(0x0120, 0x5A80); // Diabled Watchdog +} + + + #define ERASE_GLOB 0xA50E #define ERASE_ALLMAIN 0xA50C #define ERASE_MASS 0xA506 @@ -159,6 +165,8 @@ void jtag430_writeflash(unsigned int adr, unsigned int data){ //! Configure flash, then write a word. void jtag430_eraseflash(unsigned int mode, unsigned int adr, unsigned int count){ + jtag430_haltcpu(); + //FCTL1= erase mode jtag430_writemem(0x0128, mode); //FCTL2=0xA540, selecting MCLK as source, DIV=1 @@ -178,6 +186,8 @@ void jtag430_eraseflash(unsigned int mode, unsigned int adr, unsigned int count) //FCTL1=0xA500, disabling flash write jtag430_writemem(0x0128, 0xA500); + + jtag430_releasecpu(); } @@ -185,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. @@ -205,7 +216,7 @@ void jtag430_resettap(){ /* sacred, by spec. - Sometimes this isn't necessary. */ + Sometimes this isn't necessary. */ // fuse check CLRTMS; delay(50); @@ -237,6 +248,9 @@ void jtag430_start(){ SETRST; P5DIR&=~RST; delay(0xFFFF); + + //Perform a reset and disable watchdog. + jtag430_por(); } //! Set CPU to Instruction Fetch @@ -252,17 +266,19 @@ void jtag430_setinstrfetch(){ } } -//! Handles unique MSP430 JTAG commands. Forwards others to JTAG. -void jtag430handle(unsigned char app, + +//! Handles classic MSP430 JTAG commands. Forwards others to JTAG. +void oldjtag430handle(unsigned char app, unsigned char verb, unsigned char len){ - unsigned char i; + switch(verb){ case START: //Enter JTAG mode. jtag430_start(); //TAP setup, fuse check jtag430_resettap(); + txdata(app,verb,0); break; case JTAG430_HALTCPU: @@ -277,7 +293,6 @@ void jtag430handle(unsigned char app, jtag430_setinstrfetch(); txdata(app,verb,0); break; - case JTAG430_READMEM: case PEEK: @@ -286,8 +301,8 @@ void jtag430handle(unsigned char app, 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: @@ -311,3 +326,16 @@ void jtag430handle(unsigned char app, 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); + } +}