Skip to content
Snippets Groups Projects
Commit 88950d69 authored by Wolfgang Draxinger's avatar Wolfgang Draxinger
Browse files

added CMSID-DAP command to select interface by path

parent 90d82818
Branches ch3/leds-api
No related tags found
1 merge request!1added CMSID-DAP command to select interface by path
...@@ -62,6 +62,7 @@ ...@@ -62,6 +62,7 @@
static uint16_t cmsis_dap_vid[MAX_USB_IDS + 1] = { 0 }; static uint16_t cmsis_dap_vid[MAX_USB_IDS + 1] = { 0 };
static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 }; static uint16_t cmsis_dap_pid[MAX_USB_IDS + 1] = { 0 };
static wchar_t *cmsis_dap_serial; static wchar_t *cmsis_dap_serial;
static char *cmsis_dap_path;
static bool swd_mode; static bool swd_mode;
#define PACKET_SIZE (64 + 1) /* 64 bytes plus report id */ #define PACKET_SIZE (64 + 1) /* 64 bytes plus report id */
...@@ -230,8 +231,10 @@ static int cmsis_dap_usb_open(void) ...@@ -230,8 +231,10 @@ static int cmsis_dap_usb_open(void)
struct hid_device_info *devs, *cur_dev; struct hid_device_info *devs, *cur_dev;
unsigned short target_vid, target_pid; unsigned short target_vid, target_pid;
wchar_t *target_serial = NULL; wchar_t *target_serial = NULL;
char *target_path = NULL;
bool found = false; bool found = false;
bool path_found = false;
bool serial_found = false; bool serial_found = false;
target_vid = 0; target_vid = 0;
...@@ -269,9 +272,19 @@ static int cmsis_dap_usb_open(void) ...@@ -269,9 +272,19 @@ static int cmsis_dap_usb_open(void)
} }
if (found) { if (found) {
if( cmsis_dap_path ){
if( cur_dev->path
&& !strcmp(cur_dev->path, cmsis_dap_path)
){
LOG_INFO("Using CMSIS-DAP device with path '%s'", cmsis_dap_path);
path_found = true;
break;
}
} else
/* we have found an adapter, so exit further checks */ /* we have found an adapter, so exit further checks */
/* check serial number matches if given */ /* check serial number matches if given */
if (cmsis_dap_serial != NULL) { if( cmsis_dap_serial ){
LOG_INFO(">>> Considering CMSIS-DAP device with path '%s' <<<", cur_dev->path);
if ((cur_dev->serial_number != NULL) && wcscmp(cmsis_dap_serial, cur_dev->serial_number) == 0) { if ((cur_dev->serial_number != NULL) && wcscmp(cmsis_dap_serial, cur_dev->serial_number) == 0) {
serial_found = true; serial_found = true;
break; break;
...@@ -288,9 +301,13 @@ static int cmsis_dap_usb_open(void) ...@@ -288,9 +301,13 @@ static int cmsis_dap_usb_open(void)
if (NULL != cur_dev) { if (NULL != cur_dev) {
target_vid = cur_dev->vendor_id; target_vid = cur_dev->vendor_id;
target_pid = cur_dev->product_id; target_pid = cur_dev->product_id;
if (serial_found) if( serial_found ){
target_serial = cmsis_dap_serial; target_serial = cmsis_dap_serial;
} }
if( path_found ){
target_path = cmsis_dap_path;
}
}
hid_free_enumeration(devs); hid_free_enumeration(devs);
...@@ -304,7 +321,11 @@ static int cmsis_dap_usb_open(void) ...@@ -304,7 +321,11 @@ static int cmsis_dap_usb_open(void)
return ERROR_FAIL; return ERROR_FAIL;
} }
if( target_path ){
dev = hid_open_path(target_path);
} else {
dev = hid_open(target_vid, target_pid, target_serial); dev = hid_open(target_vid, target_pid, target_serial);
}
if (dev == NULL) { if (dev == NULL) {
LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid); LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
...@@ -1745,6 +1766,20 @@ COMMAND_HANDLER(cmsis_dap_handle_serial_command) ...@@ -1745,6 +1766,20 @@ COMMAND_HANDLER(cmsis_dap_handle_serial_command)
return ERROR_OK; return ERROR_OK;
} }
COMMAND_HANDLER(cmsis_dap_handle_path_command)
{
if (CMD_ARGC == 1) {
cmsis_dap_path = strdup(CMD_ARGV[0]);
if( !cmsis_dap_path ){
LOG_ERROR("unable to allocate memory");
return ERROR_OK;
}
} else {
LOG_ERROR("expected exactly one argument to cmsis_dap_path <usb-path>");
}
return ERROR_OK;
}
static const struct command_registration cmsis_dap_subcommand_handlers[] = { static const struct command_registration cmsis_dap_subcommand_handlers[] = {
{ {
.name = "info", .name = "info",
...@@ -1785,6 +1820,13 @@ static const struct command_registration cmsis_dap_command_handlers[] = { ...@@ -1785,6 +1820,13 @@ static const struct command_registration cmsis_dap_command_handlers[] = {
.help = "set the serial number of the adapter", .help = "set the serial number of the adapter",
.usage = "serial_string", .usage = "serial_string",
}, },
{
.name = "cmsis_dap_path",
.handler = &cmsis_dap_handle_path_command,
.mode = COMMAND_CONFIG,
.help = "set the path of the adapter",
.usage = "path_string",
},
COMMAND_REGISTRATION_DONE COMMAND_REGISTRATION_DONE
}; };
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment