SWD: Use dp_low_write to allow multidrop scan.

This commit is contained in:
Uwe Bonnes 2021-10-23 21:08:26 +02:00
parent 4f36c1ddf8
commit a1d4649795
3 changed files with 12 additions and 17 deletions

View File

@ -457,10 +457,9 @@ int dap_swdptap_init(ADIv5_DP_t *dp)
/* DAP_SWD_SEQUENCE does not do auto turnaround, use own!*/ /* DAP_SWD_SEQUENCE does not do auto turnaround, use own!*/
dp->dp_low_write = dap_dp_low_write; dp->dp_low_write = dap_dp_low_write;
} else { } else {
dp->error = dap_dp_error; dp->dp_low_write = NULL;
} }
dp->seq_out = dap_swdptap_seq_out; dp->seq_out = dap_swdptap_seq_out;
dp->seq_out_parity = dap_swdptap_seq_out_parity;
dp->dp_read = dap_dp_read_reg; dp->dp_read = dap_dp_read_reg;
/* For error() use the TARGETID switching firmware_swdp_error */ /* For error() use the TARGETID switching firmware_swdp_error */
dp->low_access = dap_dp_low_access; dp->low_access = dap_dp_low_access;

View File

@ -331,12 +331,8 @@ static uint32_t wait_word(uint8_t *buf, int size, int len, uint8_t *dp_fault)
if (buf[1] > DAP_TRANSFER_WAIT) { if (buf[1] > DAP_TRANSFER_WAIT) {
DEBUG_WARN("dap wait_word reg %x fault %x\n", DEBUG_WARN("dap wait_word reg %x fault %x\n",
cmd_copy[3] & 0x7c, buf[1]); cmd_copy[3], buf[1]);
*dp_fault = 1; *dp_fault = 1;
if (buf[1] == DAP_TRANSFER_ERROR) {
DEBUG_WARN("dap_read_reg, protocoll error\n");
dap_line_reset();
}
return 0; return 0;
} }
uint32_t res = uint32_t res =

View File

@ -92,8 +92,8 @@ int adiv5_swdp_scan(uint32_t targetid)
initial_dp->seq_out(0x1a0, 12); initial_dp->seq_out(0x1a0, 12);
uint32_t idcode = 0; uint32_t idcode = 0;
volatile uint32_t target_id; volatile uint32_t target_id;
bool is_v2 = true; bool scan_multidrop = true;
if (!targetid || (initial_dp->error != firmware_swdp_error)) { if (!targetid || !initial_dp->dp_low_write) {
/* No targetID given on the command line or probe can not /* No targetID given on the command line or probe can not
* handle multi-drop. Try to read ID */ * handle multi-drop. Try to read ID */
dp_line_reset(initial_dp); dp_line_reset(initial_dp);
@ -102,7 +102,7 @@ int adiv5_swdp_scan(uint32_t targetid)
idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE); idcode = initial_dp->dp_read(initial_dp, ADIV5_DP_IDCODE);
} }
if (e.type || initial_dp->fault) { if (e.type || initial_dp->fault) {
is_v2 = false; scan_multidrop = false;
DEBUG_WARN("Trying old JTAG to SWD sequence\n"); DEBUG_WARN("Trying old JTAG to SWD sequence\n");
initial_dp->seq_out(0xFFFFFFFF, 32); initial_dp->seq_out(0xFFFFFFFF, 32);
initial_dp->seq_out(0xFFFFFFFF, 32); initial_dp->seq_out(0xFFFFFFFF, 32);
@ -119,7 +119,7 @@ int adiv5_swdp_scan(uint32_t targetid)
} }
} }
if ((idcode & ADIV5_DP_VERSION_MASK) == ADIV5_DPv2) { if ((idcode & ADIV5_DP_VERSION_MASK) == ADIV5_DPv2) {
is_v2 = true; scan_multidrop = true;
/* Read TargetID. Can be done with device in WFI, sleep or reset!*/ /* Read TargetID. Can be done with device in WFI, sleep or reset!*/
adiv5_dp_write(initial_dp, ADIV5_DP_SELECT, 2); adiv5_dp_write(initial_dp, ADIV5_DP_SELECT, 2);
target_id = adiv5_dp_read(initial_dp, ADIV5_DP_CTRLSTAT); target_id = adiv5_dp_read(initial_dp, ADIV5_DP_CTRLSTAT);
@ -131,21 +131,21 @@ int adiv5_swdp_scan(uint32_t targetid)
adiv5_dp_write(initial_dp, ADIV5_DP_CTRLSTAT, 0); adiv5_dp_write(initial_dp, ADIV5_DP_CTRLSTAT, 0);
break; break;
} }
if (initial_dp->error != firmware_swdp_error) { if (!initial_dp->dp_low_write) {
DEBUG_WARN("CMSIS_DAP < V1.2 can not handle multi-drop!\n"); DEBUG_WARN("CMSIS_DAP < V1.2 can not handle multi-drop!\n");
/* E.g. CMSIS_DAP < V1.2 can not handle multi-drop!*/ /* E.g. CMSIS_DAP < V1.2 can not handle multi-drop!*/
is_v2 = false; scan_multidrop = false;
} }
} else { } else {
is_v2 = false; scan_multidrop = false;
} }
} else { } else {
target_id = targetid; target_id = targetid;
} }
volatile int nr_dps = (is_v2) ? 16: 1; volatile int nr_dps = (scan_multidrop) ? 16: 1;
volatile uint32_t dp_targetid; volatile uint32_t dp_targetid;
for (volatile int i = 0; i < nr_dps; i++) { for (volatile int i = 0; i < nr_dps; i++) {
if (is_v2) { if (scan_multidrop) {
dp_line_reset(initial_dp); dp_line_reset(initial_dp);
dp_targetid = (i << 28) | (target_id & 0x0fffffff); dp_targetid = (i << 28) | (target_id & 0x0fffffff);
initial_dp->dp_low_write(initial_dp, ADIV5_DP_TARGETSEL, initial_dp->dp_low_write(initial_dp, ADIV5_DP_TARGETSEL,
@ -158,7 +158,7 @@ int adiv5_swdp_scan(uint32_t targetid)
continue; continue;
} }
} else { } else {
dp_targetid = 0; dp_targetid = target_id;
} }
ADIv5_DP_t *dp = (void*)calloc(1, sizeof(*dp)); ADIv5_DP_t *dp = (void*)calloc(1, sizeof(*dp));
if (!dp) { /* calloc failed: heap exhaustion */ if (!dp) { /* calloc failed: heap exhaustion */