Most of ST-Link commands return an error code, but this is almost
never checked.
Check for the error code for every command that returns it.
Change-Id: Ifc4e32f8c73196de23700ba0989bfdfe0f5b46e3
Signed-off-by: Antonio Borneo <borneo.antonio@gmail.com>
Reviewed-on: http://openocd.zylin.com/4825
Tested-by: jenkins
Reviewed-by: Tomas Vanek <vanekt@fbl.cz>
transfers block in cmdbuf
<size> indicates number of bytes in the following
data phase.
transfers block in cmdbuf
<size> indicates number of bytes in the following
data phase.
+ Ignore the (eventual) error code in the received packet.
-static int stlink_usb_xfer(void *handle, const uint8_t *buf, int size)
+static int stlink_usb_xfer_noerrcheck(void *handle, const uint8_t *buf, int size)
{
int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h = handle;
{
int err, cmdsize = STLINK_CMD_SIZE_V2;
struct stlink_usb_handle_s *h = handle;
+/*
+ * Wrapper around stlink_usb_xfer_noerrcheck()
+ * to check the error code in the received packet
+ */
+static int stlink_usb_xfer_errcheck(void *handle, const uint8_t *buf, int size)
+{
+ int retval;
+
+ assert(size > 0);
+
+ retval = stlink_usb_xfer_noerrcheck(handle, buf, size);
+ if (retval != ERROR_OK)
+ return retval;
+
+ return stlink_usb_error_check(handle);
+}
/** Issue an STLINK command via USB transfer, with retries on any wait status responses.
/** Issue an STLINK command via USB transfer, with retries on any wait status responses.
while (1) {
if ((h->transport != HL_TRANSPORT_SWIM) || !retries) {
while (1) {
if ((h->transport != HL_TRANSPORT_SWIM) || !retries) {
- res = stlink_usb_xfer(handle, buf, size);
+ res = stlink_usb_xfer_noerrcheck(handle, buf, size);
if (res != ERROR_OK)
return res;
}
if (res != ERROR_OK)
return res;
}
h->cmdbuf[h->cmdidx++] = STLINK_GET_VERSION;
h->cmdbuf[h->cmdidx++] = STLINK_GET_VERSION;
- res = stlink_usb_xfer(handle, h->databuf, 6);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 6);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h->cmdbuf[h->cmdidx++] = STLINK_APIV3_GET_VERSION_EX;
h->cmdbuf[h->cmdidx++] = STLINK_APIV3_GET_VERSION_EX;
- res = stlink_usb_xfer(handle, h->databuf, 12);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 12);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h->cmdbuf[h->cmdidx++] = STLINK_GET_TARGET_VOLTAGE;
h->cmdbuf[h->cmdidx++] = STLINK_GET_TARGET_VOLTAGE;
- int result = stlink_usb_xfer(handle, h->databuf, 8);
+ int result = stlink_usb_xfer_noerrcheck(handle, h->databuf, 8);
if (result != ERROR_OK)
return result;
if (result != ERROR_OK)
return result;
h->cmdbuf[h->cmdidx++] = STLINK_GET_CURRENT_MODE;
h->cmdbuf[h->cmdidx++] = STLINK_GET_CURRENT_MODE;
- res = stlink_usb_xfer(handle, h->databuf, 2);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 2);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
- res = stlink_usb_xfer(handle, 0, 0);
+ res = stlink_usb_xfer_noerrcheck(handle, 0, 0);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
stlink_usb_init_buffer(handle, h->rx_ep, 4);
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_READSTATUS;
stlink_usb_init_buffer(handle, h->rx_ep, 4);
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_READSTATUS;
- res = stlink_usb_xfer(handle, h->databuf, 4);
+ /* error is checked by the caller */
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 4);
if (res != ERROR_OK)
return res;
return ERROR_OK;
if (res != ERROR_OK)
return res;
return ERROR_OK;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_READ_CAP;
h->cmdbuf[h->cmdidx++] = 0x01;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_READ_CAP;
h->cmdbuf[h->cmdidx++] = 0x01;
- res = stlink_usb_xfer(handle, h->databuf, 8);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 8);
if (res != ERROR_OK)
return res;
memcpy(cap, h->databuf, 8);
if (res != ERROR_OK)
return res;
memcpy(cap, h->databuf, 8);
stlink_usb_init_buffer(handle, h->rx_ep, len);
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_READBUF;
stlink_usb_init_buffer(handle, h->rx_ep, len);
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_SWIM_READBUF;
- res = stlink_usb_xfer(handle, data, len);
+ res = stlink_usb_xfer_noerrcheck(handle, data, len);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_READCOREID;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_READCOREID;
- res = stlink_usb_xfer(handle, h->databuf, 4);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 4);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_GET_TRACE_NB;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_GET_TRACE_NB;
- res = stlink_usb_xfer(handle, h->databuf, 2);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 2);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_GETSTATUS;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_GETSTATUS;
- res = stlink_usb_xfer(handle, h->databuf, 2);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 2);
if (res != ERROR_OK)
return TARGET_UNKNOWN;
if (res != ERROR_OK)
return TARGET_UNKNOWN;
stlink_usb_init_buffer(handle, h->rx_ep, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_STOP_TRACE_RX;
stlink_usb_init_buffer(handle, h->rx_ep, 2);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_STOP_TRACE_RX;
- res = stlink_usb_xfer(handle, h->databuf, 2);
+ res = stlink_usb_xfer_errcheck(handle, h->databuf, 2);
if (res == ERROR_OK)
h->trace.enabled = false;
if (res == ERROR_OK)
h->trace.enabled = false;
h_u32_to_le(h->cmdbuf+h->cmdidx, h->trace.source_hz);
h->cmdidx += 4;
h_u32_to_le(h->cmdbuf+h->cmdidx, h->trace.source_hz);
h->cmdidx += 4;
- res = stlink_usb_xfer(handle, h->databuf, 2);
+ res = stlink_usb_xfer_errcheck(handle, h->databuf, 2);
if (res == ERROR_OK) {
h->trace.enabled = true;
if (res == ERROR_OK) {
h->trace.enabled = true;
if (h->version.jtag_api == STLINK_JTAG_API_V1) {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV1_READALLREGS;
if (h->version.jtag_api == STLINK_JTAG_API_V1) {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV1_READALLREGS;
- res = stlink_usb_xfer(handle, h->databuf, 84);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 84);
/* regs data from offset 0 */
} else {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_READALLREGS;
/* regs data from offset 0 */
} else {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_READALLREGS;
- res = stlink_usb_xfer(handle, h->databuf, 88);
+ res = stlink_usb_xfer_errcheck(handle, h->databuf, 88);
/* status at offset 0, regs data from offset 4 */
}
/* status at offset 0, regs data from offset 4 */
}
h->cmdbuf[h->cmdidx++] = num;
if (h->version.jtag_api == STLINK_JTAG_API_V1) {
h->cmdbuf[h->cmdidx++] = num;
if (h->version.jtag_api == STLINK_JTAG_API_V1) {
- res = stlink_usb_xfer(handle, h->databuf, 4);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, 4);
if (res != ERROR_OK)
return res;
*val = le_to_h_u32(h->databuf);
if (res != ERROR_OK)
return res;
*val = le_to_h_u32(h->databuf);
static int stlink_usb_get_rw_status(void *handle)
{
static int stlink_usb_get_rw_status(void *handle)
{
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
struct stlink_usb_handle_s *h = handle;
assert(handle != NULL);
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
if (h->version.flags & STLINK_F_HAS_GETLASTRWSTATUS2) {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_GETLASTRWSTATUS2;
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_COMMAND;
if (h->version.flags & STLINK_F_HAS_GETLASTRWSTATUS2) {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_GETLASTRWSTATUS2;
-
- res = stlink_usb_xfer(handle, h->databuf, 12);
+ return stlink_usb_xfer_errcheck(handle, h->databuf, 12);
} else {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_GETLASTRWSTATUS;
} else {
h->cmdbuf[h->cmdidx++] = STLINK_DEBUG_APIV2_GETLASTRWSTATUS;
-
- res = stlink_usb_xfer(handle, h->databuf, 2);
+ return stlink_usb_xfer_errcheck(handle, h->databuf, 2);
-
- if (res != ERROR_OK)
- return res;
-
- return stlink_usb_error_check(h);
if (read_len == 1)
read_len++;
if (read_len == 1)
read_len++;
- res = stlink_usb_xfer(handle, h->databuf, read_len);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, read_len);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
- res = stlink_usb_xfer(handle, buffer, len);
+ res = stlink_usb_xfer_noerrcheck(handle, buffer, len);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
- res = stlink_usb_xfer(handle, h->databuf, len);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, len);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
- res = stlink_usb_xfer(handle, buffer, len);
+ res = stlink_usb_xfer_noerrcheck(handle, buffer, len);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
- res = stlink_usb_xfer(handle, h->databuf, len);
+ res = stlink_usb_xfer_noerrcheck(handle, h->databuf, len);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
h_u16_to_le(h->cmdbuf+h->cmdidx, len);
h->cmdidx += 2;
- res = stlink_usb_xfer(handle, buffer, len);
+ res = stlink_usb_xfer_noerrcheck(handle, buffer, len);
if (res != ERROR_OK)
return res;
if (res != ERROR_OK)
return res;
h->cmdbuf[h->cmdidx++] = STLINK_APIV3_GET_COM_FREQ;
h->cmdbuf[h->cmdidx++] = is_jtag ? 1 : 0;
h->cmdbuf[h->cmdidx++] = STLINK_APIV3_GET_COM_FREQ;
h->cmdbuf[h->cmdidx++] = is_jtag ? 1 : 0;
- int res = stlink_usb_xfer(handle, h->databuf, 52);
+ int res = stlink_usb_xfer_errcheck(handle, h->databuf, 52);
int size = h->databuf[8];
int size = h->databuf[8];
h_u32_to_le(&h->cmdbuf[4], frequency);
h_u32_to_le(&h->cmdbuf[4], frequency);
- return stlink_usb_xfer(handle, h->databuf, 8);
+ return stlink_usb_xfer_errcheck(handle, h->databuf, 8);
}
static int stlink_speed_v3(void *handle, bool is_jtag, int khz, bool query)
}
static int stlink_speed_v3(void *handle, bool is_jtag, int khz, bool query)
Linking to existing account procedure
If you already have an account and want to add another login method
you
MUST first sign in with your existing account and
then change URL to read
https://review.openocd.org/login/?link
to get to this page again but this time it'll work for linking. Thank you.
SSH host keys fingerprints
1024 SHA256:YKx8b7u5ZWdcbp7/4AeXNaqElP49m6QrwfXaqQGJAOk gerrit-code-review@openocd.zylin.com (DSA)
384 SHA256:jHIbSQa4REvwCFG4cq5LBlBLxmxSqelQPem/EXIrxjk gerrit-code-review@openocd.org (ECDSA)
521 SHA256:UAOPYkU9Fjtcao0Ul/Rrlnj/OsQvt+pgdYSZ4jOYdgs gerrit-code-review@openocd.org (ECDSA)
256 SHA256:A13M5QlnozFOvTllybRZH6vm7iSt0XLxbA48yfc2yfY gerrit-code-review@openocd.org (ECDSA)
256 SHA256:spYMBqEYoAOtK7yZBrcwE8ZpYt6b68Cfh9yEVetvbXg gerrit-code-review@openocd.org (ED25519)
+--[ED25519 256]--+
|=.. |
|+o.. . |
|*.o . . |
|+B . . . |
|Bo. = o S |
|Oo.+ + = |
|oB=.* = . o |
| =+=.+ + E |
|. .=o . o |
+----[SHA256]-----+
2048 SHA256:0Onrb7/PHjpo6iVZ7xQX2riKN83FJ3KGU0TvI0TaFG4 gerrit-code-review@openocd.zylin.com (RSA)