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 */
{
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 */
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);