From 2ec1e2b25d75766095e99ac158517d5128e2d287 Mon Sep 17 00:00:00 2001 From: Fabien Le Mentec Date: Mon, 17 Oct 2011 16:21:29 -0500 Subject: [PATCH] [fix] read_mem32 needs to add +1 to len --- flash/main.c | 10 ++++++---- src/stlink-usb.c | 3 +++ 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/flash/main.c b/flash/main.c index 5fb6f1c..3b9416d 100644 --- a/flash/main.c +++ b/flash/main.c @@ -83,9 +83,6 @@ int main(int ac, char** av) static const int scsi_verbose = 2; sl = stlink_quirk_open(o.devname, scsi_verbose); if (sl == NULL) goto on_error; - - if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) - stlink_exit_dfu_mode(sl); } else /* stlinkv2 */ { @@ -93,7 +90,12 @@ int main(int ac, char** av) if (sl == NULL) goto on_error; } - stlink_enter_swd_mode(sl); + if (stlink_current_mode(sl) == STLINK_DEV_DFU_MODE) + stlink_exit_dfu_mode(sl); + + if (stlink_current_mode(sl) != STLINK_DEV_DEBUG_MODE) + stlink_enter_swd_mode(sl); + stlink_reset(sl); if (o.do_read == 0) /* write */ diff --git a/src/stlink-usb.c b/src/stlink-usb.c index 533a632..9c28e9f 100644 --- a/src/stlink-usb.c +++ b/src/stlink-usb.c @@ -398,6 +398,9 @@ void _stlink_usb_read_mem32(stlink_t *sl, uint32_t addr, uint16_t len) { buf[0] = STLINK_DEBUG_COMMAND; buf[1] = STLINK_DEBUG_READMEM_32BIT; write_uint32(buf + 2, addr); + + /* need to add +1 to len, otherwise get residue errors */ + len += 1; buf[6] = (uint8_t) len; buf[7] = (uint8_t) (len >> 8); -- 2.30.2