<h3>Contribution description</h3>
<p>Do not set 'OPENOCD_EXTRA_INIT' but rely on<br>
'openocd/openocd-adapters/dap.inc.mk' to select the adapter.<br>
Using 'OPENOCD_EXTRA_INIT' for this was deprecated.</p>
<p>When 'DEBUG_ADAPTER_ID' was set it was already the case but not with 'SERIAL'.<br>
The compatibility with using 'SERIAL' is maintained.</p>
<h3>Review procedure</h3>
<p>No other boards is setting <code>OPENOCD_EXTRA_INIT</code>:</p>
<details><summary>git grep OPENOCD_EXTRA_INIT</summary>
<pre><code>git grep OPENOCD_EXTRA_INIT
boards/common/frdm/Makefile.include:export OPENOCD_EXTRA_INIT
dist/tools/openocd/openocd.sh:: ${OPENOCD_EXTRA_INIT:=}
dist/tools/openocd/openocd.sh:            ${OPENOCD_EXTRA_INIT} \
dist/tools/openocd/openocd.sh:            ${OPENOCD_EXTRA_INIT} \
dist/tools/openocd/openocd.sh:            ${OPENOCD_EXTRA_INIT} \
dist/tools/openocd/openocd.sh:            ${OPENOCD_EXTRA_INIT} \
</code></pre>
</details>
<p>The configuration of the adapter does end up in almost the same place with <code>OPENOCD_ADAPTER_INIT</code></p>
<p><div class="border rounded-1 my-2">
  <div class="f6 px-3 py-2 lh-condensed border-bottom bg-gray-light">
    <p class="mb-0 text-bold">
      <a href="https://github.com/RIOT-OS/RIOT/blob/f74381c77b58b97e5c86a18cb162fe17a5df75ba/dist/tools/openocd/openocd.sh#L353-L355">RIOT/dist/tools/openocd/openocd.sh</a>
    </p>
    <p class="mb-0 text-gray-light">
        Lines 353 to 355
      in
      <a data-pjax="true" class="commit-tease-sha" href="/RIOT-OS/RIOT/commit/f74381c77b58b97e5c86a18cb162fe17a5df75ba">f74381c</a>
    </p>
    </div>
    <div itemprop="text" class="blob-wrapper blob-wrapper-embedded data">
    <table class="highlight tab-size mb-0 js-file-line-container" data-tab-size="8">

        <tbody><tr class="border-0">
          <td id="L353" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="353"></td>
          <td id="LC353" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-s">            <span class="pl-smi">${OPENOCD_ADAPTER_INIT}</span> <span class="pl-cce">\</span></span> </td>
        </tr>

        <tr class="border-0">
          <td id="L354" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="354"></td>
          <td id="LC354" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-s">            -f '<span class="pl-smi">${OPENOCD_CONFIG}</span>' <span class="pl-cce">\</span></span> </td>
        </tr>

        <tr class="border-0">
          <td id="L355" class="blob-num border-0 px-3 py-0 bg-white js-line-number" data-line-number="355"></td>
          <td id="LC355" class="blob-code border-0 px-3 py-0 bg-white blob-code-inner js-file-line"> <span class="pl-s">            <span class="pl-smi">${OPENOCD_EXTRA_INIT}</span> <span class="pl-cce">\</span></span> </td>
        </tr>
    </tbody></table>
  </div>
</div>
</p>
<p>And is the way we use for many other boards:</p>
<details><summary>git grep '$(DEBUG_ADAPTER_ID)'</summary>
<pre><code>git grep '$(DEBUG_ADAPTER_ID)'
boards/mulle/Makefile.include:    ifneq ($(DEBUG_ADAPTER_ID),)
boards/mulle/Makefile.include:      PORT := $(firstword $(shell $(RIOTTOOLS)/usb-serial/find-tty.sh '^$(DEBUG_ADAPTER_ID)$$'))
boards/mulle/Makefile.include:    ifneq ($(DEBUG_ADAPTER_ID),)
boards/mulle/Makefile.include:      PORT := /dev/tty.usbserial-$(DEBUG_ADAPTER_ID)B
makefiles/tools/edbg.inc.mk:ifneq (,$(DEBUG_ADAPTER_ID))
makefiles/tools/edbg.inc.mk:  EDBG_ARGS += --serial $(DEBUG_ADAPTER_ID)
makefiles/tools/openocd-adapters/dap.inc.mk:ifneq (,$(DEBUG_ADAPTER_ID))
makefiles/tools/openocd-adapters/dap.inc.mk:  OPENOCD_ADAPTER_INIT += -c 'cmsis_dap_serial $(DEBUG_ADAPTER_ID)'
makefiles/tools/openocd-adapters/jlink.inc.mk:ifneq (,$(DEBUG_ADAPTER_ID))
makefiles/tools/openocd-adapters/jlink.inc.mk:  OPENOCD_ADAPTER_INIT += -c 'jlink serial $(DEBUG_ADAPTER_ID)'
makefiles/tools/openocd-adapters/mulle.inc.mk:ifneq (,$(DEBUG_ADAPTER_ID))
makefiles/tools/openocd-adapters/mulle.inc.mk:  ifeq "100" "$(word 1, $(sort 100 $(DEBUG_ADAPTER_ID)))"
makefiles/tools/openocd-adapters/mulle.inc.mk:    ifneq "149" "$(word 1, $(sort 149 $(DEBUG_ADAPTER_ID)))"
makefiles/tools/openocd-adapters/mulle.inc.mk:ifneq (,$(DEBUG_ADAPTER_ID))
makefiles/tools/openocd-adapters/mulle.inc.mk:  OPENOCD_ADAPTER_INIT += -c 'ftdi_serial $(DEBUG_ADAPTER_ID)'
makefiles/tools/openocd-adapters/stlink.inc.mk:ifneq (,$(DEBUG_ADAPTER_ID))
makefiles/tools/openocd-adapters/stlink.inc.mk:  OPENOCD_ADAPTER_INIT += -c 'hla_serial $(DEBUG_ADAPTER_ID)'
</code></pre>
</details>
<h3>Testing procedure</h3>
<p>Note: I will set <code>SERIAL_TTY</code> from the command line to not trigger the usb listing when using random serial number.</p>
<p>With this PR, the selection to <code>OPENOCD_ADAPTER_INIT</code>¬†works with both <code>SERIAL</code> and <code>DEBUG_ADAPTER_ID</code>:</p>
<pre><code>DEBUG_ADAPTER_ID=anything BOARD=pba-d-01-kw2x make --no-print-directory -C examples/hello-world/ info-debug-variable-OPENOCD_ADAPTER_INIT SERIAL_TTY=/dev/null
-c source [find interface/cmsis-dap.cfg] -c cmsis_dap_serial anything
</code></pre>
<pre><code>SERIAL=anything BOARD=pba-d-01-kw2x make --no-print-directory -C examples/hello-world/ info-debug-variable-OPENOCD_ADAPTER_INIT SERIAL_TTY=/dev/null
-c source [find interface/cmsis-dap.cfg] -c cmsis_dap_serial anything
</code></pre>
<p>In master we had the same behavior with <code>DEBUG_ADAPTER_ID</code></p>
<pre><code>DEBUG_ADAPTER_ID=anything BOARD=pba-d-01-kw2x make --no-print-directory -C examples/hello-world/ info-debug-variable-OPENOCD_ADAPTER_INIT SERIAL_TTY=/dev/null
-c source [find interface/cmsis-dap.cfg] -c cmsis_dap_serial anything
</code></pre>
<p>And when using <code>SERIAL</code> this was handled through <code>OPENOCD_EXTRA_INIT</code> instead of <code>OPENOCD_ADAPTER_INIT</code></p>
<pre><code>SERIAL=anything BOARD=pba-d-01-kw2x make --no-print-directory -C examples/hello-world/ info-debug-variable-OPENOCD_EXTRA_INIT SERIAL_TTY=/dev/null
-c cmsis_dap_serial anything
</code></pre>
<h4>When multiple boards are connected, flashing is correctly handled:</h4>
<details><summary>No serial configuration fails (for reference)</summary>
<pre><code>BOARD=pba-d-01-kw2x BUILD_IN_DOCKER=1 RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
...
GNU MCU Eclipse 64-bit Open On-Chip Debugger 0.10.0+dev-00462-gdd1d90111 (2019-01-18-11:37)
Licensed under GNU GPL v2
For bug reports, read
        http://openocd.org/doc/doxygen/bugs.html
Info : auto-selecting first available session transport "swd". To override use 'transport select <transport>'.
Info : add flash_bank kinetis kx.pflash
adapter speed: 1000 kHz
none separate
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: JTAG Supported
Info : CMSIS-DAP: FW Version = 1.2.0
Info : CMSIS-DAP: Serial# = L1000973
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 0 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz


