Detecting JLINK with nrfjprog

Hi all,

I'm trying something similar to this:

https://devzone.nordicsemi.com/f/nordic-q-a/21628/how-to-use-nrfjprog-dll

i.e. using the nrfprog.dll to connect with a Jlink from a c# application.

Opening the .dll works fine and I now want to use this function:

nrfjprogdll_err_t NRFJPROG_enum_emu_snr(uint32_t serial_numbers[], uint32_t serial_numbers_len, uint32_t * num_available);

wrapped in my App as:

[DllImport("nrfjprog.dll", CallingConvention = CallingConvention.Cdecl)]
private static extern int NRFJPROG_enum_emu_snr(UInt32[] serial_numbers,UInt32 serial_numbers_len, out UInt32 num_available);

The num_available returned is correct, i.e. 1 if one JLINK is connected, 2 if two are connected etc. The serial_numbers and serial_numbers_len are, however, empty.

Looking at the arguments one would think that this is because serial_numbers and serial_numbers_len are not "pointers" and can therefore not "return" any values. 

Consequently I try to modify the wrapper to:

private static extern int NRFJPROG_enum_emu_snr(out UInt32[] serial_numbers,out UInt32 serial_numbers_len, out UInt32 num_available);

Unfortunately this result in the following runtime error:

>>Exception thrown: 'System.AccessViolationException' in NRFJPROG.exe
>>An unhandled exception of type 'System.AccessViolationException' occurred in NRFJPROG.exe
>>Attempted to read or write protected memory. This is often an indication that other memory is corrupt.

Any ideas on how to make this work ?

Cheers

Eric

Parents
  • Hi,

    What is the initial value of the serial_numbers_len?

    Best regards,
    Dejan

  • Hi,

    I initiated serial_numbers_len to 0 as suggested in the header file.

    However, I just discovered that when NRFJPROG_connect_to_emu_without_snr is called, and several JLINKs are attached, a selection pop-up is automatically created. Thus, no need to implement this myself.

    \Eric

  • Hi,

    There is an update for nRF Command Line Tools. Please update your nRF Command Line Tools to the version 10.16.0.

    Best regards,
    Dejan

  • Hi Dejan,

    I have tested upgrading to 10.16.0 but the problem persists, i.e. the JLINK still responds with "0" if its serial number is read while it is NOT connected to a target MCU.

    Was this supposed to have been fixed ? There is, at least, nothing about it in the 10.16.0 release log.

    \Eric 

  • Hi,

    Eric Wiebols said:
    Was this supposed to have been fixed ? There is, at least, nothing about it in the 10.16.0 release log.

    As far as I know, it should have been fixed with nRF Command Line Tools 10.16.0.

    Could you provide log using nRF Command Line Tools v10.16.0?

    Best regards,
    Dejan

  • Start
    [SeggerBackend] [Debug] Logger sink registered in Segger backend logger
    [JLink] [Debug] Logger sink registered in JLink logger
    [nRF52] [Debug] open
    [nRF52] [Debug] just_check_family
    [SeggerBackend] [Debug] open_dll
    [SeggerBackend] [Info] Load library at C:\Program Files\SEGGER\JLink\JLink_x64.dll.
    [SeggerBackend] [Info] Library loaded, loading member functions.
    [SeggerBackend] [Info] Member functions succesfully loaded.
    [SeggerBackend] [Debug] dll_version
    [SeggerBackend] [Info] Segger dll version 7.66.b loaded.
    [nRF52] [Debug] connect_to_emu_without_snr
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Debug] connect_to_emu_without_snr
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Debug] ---just_get_num_emus
    [SeggerBackend] [Debug] ---just_connect_to_emu_without_snr
    [SeggerBackend] [Debug] Segger logging enabled.
    [JLink] [None] Firmware: J-Link V11 compiled May 18 2022 17:08:14
    [JLink] [None] Firmware: J-Link V11 compiled May 18 2022 17:08:14
    [JLink] [None] Hardware: V11.00
    [JLink] [None] S/N: 821008216
    [JLink] [None] OEM: SEGGER
    [JLink] [None] Feature(s): GDB
    [JLink] [None] USB speed mode: High speed (480 MBit/s)
    [JLink] [None] TELNET listener socket opened on port 19021
    [JLink] [None] WEBSRV WEBSRV_Init(): Starting webserver thread(s)
    [JLink] [None] WEBSRV Webserver running on local port 19080
    [JLink] [None] - 18.351ms returns "O.K."  
    [JLink] [None] JLINK_HasError()  
    [JLink] [None] JLINK_Lock()  
    [JLink] [None] JLINK_ExecCommand("SetRestartOnClose = 0", ...).   
    [JLink] [None] - 0.005ms returns 0x01  
    [JLink] [None] JLINK_HasError()  
    [JLink] [None] JLINK_ExecCommand("DisableFlashDL", ...).   
    [JLink] [None] - 0.004ms returns 0x00  
    [JLink] [None] JLINK_HasError()  
    [JLink] [None] JLINK_ExecCommand("ExcludeFlashCacheRange 0x0-0xFFFFFFFF", ...).   
    [JLink] [None] - 0.007ms returns 0x00  
    [JLink] [None] JLINK_HasError()  
    [JLink] [None] JLINK_SetHookUnsecureDialog  
    [JLink] [None] JLINK_SetHookUnsecureDialog(...)
    [JLink] [None] - 0.270ms returns 0  
    [JLink] [None] JLINK_HasError()  
    [JLink] [None] JLINK_TIF_Select(JLINKARM_TIF_SWD)  
    [JLink] [None] - 1.707ms returns 0x00  
    [JLink] [None] JLINK_HasError()  
    [JLink] [None] JLINK_GetSpeedInfo()  
    [JLink] [None] 180000000 Hz / n, n >= 12
    [JLink] [None] - 0.233ms  
    [JLink] [None] JLINK_HasError()  
    [SeggerBackend] [Debug] Connected emulator supports SWD speeds up to 15000kHz
    [JLink] [None] JLINK_SetSpeed(4000)  
    [JLink] [None] - 0.487ms  
    [JLink] [None] JLINK_HasError()  
    [JLink] [None] JLINK_GetSpeed()  
    [JLink] [None] - 0.137ms returns 4000  
    [JLink] [None] JLINK_HasError()  
    [SeggerBackend] [Debug] SWD clock set to 4000kHz
    [JLink] [None] JLINK_GetSN()  
    [JLink] [None] - 0.191ms returns 821008216  
    [JLink] [None] JLINK_HasError()  
    [SeggerBackend] [Debug] read_debug_port_idr
    [SeggerBackend] [Debug] read_debug_port_register
    [SeggerBackend] [Debug] ---just_read_debug_port_register
    [SeggerBackend] [Debug] coresight_configure
    [JLink] [None] JLINK_GetHWStatus(...)  
    [JLink] [None] - 0.666ms returns 0  
    [JLink] [None] JLINK_HasError()  
    [SeggerBackend] [Error] Low voltage 0 detected in target device.
    [JLink] [None] - 0.235ms  
    [JLink] [None] JLINK_Close()  
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Debug] is_connected_to_emu
    [nRF52] [Debug] read_connected_emu_snr
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Debug] read_connected_emu_snr
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Error] Cannot call read_connected_emu_snr when connect_to_emu_without_snr or connect_to_emu_with_snr has not been called.
    [SeggerBackend] [Debug] is_connected_to_emu
    [nRF52] [Debug] close
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Debug] close
    [SeggerBackend] [Debug] disconnect_from_emu
    [SeggerBackend] [Debug] is_connected_to_emu
    [SeggerBackend] [Debug] Segger Backend closed.
    [nRF52] [Debug] nRF family DLL closed
    

    Log attached

  • Hi Eric,

    Thank you for the log.

    I'll get back to you when new information is available, possibly till the end of this week.

    Best regards,
    Dejan

Reply Children
Related