hosted/stlink: make swd scan function more consisted with other probes

Signed-off-by: Rafael Silva <perigoso@riseup.net>
This commit is contained in:
Rafael Silva 2022-08-06 02:32:12 +01:00 committed by Rachel Mant
parent ce6477886f
commit 3a673225b7
3 changed files with 18 additions and 23 deletions

View File

@ -147,24 +147,8 @@ int platform_adiv5_swdp_scan(uint32_t targetid)
return adiv5_swdp_scan(targetid); return adiv5_swdp_scan(targetid);
break; break;
case BMP_TYPE_STLINKV2: { case BMP_TYPE_STLINKV2:
target_list_free(); return stlink_swdp_scan(&info);
ADIv5_DP_t *dp = calloc(1, sizeof(*dp));
if (!dp) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return 0;
}
if (stlink_enter_debug_swd(&info, dp)) {
free(dp);
} else {
adiv5_dp_init(dp);
if (target_list)
return 1;
}
break;
}
case BMP_TYPE_JLINK: case BMP_TYPE_JLINK:
return jlink_swdp_scan(&info); return jlink_swdp_scan(&info);

View File

@ -33,6 +33,7 @@
#include "jtag_devs.h" #include "jtag_devs.h"
#include "target.h" #include "target.h"
#include "cortexm.h" #include "cortexm.h"
#include "target_internal.h"
#include <assert.h> #include <assert.h>
#include <unistd.h> #include <unistd.h>
@ -1067,8 +1068,10 @@ void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp)
dp->mem_write_sized = stlink_mem_write_sized; dp->mem_write_sized = stlink_mem_write_sized;
} }
int stlink_enter_debug_swd(bmp_info_t *info, ADIv5_DP_t *dp) int stlink_swdp_scan(bmp_info_t *info)
{ {
target_list_free();
stlink_leave_state(info); stlink_leave_state(info);
uint8_t cmd[16] = {STLINK_DEBUG_COMMAND, uint8_t cmd[16] = {STLINK_DEBUG_COMMAND,
@ -1079,7 +1082,13 @@ int stlink_enter_debug_swd(bmp_info_t *info, ADIv5_DP_t *dp)
stlink_send_recv_retry(cmd, 16, data, 2); stlink_send_recv_retry(cmd, 16, data, 2);
if (stlink_usb_error_check(data, true)) if (stlink_usb_error_check(data, true))
exit( -1); return 0;
ADIv5_DP_t *dp = calloc(1, sizeof(*dp));
if (!dp) { /* calloc failed: heap exhaustion */
DEBUG_WARN("calloc: failed in %s\n", __func__);
return 0;
}
dp->dp_read = stlink_dp_read; dp->dp_read = stlink_dp_read;
dp->error = stlink_dp_error; dp->error = stlink_dp_error;
@ -1088,7 +1097,9 @@ int stlink_enter_debug_swd(bmp_info_t *info, ADIv5_DP_t *dp)
stlink_dp_error(dp); stlink_dp_error(dp);
return 0; adiv5_dp_init(dp);
return target_list ? 1U : 0U;
} }
#define V2_USED_SWD_CYCLES 20 #define V2_USED_SWD_CYCLES 20

View File

@ -32,7 +32,7 @@ int stlink_hwversion(void) { return -1; }
const char *stlink_target_voltage(bmp_info_t *info) { return "ERROR"; } const char *stlink_target_voltage(bmp_info_t *info) { return "ERROR"; }
void stlink_nrst_set_val(bmp_info_t *info, bool assert) { } void stlink_nrst_set_val(bmp_info_t *info, bool assert) { }
bool stlink_nrst_get_val(void) { return true; } bool stlink_nrst_get_val(void) { return true; }
int stlink_enter_debug_swd(bmp_info_t *info, ADIv5_DP_t *dp) { return -1; } int stlink_swdp_scan(bmp_info_t *info) { return 0; }
void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp) { } void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp) { }
int stlink_jtag_dp_init(ADIv5_DP_t *dp) { return false; } int stlink_jtag_dp_init(ADIv5_DP_t *dp) { return false; }
int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens) { return 0; } int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens) { return 0; }
@ -46,7 +46,7 @@ int stlink_hwversion(void);
const char *stlink_target_voltage(bmp_info_t *info); const char *stlink_target_voltage(bmp_info_t *info);
void stlink_nrst_set_val(bmp_info_t *info, bool assert); void stlink_nrst_set_val(bmp_info_t *info, bool assert);
bool stlink_nrst_get_val(void); bool stlink_nrst_get_val(void);
int stlink_enter_debug_swd(bmp_info_t *info, ADIv5_DP_t *dp); int stlink_swdp_scan(bmp_info_t *info);
void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp); void stlink_adiv5_dp_defaults(ADIv5_DP_t *dp);
int stlink_jtag_dp_init(ADIv5_DP_t *dp); int stlink_jtag_dp_init(ADIv5_DP_t *dp);
int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens); int jtag_scan_stlinkv2(bmp_info_t *info, const uint8_t *irlens);