7 //! Set the program counter.
8 void jtag430_setpc(unsigned int adr){
9 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
10 jtag_dr_shift16(0x3401);// release low byte
11 jtag_ir_shift8(IR_DATA_16BIT);
12 jtag_dr_shift16(0x4030);//Instruction to load PC
15 jtag_dr_shift16(adr);// Value for PC
17 jtag_ir_shift8(IR_ADDR_CAPTURE);
19 CLRTCLK ;// Now PC is set to "PC_Value"
20 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
21 jtag_dr_shift16(0x2401);// low byte controlled by JTAG
25 void jtag430_haltcpu(){
26 //jtag430_setinstrfetch();
28 jtag_ir_shift8(IR_DATA_16BIT);
29 jtag_dr_shift16(0x3FFF);//JMP $+0
32 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
33 jtag_dr_shift16(0x2409);//set JTAG_HALT bit
38 void jtag430_releasecpu(){
40 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
41 jtag_dr_shift16(0x2401);
42 jtag_ir_shift8(IR_ADDR_CAPTURE);
46 //! Read data from address
47 unsigned int jtag430_readmem(unsigned int adr){
51 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
53 jtag_dr_shift16(0x2409);//word read
55 jtag_dr_shift16(0x2419);//byte read
56 jtag_ir_shift8(IR_ADDR_16BIT);
57 jtag_dr_shift16(adr);//address
58 jtag_ir_shift8(IR_DATA_TO_ADDR);
62 toret=jtag_dr_shift16(0x0000);//16 bit return
67 //! Write data to address.
68 void jtag430_writemem(unsigned int adr, unsigned int data){
70 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
72 jtag_dr_shift16(0x2408);//word write
74 jtag_dr_shift16(0x2418);//byte write
75 jtag_ir_shift8(IR_ADDR_16BIT);
77 jtag_ir_shift8(IR_DATA_TO_ADDR);
78 jtag_dr_shift16(data);
82 //! Defined in jtag430asm.S
83 void jtag430_tclk_flashpulses(int);
84 /* //! Pulse TCLK at 350kHz +/- 100kHz */
85 /* void jtag430_tclk_flashpulses(register i){ */
86 /* //TODO check this on a scope. */
89 /* //At 2MHz, 350kHz is obtained with 5 clocks of delay */
92 /* What happens if the frequency is too low or to high? */
93 /* Is there any risk of damaging the chip, or only of a poor write? */
104 //! Write data to flash memory. Must be preconfigured.
105 void jtag430_writeflashword(unsigned int adr, unsigned int data){
108 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
109 jtag_dr_shift16(0x2408);//word write
110 jtag_ir_shift8(IR_ADDR_16BIT);
111 jtag_dr_shift16(adr);
112 jtag_ir_shift8(IR_DATA_TO_ADDR);
113 jtag_dr_shift16(data);
116 //Return to read mode.
118 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
119 jtag_dr_shift16(0x2409);
122 jtag430_writemem(adr,data);
124 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
125 jtag_dr_shift16(0x2409);
128 jtag430_tclk_flashpulses(35); //35 standard
132 //! Configure flash, then write a word.
133 void jtag430_writeflash(unsigned int adr, unsigned int data){
136 //FCTL1=0xA540, enabling flash write
137 jtag430_writemem(0x0128, 0xA540);
138 //FCTL2=0xA540, selecting MCLK as source, DIV=1
139 jtag430_writemem(0x012A, 0xA540);
140 //FCTL3=0xA500, should be 0xA540 for Info Seg A on 2xx chips.
141 jtag430_writemem(0x012C, 0xA500);
143 //Write the word itself.
144 jtag430_writeflashword(adr,data);
146 //FCTL1=0xA500, disabling flash write
147 jtag430_writemem(0x0128, 0xA500);
149 jtag430_releasecpu();
154 #define ERASE_GLOB 0xA50E
155 #define ERASE_ALLMAIN 0xA50C
156 #define ERASE_MASS 0xA506
157 #define ERASE_MAIN 0xA504
158 #define ERASE_SGMT 0xA502
160 //! Configure flash, then write a word.
161 void jtag430_eraseflash(unsigned int mode, unsigned int adr, unsigned int count){
163 jtag430_writemem(0x0128, mode);
164 //FCTL2=0xA540, selecting MCLK as source, DIV=1
165 jtag430_writemem(0x012A, 0xA540);
166 //FCTL3=0xA500, should be 0xA540 for Info Seg A on 2xx chips.
167 jtag430_writemem(0x012C, 0xA500);
169 //Write the erase word.
170 jtag430_writemem(adr, 0x55AA);
171 //Return to read mode.
173 jtag_ir_shift8(IR_CNTRL_SIG_16BIT);
174 jtag_dr_shift16(0x2409);
177 jtag430_tclk_flashpulses(count);
179 //FCTL1=0xA500, disabling flash write
180 jtag430_writemem(0x0128, 0xA500);
184 //! Reset the TAP state machine.
185 void jtag430_resettap(){
192 // Navigate to reset state.
193 // Should be at least six.
208 Sometimes this isn't necessary. */
220 //! Start JTAG, take pins
221 void jtag430_start(){
224 //Known-good starting position.
225 //Might be unnecessary.
230 //Entry sequence from Page 67 of SLAU265A for 4-wire MSP430 JTAG
242 //! Set CPU to Instruction Fetch
243 void jtag430_setinstrfetch(){
244 jtag_ir_shift8(IR_CNTRL_SIG_CAPTURE);
246 // Wait until instruction fetch state.
248 if (jtag_dr_shift16(0x0000) & 0x0080)
255 //! Handles unique MSP430 JTAG commands. Forwards others to JTAG.
256 void jtag430handle(unsigned char app,
264 //TAP setup, fuse check
268 case JTAG430_HALTCPU:
272 case JTAG430_RELEASECPU:
273 jtag430_releasecpu();
276 case JTAG430_SETINSTRFETCH:
277 jtag430_setinstrfetch();
282 case JTAG430_READMEM:
284 cmddataword[0]=jtag430_readmem(cmddataword[0]);
287 case JTAG430_WRITEMEM:
289 jtag430_writemem(cmddataword[0],cmddataword[1]);
290 cmddataword[0]=jtag430_readmem(cmddataword[0]);
293 case JTAG430_WRITEFLASH:
294 jtag430_writeflash(cmddataword[0],cmddataword[1]);
295 cmddataword[0]=jtag430_readmem(cmddataword[0]);
298 case JTAG430_ERASEFLASH:
299 jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
300 jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
301 jtag430_eraseflash(ERASE_MASS,0xFFFE,0xFFFF);
305 jtag430_setpc(cmddataword[0]);
309 jtaghandle(app,verb,len);