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

  • Hi,

    Eric Wiebols said:
    Connection established with what ?

    The connection is established to the emulator/debugger. Proper steps for establishing the connection are given in the header file I mentioned before.

    Eric Wiebols said:
    Why does the emulator need to be connected to a target in order for its (the emulator's) serial number to be read ?

    This is the way how it is done - first establish the connection and then read the serial number.

    Best regards,
    Dejan

  • Sorry, but you misinterpret my question;

    Yes, I establish the connection with the debugger/emulator and can read out the serial number, but, ONLY, if the debugger/emulator is connected to a powered target system (e.g. nRF52). If it is not the serial number returned is "0". Have you tested this on your end ?

    \Eric

  • Hi,

    I could get serial number if there is a connection to the debugger on nRF52840-DK. As long as the debugger is powered on, I could read its serial number with "nrfjprog --ids".

    Are you using external debugger? Are you using development kit or custom board? In case you are using development kit, how are you cutting power to the nrf52 chip?

    Can you get serial number by running the command "nrfjprog --ids" from the command line?

    Best regards,
    Dejan

  • I have a JLink+ with a custom board.

    Yes, with nrfjprog --ids I get the id from the emulator regardless if it is connected to a target or not. So, either the NRFJPROG_read_connected_emu_snr (out snr) function has an issue when called from C# or the nrfprog application uses another function in the .dll API. Maybe you can investigate internally what it uses ?

    \Eric

  • Hi,

    Could you please confirm that serial_numbers_length in your code is not zero?

    Best regards,
    Dejan

1 2 3 4 5 »