/* vid = pid = 0 marks the end of the list */
static uint16_t cmsis_dap_vid[MAX_USB_IDS + 1] = { 0 };
static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 };
+static bool swd_mode;
#define PACKET_SIZE (64 + 1) /* 64 bytes plus report id */
#define USB_TIMEOUT 1000
if ((cmsis_dap_vid[i] == cur_dev->vendor_id) && (cmsis_dap_pid[i] == cur_dev->product_id))
break;
}
+ if (cmsis_dap_vid[i] || cmsis_dap_pid[i])
+ break;
}
cur_dev = cur_dev->next;
hid_free_enumeration(devs);
+ if (target_vid == 0 && target_pid == 0) {
+ LOG_ERROR("unable to find CMSIS-DAP device");
+ return ERROR_FAIL;
+ }
+
if (hid_init() != 0) {
LOG_ERROR("unable to open HIDAPI");
return ERROR_FAIL;
}
#endif
-static int cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value)
+static int queued_retval;
+
+static void cmsis_dap_swd_read_reg(struct adiv5_dap *dap, uint8_t cmd, uint32_t *value)
{
+ if (queued_retval != ERROR_OK)
+ return;
+
uint8_t *buffer = cmsis_dap_handle->packet_buffer;
int retval;
uint32_t val;
/* TODO - need better response checking */
if (retval != ERROR_OK || buffer[1] != 0x01) {
LOG_ERROR("CMSIS-DAP: Read Error (0x%02" PRIx8 ")", buffer[2]);
- return buffer[2];
+ queued_retval = buffer[2];
+ return;
}
val = le_to_h_u32(&buffer[3]);
if (value)
*value = val;
- return retval;
+ queued_retval = retval;
}
-static int cmsis_dap_swd_write_reg(uint8_t cmd, uint32_t value)
+static void cmsis_dap_swd_write_reg(struct adiv5_dap *dap, uint8_t cmd, uint32_t value)
{
+ if (queued_retval != ERROR_OK)
+ return;
+
uint8_t *buffer = cmsis_dap_handle->packet_buffer;
DEBUG_IO("CMSIS-DAP: Write Reg 0x%02" PRIx8 " 0x%08" PRIx32, cmd, value);
retval = buffer[2];
}
+ queued_retval = retval;
+}
+
+static int cmsis_dap_swd_run(struct adiv5_dap *dap)
+{
+ int retval = queued_retval;
+ queued_retval = ERROR_OK;
return retval;
}
return retval;
}
+static int cmsis_dap_swd_open(void)
+{
+ int retval;
+
+ DEBUG_IO("CMSIS-DAP: cmsis_dap_swd_open");
+
+ if (cmsis_dap_handle == NULL) {
+
+ /* SWD init */
+ retval = cmsis_dap_usb_open();
+ if (retval != ERROR_OK)
+ return retval;
+
+ retval = cmsis_dap_get_caps_info();
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
+ if (!(cmsis_dap_handle->caps & INFO_CAPS_SWD)) {
+ LOG_ERROR("CMSIS-DAP: SWD not supported");
+ return ERROR_JTAG_DEVICE_ERROR;
+ }
+
+ retval = cmsis_dap_cmd_DAP_Connect(CONNECT_SWD);
+ if (retval != ERROR_OK)
+ return retval;
+
+ /* Add more setup here.??... */
+
+ LOG_INFO("CMSIS-DAP: Interface Initialised (SWD)");
+ return ERROR_OK;
+}
+
static int cmsis_dap_init(void)
{
int retval;
uint8_t *data;
+ if (swd_mode) {
+ retval = cmsis_dap_swd_open();
+ if (retval != ERROR_OK)
+ return retval;
+ }
+
if (cmsis_dap_handle == NULL) {
/* JTAG init */
return ERROR_OK;
}
-static int cmsis_dap_swd_init(uint8_t trn)
+static int cmsis_dap_swd_init(void)
{
- int retval;
-
- DEBUG_IO("CMSIS-DAP: cmsis_dap_swd_init");
-
- if (cmsis_dap_handle == NULL) {
-
- /* SWD init */
- retval = cmsis_dap_usb_open();
- if (retval != ERROR_OK)
- return retval;
-
- retval = cmsis_dap_get_caps_info();
- if (retval != ERROR_OK)
- return retval;
- }
-
- if (!(cmsis_dap_handle->caps & INFO_CAPS_SWD)) {
- LOG_ERROR("CMSIS-DAP: SWD not supported");
- return ERROR_JTAG_DEVICE_ERROR;
- }
-
- retval = cmsis_dap_cmd_DAP_Connect(CONNECT_SWD);
- if (retval != ERROR_OK)
- return retval;
-
- /* Add more setup here.??... */
-
- LOG_INFO("CMSIS-DAP: Interface Initialised (SWD)");
+ swd_mode = true;
return ERROR_OK;
}
COMMAND_REGISTRATION_DONE
};
-COMMAND_HANDLER(cmsis_dap_reset_command)
-{
- LOG_DEBUG("cmsis_dap_reset_command");
- return ERROR_OK;
-}
-
-COMMAND_HANDLER(cmsis_dap_jtag_command)
-{
- LOG_DEBUG("cmsis_dap_jtag_command");
- return ERROR_OK;
-}
-
-static const struct command_registration cmsis_dap_jtag_subcommand_handlers[] = {
- {
- .name = "init",
- .mode = COMMAND_ANY,
- .handler = cmsis_dap_jtag_command,
- .usage = ""
- },
- {
- .name = "arp_init",
- .mode = COMMAND_ANY,
- .handler = cmsis_dap_jtag_command,
- .usage = ""
- },
- {
- .name = "arp_init-reset",
- .mode = COMMAND_ANY,
- .handler = cmsis_dap_reset_command,
- .usage = ""
- },
- {
- .name = "tapisenabled",
- .mode = COMMAND_EXEC,
- .jim_handler = jim_jtag_tap_enabler,
- },
- {
- .name = "tapenable",
- .mode = COMMAND_EXEC,
- .jim_handler = jim_jtag_tap_enabler,
- },
- {
- .name = "tapdisable",
- .mode = COMMAND_EXEC,
- .handler = cmsis_dap_jtag_command,
- .usage = "",
- },
- {
- .name = "configure",
- .mode = COMMAND_EXEC,
- .handler = cmsis_dap_jtag_command,
- .usage = "",
- },
- {
- .name = "cget",
- .mode = COMMAND_EXEC,
- .jim_handler = jim_jtag_configure,
- },
- {
- .name = "names",
- .mode = COMMAND_ANY,
- .handler = cmsis_dap_jtag_command,
- .usage = "",
- },
- COMMAND_REGISTRATION_DONE
-};
-
static const struct command_registration cmsis_dap_command_handlers[] = {
{
.name = "cmsis-dap",
.help = "the vendor ID and product ID of the CMSIS-DAP device",
.usage = "(vid pid)* ",
},
- {
- /* this is currently a nasty hack so we get
- * reset working with non jtag interfaces */
- .name = "jtag",
- .mode = COMMAND_ANY,
- .usage = "",
- .chain = cmsis_dap_jtag_subcommand_handlers,
- },
COMMAND_REGISTRATION_DONE
};
static const struct swd_driver cmsis_dap_swd_driver = {
- .init = cmsis_dap_swd_init,
- .read_reg = cmsis_dap_swd_read_reg,
- .write_reg = cmsis_dap_swd_write_reg,
+ .init = cmsis_dap_swd_init,
+ .read_reg = cmsis_dap_swd_read_reg,
+ .write_reg = cmsis_dap_swd_write_reg,
+ .run = cmsis_dap_swd_run,
};
const char *cmsis_dap_transport[] = {"cmsis-dap", NULL};