Menu

#255 LPC-Link2 Not Working as CMSIS-DAP

0.9.0
new
nobody
None
2020-06-30
2019-11-04
No

Hi,

I'm working on a project with the NXP LPC824 using VisualGDB and OpenOCD. Using the LPCXpresso824-MAX dev board I had no trouble programming and debugging using OpenOCD. I have recently built my first prototype PCB for this project and purchased an LPC-Link2 to use as a CMSIS-DAP debugger with it. However, I am unable to get the LPC-Link2 to work with OpenOCD. I keep getting a "CMSIS-DAP command CMD_INFO failed" error.

I have flashed the CMSIS-DAP firmware to the LPC-Link2, reinstalled the drivers, and followed any other troubleshooting tips I could find, but with no success. The LPC-Link2 works when flashed with the Segger J-Link firmware and also with the CMSIS-DAP firmware when debugging through MCUXpresso, so it does not appear to be a problem with the probe or the firmware but rather something specific to OpenOCD. There is nothing wrong with the target board because, as a workaround, I have removed the target MCU from the LPCXpresso824-MAX and am using its external debug header to debug the target MCU on my PCB.

I am using the version of OpenOCD that comes with VisualGDB (0.10.0) but I have also tried the 0.10.0 version that is from the MSYS2 repositories I am on Windows 10.

Here is the output of my version of OpenOCD with the LPC-Link2 with debug turned on.

