swd: handle various failure conditions

When communication with target fails for whatever reason, it makes
sense to do JTAG-to-SWD (in case the target got power-cycled or the
DAP method was reset anyhow), SWD line reset sequence (part of
JTAG-to-SWD already) and the mandatory IDCODE read. Schedule that to
be performed on the next poll.

Fix the return values for ftdi and jlink drivers to be consistent with
OpenOCD error codes and remove ad-hoc calls to perform DAP method
switching (as it's now done from the upper layer automatically).

Change-Id: Ie18797d4ce7ac43d8249f8f81f1064a2424e02be
Signed-off-by: Paul Fertser <fercerpav@gmail.com>
Reviewed-on: http://openocd.zylin.com/2371
Tested-by: jenkins
Reviewed-by: Spencer Oliver <spen@spen-soft.co.uk>
Reviewed-by: Mateusz Manowiecki <segmentation@fault.pl>
This commit is contained in:
Paul Fertser
2014-11-02 15:16:13 +03:00
committed by Spencer Oliver
parent c120fb6d89
commit 9f6d4d1302
4 changed files with 51 additions and 40 deletions

View File

@@ -655,11 +655,6 @@ static int ftdi_initialize(void)
freq = mpsse_set_frequency(mpsse_ctx, jtag_get_speed_khz() * 1000);
if (swd_mode)
ftdi_swd_switch_seq(NULL, JTAG_TO_SWD);
else
ftdi_swd_switch_seq(NULL, SWD_TO_JTAG);
return mpsse_flush(mpsse_ctx);
}
@@ -981,7 +976,7 @@ static int ftdi_swd_run_queue(struct adiv5_dap *dap)
1 + 3 + (swd_cmd_queue[i].cmd & SWD_CMD_RnW ? 0 : 1), 32));
if (ack != SWD_ACK_OK) {
queued_retval = ack;
queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL;
goto skip;
} else if (swd_cmd_queue[i].cmd & SWD_CMD_RnW) {

View File

@@ -590,12 +590,6 @@ static int jlink_init(void)
jlink_tap_execute();
}
if (swd_mode)
jlink_swd_switch_seq(NULL, JTAG_TO_SWD);
else
jlink_swd_switch_seq(NULL, SWD_TO_JTAG);
jlink_swd_run_queue(NULL);
return ERROR_OK;
}
@@ -1664,9 +1658,9 @@ static int jlink_swd_run_queue(struct adiv5_dap *dap)
int ack = buf_get_u32(usb_in_buffer, pending_scan_results_buffer[i].first, 3);
if (ack != SWD_ACK_OK) {
LOG_ERROR("SWD ack not OK: %d %s", ack,
LOG_DEBUG("SWD ack not OK: %d %s", ack,
ack == SWD_ACK_WAIT ? "WAIT" : ack == SWD_ACK_FAULT ? "FAULT" : "JUNK");
queued_retval = ack;
queued_retval = ack == SWD_ACK_WAIT ? ERROR_WAIT : ERROR_FAIL;
goto skip;
} else if (pending_scan_results_buffer[i].length) {
uint32_t data = buf_get_u32(usb_in_buffer, 3 + pending_scan_results_buffer[i].first, 32);