AnsweredAssumed Answered

Problem with LPC-LINK2/CMSIS-DAP with OpenOCD and VirtualBox/Vagrant

Question asked by Phil McMillan on Jun 14, 2019
Latest reply on Jun 26, 2019 by Erich Styger

I am trying to set up a few debug probes with OpenOCD under Vagrant (using VirtualBox).  Mostly this has been very successful.  I have the following working:
- LPC-Link2 using J-Link firmware with VirtualBox
- FRDM-K28F using CMSIS-DAP firmware with VirtualBox

- LPC-Link2 using CMSIS-DAP firmware (on the host directly, without VirtualBox)

 

LPC-Link2 using CMSIS-DAP firmware *does not work* using VirtualBox.  Given that it works fine on the host with the same configuration when VirtualBox is *not* used, this would seem to rule out common issues with the USB cabling, host hardware etc.

 

Looking for some guidance in where the problem with the specific LPC-Link2 + CMSIS-DAP + VirtualBox configuration is not working.  Given that all other combinations work flawlessly, I expect this is a bug somewhere.  I'd like to get this working because CMSIS-DAP on LPC-Link2 under Vagrant/VirtualBox is my preferred configuration.

 

I note also that when HID enumerates the LPC-Link2 and FRDM-K28F board with CMSIS-DAP firmware, LPC-Link2 shows up as 3 devices/paths, whereas the Freedom board shows up as only 1.  So there may be some architectural difference between the two implementations that is causing the failure.

 

Debug on the failing configuration shows that although the enumeration of the LPC-Link2 seems to work correctly under VirtualBox, the LPC-Link2 isn't receiving a reply from the USB transfer associated with the GET_INFO request, and is timing out.

 

More details below:

 

LPC-Link2 with CMSIS-DAP Firmware with OpenOCD with VirtualBox

 

This is the failing configuration.

 

vagrant@vagrant-ubuntu-trusty-64:~$ openocd -f interface/cmsis-dap.cfg -c "transport select swd" -c "adapter_khz 500" -f target/kx.cfg
Open On-Chip Debugger 0.10.0+dev-00910-g4dbcb1e (2019-06-15-02:46)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
swd
adapter speed: 500 kHz

 

Info : add flash_bank kinetis kx.pflash
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Error: CMSIS-DAP command CMD_INFO failed.

 

vagrant@vagrant-ubuntu-trusty-64:~$

 

 

With debug...

 

vagrant@vagrant-ubuntu-trusty-64:~$ openocd -d -f interface/cmsis-dap.cfg -c
openocd -d -f interface/cmsis-dap.cfg -c "transport select swd" -c "adapter_khz 500" -f target/kx.cfg
...
<<many lines deleted>>
...
Debug: 200 1041 cmsis_dap_usb.c:409 cmsis_dap_usb_xfer(): error reading data: (null)
Error: 201 1042 cmsis_dap_usb.c:503 cmsis_dap_cmd_DAP_Info(): CMSIS-DAP command CMD_INFO failed.
Debug: 202 1044 command.c:630 run_command(): Command 'init' failed with error code -107


Review of the OpenOCD / HIDAPI code indicates a timeout is occurring without data being received from the command (I have confirmed this by changing the timeout from 1 second default to 5 seconds and noting the same failure after 5 seconds).

 

LPC-Link2 with CMSIS-DAP Firmware with OpenOCD on the host (no VirtualBox)

 

When VirtualBox is not used, this configuration works as expected.

phil@pop-os:~$ sudo openocd -f interface/cmsis-dap.cfg -c "transport select swd" -c "adapter_khz 500" -f target/kx.cfg
Open On-Chip Debugger 0.10.0
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
swd
adapter speed: 500 kHz
Info : add flash_bank kinetis kx.flash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : CMSIS-DAP: FW Version = 1.10
Info : SWCLK/TCK = 1 SWDIO/TMS = 1 TDI = 1 TDO = 1 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x0bc11477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 2 breakpoints, 2 watchpoints
^C
phil@pop-os:~$

 

LPC-Link2 with J-Link Firmware with OpenOCD with VirtualBox

 

This works perfectly under VirtualBox/OpenOCD.

 

vagrant@vagrant-ubuntu-trusty-64:~$ openocd -f interface/jlink.cfg -c "transport select swd" -c "adapter_khz 500" -f target/kx.cfg
Open On-Chip Debugger 0.10.0+dev-00910-g4dbcb1e (2019-06-15-02:46)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
swd
adapter speed: 500 kHz

 

