[fix] read_mem32 needs to add +1 to len
authorFabien Le Mentec <texane@gmail.com>
Mon, 17 Oct 2011 21:21:29 +0000 (16:21 -0500)
committerFabien Le Mentec <texane@gmail.com>
Mon, 17 Oct 2011 21:21:29 +0000 (16:21 -0500)
flash/main.c
src/stlink-usb.c

index 5fb6f1c97f902687250d4f238258749fd373d893..3b9416dff1b885f2d8714dacb7f60bf01b407bbd 100644 (file)
@@ -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 */
index 533a632ea081ca461e14aa4dd3aa0dc02219be91..9c28e9f3bceff283d7f8bff54bcf16e2c3c5d2b5 100644 (file)
@@ -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);