<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://devzone.nordicsemi.com/cfs-file/__key/system/syndication/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>nrfjprog: Determine which JLink was selected in previous invocation</title><link>https://devzone.nordicsemi.com/f/nordic-q-a/87618/nrfjprog-determine-which-jlink-was-selected-in-previous-invocation</link><description>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</description><dc:language>en-US</dc:language><generator>Telligent Community 13</generator><lastBuildDate>Mon, 09 May 2022 05:41:06 GMT</lastBuildDate><atom:link rel="self" type="application/rss+xml" href="https://devzone.nordicsemi.com/f/nordic-q-a/87618/nrfjprog-determine-which-jlink-was-selected-in-previous-invocation" /><item><title>RE: nrfjprog: Determine which JLink was selected in previous invocation</title><link>https://devzone.nordicsemi.com/thread/366829?ContentTypeID=1</link><pubDate>Mon, 09 May 2022 05:41:06 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:6af77571-e50e-47a7-8d67-d9de065625fa</guid><dc:creator>m.wagner</dc:creator><description>&lt;p&gt;Hi Marte,&lt;/p&gt;
&lt;p&gt;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&amp;#39;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.&lt;/p&gt;
&lt;p&gt;Best regars,&lt;/p&gt;
&lt;p&gt;-mike&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item><item><title>RE: nrfjprog: Determine which JLink was selected in previous invocation</title><link>https://devzone.nordicsemi.com/thread/366521?ContentTypeID=1</link><pubDate>Thu, 05 May 2022 14:23:36 GMT</pubDate><guid isPermaLink="false">137ad170-7792-4731-bb38-c0d22fbe4515:cc70cb72-2386-4e15-860b-de7e19009e7c</guid><dc:creator>Marte Myrvold</dc:creator><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;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:&lt;/p&gt;
&lt;p&gt;&lt;pre class="ui-code" data-mode="text"&gt;#!/bin/sh

device_list=( $(nrfjprog --ids) )
echo &amp;#39;Select device&amp;#39;
for i in &amp;quot;${!device_list[@]}&amp;quot;; do printf &amp;#39;%s: %s\n&amp;#39; &amp;quot;$i&amp;quot; &amp;quot;${device_list[$i]}&amp;quot;; 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]}&lt;/pre&gt;&lt;/p&gt;
&lt;p&gt;This script takes the file you want to program as input, for example:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;sh program.sh _build\nrf52840_xxaa.hex&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;It will find&amp;nbsp;and display the serial number of all debuggers connected and let you select which one you want to use by using the index. Using&amp;nbsp;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.&lt;/p&gt;
&lt;p&gt;So it will look something like this&lt;/p&gt;
&lt;p&gt;&lt;code&gt;Select device&lt;/code&gt;&lt;br /&gt;&lt;code&gt;0: 1050075853&lt;/code&gt;&lt;br /&gt;&lt;code&gt;1: 683009952&lt;/code&gt;&lt;br /&gt;&lt;code&gt;2: 685611083&lt;/code&gt;&lt;br /&gt;&lt;code&gt;&amp;gt; 1&lt;/code&gt;&lt;br /&gt;&lt;code&gt;Recovering device. This operation might take 30s.&lt;/code&gt;&lt;br /&gt;&lt;code&gt;Erasing user code and UICR flash areas.&lt;/code&gt;&lt;br /&gt;&lt;code&gt;Parsing image file.&lt;/code&gt;&lt;br /&gt;&lt;code&gt;Verifying programming.&lt;/code&gt;&lt;br /&gt;&lt;code&gt;Verified OK.&lt;/code&gt;&lt;br /&gt;&lt;code&gt;Applying system reset.&lt;/code&gt;&lt;br /&gt;&lt;code&gt;Run.&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Best regards,&lt;/p&gt;
&lt;p&gt;Marte&lt;/p&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;</description></item></channel></rss>