PlatformIO J-Link Drivers

Hi,
I would like to use my J-link Ultra with PlatformIO. I tried to install WinUSB for my J-link (Ver 4.5) and the Segger J-Link configuration tool WinUSB driver option was grayed out. Segger was not very helpful and said I needed a newer J-link (Ver 5) to use the WinUSB driver. I saw a posting about drivers and a installation executable that resided in a subdirectory of .platformio but that directory does not exist in my installation. Has anyone been able to use a pre version 5 J-link for debugging with PlatformIO?

See docs. If the package is not yet installed that indicites you’re not yet using a project that uses the native J-Link tools (e.g., OpenOCD).

You can manually install the package in the CLI with

pio pkg install -g -t tool-jlink

And it will be at the predescribed path.

However, I don’t see why you would need a lower version driver? What exactly doesn’t work?

1 Like

I am trying to debug with ESP32. I manually installed the package and can see the tool-openocd-esp32 subdirectory. I added debug_tool = jlink to platformio.ini. Is there more configuration items that I need to add to platformio.ini? I see other entries for OpenOCD and ST-Link in the documentation. I tried to start debugging and I saw the build process but no attempt to upload or start debugging in the terminal window.

What does “Debug Console” in VSCode say after you started “PIO Debug” in the Debugger sidebar?

Here is the debug console output:

undefinedC:.platformio\packages\toolchain-xtensa-esp32\bin\xtensa-esp32-elf-gdb.exe: warning: Couldn’t determine a path for the index cache directory.
Reading symbols from c:\Users\PWM\Documents\PlatformIO\Projects\Sliders.pio\build\nodemcu-32s\firmware.elf…
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target…
Open On-Chip Debugger v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
adapter speed: 5000 kHz

Info : tcl server disabled
Info : telnet server disabled
Warn : Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED.
Warn : Failed to open device: LIBUSB_ERROR_NOT_FOUND.
Error: No J-Link device found

.pioinit:11: Error in sourced command file:
Remote communication error. Target disconnected.: Success.

Segger J-Link Configurator sees the probe.

Okay, so that path with OpenOCD won’t work if you can’t load WinUSB drivers on the JLink.

However, can you connect using the native JLink tools, aka, JLinkGDBServer, with the latest driver package?

If yes, just adapt the debugging configuration in the platformio.ini to make PlatformIO use a custom-opened GDB server. E.g.

debug_tool = custom
debug_port = 127.0.0.1:2331

(you may also need these debug_init_cmds).

1 Like

I tried to use JlinkGDBServer but there are no ESP devices in the configuration. I tried running it with unspecified device name with no success:

SEGGER J-Link GDB Server V7.84a LogFile
Logging started @ 2023-01-10 23:40
03-00000000-00-00000000-001F: SEGGER J-Link GDB Server V7.84a
03-00000000-00-00000000-000E: GUI Version

03-00000000-00-00000000-0039: JLinkARM.dll V7.84a (DLL compiled Dec 22 2022 16:11:39)

03-00000000-00-00000000-01B7: -----GDB Server start settings-----
GDBInit file: none
GDB Server Listening port: 2331
SWO raw output listening port: 2332
Terminal I/O port: 2333
Accept remote connection: localhost only
Generate logfile: on
Verify download: off
Init regs on start: off
Silent mode: off
Single run mode: off
Target connection timeout: 5000 ms

03-00000000-00-00000000-0173: ------J-Link related settings------
J-Link Host interface: USB
J-Link script: none
J-Link settings file: none
------Target related settings------
Target device: Unspecified
Target device parameters: none
Target interface: JTAG
Target interface speed: 4000kHz
Target endian: little

03-00000000-00-00000000-0001:

03-00000000-00-00000001-0018: Connecting to J-Link…

02-00000000-00-00000009-004B: T80D8 036:958.964 Firmware: J-Link Ultra V4 compiled Sep 22 2022 15:00:10
02-00000000-00-00000009-004B: T80D8 036:959.288 Firmware: J-Link Ultra V4 compiled Sep 22 2022 15:00:10
02-00000000-00-00000009-0039: T80D8 036:959.416 Decompressing FW timestamp took 95 us
02-00000000-00-00000011-0023: T80D8 036:961.080 Hardware: V4.00
02-00000000-00-00000011-0022: T80D8 036:961.104 S/N: XXX505407
02-00000000-00-00000011-001F: T80D8 036:961.116 OEM: SEGGER
02-00000000-00-00000011-0042: T80D8 036:961.124 Feature(s): RDI, FlashBP, FlashDL, JFlash, GDB
02-00000000-00-00000013-003F: T80D8 036:963.112 TELNET listener socket opened on port 19021
02-00000000-00-00000014-0046: T80D8 036:963.312 WEBSRV WEBSRV_Init(): Starting webserver thread(s)
02-00000000-00-00000014-0040: T80D8 036:963.528 WEBSRV Webserver running on local port 19080
02-00000000-00-00000035-002B: T80D8 036:984.476 - 34.279ms returns “O.K.”
03-00000000-00-00000035-0015: J-Link is connected.

