From 3388e48d9229475f183fc66433aeb68fc1d2027c Mon Sep 17 00:00:00 2001 From: Uwe Bonnes Date: Sun, 26 May 2019 22:10:42 +0200 Subject: [PATCH] stlinkv2: Do not loop endless when Read DP fails. --- src/platforms/pc-stlinkv2/stlinkv2.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/platforms/pc-stlinkv2/stlinkv2.c b/src/platforms/pc-stlinkv2/stlinkv2.c index 77fc87f..ee0654e 100644 --- a/src/platforms/pc-stlinkv2/stlinkv2.c +++ b/src/platforms/pc-stlinkv2/stlinkv2.c @@ -311,7 +311,7 @@ static int submit_wait(struct libusb_transfer * trans) { return 0; } - +#define STLINK_ERROR_DP_FAULT -2 static int send_recv(uint8_t *txbuf, size_t txsize, uint8_t *rxbuf, size_t rxsize) { @@ -421,7 +421,7 @@ static int stlink_usb_error_check(uint8_t *data, bool verbose) */ if (verbose) DEBUG("STLINK_SWD_AP_FAULT\n"); - return STLINK_ERROR_FAIL; + return STLINK_ERROR_DP_FAULT; case STLINK_SWD_AP_ERROR: if (verbose) DEBUG("STLINK_SWD_AP_ERROR\n"); @@ -1015,10 +1015,13 @@ uint32_t stlink_dp_low_access(ADIv5_DP_t *dp, uint8_t RnW, if (res == STLINK_ERROR_WAIT) raise_exception(EXCEPTION_TIMEOUT, "DP ACK timeout"); - if(res == STLINK_ERROR_FAIL) { + if(res == STLINK_ERROR_DP_FAULT) { dp->fault = 1; return 0; } + if(res == STLINK_ERROR_FAIL) + raise_exception(EXCEPTION_ERROR, "SWDP invalid ACK"); + return response; }