Skip to content

probe: jlink: open emulator before issuing commands#1927

Open
dottspina wants to merge 1 commit intopyocd:developfrom
dottspina:jlink-open-before-commands
Open

probe: jlink: open emulator before issuing commands#1927
dottspina wants to merge 1 commit intopyocd:developfrom
dottspina:jlink-open-before-commands

Conversation

@dottspina
Copy link
Copy Markdown

Problem description

Using a JLink probe (USB) with JLink DLL version 9.14a and above (latest immune version is 9.12), pyOCD will fail to connect to the emulator, raising "No emulator with serial number XXXXXXXXXX" or "Could not connect to default emulator", depending on the command line arguments.

I myself encountered this problem (programming/debugging an nRF52840-DK), as did at least one other pyOCD user [1], and one pylink user [2].
On my machine (Linux), pyOCD will additionally segfault in JLINKARM_Close() , probably on library unload (seen in coredump).

Proposed solution

It seems that the required emulator status (opened, connected) for executing some commands in JLink.disable_dialog_boxes() have changed in the JLink SDK v9.14, triggering automatic connections the pylink interface does not take into account (yet ?).
They've started looking into it, but they're working (like most of us probably) without the JLink SDK documentation, and reverse engineering the state machine might not be straightforward: It is not even certain that JLINKARM Open() should not have to be called, in one way or another, before dispatching commands.

Proposed solution: in pyOCD JLinkProbe.open(), call JLink.disable_dialog_boxes() after JLink.open().

This fix Works for me (TM), and test/automated_test.py -d succeeds, expect "Gdb Test" which is ignored (I don't have the right Python runtime for the versions of arm-none-eabi-gdb that I have at hand).
Bellow is my pyocd.yaml:

probes:
  XXXXXXXXX # My probe's serial number.
    target_override:  nrf52
    test_binary:      l1_nrf52840-dk.bin
    frequency:        6000000

Hope this helps.

[1] #1925 Jlink V9.22 No emulator with serial number
[2] square/pylink#254 Can't connect to the emulator

@StarSphere-1024
Copy link
Copy Markdown
Contributor

StarSphere-1024 commented Mar 13, 2026

Yes, almost simultaneously, I also discovered the issue and the solution:
#1889 (comment)

@dottspina
Copy link
Copy Markdown
Author

Yes, almost simultaneously, I also discovered the issue and the solution: #1889 (comment)

@StarSphere-1024, yes same issue and same root cause identified.

AFAICT #1889 does not include the fix, rightly since its purpose is to "add support for nRF54LM20A". I think we can merge both pull requests, one per topic.

Would that be good for you?

@StarSphere-1024
Copy link
Copy Markdown
Contributor

Sure.my PR (#1889) is strictly for nRF54LM20A support. Since I use DAPLink, this J-Link issue doesn't affect me personally. However, it definitely needs a quick fix. Hope it gets merged soon—the review process has been so slow (my PR waited ~4 months) that I had to switch to OpenOCD for my project.

With JLink DLL versions 9.14 and above, calling disable_dialog_boxes()
before open() puts the pylink adapter into an inconsistent state.
As a result pyOCD will fail to open the J-Link emulator,
and possibly segfault.

The approach here is to preserve the current behavior as much
as possible, while allowing to develop/test/use pyOCD with
current versions of the JLink DLL.

See:
- pyocd#1925 "Jlink V9.22 No emulator with serial number"
- pyocd#1927 "probe: jlink: open emulator before issuing commands"
- square/pylink#259 "Fix exec command"
@dottspina dottspina force-pushed the jlink-open-before-commands branch from ce37041 to 2907441 Compare March 23, 2026 22:25
@dottspina
Copy link
Copy Markdown
Author

dottspina commented Mar 23, 2026

Follow-up.

Problem description (update)

Currently, when using JLink DLL above version 9.12:

  • semi-hosting unit tests (test/unit/test_semihosting.py) fail
  • automated tests (automated_test.py) fail (nrf52840 target)
  • pyocd fails to open J-Link probes connected to USB (either default or with serial number), and will possibly segfault

It is confirmed that the issue comes from automatic connections created by JLink.disable_dialog_boxes() when called before JLink.open(), which is what pyOCD does in JLinkProbe.open().
The error only occurs when using a version of JLINK DLL above 9.12 (v912). Observed with 9.14 to 9.28.

This is being investigated on the pylink side (square/pylink#259), and the real fix will eventually come from there.
AFAICT, the most promising approach seems to be to patch disable_dialog_boxes() to skip/defer the J-Link commands whose behavior has changed.
But this is still debated (there is no public documentation to rely on).

Proposed change (update)

The initial version of this PR, i.e. the reordering of calls to JLink.disable_dialog_boxes() and JLink.open(), fixed all the above problems (tests pass, including automated_test.py -i "Gdb Test", and emulators are found), but could degrade the user experience: on Windows, some dialog boxes will appear on JLinkProbe.open(), even though they should have been disabled.

This second version instead adds a workaround that should:

  • preserve the current behavior as much as possible, i.e. call disable_dialog_boxes() before open() when it is considered safe
  • while allowing the use, but also the development and testing, of pyOCD with current versions of the JLink DLL

Once the root cause is fixed in pylink and the fix is available (PyPI), we should be able to:

  • unconditionally call disable_dialog_boxes() before open()
  • update pyOCD requirements with the appropriate versions of the pylink adapter (note that it is unlikely that the fix will be backported to the 1.7 branch of pyocd pylink)

Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants