2 \author Travis Goodspeed <travis at radiantmachines.com>
4 This is an implementation of the MSP430X2 JTAG protocol
5 for the GoodFET project at http://goodfet.sf.net/
7 See the license file for details of proper use.
17 unsigned char jtag430x2_jtagid(){
19 return jtagid=jtag_ir_shift8(IR_BYPASS);
21 //! Start JTAG, take pins
22 unsigned char jtag430x2_start(){
25 //Known-good starting position.
26 //Might be unnecessary.
32 //Entry sequence from Page 67 of SLAU265A for 4-wire MSP430 JTAG
45 //Perform a reset and disable watchdog.
46 return jtag430x2_jtagid();
49 unsigned int jtag430_coreid(){
50 jtag_ir_shift8(IR_COREIP_ID);
51 return jtag_dr_shift16(0);
54 unsigned long jtag430_deviceid(){
55 jtag_ir_shift8(IR_DEVICE_ID);
56 return jtag_dr_shift20(0);
59 //! Set the program counter.
60 void jtag430x2_setpc(unsigned long pc){
67 Mova += (unsigned short)((pc>>8) & 0x00000F00);
68 Pc_l = (unsigned short)((pc & 0xFFFF));
70 // Check Full-Emulation-State at the beginning
71 jtag_ir_shift8(IR_CNTRL_SIG_CAPTURE);
72 if(jtag_dr_shift16(0) & 0x0301){
75 // take over bus control during clock LOW phase
76 jtag_ir_shift8(IR_DATA_16BIT);
78 jtag_dr_shift16(Mova);
79 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
80 jtag_dr_shift16(0x1400);
81 jtag_ir_shift8(IR_DATA_16BIT);
84 jtag_dr_shift16(Pc_l);
87 jtag_dr_shift16(0x4303);
89 jtag_ir_shift8(IR_ADDR_CAPTURE);
90 jtag_dr_shift20(0x00000);
92 while(1) P1OUT^=1; //Lock LED if locked up.
97 //! Read data from address
98 unsigned int jtag430x2_readmem(unsigned int adr){
101 jtag430x2_setpc(adr);
103 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
104 jtag_dr_shift16(0x0501);
105 jtag_ir_shift8(IR_ADDR_CAPTURE);
107 jtag_ir_shift8(IR_DATA_QUICK);
111 toret = jtag_dr_shift16(0);//read
113 jtag_ir_shift8(IR_CNTRL_SIG_CAPTURE);
119 //! Handles classic MSP430 JTAG commands. Forwards others to JTAG.
120 void jtag430x2handle(unsigned char app,
127 do cmddata[0]=jtag430x2_start();
128 while(cmddata[0]==00 || cmddata[0]==0xFF);
131 if(jtagid==MSP430JTAGID){
132 jtag430mode=MSP430MODE;
134 }else if(jtagid==MSP430X2JTAGID){
135 jtag430mode=MSP430X2MODE;
142 //TAP setup, fuse check
143 //jtag430_resettap();
146 case JTAG430_READMEM:
148 cmddataword[0]=jtag430x2_readmem(cmddataword[0]);
149 //cmddataword[0]=jtag430_readmem(cmddataword[0]);
152 case JTAG430_COREIP_ID:
153 cmddataword[0]=jtag430_coreid();
156 case JTAG430_DEVICE_ID:
157 cmddatalong[0]=jtag430_deviceid();
160 case JTAG430_HALTCPU:
161 case JTAG430_RELEASECPU:
162 case JTAG430_SETINSTRFETCH:
163 case JTAG430_WRITEMEM:
165 case JTAG430_WRITEFLASH:
166 case JTAG430_ERASEFLASH:
169 jtaghandle(app,verb,len);