02-00000000-00-00000040-0042: T80D8 036:989.356 JLINK_DEVICE_GetIndex(sDeviceName = Unspecified)
02-00000000-00-00000040-0026: T80D8 036:989.920 - 0.565ms returns -1
03-00000000-00-00000040-0032: Failed to get index for device name ‘Unspecified’.
03-00000000-00-00000040-001C: GDBServer will be closed…

02-00000000-00-00002051-0020: T80D8 039:001.024 JLINK_IsOpen()
02-00000000-00-00002051-0028: T80D8 039:001.096 - 0.075ms returns 0x01
02-00000000-00-00002057-001F: T80D8 039:006.580 JLINK_Close()
03-00000000-00-00002066-0011: Shutting down…

…you are right, although ESP32 devices are listed here, that’s only for flashing, the “JLink” column is crossed out as unsupported.

Can you still the WinUSB installer method per this using the SysProgs USB Driver Tool tool and revert to debug_tool = jlink? If it doesn’t work, you can revert to the stock drivers.

I installed the winUSB driver with UsbDriverTool and tried to start debugging:

Reading symbols from c:\Users\PWM\Documents\PlatformIO\Projects\Sliders.pio\build\nodemcu-32s\firmware.elf…
PlatformIO Unified Debugger → Redirecting...
PlatformIO: debug_tool = jlink
PlatformIO: Initializing remote target…
Open On-Chip Debugger v0.11.0-esp32-20220706 (2022-07-06-15:48)
Licensed under GNU GPL v2
For bug reports, read
OpenOCD: Bug Reporting
WARNING: boards/esp-wroom-32.cfg is deprecated, and may be removed in a future release.
adapter speed: 5000 kHz
Info : tcl server disabled
Info : telnet server disabled
Warn : Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED.
Info : J-Link Ultra V4 compiled Sep 22 2022 15:00:10
Info : Hardware version: 4.00
Info : VTarget = 3.298 V
Info : clock speed 5000 kHz
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway…
Error: esp32.cpu0: IR capture error; saw 0x1f not 0x01
Warn : Bypassing JTAG setup events due to errors
Error: Unexpected OCD_ID = ffffffff
Warn : target esp32.cpu0 examination failed
Error: Unexpected OCD_ID = ffffffff
Warn : target esp32.cpu1 examination failed
Info : starting gdb server for esp32.cpu0 on pipe
Info : accepting ‘gdb’ connection from pipe
Error: Target not examined yet
Error executing event gdb-attach on target esp32.cpu0:
Warn : No symbols for FreeRTOS!
Error: Target not halted
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use ‘gdb_memory_map disable’.
Error: attempted ‘gdb’ connection rejected
Error: error during select: Unknown error
.pioinit:11: Error in sourced command file:
Remote communication error. Target disconnected.: Success.

I have an Olimex ARM-USB-OCD-H that should arrive today. I hope that probe will work without issue.

That does look much better though. Either the cable wireup is not right or the debug speed is too high. Have you connect the JTAG signals according to Low-cost ESP32 In-circuit Debugging | by Manuel Bl. | Medium to your JLink’s pinout correctly?

Are you powering the ESP32 externally, not via the JLink?

Have you tried adding debug_speed = 500 to the platformio.ini?

Are you using good and short cables between the ESP32 and the J-Link?

I verified the pinout and there are no errors. I am powering it from the USB connected LDO on the ESP32 module.

I added debug_speed = 500 but there is still no response from JTAG:

Info : tcl server disabled
Info : telnet server disabled
Warn : Failed to open device: LIBUSB_ERROR_NOT_SUPPORTED.
Info : J-Link Ultra V4 compiled Sep 22 2022 15:00:10
Info : Hardware version: 4.00
Info : VTarget = 3.295 V
Info : clock speed 500 kHz
Error: JTAG scan chain interrogation failed: all ones
Error: Check JTAG interface, timings, target power, etc.
Error: Trying to use configured scan chain anyway…
Error: esp32.cpu0: IR capture error; saw 0x1f not 0x01
Warn : Bypassing JTAG setup events due to errors
Error: Unexpected OCD_ID = ffffffff
Warn : target esp32.cpu0 examination failed
Error: Unexpected OCD_ID = ffffffff
Warn : target esp32.cpu1 examination failed
Info : starting gdb server for esp32.cpu0 on pipe
Info : accepting ‘gdb’ connection from pipe
Error: Target not examined yet
Error executing event gdb-attach on target esp32.cpu0:

I put a scope probe on TCK and tried to start debugging and it stayed low throughout. TDI, TMS, TCK are low and TDO is high. Is there a way to enable telnet for openOCD to troubleshoot this further?

I switched to Ubuntu 20.04 and the Segger J-link and the Olimex-ARM-USB-OCD-H are both working great with the debugger with no changes to the connections.

2 Likes