Info : add flash_bank kinetis kx.pflash
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : J-Link LPC-Link 2 compiled Sep 23 2016 12:15:22
Info : Hardware version: 1.00
Info : VTarget = 3.300 V
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x0bc11477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 2 breakpoints, 2 watchpoints
Info : kx.cpu: external reset detected
Info : Listening on port 3333 for gdb connections

 

 

FRDM-K28F Board with CMSIS-DAP Firmware under OpenOCD/Vagrant/VirtualBox

 

This configuration works perfectly.

 

 

vagrant@vagrant-ubuntu-trusty-64:~/hidapi/hidtest$ openocd -f interface/cmsis-dap.cfg -c "transport select swd" -c "adapter_khz 500" -f target/kx.cfg
Open On-Chip Debugger 0.10.0+dev-00910-g4dbcb1e (2019-06-15-03:10)
Licensed under GNU GPL v2
For bug reports, read
    http://openocd.org/doc/doxygen/bugs.html
swd
adapter speed: 500 kHz

 

Info : add flash_bank kinetis kx.pflash
Info : Listening on port 6666 for tcl connections
Info : Listening on port 4444 for telnet connections
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : kx.cpu: external reset detected
Info : Listening on port 3333 for gdb connections

 

 

HIDAPI Enumerations under VirtualBox

 

I notice that the LPC-Link2 and FRDM-K28F enumerate differently for both HIDRAW and LIBUSB modes.  The LPC-Link2 board presents itself as three devices/paths, whereas the Freedom Board only one.

 

For LPC-Link2

 

vagrant@vagrant-ubuntu-trusty-64:~/hidapi/hidtest$ ./hidtest-hidraw
Device Found
  type: 1fc9 0090
  path: /dev/hidraw0
  serial_number: I3F4AXOR
  Manufacturer: NXP Semiconductors
  Product:      LPC-LINK2 CMSIS-DAP V5.224
  Release:      100
  Interface:    0

 

Device Found
  type: 1fc9 0090
  path: /dev/hidraw2
  serial_number: I3F4AXOR
  Manufacturer: NXP Semiconductors
  Product:      LPC-LINK2 CMSIS-DAP V5.224
  Release:      100
  Interface:    3

 

Device Found
  type: 1fc9 0090
  path: /dev/hidraw1
  serial_number: I3F4AXOR
  Manufacturer: NXP Semiconductors
  Product:      LPC-LINK2 CMSIS-DAP V5.224
  Release:      100
  Interface:    4

 

vagrant@vagrant-ubuntu-trusty-64:~/hidapi/hidtest$ ./hidtest-libusb
Device Found
  type: 1fc9 0090
  path: 0001:0002:00
  serial_number: I3F4AXOR
  Manufacturer: NXP Semiconductors
  Product:      LPC-LINK2 CMSIS-DAP V5.224
  Release:      100
  Interface:    0

 

Device Found
  type: 1fc9 0090
  path: 0001:0002:04
  serial_number: I3F4AXOR
  Manufacturer: NXP Semiconductors
  Product:      LPC-LINK2 CMSIS-DAP V5.224
  Release:      100
  Interface:    4

 

Device Found
  type: 1fc9 0090
  path: 0001:0002:03
  serial_number: I3F4AXOR
  Manufacturer: NXP Semiconductors
  Product:      LPC-LINK2 CMSIS-DAP V5.224
  Release:      100
  Interface:    3
...
vagrant@vagrant-ubuntu-trusty-64:~/hidapi/hidtest$


For FRDM-K28F

 

 

vagrant@vagrant-ubuntu-trusty-64:~/hidapi/hidtest$ ./hidtest-hidraw
Device Found
  type: 0d28 0204
  path: /dev/hidraw0
  serial_number: 0224000032044e450034700a997b002e6781000097969900
  Manufacturer: ARM
  Product:      DAPLink CMSIS-DAP
  Release:      1000
  Interface:    3

 

vagrant@vagrant-ubuntu-trusty-64:~/hidapi/hidtest$ ./hidtest-libusb
Device Found
  type: 0d28 0204
  path: 0002:0002:03
  serial_number: 0224000032044e450034700a997b002e6781000097969900
  Manufacturer: ARM
  Product:      DAPLink CMSIS-DAP
  Release:      1000
  Interface:    3

Outcomes