#define STLINK_CMD_SIZE_V1 (10)
enum stlink_jtag_api_version {
- STLINK_JTAG_API_V1 = 0,
+ STLINK_JTAG_API_V1 = 1,
STLINK_JTAG_API_V2,
};
h->pid = buf_get_u32(h->databuf, 32, 16);
/* set the supported jtag api version
- * V1 doesn't support API V2 at all
- * V2 support API V2 since JTAG V13
+ * API V2 is supported since JTAG V11
*/
- if ((h->version.stlink == 2) && (h->version.jtag > 12))
+ if (h->version.jtag >= 11)
h->version.jtag_api_max = STLINK_JTAG_API_V2;
else
h->version.jtag_api_max = STLINK_JTAG_API_V1;
h = (struct stlink_usb_handle_s *)handle;
- if (h->jtag_api == STLINK_JTAG_API_V2)
- return stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_STEP|C_DEBUGEN);
+ if (h->jtag_api == STLINK_JTAG_API_V2) {
+ /* TODO: this emulates the v1 api, it should really use a similar auto mask isr
+ * that the cortex-m3 currently does. */
+ stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_MASKINTS|C_DEBUGEN);
+ stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_STEP|C_MASKINTS|C_DEBUGEN);
+ return stlink_usb_write_debug_reg(handle, DCB_DHCSR, DBGKEY|C_HALT|C_DEBUGEN);
+ }
stlink_usb_init_buffer(handle, STLINK_RX_EP, 2);
{
int err;
struct stlink_usb_handle_s *h;
+ enum stlink_jtag_api_version api;
LOG_DEBUG("stlink_usb_open");
return err;
}
+ api = h->version.jtag_api_max;
+
+ /* check that user has not requested certain api version
+ * and if they have check it is supported */
+ if ((param->api != 0) && (param->api <= h->version.jtag_api_max)) {
+ api = param->api;
+ LOG_INFO("using stlink api v%d", api);
+ }
+
/* set the used jtag api, this will default to the newest supported version */
- h->jtag_api = h->version.jtag_api_max;
+ h->jtag_api = api;
/* initialize the debug hardware */
err = stlink_usb_init_mode(h);
.read_mem32 = stlink_usb_read_mem32,
/** */
.write_mem32 = stlink_usb_write_mem32,
+ /** */
+ .write_debug_reg = stlink_usb_write_debug_reg
};