X-Git-Url: https://review.openocd.org/gitweb?p=openocd.git;a=blobdiff_plain;f=src%2Fjtag%2Fdrivers%2Fcmsis_dap_usb.c;h=3e62ce9c87cf8e05e993bf25b585565ae316877a;hp=180a91b40b4293e234564420d8eae4c99c0eed45;hb=b675edcc95935cbdf77002db1e261536026f4cbe;hpb=d2bb14e36a03cc187ca090a0da418acccb4098b4 diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c index 180a91b40b..3e62ce9c87 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 @@ -136,7 +137,7 @@ static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 }; /* CMSIS-DAP Vendor Commands * None as yet... */ -static char *info_caps_str[] = { +static const char * const info_caps_str[] = { "SWD Supported", "JTAG Supported" }; @@ -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; @@ -718,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 */ @@ -828,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; }