Beware that this post is related to an SDK in maintenance mode
More Info: Consider nRF Connect SDK for new designs
This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

nrfjprog: Determine which JLink was selected in previous invocation

When multiple J-Link devices are connected to my computer, whenever I run nrfjprog without the --snr argument, I get a prompt to select the emulator like this:

Is there a way to retrieve the selection that was made after the nrfjprog.exe invocation? My use case is that I have a sequence of nrfjprog commands that need execution (e.g. recovery, programming, reset) and it is problematic that each time nrfjprog is started anew, I have to re-select the device.

The prompt itself is quite convenient if only shown once, but it would be helpful if I could actually find out which probe was selected...

Parents
  • Hi,

    Unfortunately there is no simple way to select the previously selected device. In some cases you can run the commands together, for example --reset can be combined with --program. Another option is to create a script to make this easier. Exactly what you want the script to do is up to you, but here you have an example that you can use as a starting point:

    #!/bin/sh
    
    device_list=( $(nrfjprog --ids) )
    echo 'Select device'
    for i in "${!device_list[@]}"; do printf '%s: %s\n' "$i" "${device_list[$i]}"; done
    read device_nr
    family=$(nrfjprog --deviceversion --snr ${device_list[$device_nr]})
    nrfjprog -f ${family:0:5} --recover --snr ${device_list[$device_nr]}
    nrfjprog -f ${family:0:5} --program $1 --snr ${device_list[$device_nr]} --verify
    nrfjprog -f ${family:0:5} --reset --snr ${device_list[$device_nr]}

    This script takes the file you want to program as input, for example:

    sh program.sh _build\nrf52840_xxaa.hex

    It will find and display the serial number of all debuggers connected and let you select which one you want to use by using the index. Using the serial number it will find the device family, and in the end it will use the device family and serial number to run the recover, program and reset commands.

    So it will look something like this

    Select device
    0: 1050075853
    1: 683009952
    2: 685611083
    > 1
    Recovering device. This operation might take 30s.
    Erasing user code and UICR flash areas.
    Parsing image file.
    Verifying programming.
    Verified OK.
    Applying system reset.
    Run.

    Best regards,

    Marte

Reply
  • Hi,

    Unfortunately there is no simple way to select the previously selected device. In some cases you can run the commands together, for example --reset can be combined with --program. Another option is to create a script to make this easier. Exactly what you want the script to do is up to you, but here you have an example that you can use as a starting point:

    #!/bin/sh
    
    device_list=( $(nrfjprog --ids) )
    echo 'Select device'
    for i in "${!device_list[@]}"; do printf '%s: %s\n' "$i" "${device_list[$i]}"; done
    read device_nr
    family=$(nrfjprog --deviceversion --snr ${device_list[$device_nr]})
    nrfjprog -f ${family:0:5} --recover --snr ${device_list[$device_nr]}
    nrfjprog -f ${family:0:5} --program $1 --snr ${device_list[$device_nr]} --verify
    nrfjprog -f ${family:0:5} --reset --snr ${device_list[$device_nr]}

    This script takes the file you want to program as input, for example:

    sh program.sh _build\nrf52840_xxaa.hex

    It will find and display the serial number of all debuggers connected and let you select which one you want to use by using the index. Using the serial number it will find the device family, and in the end it will use the device family and serial number to run the recover, program and reset commands.

    So it will look something like this

    Select device
    0: 1050075853
    1: 683009952
    2: 685611083
    > 1
    Recovering device. This operation might take 30s.
    Erasing user code and UICR flash areas.
    Parsing image file.
    Verifying programming.
    Verified OK.
    Applying system reset.
    Run.

    Best regards,

    Marte

Children
  • Hi Marte,

    Thank you for your thorough response. I was aware of the possibility to list the connected J-Link devices via nrfjprog --ids. Unfortunately this won't work in my scenario, since I call the script in question from Keil uVision which seems to be unable to display script output while the script is still executing.

    Best regars,

    -mike

Related