This is an automated email from Gerrit.

Peter Lawrence (majbt...@gmail.com) just uploaded a new patch set to Gerrit, 
which you can find at http://openocd.zylin.com/1886

-- gerrit

commit 9e68b1250f2fe2ec03992ef050cbfd8848e88b1d
Author: Peter Lawrence <majbt...@gmail.com>
Date:   Sat Jan 18 15:10:18 2014 -0700

    CMSIS-DAP: auto-detect CMSIS-DAP USB VID:PID
    
    The current OpenOCD implementation requires CMSIS-DAP adapter USB
    VID:PID values to either be hard-coded in the source or manually
    supplied by the user's configuration files.  The CMSIS-DAP
    specification stipulates that all compliant adapters should have
    "CMSIS-DAP" in the product string.  This should obviate the need
    for hard-coding.  This proposed patch adds support for said official
    mechanism whilst providing backwards-compatibility to the existing
    hard-coded approach.
    
    Change-Id: Icfc9387c4d2518be9891c6a683a6b721a601eb9c
    Signed-off-by: Peter Lawrence <majbt...@gmail.com>

diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c
index 5cd117f..e73c74e 100644
--- a/src/jtag/drivers/cmsis_dap_usb.c
+++ b/src/jtag/drivers/cmsis_dap_usb.c
@@ -159,17 +159,45 @@ static int cmsis_dap_usb_open(void)
 {
        hid_device *dev = NULL;
        int i;
+       struct hid_device_info *devs, *cur_dev;
+       unsigned short target_vid, target_pid;
+
+       target_vid = 0;
+       target_pid = 0;
+
+       /*
+       The CMSIS-DAP specification stipulates:
+       "The Product String must contain "CMSIS-DAP" somewhere in the string. 
This is used by the
+       debuggers to idenify a CMSIS-DAP compliant Debug Unit that is connected 
to a host computer."
+       */
+       devs = hid_enumerate(0x0, 0x0);
+       cur_dev = devs;
+       while (NULL != cur_dev) {
+               if (wcsstr(cur_dev->product_string, L"CMSIS-DAP")) {
+                       break;
+               } else {
+                       for (i = 0; cmsis_dap_vid[i] || cmsis_dap_pid[i]; i++) {
+                               if ((cmsis_dap_vid[i] == cur_dev->vendor_id) && 
(cmsis_dap_pid[i] == cur_dev->product_id))
+                                       break;
+                       }
+               }
+
+               cur_dev = cur_dev->next;
+       }
+
+       if (NULL != cur_dev) {
+               target_vid = cur_dev->vendor_id;
+               target_pid = cur_dev->product_id;
+       }
+
+       hid_free_enumeration(devs);
 
        if (hid_init() != 0) {
                LOG_ERROR("unable to open HIDAPI");
                return ERROR_FAIL;
        }
 
-       for (i = 0; cmsis_dap_vid[i] || cmsis_dap_pid[i]; i++) {
-               dev = hid_open(cmsis_dap_vid[i], cmsis_dap_pid[i], NULL);
-               if (dev != NULL)
-                       break;
-       }
+       dev = hid_open(target_vid, target_pid, NULL);
 
        if (dev == NULL) {
                LOG_ERROR("unable to open CMSIS-DAP device");
@@ -196,7 +224,7 @@ static int cmsis_dap_usb_open(void)
        int packet_size = PACKET_SIZE;
 
        /* atmel cmsis-dap uses 512 byte reports */
-       if (cmsis_dap_vid[i] == 0x03eb && cmsis_dap_pid[i] == 0x2111)
+       if (target_vid == 0x03eb && target_pid == 0x2111)
                packet_size = 512 + 1;
 
        cmsis_dap_handle->packet_buffer = malloc(packet_size);

-- 

------------------------------------------------------------------------------
CenturyLink Cloud: The Leader in Enterprise Cloud Services.
Learn Why More Businesses Are Choosing CenturyLink Cloud For
Critical Workloads, Development Environments & Everything In Between.
Get a Quote or Start a Free Trial Today. 
http://pubads.g.doubleclick.net/gampad/clk?id=119420431&iu=/4140/ostg.clktrk
_______________________________________________
OpenOCD-devel mailing list
OpenOCD-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/openocd-devel

Reply via email to