1 /***************************************************************************
2 * Copyright (C) 2011 by Rodrigo L. Rosa *
3 * rodrigorosa.LG@gmail.com *
5 * Based on dsp563xx_once.h written by Mathias Kuester *
6 * mkdorg@users.sourceforge.net *
8 * This program is free software; you can redistribute it and/or modify *
9 * it under the terms of the GNU General Public License as published by *
10 * the Free Software Foundation; either version 2 of the License, or *
11 * (at your option) any later version. *
13 * This program is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
16 * GNU General Public License for more details. *
18 * You should have received a copy of the GNU General Public License *
19 * along with this program; if not, write to the *
20 * Free Software Foundation, Inc., *
21 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
22 ***************************************************************************/
28 #include "target_type.h"
29 #include "dsp5680xx.h"
31 struct dsp5680xx_common dsp5680xx_context
;
33 #define _E "DSP5680XX_ERROR:%d\nAt:%s:%d:%s"
34 #define err_check(r, c, m) if (r != ERROR_OK) {LOG_ERROR(_E, c, __func__, __LINE__, m); return r; }
35 #define err_check_propagate(retval) if (retval != ERROR_OK) return retval;
36 #define DEBUG_MSG "Debug mode be enabled to read mem."
37 #define DEBUG_FAIL { err_check(ERROR_FAIL, DSP5680XX_ERROR_NOT_IN_DEBUG, DEBUG_MSG) }
38 #define CHECK_DBG if (!dsp5680xx_context.debug_mode_enabled) DEBUG_FAIL
39 #define HALT_MSG "Target must be halted."
40 #define HALT_FAIL { err_check(ERROR_FAIL, DSP5680XX_ERROR_TARGET_RUNNING, HALT_MSG) }
41 #define CHECK_HALT(target) if (target->state != TARGET_HALTED) HALT_FAIL
42 #define check_halt_and_debug(target) { CHECK_HALT(target); CHECK_DBG; }
44 int dsp5680xx_execute_queue(void){
46 retval
= jtag_execute_queue();
53 static int reset_jtag(void){
55 tap_state_t states
[2];
56 const char *cp
= "RESET";
57 states
[0] = tap_state_by_name(cp
);
58 retval
= jtag_add_statemove(states
[0]);
59 err_check_propagate(retval
);
60 retval
= jtag_execute_queue();
61 err_check_propagate(retval
);
62 jtag_add_pathmove(0, states
+ 1);
63 retval
= jtag_execute_queue();
67 static int dsp5680xx_drscan(struct target
* target
, uint8_t * data_to_shift_into_dr
, uint8_t * data_shifted_out_of_dr
, int len
){
68 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
71 // - data_to_shift_into_dr: This is the data that will be shifted into the JTAG DR reg.
72 // - data_shifted_out_of_dr: The data that will be shifted out of the JTAG DR reg will stored here
73 // - len: Length of the data to be shifted to JTAG DR.
75 // Note: If data_shifted_out_of_dr == NULL, discard incoming bits.
77 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
78 int retval
= ERROR_OK
;
79 if (NULL
== target
->tap
){
81 err_check(retval
, DSP5680XX_ERROR_JTAG_INVALID_TAP
, "Invalid tap");
85 err_check(retval
, DSP5680XX_ERROR_JTAG_DR_LEN_OVERFLOW
, "dr_len overflow, maxium is 32");
87 //TODO what values of len are valid for jtag_add_plain_dr_scan?
88 //can i send as many bits as i want?
89 //is the casting necessary?
90 jtag_add_plain_dr_scan(len
,data_to_shift_into_dr
,data_shifted_out_of_dr
, TAP_IDLE
);
91 if(dsp5680xx_context
.flush
){
92 retval
= dsp5680xx_execute_queue();
93 err_check(retval
, DSP5680XX_ERROR_JTAG_DRSCAN
, "drscan failed!");
95 if(data_shifted_out_of_dr
!=NULL
){
96 LOG_DEBUG("Data read (%d bits): 0x%04X",len
,*data_shifted_out_of_dr
);
98 LOG_DEBUG("Data read was discarded.");
102 /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
104 * - data_to_shift_into_ir: This is the data that will be shifted into the JTAG IR reg.
105 * - data_shifted_out_of_ir: The data that will be shifted out of the JTAG IR reg will be
107 * - len: Length of the data to be shifted to JTAG IR.
109 * -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
111 static int dsp5680xx_irscan(struct target
*target
, uint32_t *d_in
, uint32_t *d_out
, uint8_t ir_len
)
113 int retval
= ERROR_OK
;
114 uint16_t tap_ir_len
= DSP5680XX_JTAG_MASTER_TAP_IRLEN
;
115 if (NULL
== target
->tap
) {
117 err_check(retval
, DSP5680XX_ERROR_JTAG_INVALID_TAP
, "Invalid tap");
119 if (ir_len
!= target
->tap
->ir_length
) {
120 if (target
->tap
->enabled
) {
122 err_check(retval
, DSP5680XX_ERROR_INVALID_IR_LEN
, "Invalid irlen");
124 struct jtag_tap
*t
= jtag_tap_by_string("dsp568013.chp");
125 if ((t
== NULL
) || ((t
->enabled
) && (ir_len
!= tap_ir_len
))) {
127 err_check(retval
, DSP5680XX_ERROR_INVALID_IR_LEN
, "Invalid irlen");
131 jtag_add_plain_ir_scan(ir_len
, (uint8_t *)d_in
, (uint8_t *)d_out
, TAP_IDLE
);
132 if (dsp5680xx_context
.flush
) {
133 retval
= dsp5680xx_execute_queue();
134 err_check(retval
, DSP5680XX_ERROR_JTAG_IRSCAN
, "irscan failed!");
139 static int dsp5680xx_jtag_status(struct target
*target
, uint8_t * status
){
140 uint32_t read_from_ir
;
143 instr
= JTAG_INSTR_ENABLE_ONCE
;
144 retval
= dsp5680xx_irscan(target
, &instr
, &read_from_ir
, DSP5680XX_JTAG_CORE_TAP_IRLEN
);
145 err_check_propagate(retval
);
147 *status
= (uint8_t)read_from_ir
;
151 static int jtag_data_read(struct target
* target
, uint8_t * data_read
, int num_bits
){
152 uint32_t bogus_instr
= 0;
153 int retval
= dsp5680xx_drscan(target
,(uint8_t *) & bogus_instr
,data_read
,num_bits
);
154 LOG_DEBUG("Data read (%d bits): 0x%04X",num_bits
,*data_read
);//TODO remove this or move to jtagio?
158 #define jtag_data_read8(target,data_read) jtag_data_read(target,data_read,8)
159 #define jtag_data_read16(target,data_read) jtag_data_read(target,data_read,16)
160 #define jtag_data_read32(target,data_read) jtag_data_read(target,data_read,32)
162 static uint32_t data_read_dummy
;
163 static int jtag_data_write(struct target
* target
, uint32_t instr
,int num_bits
, uint32_t * data_read
){
165 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr
,(uint8_t *) & data_read_dummy
,num_bits
);
166 err_check_propagate(retval
);
167 if(data_read
!= NULL
)
168 *data_read
= data_read_dummy
;
172 #define jtag_data_write8(target,instr,data_read) jtag_data_write(target,instr,8,data_read)
173 #define jtag_data_write16(target,instr,data_read) jtag_data_write(target,instr,16,data_read)
174 #define jtag_data_write24(target,instr,data_read) jtag_data_write(target,instr,24,data_read)
175 #define jtag_data_write32(target,instr,data_read) jtag_data_write(target,instr,32,data_read)
178 * Executes EOnCE instruction.
181 * @param instr Instruction to execute.
185 * @param eonce_status Value read from the EOnCE status register.
189 static int eonce_instruction_exec_single(struct target
* target
, uint8_t instr
, uint8_t rw
, uint8_t go
, uint8_t ex
,uint8_t * eonce_status
){
192 uint8_t instr_with_flags
= instr
|(rw
<<7)|(go
<<6)|(ex
<<5);
193 retval
= jtag_data_write(target
, instr_with_flags
, 8, &dr_out_tmp
);
194 err_check_propagate(retval
);
195 if(eonce_status
!= NULL
)
196 *eonce_status
= (uint8_t) dr_out_tmp
;
200 ///wrappers for multi opcode instructions
201 #define dsp5680xx_exe_1(target,opcode1,opcode2,opcode3) dsp5680xx_exe1(target,opcode1)
202 #define dsp5680xx_exe_2(target,opcode1,opcode2,opcode3) dsp5680xx_exe2(target,opcode1,opcode2)
203 #define dsp5680xx_exe_3(target,opcode1,opcode2,opcode3) dsp5680xx_exe3(target,opcode1,opcode2,opcode3)
204 #define dsp5680xx_exe_generic(target,words,opcode1,opcode2,opcode3) dsp5680xx_exe_##words(target,opcode1,opcode2,opcode3)
206 /// Executes one word DSP instruction
207 static int dsp5680xx_exe1(struct target
* target
, uint16_t opcode
){
209 retval
= eonce_instruction_exec_single(target
,0x04,0,1,0,NULL
);
210 err_check_propagate(retval
);
211 retval
= jtag_data_write16(target
,opcode
,NULL
);
212 err_check_propagate(retval
);
216 /// Executes two word DSP instruction
217 static int dsp5680xx_exe2(struct target
* target
,uint16_t opcode1
, uint16_t opcode2
){
219 retval
= eonce_instruction_exec_single(target
,0x04,0,0,0,NULL
);
220 err_check_propagate(retval
);
221 retval
= jtag_data_write16(target
,opcode1
,NULL
);
222 err_check_propagate(retval
);
223 retval
= eonce_instruction_exec_single(target
,0x04,0,1,0,NULL
);
224 err_check_propagate(retval
);
225 retval
= jtag_data_write16(target
,opcode2
,NULL
);
226 err_check_propagate(retval
);
230 /// Executes three word DSP instruction
231 static int dsp5680xx_exe3(struct target
* target
, uint16_t opcode1
,uint16_t opcode2
,uint16_t opcode3
){
233 retval
= eonce_instruction_exec_single(target
,0x04,0,0,0,NULL
);
234 err_check_propagate(retval
);
235 retval
= jtag_data_write16(target
,opcode1
,NULL
);
236 err_check_propagate(retval
);
237 retval
= eonce_instruction_exec_single(target
,0x04,0,0,0,NULL
);
238 err_check_propagate(retval
);
239 retval
= jtag_data_write16(target
,opcode2
,NULL
);
240 err_check_propagate(retval
);
241 retval
= eonce_instruction_exec_single(target
,0x04,0,1,0,NULL
);
242 err_check_propagate(retval
);
243 retval
= jtag_data_write16(target
,opcode3
,NULL
);
244 err_check_propagate(retval
);
249 * --------------- Real-time data exchange ---------------
250 * The EOnCE Transmit (OTX) and Receive (ORX) registers are data memory mapped, each with an upper and lower 16 bit word.
251 * Transmit and receive directions are defined from the core’s perspective.
252 * The core writes to the Transmit register and reads the Receive register, and the host through JTAG writes to the Receive register and reads the Transmit register.
253 * Both registers have a combined data memory mapped OTXRXSR which provides indication when each may be accessed.
254 *ref: eonce_rev.1.0_0208081.pdf@36
257 /// writes data into upper ORx register of the target
258 static int core_tx_upper_data(struct target
* target
, uint16_t data
, uint32_t * eonce_status_low
){
260 retval
= eonce_instruction_exec_single(target
,DSP5680XX_ONCE_ORX1
,0,0,0,NULL
);
261 err_check_propagate(retval
);
262 retval
= jtag_data_write16(target
,data
,eonce_status_low
);
263 err_check_propagate(retval
);
267 /// writes data into lower ORx register of the target
268 #define core_tx_lower_data(target,data) eonce_instruction_exec_single(target,DSP5680XX_ONCE_ORX,0,0,0,NULL);\
269 jtag_data_write16(target,data)
274 * @param data_read: Returns the data read from the upper OTX register via JTAG.
275 * @return: Returns an error code (see error code documentation)
277 static int core_rx_upper_data(struct target
* target
, uint8_t * data_read
)
280 retval
= eonce_instruction_exec_single(target
,DSP5680XX_ONCE_OTX1
,1,0,0,NULL
);
281 err_check_propagate(retval
);
282 retval
= jtag_data_read16(target
,data_read
);
283 err_check_propagate(retval
);
290 * @param data_read: Returns the data read from the lower OTX register via JTAG.
291 * @return: Returns an error code (see error code documentation)
293 static int core_rx_lower_data(struct target
* target
,uint8_t * data_read
)
296 retval
= eonce_instruction_exec_single(target
,DSP5680XX_ONCE_OTX
,1,0,0,NULL
);
297 err_check_propagate(retval
);
298 retval
= jtag_data_read16(target
,data_read
);
299 err_check_propagate(retval
);
304 * -- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- --
305 * -- -- -- -- --- -- -- -Core Instructions- -- -- -- --- -- -- -- --- --
306 * -- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- -- -- -- --- --
310 #define core_move_long_to_r0(target,value) dsp5680xx_exe_generic(target,3,0xe418,value&0xffff,value>>16)
313 #define core_move_long_to_n(target,value) dsp5680xx_exe_generic(target,3,0xe41e,value&0xffff,value>>16)
316 #define core_move_at_r0_to_y0(target) dsp5680xx_exe_generic(target,1,0xF514,0,0)
319 #define core_move_at_r0_to_y1(target) dsp5680xx_exe_generic(target,1,0xF714,0,0)
322 #define core_move_long_at_r0_y(target) dsp5680xx_exe_generic(target,1,0xF734,0,0)
325 #define core_move_y0_at_r0(target) dsp5680xx_exe_generic(target,1,0xd514,0,0)
327 /// bfclr #value,x:(r0)
328 #define eonce_bfclr_at_r0(target,value) dsp5680xx_exe_generic(target,2,0x8040,value,0)
331 #define core_move_value_to_y0(target,value) dsp5680xx_exe_generic(target,2,0x8745,value,0)
333 /// move.w y0,x:(r0)+
334 #define core_move_y0_at_r0_inc(target) dsp5680xx_exe_generic(target,1,0xd500,0,0)
336 /// move.w y0,p:(r0)+
337 #define core_move_y0_at_pr0_inc(target) dsp5680xx_exe_generic(target,1,0x8560,0,0)
339 /// move.w p:(r0)+,y0
340 #define core_move_at_pr0_inc_to_y0(target) dsp5680xx_exe_generic(target,1,0x8568,0,0)
342 /// move.w p:(r0)+,y1
343 #define core_move_at_pr0_inc_to_y1(target) dsp5680xx_exe_generic(target,1,0x8768,0,0)
346 #define core_move_long_to_r2(target,value) dsp5680xx_exe_generic(target,3,0xe41A,value&0xffff,value>>16)
349 #define core_move_y0_at_r2(target) dsp5680xx_exe_generic(target,1,0xd516,0,0)
351 /// move.w #<value>,x:(r2)
352 #define core_move_value_at_r2(target,value) dsp5680xx_exe_generic(target,2,0x8642,value,0)
354 /// move.w #<value>,x:(r0)
355 #define core_move_value_at_r0(target,value) dsp5680xx_exe_generic(target,2,0x8640,value,0)
357 /// move.w #<value>,x:(R2+<disp>)
358 #define core_move_value_at_r2_disp(target,value,disp) dsp5680xx_exe_generic(target,3,0x8646,value,disp)
361 #define core_move_at_r2_to_y0(target) dsp5680xx_exe_generic(target,1,0xF516,0,0)
363 /// move.w p:(r2)+,y0
364 #define core_move_at_pr2_inc_to_y0(target) dsp5680xx_exe_generic(target,1,0x856A,0,0)
367 #define core_move_long_to_r1(target,value) dsp5680xx_exe_generic(target,3,0xE419,value&0xffff,value>>16)
370 #define core_move_long_to_r3(target,value) dsp5680xx_exe_generic(target,3,0xE41B,value&0xffff,value>>16)
372 /// move.w y0,p:(r3)+
373 #define core_move_y0_at_pr3_inc(target) dsp5680xx_exe_generic(target,1,0x8563,0,0)
376 #define core_move_y0_at_r3(target) dsp5680xx_exe_generic(target,1,0xD503,0,0)
379 #define core_move_long_to_r4(target,value) dsp5680xx_exe_generic(target,3,0xE41C,value&0xffff,value>>16)
382 #define core_move_pc_to_r4(target) dsp5680xx_exe_generic(target,1,0xE716,0,0)
385 #define core_move_r4_to_y(target) dsp5680xx_exe_generic(target,1,0xe764,0,0)
387 /// move.w p:(r0)+,y0
388 #define core_move_at_pr0_inc_to_y0(target) dsp5680xx_exe_generic(target,1,0x8568,0,0)
390 /// move.w x:(r0)+,y0
391 #define core_move_at_r0_inc_to_y0(target) dsp5680xx_exe_generic(target,1,0xf500,0,0)
394 #define core_move_at_r0_y0(target) dsp5680xx_exe_generic(target,1,0xF514,0,0)
397 #define eonce_nop(target) dsp5680xx_exe_generic(target,1,0xe700,0,0)
399 /// move.w x:(R2+<disp>),Y0
400 #define core_move_at_r2_disp_to_y0(target,disp) dsp5680xx_exe_generic(target,2,0xF542,disp,0)
403 #define core_move_y1_at_r2(target) dsp5680xx_exe_generic(target,1,0xd716,0,0)
406 #define core_move_y1_at_r0(target) dsp5680xx_exe_generic(target,1,0xd714,0,0)
408 /// move.bp y0,x:(r0)+
409 #define core_move_byte_y0_at_r0(target) dsp5680xx_exe_generic(target,1,0xd5a0,0,0)
411 /// move.w y1,p:(r0)+
412 #define core_move_y1_at_pr0_inc(target) dsp5680xx_exe_generic(target,1,0x8760,0,0)
414 /// move.w y1,x:(r0)+
415 #define core_move_y1_at_r0_inc(target) dsp5680xx_exe_generic(target,1,0xD700,0,0)
418 #define core_move_long_to_y(target,value) dsp5680xx_exe_generic(target,3,0xe417,value&0xffff,value>>16)
420 static int core_move_value_to_pc(struct target
* target
, uint32_t value
){
421 check_halt_and_debug(target
);
423 retval
= dsp5680xx_exe_generic(target
,3,0xE71E,value
&0xffff,value
>>16);
424 err_check_propagate(retval
);
428 static int eonce_load_TX_RX_to_r0(struct target
* target
)
431 retval
= core_move_long_to_r0(target
,((MC568013_EONCE_TX_RX_ADDR
)+(MC568013_EONCE_OBASE_ADDR
<<16)));
435 static int core_load_TX_RX_high_addr_to_r0(struct target
* target
)
438 retval
= core_move_long_to_r0(target
,((MC568013_EONCE_TX1_RX1_HIGH_ADDR
)+(MC568013_EONCE_OBASE_ADDR
<<16)));
442 static int dsp5680xx_read_core_reg(struct target
* target
, uint8_t reg_addr
, uint16_t * data_read
)
444 //TODO implement a general version of this which matches what openocd uses.
446 uint32_t dummy_data_to_shift_into_dr
;
447 retval
= eonce_instruction_exec_single(target
,reg_addr
,1,0,0,NULL
);
448 err_check_propagate(retval
);
449 retval
= dsp5680xx_drscan(target
,(uint8_t *)& dummy_data_to_shift_into_dr
,(uint8_t *) data_read
, 8);
450 err_check_propagate(retval
);
451 LOG_DEBUG("Reg. data: 0x%02X.",*data_read
);
455 static int eonce_read_status_reg(struct target
* target
, uint16_t * data
){
457 retval
= dsp5680xx_read_core_reg(target
,DSP5680XX_ONCE_OSR
,data
);
458 err_check_propagate(retval
);
463 * Takes the core out of debug mode.
466 * @param eonce_status Data read from the EOnCE status register.
470 static int eonce_exit_debug_mode(struct target
* target
,uint8_t * eonce_status
){
472 retval
= eonce_instruction_exec_single(target
,0x1F,0,0,1,eonce_status
);
473 err_check_propagate(retval
);
477 static int switch_tap(struct target
* target
, struct jtag_tap
* master_tap
,struct jtag_tap
* core_tap
){
478 int retval
= ERROR_OK
;
480 uint32_t ir_out
;//not used, just to make jtag happy.
481 if(master_tap
== NULL
){
482 master_tap
= jtag_tap_by_string("dsp568013.chp");
483 if(master_tap
== NULL
){
485 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER
, "Failed to get master tap.");
488 if(core_tap
== NULL
){
489 core_tap
= jtag_tap_by_string("dsp568013.cpu");
490 if(core_tap
== NULL
){
492 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE
, "Failed to get core tap.");
496 if(!(((int)master_tap
->enabled
) ^ ((int)core_tap
->enabled
))){
497 LOG_WARNING("Wrong tap enabled/disabled status:\nMaster tap:%d\nCore Tap:%d\nOnly one tap should be enabled at a given time.\n",(int)master_tap
->enabled
,(int)core_tap
->enabled
);
500 if(master_tap
->enabled
){
502 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_MASTER_TAP_IRLEN
);
503 err_check_propagate(retval
);
505 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr
,(uint8_t *) & ir_out
,4);
506 err_check_propagate(retval
);
507 core_tap
->enabled
= true;
508 master_tap
->enabled
= false;
511 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_CORE_TAP_IRLEN
);
512 err_check_propagate(retval
);
514 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr
,(uint8_t *) & ir_out
,4);
515 err_check_propagate(retval
);
516 core_tap
->enabled
= false;
517 master_tap
->enabled
= true;
523 * Puts the core into debug mode, enabling the EOnCE module.
524 * This will not always work, eonce_enter_debug_mode executes much
525 * more complicated routine, which is guaranteed to work, but requires
526 * a reset. This will complicate comm with the flash module, since
527 * after a reset clock divisors must be set again.
528 * This implementation works most of the time, and is not accesible to the
532 * @param eonce_status Data read from the EOnCE status register.
536 static int eonce_enter_debug_mode_without_reset(struct target
* target
, uint16_t * eonce_status
){
538 uint32_t instr
= JTAG_INSTR_DEBUG_REQUEST
;
539 uint32_t ir_out
;//not used, just to make jtag happy.
541 retval
= dsp5680xx_irscan(target
, &instr
, &ir_out
, DSP5680XX_JTAG_CORE_TAP_IRLEN
);
542 err_check_propagate(retval
);
544 // Enable EOnCE module
545 instr
= JTAG_INSTR_ENABLE_ONCE
;
546 //Two rounds of jtag 0x6 (enable eonce) to enable EOnCE.
547 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_CORE_TAP_IRLEN
);
548 err_check_propagate(retval
);
549 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_CORE_TAP_IRLEN
);
550 err_check_propagate(retval
);
551 if ((ir_out
&JTAG_STATUS_MASK
) == JTAG_STATUS_DEBUG
)
552 target
->state
= TARGET_HALTED
;
555 err_check_propagate(retval
);
557 // Verify that debug mode is enabled
558 uint16_t data_read_from_dr
;
559 retval
= eonce_read_status_reg(target
, &data_read_from_dr
);
560 err_check_propagate(retval
);
561 if ((data_read_from_dr
&0x30) == 0x30) {
562 LOG_DEBUG("EOnCE successfully entered debug mode.");
563 dsp5680xx_context
.debug_mode_enabled
= true;
566 dsp5680xx_context
.debug_mode_enabled
= false;
567 retval
= ERROR_TARGET_FAILURE
;
569 * No error msg here, since there is still hope with full halting sequence
571 err_check_propagate(retval
);
573 if (eonce_status
!= NULL
)
574 *eonce_status
= data_read_from_dr
;
579 * Puts the core into debug mode, enabling the EOnCE module.
582 * @param eonce_status Data read from the EOnCE status register.
586 static int eonce_enter_debug_mode(struct target
* target
, uint16_t * eonce_status
){
587 int retval
= ERROR_OK
;
588 uint32_t instr
= JTAG_INSTR_DEBUG_REQUEST
;
589 uint32_t ir_out
;//not used, just to make jtag happy.
593 // First try the easy way
594 retval
= eonce_enter_debug_mode_without_reset(target
,eonce_status
);
595 if(retval
== ERROR_OK
)
598 struct jtag_tap
* tap_chp
;
599 struct jtag_tap
* tap_cpu
;
600 tap_chp
= jtag_tap_by_string("dsp568013.chp");
603 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_FIND_MASTER
, "Failed to get master tap.");
605 tap_cpu
= jtag_tap_by_string("dsp568013.cpu");
608 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_FIND_CORE
, "Failed to get master tap.");
612 tap_chp
->enabled
= true;
613 tap_cpu
->enabled
= false;
615 instr
= MASTER_TAP_CMD_IDCODE
;
616 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_MASTER_TAP_IRLEN
);
617 err_check_propagate(retval
);
618 jtag_add_sleep(TIME_DIV_FREESCALE
*100*1000);
620 // Enable EOnCE module
622 jtag_add_sleep(TIME_DIV_FREESCALE
*200*1000);
623 instr
= 0x0606ffff;// This was selected experimentally.
624 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr
,(uint8_t *) & ir_out
,32);
625 err_check_propagate(retval
);
626 // ir_out now hold tap idcode
629 tap_chp
->enabled
= true;
630 retval
= switch_tap(target
,tap_chp
,tap_cpu
);
631 err_check_propagate(retval
);
633 instr
= JTAG_INSTR_ENABLE_ONCE
;
634 //Two rounds of jtag 0x6 (enable eonce) to enable EOnCE.
635 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_CORE_TAP_IRLEN
);
636 err_check_propagate(retval
);
637 instr
= JTAG_INSTR_DEBUG_REQUEST
;
638 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_CORE_TAP_IRLEN
);
639 err_check_propagate(retval
);
641 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr_16
,(uint8_t *) & read_16
,8);
642 err_check_propagate(retval
);
644 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr_16
,(uint8_t *) & read_16
,8);
645 err_check_propagate(retval
);
646 jtag_add_sleep(TIME_DIV_FREESCALE
*100*1000);
648 jtag_add_sleep(TIME_DIV_FREESCALE
*300*1000);
650 instr
= JTAG_INSTR_ENABLE_ONCE
;
651 //Two rounds of jtag 0x6 (enable eonce) to enable EOnCE.
652 for(int i
= 0; i
<3; i
++){
653 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_CORE_TAP_IRLEN
);
654 err_check_propagate(retval
);
656 if ((ir_out
&JTAG_STATUS_MASK
) == JTAG_STATUS_DEBUG
)
657 target
->state
= TARGET_HALTED
;
660 err_check(retval
, DSP5680XX_ERROR_HALT
, "Failed to halt target.");
663 for(int i
= 0; i
<3; i
++){
665 dsp5680xx_drscan(target
,(uint8_t *) & instr_16
,(uint8_t *) & read_16
,16);
667 dsp5680xx_drscan(target
,(uint8_t *) & instr_16
,(uint8_t *) & read_16
,16);
670 // Verify that debug mode is enabled
671 uint16_t data_read_from_dr
;
672 retval
= eonce_read_status_reg(target
, &data_read_from_dr
);
673 err_check_propagate(retval
);
674 if((data_read_from_dr
&0x30) == 0x30){
675 LOG_DEBUG("EOnCE successfully entered debug mode.");
676 dsp5680xx_context
.debug_mode_enabled
= true;
679 const char *msg
= "Failed to set EOnCE module to debug mode";
680 retval
= ERROR_TARGET_FAILURE
;
681 err_check(retval
, DSP5680XX_ERROR_ENTER_DEBUG_MODE
, msg
);
683 if(eonce_status
!=NULL
)
684 *eonce_status
= data_read_from_dr
;
689 * Reads the current value of the program counter and stores it.
695 static int eonce_pc_store(struct target
* target
){
698 retval
= core_move_pc_to_r4(target
);
699 err_check_propagate(retval
);
700 retval
= core_move_r4_to_y(target
);
701 err_check_propagate(retval
);
702 retval
= eonce_load_TX_RX_to_r0(target
);
703 err_check_propagate(retval
);
704 retval
= core_move_y0_at_r0(target
);
705 err_check_propagate(retval
);
706 retval
= core_rx_lower_data(target
,tmp
);
707 err_check_propagate(retval
);
708 LOG_USER("PC value: 0x%X%X\n",tmp
[1],tmp
[0]);
709 dsp5680xx_context
.stored_pc
= (tmp
[0]|(tmp
[1]<<8));
713 static int dsp5680xx_target_create(struct target
*target
, Jim_Interp
* interp
){
714 struct dsp5680xx_common
*dsp5680xx
= calloc(1, sizeof(struct dsp5680xx_common
));
715 target
->arch_info
= dsp5680xx
;
719 static int dsp5680xx_init_target(struct command_context
*cmd_ctx
, struct target
*target
){
720 dsp5680xx_context
.stored_pc
= 0;
721 dsp5680xx_context
.flush
= 1;
722 dsp5680xx_context
.debug_mode_enabled
= false;
723 LOG_DEBUG("target initiated!");
724 //TODO core tap must be enabled before running these commands, currently this is done in the .cfg tcl script.
728 static int dsp5680xx_arch_state(struct target
*target
){
729 LOG_USER("%s not implemented yet.", __func__
);
733 int dsp5680xx_target_status(struct target
* target
, uint8_t * jtag_st
, uint16_t * eonce_st
){
734 return target
->state
;
737 static int dsp5680xx_assert_reset(struct target
*target
){
738 target
->state
= TARGET_RESET
;
742 static int dsp5680xx_deassert_reset(struct target
*target
){
743 target
->state
= TARGET_RUNNING
;
747 static int dsp5680xx_halt(struct target
*target
){
749 uint16_t eonce_status
= 0xbeef;
750 if ((target
->state
== TARGET_HALTED
) && (dsp5680xx_context
.debug_mode_enabled
)) {
751 LOG_USER("Target already halted and in debug mode.");
754 if (target
->state
== TARGET_HALTED
)
755 LOG_USER("Target already halted, re attempting to enter debug mode.");
757 retval
= eonce_enter_debug_mode(target
,&eonce_status
);
758 err_check_propagate(retval
);
759 retval
= eonce_pc_store(target
);
760 err_check_propagate(retval
);
761 if (dsp5680xx_context
.debug_mode_enabled
) {
762 retval
= eonce_pc_store(target
);
763 err_check_propagate(retval
);
768 static int dsp5680xx_poll(struct target
*target
)
772 uint8_t eonce_status
;
774 retval
= dsp5680xx_jtag_status(target
, &jtag_status
);
775 err_check_propagate(retval
);
776 if (jtag_status
== JTAG_STATUS_DEBUG
)
777 if (target
->state
!= TARGET_HALTED
) {
778 retval
= eonce_enter_debug_mode(target
, &read_tmp
);
779 err_check_propagate(retval
);
780 eonce_status
= (uint8_t) read_tmp
;
781 if ((eonce_status
&EONCE_STAT_MASK
) != DSP5680XX_ONCE_OSCR_DEBUG_M
) {
782 const char *msg
= "%s: Failed to put EOnCE in debug mode.Flash locked?...";
783 LOG_WARNING(msg
, __func__
);
784 return ERROR_TARGET_FAILURE
;
786 target
->state
= TARGET_HALTED
;
790 if (jtag_status
== JTAG_STATUS_NORMAL
) {
791 if (target
->state
== TARGET_RESET
) {
792 retval
= dsp5680xx_halt(target
);
793 err_check_propagate(retval
);
794 retval
= eonce_exit_debug_mode(target
, &eonce_status
);
795 err_check_propagate(retval
);
796 if ((eonce_status
&EONCE_STAT_MASK
) != DSP5680XX_ONCE_OSCR_NORMAL_M
) {
797 const char *msg
= "%s: JTAG running, but EOnCE run failed.Try resetting..";
798 LOG_WARNING(msg
, __func__
);
799 return ERROR_TARGET_FAILURE
;
801 target
->state
= TARGET_RUNNING
;
805 if (target
->state
!= TARGET_RUNNING
) {
806 retval
= eonce_read_status_reg(target
, &read_tmp
);
807 err_check_propagate(retval
);
808 eonce_status
= (uint8_t) read_tmp
;
809 if ((eonce_status
&EONCE_STAT_MASK
) != DSP5680XX_ONCE_OSCR_NORMAL_M
) {
810 LOG_WARNING("Inconsistent target status. Restart!");
811 return ERROR_TARGET_FAILURE
;
814 target
->state
= TARGET_RUNNING
;
817 if (jtag_status
== JTAG_STATUS_DEAD
) {
818 LOG_ERROR("%s: Cannot communicate with JTAG. Check connection...", __func__
);
819 target
->state
= TARGET_UNKNOWN
;
820 return ERROR_TARGET_FAILURE
;
822 if (target
->state
== TARGET_UNKNOWN
) {
823 LOG_ERROR("%s: Target status invalid - communication failure", __func__
);
824 return ERROR_TARGET_FAILURE
;
829 static int dsp5680xx_resume(struct target
*target
, int current
, uint32_t address
, int hb
, int d
)
831 if (target
->state
== TARGET_RUNNING
) {
832 LOG_USER("Target already running.");
836 uint8_t eonce_status
;
838 if (dsp5680xx_context
.debug_mode_enabled
) {
840 retval
= core_move_value_to_pc(target
, address
);
841 err_check_propagate(retval
);
845 while (retry
-- > 1) {
846 retval
= eonce_exit_debug_mode(target
, &eonce_status
);
847 err_check_propagate(retval
);
848 if (eonce_status
== DSP5680XX_ONCE_OSCR_NORMAL_M
)
852 retval
= ERROR_TARGET_FAILURE
;
853 err_check(retval
, DSP5680XX_ERROR_EXIT_DEBUG_MODE
, "Failed to exit debug mode...");
855 target
->state
= TARGET_RUNNING
;
856 dsp5680xx_context
.debug_mode_enabled
= false;
858 LOG_DEBUG("EOnCE status: 0x%02X.", eonce_status
);
861 * If debug mode was not enabled but target was halted, then it is most likely that
862 * access to eonce registers is locked.
863 * Reset target to make it run again.
865 jtag_add_reset(0, 1);
866 jtag_add_sleep(TIME_DIV_FREESCALE
*200*1000);
868 retval
= reset_jtag();
869 err_check(retval
, DSP5680XX_ERROR_JTAG_RESET
, "Failed to reset JTAG state machine");
870 jtag_add_sleep(TIME_DIV_FREESCALE
*100*1000);
871 jtag_add_reset(0, 0);
872 jtag_add_sleep(TIME_DIV_FREESCALE
*300*1000);
873 retval
= dsp5680xx_jtag_status(target
, &jtag_status
);
874 err_check_propagate(retval
);
875 if ((jtag_status
&JTAG_STATUS_MASK
) == JTAG_STATUS_NORMAL
) {
876 target
->state
= TARGET_RUNNING
;
877 dsp5680xx_context
.debug_mode_enabled
= false;
879 retval
= ERROR_TARGET_FAILURE
;
880 err_check(retval
, DSP5680XX_ERROR_RESUME
, "Failed to resume target");
892 * The value of @address determines if it corresponds to P: (program) or X: (dat) memory. If the address is over 0x200000 then it is considered X: memory, and @pmem = 0.
893 * The special case of 0xFFXXXX is not modified, since it allows to read out the memory mapped EOnCE registers.
900 static int dsp5680xx_convert_address(uint32_t *address
, int *pmem
)
903 * Distinguish data memory (x) from program memory (p) by the address.
904 * Addresses over S_FILE_DATA_OFFSET are considered (x) memory.
906 if (*address
>= S_FILE_DATA_OFFSET
) {
908 if (((*address
)&0xff0000) != 0xff0000)
909 *address
-= S_FILE_DATA_OFFSET
;
914 static int dsp5680xx_read_16_single(struct target
*t
, uint32_t a
, uint8_t *data_read
, int r_pmem
)
916 struct target
*target
= t
;
917 uint32_t address
= a
;
919 retval
= core_move_long_to_r0(target
,address
);
920 err_check_propagate(retval
);
922 retval
= core_move_at_pr0_inc_to_y0(target
);
924 retval
= core_move_at_r0_to_y0(target
);
925 err_check_propagate(retval
);
926 retval
= eonce_load_TX_RX_to_r0(target
);
927 err_check_propagate(retval
);
928 retval
= core_move_y0_at_r0(target
);
929 err_check_propagate(retval
);
930 // at this point the data i want is at the reg eonce can read
931 retval
= core_rx_lower_data(target
,data_read
);
932 err_check_propagate(retval
);
933 LOG_DEBUG("%s:Data read from 0x%06X: 0x%02X%02X", __func__
, address
, data_read
[1], data_read
[0]);
937 static int dsp5680xx_read_32_single(struct target
*t
, uint32_t a
, uint8_t *data_read
, int r_pmem
)
939 struct target
*target
= t
;
940 uint32_t address
= a
;
942 address
= (address
& 0xFFFFF);
943 // Get data to an intermediate register
944 retval
= core_move_long_to_r0(target
,address
);
945 err_check_propagate(retval
);
947 retval
= core_move_at_pr0_inc_to_y0(target
);
948 err_check_propagate(retval
);
949 retval
= core_move_at_pr0_inc_to_y1(target
);
950 err_check_propagate(retval
);
952 retval
= core_move_at_r0_inc_to_y0(target
);
953 err_check_propagate(retval
);
954 retval
= core_move_at_r0_to_y1(target
);
955 err_check_propagate(retval
);
957 // Get lower part of data to TX/RX
958 retval
= eonce_load_TX_RX_to_r0(target
);
959 err_check_propagate(retval
);
960 retval
= core_move_y0_at_r0_inc(target
); // This also load TX/RX high to r0
961 err_check_propagate(retval
);
962 // Get upper part of data to TX/RX
963 retval
= core_move_y1_at_r0(target
);
964 err_check_propagate(retval
);
965 // at this point the data i want is at the reg eonce can read
966 retval
= core_rx_lower_data(target
,data_read
);
967 err_check_propagate(retval
);
968 retval
= core_rx_upper_data(target
,data_read
+2);
969 err_check_propagate(retval
);
973 static int dsp5680xx_read(struct target
*t
, uint32_t a
, unsigned size
, unsigned count
, uint8_t *buf
)
975 struct target
*target
= t
;
976 uint32_t address
= a
;
977 uint8_t *buffer
= buf
;
978 check_halt_and_debug(target
);
980 int retval
= ERROR_OK
;
983 retval
= dsp5680xx_convert_address(&address
, &pmem
);
984 err_check_propagate(retval
);
986 dsp5680xx_context
.flush
= 0;
987 int counter
= FLUSH_COUNT_READ_WRITE
;
989 for (unsigned i
= 0; i
< count
; i
++) {
990 if (--counter
== 0) {
991 dsp5680xx_context
.flush
= 1;
992 counter
= FLUSH_COUNT_READ_WRITE
;
997 retval
= dsp5680xx_read_16_single(target
, address
+ i
/2, buffer
+ i
, pmem
);
1000 retval
= dsp5680xx_read_16_single(target
, address
+ i
, buffer
+2*i
, pmem
);
1003 retval
= dsp5680xx_read_32_single(target
, address
+ 2*i
, buffer
+ 4*i
, pmem
);
1006 LOG_USER("%s: Invalid read size.", __func__
);
1009 err_check_propagate(retval
);
1010 dsp5680xx_context
.flush
= 0;
1013 dsp5680xx_context
.flush
= 1;
1014 retval
= dsp5680xx_execute_queue();
1015 err_check_propagate(retval
);
1020 static int dsp5680xx_write_16_single(struct target
*t
, uint32_t a
, uint16_t data
, uint8_t w_pmem
)
1022 struct target
*target
= t
;
1023 uint32_t address
= a
;
1025 retval
= core_move_long_to_r0(target
,address
);
1026 err_check_propagate(retval
);
1028 retval
= core_move_value_to_y0(target
, data
);
1029 err_check_propagate(retval
);
1030 retval
= core_move_y0_at_pr0_inc(target
);
1031 err_check_propagate(retval
);
1033 retval
= core_move_value_at_r0(target
, data
);
1034 err_check_propagate(retval
);
1039 static int dsp5680xx_write_32_single(struct target
*t
, uint32_t a
, uint32_t data
, int w_pmem
)
1041 struct target
*target
= t
;
1042 uint32_t address
= a
;
1043 int retval
= ERROR_OK
;
1044 retval
= core_move_long_to_r0(target
, address
);
1045 err_check_propagate(retval
);
1046 retval
= core_move_long_to_y(target
, data
);
1047 err_check_propagate(retval
);
1049 retval
= core_move_y0_at_pr0_inc(target
);
1051 retval
= core_move_y0_at_r0_inc(target
);
1052 err_check_propagate(retval
);
1054 retval
= core_move_y1_at_pr0_inc(target
);
1056 retval
= core_move_y1_at_r0_inc(target
);
1057 err_check_propagate(retval
);
1061 static int dsp5680xx_write_8(struct target
*t
, uint32_t a
, uint32_t c
, const uint8_t *d
, int pmem
)
1063 struct target
*target
= t
;
1064 uint32_t address
= a
;
1066 const uint8_t *data
= d
;
1071 int counter
= FLUSH_COUNT_READ_WRITE
;
1072 for (iter
= 0; iter
< count
/2; iter
++) {
1073 if (--counter
== 0) {
1074 dsp5680xx_context
.flush
= 1;
1075 counter
= FLUSH_COUNT_READ_WRITE
;
1077 data_16
= (data
[2*iter
]|(data
[2*iter
+1] << 8));
1078 retval
= dsp5680xx_write_16_single(target
, address
+iter
, data_16
, pmem
);
1079 if (retval
!= ERROR_OK
) {
1080 LOG_ERROR("%s: Could not write to p:0x%04X", __func__
, address
);
1081 dsp5680xx_context
.flush
= 1;
1084 dsp5680xx_context
.flush
= 0;
1086 dsp5680xx_context
.flush
= 1;
1088 // Only one byte left, let's not overwrite the other byte (mem is 16bit)
1089 // Need to retrieve the part we do not want to overwrite.
1091 if ((count
== 1) || (count
%2)) {
1092 retval
= dsp5680xx_read(target
, address
+iter
, 1, 1, (uint8_t *)&data_old
);
1093 err_check_propagate(retval
);
1095 data_old
= (((data_old
&0xff)<<8)|data
[0]);/* preserve upper byte */
1097 data_old
= (((data_old
&0xff)<<8)|data
[2*iter
+1]);
1098 retval
= dsp5680xx_write_16_single(target
, address
+iter
, data_old
, pmem
);
1099 err_check_propagate(retval
);
1104 static int dsp5680xx_write_16(struct target
*t
, uint32_t a
, uint32_t c
, const uint8_t *d
, int pmem
)
1106 struct target
*target
= t
;
1107 uint32_t address
= a
;
1109 const uint8_t *data
= d
;
1110 int retval
= ERROR_OK
;
1112 int counter
= FLUSH_COUNT_READ_WRITE
;
1114 for (iter
= 0; iter
< count
; iter
++) {
1115 if (--counter
== 0) {
1116 dsp5680xx_context
.flush
= 1;
1117 counter
= FLUSH_COUNT_READ_WRITE
;
1119 retval
= dsp5680xx_write_16_single(target
, address
+iter
, data
[iter
], pmem
);
1120 if (retval
!= ERROR_OK
) {
1121 LOG_ERROR("%s: Could not write to p:0x%04X", __func__
, address
);
1122 dsp5680xx_context
.flush
= 1;
1125 dsp5680xx_context
.flush
= 0;
1127 dsp5680xx_context
.flush
= 1;
1131 static int dsp5680xx_write_32(struct target
*t
, uint32_t a
, uint32_t c
, const uint8_t *d
, int pmem
)
1133 struct target
*target
= t
;
1134 uint32_t address
= a
;
1136 const uint8_t *data
= d
;
1137 int retval
= ERROR_OK
;
1139 int counter
= FLUSH_COUNT_READ_WRITE
;
1141 for (iter
= 0; iter
< count
; iter
++) {
1142 if (--counter
== 0) {
1143 dsp5680xx_context
.flush
= 1;
1144 counter
= FLUSH_COUNT_READ_WRITE
;
1146 retval
= dsp5680xx_write_32_single(target
, address
+(iter
<<1), data
[iter
], pmem
);
1147 if (retval
!= ERROR_OK
) {
1148 LOG_ERROR("%s: Could not write to p:0x%04X", __func__
, address
);
1149 dsp5680xx_context
.flush
= 1;
1152 dsp5680xx_context
.flush
= 0;
1154 dsp5680xx_context
.flush
= 1;
1159 * Writes @buffer to memory.
1160 * The parameter @address determines whether @buffer should be written to
1161 * P: (program) memory or X: (dat) memory.
1165 * @param size Bytes (1), Half words (2), Words (4).
1166 * @param count In bytes.
1171 static int dsp5680xx_write(struct target
*t
, uint32_t a
, uint32_t s
, uint32_t c
, const uint8_t *b
)
1173 /* TODO Cannot write 32bit to odd address, will write 0x12345678 as 0x5678 0x0012 */
1174 struct target
*target
= t
;
1175 uint32_t address
= a
;
1177 uint8_t const *buffer
= b
;
1179 check_halt_and_debug(target
);
1183 retval
= dsp5680xx_convert_address(&address
, &p_mem
);
1184 err_check_propagate(retval
);
1188 retval
= dsp5680xx_write_8(target
, address
, count
, buffer
, p_mem
);
1191 retval
= dsp5680xx_write_16(target
, address
, count
, buffer
, p_mem
);
1194 retval
= dsp5680xx_write_32(target
, address
, count
, buffer
, p_mem
);
1197 retval
= ERROR_TARGET_DATA_ABORT
;
1198 err_check(retval
, DSP5680XX_ERROR_INVALID_DATA_SIZE_UNIT
, "Invalid data size.");
1204 static int dsp5680xx_bulk_write_memory(struct target
*t
, uint32_t a
, uint32_t al
, const uint8_t *b
)
1206 LOG_ERROR("Not implemented yet.");
1210 static int dsp5680xx_write_buffer(struct target
*t
, uint32_t a
, uint32_t size
, const uint8_t *b
)
1212 check_halt_and_debug(t
);
1213 return dsp5680xx_write(t
, a
, 1, size
, b
);
1217 * This function is called by verify_image, it is used to read data from memory.
1220 * @param address Word addressing.
1221 * @param size In bytes.
1226 static int dsp5680xx_read_buffer(struct target
*t
, uint32_t a
, uint32_t size
, uint8_t *buf
)
1228 check_halt_and_debug(t
);
1229 /* The "/2" solves the byte/word addressing issue.*/
1230 return dsp5680xx_read(t
, a
, 2, size
/2, buf
);
1234 * This function is not implemented.
1235 * It returns an error in order to get OpenOCD to do read out the data and calculate the CRC, or try a binary comparison.
1238 * @param address Start address of the image.
1239 * @param size In bytes.
1244 static int dsp5680xx_checksum_memory(struct target
*t
, uint32_t a
, uint32_t s
, uint32_t *checksum
)
1250 * Calculates a signature over @word_count words in the data from @buff16. The algorithm used is the same the FM uses, so the @return may be used to compare with the one generated by the FM module, and check if flashing was successful.
1251 * This algorithm is based on the perl script available from the Freescale website at FAQ 25630.
1258 static int perl_crc(uint8_t *buff8
, uint32_t word_count
)
1260 uint16_t checksum
= 0xffff;
1261 uint16_t data
,fbmisr
;
1263 for (i
= 0; i
< word_count
; i
++) {
1264 data
= (buff8
[2*i
]|(buff8
[2*i
+1]<<8));
1265 fbmisr
= (checksum
& 2)>>1^(checksum
& 4)>>2^(checksum
& 16)>>4^(checksum
& 0x8000)>>15;
1266 checksum
= (data
^ ((checksum
<< 1) | fbmisr
));
1269 for (; !(i
&0x80000000); i
--) {
1270 data
= (buff8
[2*i
]|(buff8
[2*i
+1]<<8));
1271 fbmisr
= (checksum
& 2)>>1^(checksum
& 4)>>2^(checksum
& 16)>>4^(checksum
& 0x8000)>>15;
1272 checksum
= (data
^ ((checksum
<< 1) | fbmisr
));
1278 * Resets the SIM. (System Integration Modul).
1284 int dsp5680xx_f_SIM_reset(struct target
*target
)
1286 int retval
= ERROR_OK
;
1287 uint16_t sim_cmd
= SIM_CMD_RESET
;
1289 if (strcmp(target
->tap
->chip
, "dsp568013") == 0) {
1290 sim_addr
= MC568013_SIM_BASE_ADDR
+S_FILE_DATA_OFFSET
;
1291 retval
= dsp5680xx_write(target
,sim_addr
,1,2,(const uint8_t *)&sim_cmd
);
1292 err_check_propagate(retval
);
1298 * Halts the core and resets the SIM. (System Integration Modul).
1304 static int dsp5680xx_soft_reset_halt(struct target
*target
)
1306 //TODO is this what this function is expected to do...?
1308 retval
= dsp5680xx_halt(target
);
1309 err_check_propagate(retval
);
1310 retval
= dsp5680xx_f_SIM_reset(target
);
1311 err_check_propagate(retval
);
1315 int dsp5680xx_f_protect_check(struct target
* target
, uint16_t * protected) {
1317 check_halt_and_debug(target
);
1318 if (protected == NULL
) {
1319 const char *msg
= "NULL pointer not valid.";
1320 err_check(ERROR_FAIL
, DSP5680XX_ERROR_PROTECT_CHECK_INVALID_ARGS
, msg
);
1322 retval
= dsp5680xx_read_16_single(target
,HFM_BASE_ADDR
|HFM_PROT
,(uint8_t *)protected,0);
1323 err_check_propagate(retval
);
1328 * Executes a command on the FM module.
1329 * Some commands use the parameters @address and @data, others ignore them.
1332 * @param command Command to execute.
1333 * @param address Command parameter.
1334 * @param data Command parameter.
1335 * @param hfm_ustat FM status register.
1336 * @param pmem Address is P: (program) memory (@pmem==1) or X: (dat) memory (@pmem==0)
1340 static int dsp5680xx_f_ex(struct target
*t
, uint16_t c
, uint32_t a
, uint32_t d
, uint16_t *h
, int p
)
1342 struct target
*target
= t
;
1343 uint32_t command
= c
;
1344 uint32_t address
= a
;
1346 uint16_t *hfm_ustat
= h
;
1349 retval
= core_load_TX_RX_high_addr_to_r0(target
);
1350 err_check_propagate(retval
);
1351 retval
= core_move_long_to_r2(target
,HFM_BASE_ADDR
);
1352 err_check_propagate(retval
);
1356 retval
= core_move_at_r2_disp_to_y0(target
,HFM_USTAT
); // read HMF_USTAT
1357 err_check_propagate(retval
);
1358 retval
= core_move_y0_at_r0(target
);
1359 err_check_propagate(retval
);
1360 retval
= core_rx_upper_data(target
,i
);
1361 err_check_propagate(retval
);
1362 if ((watchdog
--) == 1) {
1363 retval
= ERROR_TARGET_FAILURE
;
1364 const char *msg
= "Timed out waiting for FM to finish old command.";
1365 err_check(retval
, DSP5680XX_ERROR_FM_BUSY
, msg
);
1367 }while (!(i
[0]&0x40)); // wait until current command is complete
1369 dsp5680xx_context
.flush
= 0;
1371 retval
= core_move_value_at_r2_disp(target
,0x00,HFM_CNFG
); // write to HFM_CNFG (lock=0, select bank) -- flash_desc.bank&0x03,0x01 == 0x00,0x01 ???
1372 err_check_propagate(retval
);
1373 retval
= core_move_value_at_r2_disp(target
,0x04,HFM_USTAT
); // write to HMF_USTAT, clear PVIOL, ACCERR & BLANK bits
1374 err_check_propagate(retval
);
1375 retval
= core_move_value_at_r2_disp(target
,0x10,HFM_USTAT
); // clear only one bit at a time
1376 err_check_propagate(retval
);
1377 retval
= core_move_value_at_r2_disp(target
,0x20,HFM_USTAT
);
1378 err_check_propagate(retval
);
1379 retval
= core_move_value_at_r2_disp(target
,0x00,HFM_PROT
); // write to HMF_PROT, clear protection
1380 err_check_propagate(retval
);
1381 retval
= core_move_value_at_r2_disp(target
,0x00,HFM_PROTB
); // write to HMF_PROTB, clear protection
1382 err_check_propagate(retval
);
1383 retval
= core_move_value_to_y0(target
,data
);
1384 err_check_propagate(retval
);
1385 retval
= core_move_long_to_r3(target
,address
); // write to the flash block
1386 err_check_propagate(retval
);
1388 retval
= core_move_y0_at_pr3_inc(target
);
1389 err_check_propagate(retval
);
1391 retval
= core_move_y0_at_r3(target
);
1392 err_check_propagate(retval
);
1394 retval
= core_move_value_at_r2_disp(target
,command
,HFM_CMD
); // write command to the HFM_CMD reg
1395 err_check_propagate(retval
);
1396 retval
= core_move_value_at_r2_disp(target
,0x80,HFM_USTAT
); // start the command
1397 err_check_propagate(retval
);
1399 dsp5680xx_context
.flush
= 1;
1400 retval
= dsp5680xx_execute_queue();
1401 err_check_propagate(retval
);
1405 retval
= core_move_at_r2_disp_to_y0(target
,HFM_USTAT
); // read HMF_USTAT
1406 err_check_propagate(retval
);
1407 retval
= core_move_y0_at_r0(target
);
1408 err_check_propagate(retval
);
1409 retval
= core_rx_upper_data(target
,i
);
1410 err_check_propagate(retval
);
1411 if ((watchdog
--) == 1) {
1412 retval
= ERROR_TARGET_FAILURE
;
1413 err_check(retval
, DSP5680XX_ERROR_FM_CMD_TIMED_OUT
, "FM execution did not finish.");
1415 }while (!(i
[0]&0x40)); // wait until the command is complete
1416 *hfm_ustat
= ((i
[0]<<8)|(i
[1]));
1417 if (i
[0]&HFM_USTAT_MASK_PVIOL_ACCER
){
1418 retval
= ERROR_TARGET_FAILURE
;
1419 const char *msg
= "pviol and/or accer bits set. HFM command execution error";
1420 err_check(retval
, DSP5680XX_ERROR_FM_EXEC
, msg
);
1426 * Prior to the execution of any Flash module command, the Flash module Clock Divider (CLKDIV) register must be initialized. The values of this register determine the speed of the internal Flash Clock (FCLK). FCLK must be in the range of 150kHz ≤ FCLK ≤ 200kHz for proper operation of the Flash module. (Running FCLK too slowly wears out the module, while running it too fast under programs Flash leading to bit errors.)
1432 static int set_fm_ck_div(struct target
*target
)
1436 retval
= core_move_long_to_r2(target
,HFM_BASE_ADDR
);
1437 err_check_propagate(retval
);
1438 retval
= core_load_TX_RX_high_addr_to_r0(target
);
1439 err_check_propagate(retval
);
1440 retval
= core_move_at_r2_to_y0(target
);// read HFM_CLKD
1441 err_check_propagate(retval
);
1442 retval
= core_move_y0_at_r0(target
);
1443 err_check_propagate(retval
);
1444 retval
= core_rx_upper_data(target
,i
);
1445 err_check_propagate(retval
);
1446 unsigned int hfm_at_wrong_value
= 0;
1447 if ((i
[0]&0x7f)!=HFM_CLK_DEFAULT
) {
1448 LOG_DEBUG("HFM CLK divisor contained incorrect value (0x%02X).",i
[0]&0x7f);
1449 hfm_at_wrong_value
= 1;
1451 LOG_DEBUG("HFM CLK divisor was already set to correct value (0x%02X).",i
[0]&0x7f);
1454 retval
= core_move_value_at_r2(target
,HFM_CLK_DEFAULT
); // write HFM_CLKD
1455 err_check_propagate(retval
);
1456 retval
= core_move_at_r2_to_y0(target
); // verify HFM_CLKD
1457 err_check_propagate(retval
);
1458 retval
= core_move_y0_at_r0(target
);
1459 err_check_propagate(retval
);
1460 retval
= core_rx_upper_data(target
,i
);
1461 err_check_propagate(retval
);
1462 if (i
[0]!=(0x80|(HFM_CLK_DEFAULT
&0x7f))) {
1463 retval
= ERROR_TARGET_FAILURE
;
1464 err_check(retval
, DSP5680XX_ERROR_FM_SET_CLK
, "Unable to set HFM CLK divisor.");
1466 if (hfm_at_wrong_value
)
1467 LOG_DEBUG("HFM CLK divisor set to 0x%02x.", i
[0]&0x7f);
1472 * Executes the FM calculate signature command. The FM will calculate over the data from @address to @address + @words -1. The result is written to a register, then read out by this function and returned in @signature. The value @signature may be compared to the the one returned by perl_crc to verify the flash was written correctly.
1475 * @param address Start of flash array where the signature should be calculated.
1476 * @param words Number of words over which the signature should be calculated.
1477 * @param signature Value calculated by the FM.
1481 static int dsp5680xx_f_signature(struct target
*t
, uint32_t a
, uint32_t words
, uint16_t * signature
)
1483 struct target
*target
= t
;
1484 uint32_t address
= a
;
1487 if (!dsp5680xx_context
.debug_mode_enabled
) {
1488 retval
= eonce_enter_debug_mode_without_reset(target
, NULL
);
1490 * Generate error here, since it is not done in eonce_enter_debug_mode_without_reset
1492 err_check(retval
, DSP5680XX_ERROR_HALT
, "Failed to halt target.");
1494 retval
= dsp5680xx_f_ex(target
, HFM_CALCULATE_DATA_SIGNATURE
, address
, words
, &hfm_ustat
, 1);
1495 err_check_propagate(retval
);
1496 retval
= dsp5680xx_read_16_single(target
, HFM_BASE_ADDR
|HFM_DATA
, (uint8_t *)signature
, 0);
1500 int dsp5680xx_f_erase_check(struct target
*target
, uint8_t *erased
, uint32_t sector
)
1505 if (!dsp5680xx_context
.debug_mode_enabled
) {
1506 retval
= dsp5680xx_halt(target
);
1507 err_check_propagate(retval
);
1509 retval
= set_fm_ck_div(target
);
1510 err_check_propagate(retval
);
1512 * Check if chip is already erased.
1514 tmp
= HFM_FLASH_BASE_ADDR
+sector
*HFM_SECTOR_SIZE
/2;
1515 retval
= dsp5680xx_f_ex(target
, HFM_ERASE_VERIFY
, tmp
, 0, &hfm_ustat
, 1);
1516 err_check_propagate(retval
);
1518 *erased
= (uint8_t)(hfm_ustat
&HFM_USTAT_MASK_BLANK
);
1523 * Executes the FM page erase command.
1526 * @param sector Page to erase.
1527 * @param hfm_ustat FM module status register.
1531 static int erase_sector(struct target
*target
, int sector
, uint16_t *hfm_ustat
)
1534 uint32_t tmp
= HFM_FLASH_BASE_ADDR
+sector
*HFM_SECTOR_SIZE
/2;
1535 retval
= dsp5680xx_f_ex(target
, HFM_PAGE_ERASE
, tmp
, 0, hfm_ustat
, 1);
1536 err_check_propagate(retval
);
1541 * Executes the FM mass erase command. Erases the flash array completely.
1544 * @param hfm_ustat FM module status register.
1548 static int mass_erase(struct target
*target
, uint16_t *hfm_ustat
)
1551 retval
= dsp5680xx_f_ex(target
, HFM_MASS_ERASE
, 0, 0, hfm_ustat
, 1);
1555 int dsp5680xx_f_erase(struct target
*target
, int first
, int last
)
1558 if (!dsp5680xx_context
.debug_mode_enabled
) {
1559 retval
= dsp5680xx_halt(target
);
1560 err_check_propagate(retval
);
1562 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1564 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1565 retval
= dsp5680xx_f_SIM_reset(target
);
1566 err_check_propagate(retval
);
1567 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1569 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1570 retval
= set_fm_ck_div(target
);
1571 err_check_propagate(retval
);
1574 int do_mass_erase
= ((!(first
|last
)) || ((first
==0)&&(last
== (HFM_SECTOR_COUNT
-1))));
1575 if (do_mass_erase
) {
1577 retval
= mass_erase(target
, &hfm_ustat
);
1578 err_check_propagate(retval
);
1580 for (int i
= first
; i
<= last
; i
++) {
1581 retval
= erase_sector(target
, i
, &hfm_ustat
);
1582 err_check_propagate(retval
);
1589 * Algorithm for programming normal p: flash
1590 * Follow state machine from "56F801x Peripheral Reference Manual"@163.
1591 * Registers to set up before calling:
1592 * r0: TX/RX high address.
1593 * r2: FM module base address.
1594 * r3: Destination address in flash.
1596 * hfm_wait: // wait for buffer empty
1597 * brclr #0x80,x:(r2+0x13),hfm_wait
1598 * rx_check: // wait for input buffer full
1599 * brclr #0x01,x:(r0-2),rx_check
1600 * move.w x:(r0),y0 // read from Rx buffer
1602 * move.w #0x20,x:(r2+0x14) // write PGM command
1603 * move.w #0x80,x:(r2+0x13) // start the command
1604 * move.w X:(R2+0x13),A // Read USTAT register
1605 * brclr #0x20,A,accerr_check // protection violation check
1606 * bfset #0x20,X:(R2+0x13) // clear pviol
1609 * brclr #0x10,A,hfm_wait // access error check
1610 * bfset #0x10,X:(R2+0x13) // clear accerr
1611 * bra hfm_wait // loop
1612 *0x00000000 0x8A460013807D brclr #0x80,X:(R2+0x13),*+0
1613 *0x00000003 0xE700 nop
1614 *0x00000004 0xE700 nop
1615 *0x00000005 0x8A44FFFE017B brclr #1,X:(R0-2),*-2
1616 *0x00000008 0xE700 nop
1617 *0x00000009 0xF514 move.w X:(R0),Y0
1618 *0x0000000A 0x8563 move.w Y0,P:(R3)+
1619 *0x0000000B 0x864600200014 move.w #32,X:(R2+0x14)
1620 *0x0000000E 0x864600800013 move.w #128,X:(R2+0x13)
1621 *0x00000011 0xF0420013 move.w X:(R2+0x13),A
1622 *0x00000013 0x8B402004 brclr #0x20,A,*+6
1623 *0x00000015 0x824600130020 bfset #0x20,X:(R2+0x13)
1624 *0x00000018 0xA967 bra *-24
1625 *0x00000019 0x8B401065 brclr #0x10,A,*-25
1626 *0x0000001B 0x824600130010 bfset #0x10,X:(R2+0x13)
1627 *0x0000001E 0xA961 bra *-30
1630 const uint16_t pgm_write_pflash
[] = {0x8A46, 0x0013, 0x807D, 0xE700,\
1631 0xE700, 0x8A44, 0xFFFE, 0x017B,\
1632 0xE700, 0xF514, 0x8563, 0x8646,\
1633 0x0020, 0x0014, 0x8646, 0x0080,\
1634 0x0013, 0xF042, 0x0013, 0x8B40,\
1635 0x2004, 0x8246, 0x0013, 0x0020,\
1636 0xA967, 0x8B40, 0x1065, 0x8246,\
1637 0x0013, 0x0010, 0xA961};
1638 const uint32_t pgm_write_pflash_length
= 31;
1640 int dsp5680xx_f_wr(struct target
*t
, uint8_t *b
, uint32_t a
, uint32_t count
, int is_flash_lock
)
1642 struct target
*target
= t
;
1643 uint32_t address
= a
;
1644 uint8_t *buffer
= b
;
1645 int retval
= ERROR_OK
;
1646 if (!dsp5680xx_context
.debug_mode_enabled
) {
1647 retval
= eonce_enter_debug_mode(target
, NULL
);
1648 err_check_propagate(retval
);
1650 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1651 // Download the pgm that flashes.
1652 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1653 const uint32_t len
= pgm_write_pflash_length
;
1654 uint32_t ram_addr
= 0x8700;
1656 * This seems to be a safe address.
1657 * This one is the one used by codewarrior in 56801x_flash.cfg
1659 if (!is_flash_lock
) {
1660 retval
= dsp5680xx_write(target
, ram_addr
, 1, len
*2, (uint8_t *) pgm_write_pflash
);
1661 err_check_propagate(retval
);
1662 retval
= dsp5680xx_execute_queue();
1663 err_check_propagate(retval
);
1665 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1667 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1668 retval
= set_fm_ck_div(target
);
1669 err_check_propagate(retval
);
1670 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1671 // Setup registers needed by pgm_write_pflash
1672 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1674 dsp5680xx_context
.flush
= 0;
1676 retval
= core_move_long_to_r3(target
,address
); // Destination address to r3
1677 err_check_propagate(retval
);
1678 core_load_TX_RX_high_addr_to_r0(target
); // TX/RX reg address to r0
1679 err_check_propagate(retval
);
1680 retval
= core_move_long_to_r2(target
,HFM_BASE_ADDR
);// FM base address to r2
1681 err_check_propagate(retval
);
1682 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1683 // Run flashing program.
1684 // -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1685 retval
= core_move_value_at_r2_disp(target
,0x00,HFM_CNFG
); // write to HFM_CNFG (lock=0, select bank)
1686 err_check_propagate(retval
);
1687 retval
= core_move_value_at_r2_disp(target
,0x04,HFM_USTAT
);// write to HMF_USTAT, clear PVIOL, ACCERR & BLANK bits
1688 err_check_propagate(retval
);
1689 retval
= core_move_value_at_r2_disp(target
,0x10,HFM_USTAT
);// clear only one bit at a time
1690 err_check_propagate(retval
);
1691 retval
= core_move_value_at_r2_disp(target
,0x20,HFM_USTAT
);
1692 err_check_propagate(retval
);
1693 retval
= core_move_value_at_r2_disp(target
,0x00,HFM_PROT
);// write to HMF_PROT, clear protection
1694 err_check_propagate(retval
);
1695 retval
= core_move_value_at_r2_disp(target
,0x00,HFM_PROTB
);// write to HMF_PROTB, clear protection
1696 err_check_propagate(retval
);
1698 /* TODO implement handling of odd number of words. */
1699 retval
= ERROR_FAIL
;
1700 const char *msg
= "Cannot handle odd number of words.";
1701 err_check(retval
, DSP5680XX_ERROR_FLASHING_INVALID_WORD_COUNT
, msg
);
1704 dsp5680xx_context
.flush
= 1;
1705 retval
= dsp5680xx_execute_queue();
1706 err_check_propagate(retval
);
1708 uint32_t drscan_data
;
1709 uint16_t tmp
= (buffer
[0]|(buffer
[1]<<8));
1710 retval
= core_tx_upper_data(target
, tmp
, &drscan_data
);
1711 err_check_propagate(retval
);
1713 retval
= dsp5680xx_resume(target
, 0, ram_addr
, 0, 0);
1714 err_check_propagate(retval
);
1716 int counter
= FLUSH_COUNT_FLASH
;
1717 dsp5680xx_context
.flush
= 0;
1719 for (i
= 1; (i
< count
/2) && (i
< HFM_SIZE_WORDS
); i
++) {
1720 if (--counter
== 0) {
1721 dsp5680xx_context
.flush
= 1;
1722 counter
= FLUSH_COUNT_FLASH
;
1724 tmp
= (buffer
[2*i
]|(buffer
[2*i
+1]<<8));
1725 retval
= core_tx_upper_data(target
, tmp
, &drscan_data
);
1726 if (retval
!= ERROR_OK
) {
1727 dsp5680xx_context
.flush
= 1;
1728 err_check_propagate(retval
);
1730 dsp5680xx_context
.flush
= 0;
1732 dsp5680xx_context
.flush
= 1;
1733 if (!is_flash_lock
) {
1734 /** -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1735 * Verify flash (skip when exec lock sequence)
1736 * -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
1740 retval
= dsp5680xx_f_signature(target
, address
, i
, &signature
);
1741 err_check_propagate(retval
);
1742 pc_crc
= perl_crc(buffer
, i
);
1743 if (pc_crc
!= signature
) {
1744 retval
= ERROR_FAIL
;
1745 const char *msg
= "Flashed data failed CRC check, flash again!";
1746 err_check(retval
, DSP5680XX_ERROR_FLASHING_CRC
, msg
);
1752 int dsp5680xx_f_unlock(struct target
*target
)
1754 int retval
= ERROR_OK
;
1755 uint16_t eonce_status
;
1758 struct jtag_tap
* tap_chp
;
1759 struct jtag_tap
* tap_cpu
;
1760 tap_chp
= jtag_tap_by_string("dsp568013.chp");
1761 if (tap_chp
== NULL
) {
1762 retval
= ERROR_FAIL
;
1763 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER
, "Failed to get master tap.");
1765 tap_cpu
= jtag_tap_by_string("dsp568013.cpu");
1766 if (tap_cpu
== NULL
) {
1767 retval
= ERROR_FAIL
;
1768 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE
, "Failed to get master tap.");
1771 retval
= eonce_enter_debug_mode_without_reset(target
, &eonce_status
);
1772 if (retval
== ERROR_OK
)
1773 LOG_WARNING("Memory was not locked.");
1775 jtag_add_reset(0,1);
1776 jtag_add_sleep(TIME_DIV_FREESCALE
*200*1000);
1778 retval
= reset_jtag();
1779 err_check(retval
, DSP5680XX_ERROR_JTAG_RESET
, "Failed to reset JTAG state machine");
1780 jtag_add_sleep(150);
1783 tap_chp
->enabled
= true;
1784 retval
= switch_tap(target
,tap_chp
,tap_cpu
);
1785 err_check_propagate(retval
);
1787 instr
= JTAG_INSTR_DEBUG_REQUEST
;
1788 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_CORE_TAP_IRLEN
);
1789 err_check_propagate(retval
);
1790 jtag_add_sleep(TIME_DIV_FREESCALE
*100*1000);
1791 jtag_add_reset(0,0);
1792 jtag_add_sleep(TIME_DIV_FREESCALE
*300*1000);
1794 // Enable master tap
1795 tap_chp
->enabled
= false;
1796 retval
= switch_tap(target
,tap_chp
,tap_cpu
);
1797 err_check_propagate(retval
);
1799 // Execute mass erase to unlock
1800 instr
= MASTER_TAP_CMD_FLASH_ERASE
;
1801 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_MASTER_TAP_IRLEN
);
1802 err_check_propagate(retval
);
1804 instr
= HFM_CLK_DEFAULT
;
1805 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr
,(uint8_t *) & ir_out
,16);
1806 err_check_propagate(retval
);
1808 jtag_add_sleep(TIME_DIV_FREESCALE
*150*1000);
1809 jtag_add_reset(0,1);
1810 jtag_add_sleep(TIME_DIV_FREESCALE
*200*1000);
1812 retval
= reset_jtag();
1813 err_check(retval
, DSP5680XX_ERROR_JTAG_RESET
, "Failed to reset JTAG state machine");
1814 jtag_add_sleep(150);
1817 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr
,(uint8_t *) & ir_out
,32);
1818 err_check_propagate(retval
);
1822 retval
= dsp5680xx_irscan(target
, & instr
, & ir_out
,DSP5680XX_JTAG_MASTER_TAP_IRLEN
);
1823 err_check_propagate(retval
);
1825 retval
= dsp5680xx_drscan(target
,(uint8_t *) & instr
,(uint8_t *) & ir_out
,4);
1826 err_check_propagate(retval
);
1828 tap_cpu
->enabled
= true;
1829 tap_chp
->enabled
= false;
1830 target
->state
= TARGET_RUNNING
;
1831 dsp5680xx_context
.debug_mode_enabled
= false;
1835 int dsp5680xx_f_lock(struct target
*target
)
1838 struct jtag_tap
*tap_chp
;
1839 struct jtag_tap
*tap_cpu
;
1840 uint16_t lock_word
[] = {HFM_LOCK_FLASH
};
1841 retval
= dsp5680xx_f_wr(target
,(uint8_t *)(lock_word
),HFM_LOCK_ADDR_L
,2,1);
1842 err_check_propagate(retval
);
1844 jtag_add_reset(0,1);
1845 jtag_add_sleep(TIME_DIV_FREESCALE
*200*1000);
1847 retval
= reset_jtag();
1848 err_check(retval
, DSP5680XX_ERROR_JTAG_RESET
, "Failed to reset JTAG state machine");
1849 jtag_add_sleep(TIME_DIV_FREESCALE
*100*1000);
1850 jtag_add_reset(0,0);
1851 jtag_add_sleep(TIME_DIV_FREESCALE
*300*1000);
1853 tap_chp
= jtag_tap_by_string("dsp568013.chp");
1854 if (tap_chp
== NULL
) {
1855 retval
= ERROR_FAIL
;
1856 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_ENABLE_MASTER
, "Failed to get master tap.");
1858 tap_cpu
= jtag_tap_by_string("dsp568013.cpu");
1859 if (tap_cpu
== NULL
) {
1860 retval
= ERROR_FAIL
;
1861 err_check(retval
, DSP5680XX_ERROR_JTAG_TAP_ENABLE_CORE
, "Failed to get master tap.");
1863 target
->state
= TARGET_RUNNING
;
1864 dsp5680xx_context
.debug_mode_enabled
= false;
1865 tap_cpu
->enabled
= false;
1866 tap_chp
->enabled
= true;
1867 retval
= switch_tap(target
, tap_chp
, tap_cpu
);
1871 static int dsp5680xx_step(struct target
* target
,int current
, uint32_t address
, int handle_breakpoints
){
1872 err_check(ERROR_FAIL
, DSP5680XX_ERROR_NOT_IMPLEMENTED_STEP
, "Not implemented yet.");
1875 /** Holds methods for dsp5680xx targets. */
1876 struct target_type dsp5680xx_target
= {
1877 .name
= "dsp5680xx",
1879 .poll
= dsp5680xx_poll
,
1880 .arch_state
= dsp5680xx_arch_state
,
1882 .target_request_data
= NULL
,
1884 .halt
= dsp5680xx_halt
,
1885 .resume
= dsp5680xx_resume
,
1886 .step
= dsp5680xx_step
,
1888 .write_buffer
= dsp5680xx_write_buffer
,
1889 .read_buffer
= dsp5680xx_read_buffer
,
1891 .assert_reset
= dsp5680xx_assert_reset
,
1892 .deassert_reset
= dsp5680xx_deassert_reset
,
1893 .soft_reset_halt
= dsp5680xx_soft_reset_halt
,
1895 .read_memory
= dsp5680xx_read
,
1896 .write_memory
= dsp5680xx_write
,
1897 .bulk_write_memory
= dsp5680xx_bulk_write_memory
,
1899 .checksum_memory
= dsp5680xx_checksum_memory
,
1901 .target_create
= dsp5680xx_target_create
,
1902 .init_target
= dsp5680xx_init_target
,
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)