Connection and Erase Issue with nRF52840 via J-Link using nRF Connect and nrfjprog

Hello,

I am encountering difficulties connecting to and recovering my nRF52840 board with J-Link on macOS, both via nRF Connect and using nrfjprog in the terminal. Below are the details of the situation and the errors I’ve encountered.

Context:

- Target Board: nRF52840

- Programming Tool: J-Link

- Environment: macOS, with J-Link and nRF Connect installed

- Objective: Unlock and erase the board to flash new firmware

 Problem Encountered:

When I try to connect to the board and flash it, I receive errors both with nrfjprog and J-Link Commander. Below are the specific errors observed.

Additionally, I am able to successfully flash other Nordic microcontrollers and use the J-Link for different applications, boards, and firmware. This suggests that the J-Link itself is functioning correctly with other setups.

Logs and Error Messages:

1. Error with nrfjprog --recover --family nRF52:

When using the nrfjprog --recover --family nRF52 command, I receive the following messages:

Recovering device. This operation might take 30s.

[error] [ Client] - Encountered error -21: Command recover executed for 115 milliseconds with result -21

[error] [ Worker] - Encountered unexpected debug port ID 0, expected 2

ERROR: Recover failed. Please make sure that the correct device family is given

ERROR: and try again.

NOTE: For additional output, try running again with logging enabled (--log).

NOTE: Any generated log error messages will be displayed.

 2. Attempted Connection via J-Link Commander:

When launching J-Link Commander with the following parameters: JLinkExe -device nRF52840_xxAA -if SWD -speed 4000:

, I receive the error message:

Connecting to target via SWD

InitTarget() start

InitTarget() end - Took 3.14ms

Failed to attach to CPU. Trying connect under reset.

InitTarget() start

InitTarget() end - Took 106ms

Error occurred: Could not connect to the target device.

For troubleshooting steps visit: https://wiki.segger.com/J-Link_Troubleshooting

3. Library Error When Using nRF Connect:

When trying to flash via nRF Connect, another error related to the `libjlinkarm.dylib` library appears, suggesting a problem loading the library. Here’s the full message:

Failed "reading readback protection status for application core". Error: code: 1, description: Generic, message: Batch task protection-get failed, [Probe] Emulator error: Unable to load J-Link DLL: DlOpen { desc: "dlopen(/Applications/SEGGER/JLink/libjlinkarm.dylib, 0x0005): tried: '/Users/Engineering/Library/Application Support/nrfconnect/nrfutil-sandboxes/device/2.6.4/lib/nrfutil-device/libjlinka

Error: Failed with exit code 1. One or more batch tasks failed: - [Probe] Emulator error: Unable to load J-Link DLL: DlOpen { desc: "dlopen(/Applications/SEGGER/JLink/libjlinkarm.dylib, 0x0005): tried: '/Users/Engineering/Library/Application Support/nrfconnect/nrfutil-sandboxes/device/2.6.4/lib/nrfutil-device/libjlinka, code: Generic.

Steps Already Attempted to Resolve the Issue:

1. Reinstall the latest versions of J-Link and nRF Connect.

2. Use the command line with nrfjprog specifying --family nRF52.

3. Lower the debug speed with --clk 125kHz to see if it improves the connection.

4. Verify that `libjlinkarm.dylib` is present in `/Applications/SEGGER/JLink/`.

5. Try launching nRF Connect with the library path `DYLD_LIBRARY_PATH` set.

Despite these attempts, the errors persist.

Do you have any additional suggestions for resolving this issue? The `nrfjprog` error with the unexpected "debug port ID" seems to indicate protection, but I am unable to perform a `recover`. Any help to diagnose and unblock the situation would be greatly appreciated!

Thank you in advance for your assistance.

Related