/srv/ilab-builds/workspace/git/RIOT/examples/hello-world/../../Makefile.include:556: recipe for target 'flash' failed
</code></pre>
<details><summary>The SERIAL handling works</summary>
<pre><code>SERIAL=02000203C37B4E073E87B3FF BOARD=pba-d-01-kw2x BUILD_IN_DOCKER=1 RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
...
cortex_m reset_config sysresetreq
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 46489 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* kx.cpu             cortex_m   little kx.cpu             unknown
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000740 msp: 0x1fffc200
auto erase enabled
Info : Kinetis MK21DN512xxx5 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
wrote 10240 bytes from file /srv/ilab-builds/workspace/git/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf in 0.389989s (25.642 KiB/s)
34 bytes written at address 0x20000000
downloaded 34 bytes in 0.004008s (8.284 KiB/s)
target halted due to breakpoint, current mode: Thread 
xPSR: 0x01000000 pc: 0x20000020 msp: 0x1fffc200
verified 9424 bytes in 0.399987s (23.009 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
</code></pre>
</details>
<details><summary>And it still works with `DEBUG_ADAPTER_ID`</summary>
<pre><code>DEBUG_ADAPTER_ID=02000203C37B4E073E87B3FF BOARD=pba-d-01-kw2x BUILD_IN_DOCKER=1 RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
...
Info : CMSIS-DAP: SWD  Supported
Info : CMSIS-DAP: FW Version = 1.0
Info : CMSIS-DAP: Interface Initialised (SWD)
Info : SWCLK/TCK = 0 SWDIO/TMS = 1 TDI = 0 TDO = 0 nTRST = 0 nRESET = 1
Info : CMSIS-DAP: Interface ready
Info : clock speed 1000 kHz
Info : SWD DPIDR 0x2ba01477
Info : MDM: Chip is unsecured. Continuing.
Info : kx.cpu: hardware has 6 breakpoints, 4 watchpoints
Info : Listening on port 34461 for gdb connections
    TargetName         Type       Endian TapName            State       
--  ------------------ ---------- ------ ------------------ ------------
 0* kx.cpu             cortex_m   little kx.cpu             unknown
Info : MDM: Chip is unsecured. Continuing.
target halted due to debug-request, current mode: Thread 
xPSR: 0x01000000 pc: 0x00000740 msp: 0x1fffc200
auto erase enabled
Info : Kinetis MK21DN512xxx5 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
wrote 10240 bytes from file /srv/ilab-builds/workspace/git/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf in 0.389948s (25.644 KiB/s)
34 bytes written at address 0x20000000
downloaded 34 bytes in 0.004008s (8.284 KiB/s)
target halted due to breakpoint, current mode: Thread 
xPSR: 0x01000000 pc: 0x20000020 msp: 0x1fffc200
verified 9424 bytes in 0.400029s (23.006 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
Done flashing
</code></pre>
</details>
<h3>Issues/PRs references</h3>
<p>Found while reviewing <a class="issue-link js-issue-link" data-error-text="Failed to load issue title" data-id="477786802" data-permission-text="Issue title is private" data-url="https://github.com/RIOT-OS/RIOT/issues/11976" data-hovercard-type="pull_request" data-hovercard-url="/RIOT-OS/RIOT/pull/11976/hovercard" href="https://github.com/RIOT-OS/RIOT/pull/11976">#11976</a></p></details>

<hr>

<h4>You can view, comment on, or merge this pull request online at:</h4>
<p>  <a href='https://github.com/RIOT-OS/RIOT/pull/12151'>https://github.com/RIOT-OS/RIOT/pull/12151</a></p>

<h4>Commit Summary</h4>
<ul>
  <li>boards/pba-d-01-kw2x: rely on the common adapter selection code</li>
</ul>

<h4>File Changes</h4>
<ul>
  <li>
    <strong>M</strong>
    <a href="https://github.com/RIOT-OS/RIOT/pull/12151/files#diff-0">boards/pba-d-01-kw2x/Makefile.include</a>
    (4)
  </li>
</ul>

<h4>Patch Links:</h4>
<ul>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/12151.patch'>https://github.com/RIOT-OS/RIOT/pull/12151.patch</a></li>
  <li><a href='https://github.com/RIOT-OS/RIOT/pull/12151.diff'>https://github.com/RIOT-OS/RIOT/pull/12151.diff</a></li>
</ul>

<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />You are receiving this because you are subscribed to this thread.<br />Reply to this email directly, <a href="https://github.com/RIOT-OS/RIOT/pull/12151?email_source=notifications&email_token=ABE7WYHW47DKHUBSIPFQYADQHUD27A5CNFSM4IS5FBOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HIY6WIQ">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/ABE7WYAKSOGBEGT7HJNP6OTQHUD27ANCNFSM4IS5FBOA">mute the thread</a>.<img src="https://github.com/notifications/beacon/ABE7WYDJDANMYEZOSHDUDMDQHUD27A5CNFSM4IS5FBOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HIY6WIQ.gif" height="1" width="1" alt="" /></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/RIOT-OS/RIOT/pull/12151?email_source=notifications\u0026email_token=ABE7WYHW47DKHUBSIPFQYADQHUD27A5CNFSM4IS5FBOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HIY6WIQ",
"url": "https://github.com/RIOT-OS/RIOT/pull/12151?email_source=notifications\u0026email_token=ABE7WYHW47DKHUBSIPFQYADQHUD27A5CNFSM4IS5FBOKYY3PNVWWK3TUL52HS4DFUVEXG43VMWVGG33NNVSW45C7NFSM4HIY6WIQ",
"name": "View Pull Request"
},
"description": "View this Pull Request on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>