X-Git-Url: https://review.openocd.org/gitweb?a=blobdiff_plain;f=src%2Fjtag%2Fdrivers%2Fcmsis_dap_usb.c;h=b8f004c4758dd19fd07fa86a07aea0909497833f;hb=f75345b9150ad4b7079dd924540a871c5a4e71c1;hp=8c815230d475d199976f624677540139b44785fc;hpb=6db70bc89b34b0e3e70358d3e58eefab9e7947c8;p=openocd.git diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c index 8c815230d4..b8f004c475 100644 --- a/src/jtag/drivers/cmsis_dap_usb.c +++ b/src/jtag/drivers/cmsis_dap_usb.c @@ -60,6 +60,7 @@ /* 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 @@ -193,6 +194,8 @@ static int cmsis_dap_usb_open(void) 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; @@ -205,6 +208,11 @@ static int cmsis_dap_usb_open(void) 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; @@ -479,8 +487,13 @@ static int cmsis_dap_cmd_DAP_Delay(uint16_t delay_us) } #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; @@ -497,7 +510,8 @@ static int cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value) /* 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]); @@ -506,11 +520,14 @@ static int cmsis_dap_swd_read_reg(uint8_t cmd, uint32_t *value) 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); @@ -531,6 +548,13 @@ static int cmsis_dap_swd_write_reg(uint8_t cmd, uint32_t 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; } @@ -702,11 +726,50 @@ static int cmsis_dap_reset_link(void) 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 */ @@ -812,36 +875,9 @@ static int cmsis_dap_init(void) 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; } @@ -994,9 +1030,10 @@ static const struct command_registration cmsis_dap_command_handlers[] = { }; 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};