openocd.exe -f interface/cmsis-dap.cfg -c "debug_level 4"
Open On-Chip Debugger 0.10.0 (2019-08-28) [https://github.com/sysprogs/openocd]
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
User : 14 6 options.c:60 configuration_output_handler(): debug_level: 4
User : 15 9 options.c:60 configuration_output_handler():
Info : 16 13 server.c:311 add_service(): Listening on port 6666 for tcl connections
Info : 17 16 server.c:311 add_service(): Listening on port 4444 for telnet connections
Debug: 18 19 command.c:143 script_debug(): command - init init
Debug: 20 21 command.c:143 script_debug(): command - target target init
Debug: 22 23 command.c:143 script_debug(): command - target target names
Debug: 23 26 target.c:1431 handle_target_init_command(): Initializing targets...
Debug: 24 59 cmsis_dap_usb.c:251 cmsis_dap_usb_open(): Cannot read product string of device 0x46d:0xc232
Debug: 25 65 cmsis_dap_usb.c:251 cmsis_dap_usb_open(): Cannot read product string of device 0x46d:0xc231
Debug: 26 1075 cmsis_dap_usb.c:409 cmsis_dap_usb_xfer(): error reading data: (null)
Error: 27 1081 cmsis_dap_usb.c:503 cmsis_dap_cmd_DAP_Info(): CMSIS-DAP command CMD_INFO failed.
Debug: 28 1088 command.c:630 run_command(): Command 'init' failed with error code -107
User : 29 1103 command.c:695 command_run_line():

Any ideas? I have tried the NXP forums and StackExchange but noone seems to know anything.

Regards,
Donald

Discussion

  • Masatoshi Tateishi

    I also encountered this trouble.

    This problem due to hidapi specifications.
    LPC link has three interfaces.

    "LPCSIO": mi_03
    "LPC-LINK2 CMSIS-DAP": mi_00 -> I want to use this Interface!!
    "LPC-LINK2 DATA PORT": mi_04

    But hid_open() is used first found interface(mi_03).

    I tried followed patch to openocd.(not use hid_open())
    And I confirmed CMSIS-DAP can work with LPCLINK2.
    Please try it.

    diff --git a/src/jtag/drivers/cmsis_dap_usb.c b/src/jtag/drivers/cmsis_dap_usb.c
    index ee1cb533..90e429c8 100644
    --- a/src/jtag/drivers/cmsis_dap_usb.c
    +++ b/src/jtag/drivers/cmsis_dap_usb.c
    @@ -273,11 +273,14 @@ static int cmsis_dap_usb_open(void)
                /* check serial number matches if given */
                if (cmsis_dap_serial != NULL) {
                    if ((cur_dev->serial_number != NULL) && wcscmp(cmsis_dap_serial, cur_dev->serial_number) == 0) {
    
    +                   dev = hid_open_path(cur_dev->path);
                        serial_found = true;
                        break;
                    }
    -           } else
    +           } else {
    +               dev = hid_open_path(cur_dev->path);
                    break;
    +           }
    
                found = false;
            }
    @@ -304,7 +307,8 @@ static int cmsis_dap_usb_open(void)
            return ERROR_FAIL;
        }
    
    
    -   dev = hid_open(target_vid, target_pid, target_serial);
    +   if (dev == NULL)
    +       dev = hid_open(target_vid, target_pid, target_serial);
    
        if (dev == NULL) {
            LOG_ERROR("unable to open CMSIS-DAP device 0x%x:0x%x", target_vid, target_pid);
    
     

    Last edit: Masatoshi Tateishi 2020-06-29
  • Antonio Borneo

    Antonio Borneo - 2020-06-29

    If you can use a Linux PC, can you please post the output of command "lsusb -v -d VID:PID", where VID and PID are the values for the LPC-link2 device? To find such numbers, simpli run "lsusb" to list all the available USB devices.

     
  • Antonio Borneo

    Antonio Borneo - 2020-06-29

    I do not have the LPC link2, so I'm just guessing.
    I have run some search, so LPC link2 has at least two HID interfaces, one for the debug CMSIS-DAP and another for "LPCSIO bridge that provides communication to I2C and SPI"!
    OpenOCD does not properly manage a USB device having 2 HID interfaces and it incorreclty tries to open the LPCSIO for debug!
    Your patch works only if there is no command "cmsis_dap_vid_pid" in the configuration script. If you add
    -c 'cmsis_dap_vid_pid VID PID'
    to the command line of OpenOCD, with the VID PID of the LPClink2, the patch should fail again.

    I would like to move this thread on gerrit. Are you ok to propose a patch on gerrit, or you prefer me to post the patch there and you test and approve it?

     
  • Masatoshi Tateishi

    Thank you for reply.

    I atatched result of lsusb on linuxPC. (lsusb.txt)

    if you add
    -c 'cmsis_dap_vid_pid VID PID'
    to the command line of OpenOCD, with the VID PID of the LPClink2, the patch should fail again.

    Certainly as you say.
    I confirmed fail again with(-c "cmsis_dap_vid_pid 0x1fc9 0x90")

    Are you ok to propose a patch on gerrit, or you prefer me to post the patch there and you test and approve it?

    Yes, If you can create a patch I can test it.

     
  • Antonio Borneo

    Antonio Borneo - 2020-06-29

    I have pushed two paches in gerrit: http://openocd.zylin.com/5731 and http://openocd.zylin.com/5732
    Both are required.

    But I still cannot understand how your patch could reliably fix the issue.
    The LPC-Link2 has 3 HID interfaces, but only one is the right one for cmsis-dap.
    Every HID "device" (either physical USB device or interfaces of the same USB device) is identified by the "HID path",
    Apparently, OpenOCD find the right one in cmsis_dap_usb_open(), but then pass VID:PID + serial to hid_open(), and hid_open() opens the HID path of another interface. This I cannot understand, because both OpenOCD and hid_open() do exactly the same steps!
    By passing the HID path to hid_open_path() we force hidapi to open the right one!
    Something really weird!

    So, I switched to use hid_open_path(), that is the right API.
    But to guarantee OpenOCD always opens the right interface, I added a check in the search loop.

    I have put your sourceforge email address in the commit message. If you prefer replacing it with another email address, please let me know.

     
  • Masatoshi Tateishi

    I tested to your 2 patches.
    http://openocd.zylin.com/5731
    http://openocd.zylin.com/5732

    And I confirmed CMSIS-DAP can use collectly by LPC-LINK2.
    (both Windows and Linux build)
    (And -c "cmsis_dap_vid_pid 0x1fc9 0x90" is specified and not)

    The LPC-Link2 has 3 HID interfaces, but only one is the right one for cmsis-dap.

    Yes, It seem LPC-Link2 has 3 HID interfaces.
    Each interfaces is as followed.

    • VID=1fc9, PID=90, serial = I3F4AABA, interface number = 03, product_strings = "LPCSIO"
    • VID=1fc9, PID=90, serial = I3F4AABA, interface number = 00, product_strings = "PC-LINK2 CMSIS-DAP"
    • VID=1fc9, PID=90, serial = I3F4AABA, interface number = 04, product_strings = "LPC-LINK2 DATA PORT"

    Apparently, OpenOCD find the right one in cmsis_dap_usb_open(), but then pass VID:PID + serial to hid_open(),

    OpenOCD checks product_string if vendorid is not specified.
    "if (wcsstr(cur_dev->product_string, L"CMSIS-DAP"))"
    And then, open interface of CMSIS-DAP correctly.

    and hid_open() opens the HID path of another interface.

    But hid_open() looks only vid,pid,serial.
    And then open interface of LPCSIO.

    Of course, it doesn't work correctly when vid/pid is specified, so my before patch is bad.

    Thanks,
    tateishi

     

    Last edit: Masatoshi Tateishi 2020-06-30
  • Antonio Borneo

    Antonio Borneo - 2020-06-30

    Thanks for your tests!
    You did not replyed about the email address in the commit message, please let me know.

    After one night sleep and the logs you put in your last message, I realised that the product_string is not always the same, but depends on the backend of hidapi library.
    On Linux there are two backends: hidapi-hidraw and hidapi-libusb.

    The libusb backend puts in product_string the "iProduct" from the USB Device Descriptor, so it will be "LPC-LINK2 CMSIS-DAP V5.224" for all the three interfaces. This requires the quirk about checking the interface number I have put in my second patch.

    The hidraw backend relies on the HID kernel driver to get the product_string, and on LPC-Link2 we should get different cmsis_dap_vid_pid for each interface.

    On Windows and Mac we have other hidapi implementations. Would be good to check there too.

    By "chance" my patch set also works for the case when you add cmsis_dap_vid_pid command and use hidraw backend. Actually there is another sort-of-bug there, but I was not thinking to fix it. I will do it right now! In fact, when using cmsis_dap_vid_pid command openocd skips the check for product_string containing "CMSIS-DAP"! Again the quirk fixes it!

     
  • Antonio Borneo

    Antonio Borneo - 2020-06-30

    Well, what I called sort-of-bug, maybe should remain there but should be better documented!
    When using cmsis_dap_vid_pid command openocd skips the check for product_string containing "CMSIS-DAP".
    But different backend for libhidapi report different value as product_string.
    The CMSIS-DAP spec say that the "iProduct" from the USB Device Descriptor must contain "CMSIS-DAP" and, in case of composite devices, also the interface string must contain the same text. But on Linux only the libusb backend returns "iProduct" as product_string.
    So, better keeping a workaround in case the product_string does not contains "CMSIS-DAP" on some device with some backend. Using cmsis_dap_vid_pid skips the check on product_string.

     
  • Masatoshi Tateishi

    You did not replyed about the email address in the commit message, please let me know.

    Sorry, I forgot it.

    Please change my e-mail address.

    "Suggested-by: Masatoshi Tateishi tateishim3@users.sourceforge.net"
    ->
    "Suggested-by: Masatoshi Tateishi tateishim3@gmail.com"

    Thanks,
    tateishi

     

Log in to post a comment.

MongoDB Logo MongoDB