stlink: simplify handling of SWIM

Now that SWIM is not accessed through HLA anymore, decouple the
SWIM code and remove the conditional execution.

Fix the inconsistency of the return type for stlink_usb_state() in
case of SWIM (returns ERROR_OK while type is enum target_state)
introduced by commit 3de6b5f6e5 ("jtag/drivers/stlink_usb :
implemented and repaired SWIM support").
The code added by commit above in stlink_usb_state() is an hack to
reuse existing HLA API to perform a reconnect.
Move the SWIM specific code from stlink_usb_state() to a dedicated
stlink_swim_op_reconnect() that provides consistent data type.

Change-Id: I3fe175fef00b0735bea6139b057f217a080c9d38
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Fixes: 3de6b5f6e5 ("jtag/drivers/stlink_usb : implemented and repaired SWIM support")
Reviewed-on: http://openocd.zylin.com/5532
Tested-by: jenkins
This commit is contained in:
Antonio Borneo 2020-01-28 15:53:06 +01:00
parent 72f67790cf
commit ce9e21b769
1 changed files with 8 additions and 17 deletions

View File

@ -1761,18 +1761,6 @@ static enum target_state stlink_usb_state(void *handle)
assert(handle != NULL);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM) {
res = stlink_usb_mode_enter(handle, h->st_mode);
if (res != ERROR_OK)
return TARGET_UNKNOWN;
res = stlink_swim_resync(handle);
if (res != ERROR_OK)
return TARGET_UNKNOWN;
return ERROR_OK;
}
if (h->reconnect_pending) {
LOG_INFO("Previous state query failed, trying to reconnect");
res = stlink_usb_mode_enter(handle, h->st_mode);
@ -1892,9 +1880,6 @@ static int stlink_usb_reset(void *handle)
assert(handle != NULL);
if (h->st_mode == STLINK_MODE_DEBUG_SWIM)
return stlink_swim_generate_rst(handle);
stlink_usb_init_buffer(handle, h->rx_ep, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
@ -3536,7 +3521,7 @@ static void stlink_dap_op_quit(struct adiv5_dap *dap)
static int stlink_swim_op_srst(void)
{
return stlink_usb_reset(stlink_dap_handle);
return stlink_swim_generate_rst(stlink_dap_handle);
}
static int stlink_swim_op_read_mem(uint32_t addr, uint32_t size,
@ -3587,7 +3572,13 @@ static int stlink_swim_op_write_mem(uint32_t addr, uint32_t size,
static int stlink_swim_op_reconnect(void)
{
return stlink_usb_state(stlink_dap_handle);
int retval;
retval = stlink_usb_mode_enter(stlink_dap_handle, STLINK_MODE_DEBUG_SWIM);
if (retval != ERROR_OK)
return retval;
return stlink_swim_resync(stlink_dap_handle);
}
static int stlink_dap_config_trace(bool enabled,