Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards/pba-d-01-kw2x: rely on the common adapter selection code #12151

Conversation

cladmi
Copy link
Contributor

@cladmi cladmi commented Sep 2, 2019

Contribution description

Do not set 'OPENOCD_EXTRA_INIT' but rely on
'openocd/openocd-adapters/dap.inc.mk' to select the adapter.
Using 'OPENOCD_EXTRA_INIT' for this was deprecated.

When 'DEBUG_ADAPTER_ID' was set it was already the case but not with 'SERIAL'.
The compatibility with using 'SERIAL' is maintained.

Review procedure

No other boards is setting OPENOCD_EXTRA_INIT:

git grep OPENOCD_EXTRA_INIT
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} \

The configuration of the adapter does end up in almost the same place with OPENOCD_ADAPTER_INIT

${OPENOCD_ADAPTER_INIT} \
-f '${OPENOCD_CONFIG}' \
${OPENOCD_EXTRA_INIT} \

And is the way we use for many other boards:

git grep '$(DEBUG_ADAPTER_ID)'
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)'

Testing procedure

Note: I will set SERIAL_TTY from the command line to not trigger the usb listing when using random serial number.

With this PR, the selection to OPENOCD_ADAPTER_INIT works with both SERIAL and DEBUG_ADAPTER_ID:

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
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

In master we had the same behavior with DEBUG_ADAPTER_ID

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

And when using SERIAL this was handled through OPENOCD_EXTRA_INIT instead of OPENOCD_ADAPTER_INIT

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

When multiple boards are connected, flashing is correctly handled:

No serial configuration fails (for reference)
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
The SERIAL handling works
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
And it still works with `DEBUG_ADAPTER_ID`
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

Issues/PRs references

Found while reviewing #11976

Do not set 'OPENOCD_EXTRA_INIT' but rely on
'openocd/openocd-adapters/dap.inc.mk' to select the adapter.
Using 'OPENOCD_EXTRA_INIT' for this was deprecated.

When 'DEBUG_ADAPTER_ID' was set it was already the case but not with
'SERIAL'.
The compatibility with using 'SERIAL' is maintained.
@miri64 miri64 added Area: boards Area: Board ports Area: build system Area: Build system Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation labels Sep 10, 2019
@fjmolinas
Copy link
Contributor

Testing Procedure:

  • This PR
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 02000203C3194E743EE5B38C
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 02000203C3194E743EE5B38C
  • master
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
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]
  • With samr21-xpro and pba-d-01-kw2x connected:
DEBUG_ADAPTER_ID=02000203C3194E743EE5B38C BOARD=pba-d-01-kw2x BUILD_IN_DOCKER=1 RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
Launching build container using image "riot/riotbuild:latest".
docker run --rm -t -u "$(id -u)" \
    -v '/usr/share/zoneinfo/Europe/Paris:/etc/localtime:ro' -v '/home/francisco/workspace/RIOT:/data/riotbuild/riotbase' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'     \
    -e 'BOARD=pba-d-01-kw2x' -e 'RIOT_CI_BUILD=1' \
    -w '/data/riotbuild/riotbase/examples/hello-world/' \
    'riot/riotbuild:latest' make   
Building application "hello-world" for "pba-d-01-kw2x" with MCU "kinetis".

   text	   data	    bss	    dec	    hex	filename
   9308	    116	   2552	  11976	   2ec8	/data/riotbuild/riotbase/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf
### Flashing Target ###
/home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf is not locked.
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
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: 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 37251 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: 0x0000073c msp: 0x1fffc200
auto erase enabled
Info : Kinetis MK21DN512xxx5 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
wrote 10240 bytes from file /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf in 0.387024s (25.838 KiB/s)
34 bytes written at address 0x20000000
downloaded 34 bytes in 0.004082s (8.134 KiB/s)
target halted due to breakpoint, current mode: Thread 
xPSR: 0x01000000 pc: 0x20000020 msp: 0x1fffc200
verified 9424 bytes in 0.378145s (24.338 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
Done flashing
SERIAL=02000203C3194E743EE5B38C BOARD=pba-d-01-kw2x BUILD_IN_DOCKER=1 RIOT_CI_BUILD=1 make --no-print-directory -C examples/hello-world/ flash
Launching build container using image "riot/riotbuild:latest".
docker run --rm -t -u "$(id -u)" \
    -v '/usr/share/zoneinfo/Europe/Paris:/etc/localtime:ro' -v '/home/francisco/workspace/RIOT:/data/riotbuild/riotbase' -e 'RIOTBASE=/data/riotbuild/riotbase' -e 'CCACHE_BASEDIR=/data/riotbuild/riotbase' -e 'BUILD_DIR=/data/riotbuild/riotbase/build' -e 'RIOTPROJECT=/data/riotbuild/riotbase' -e 'RIOTCPU=/data/riotbuild/riotbase/cpu' -e 'RIOTBOARD=/data/riotbuild/riotbase/boards' -e 'RIOTMAKE=/data/riotbuild/riotbase/makefiles'     \
    -e 'BOARD=pba-d-01-kw2x' -e 'RIOT_CI_BUILD=1' \
    -w '/data/riotbuild/riotbase/examples/hello-world/' \
    'riot/riotbuild:latest' make   
Building application "hello-world" for "pba-d-01-kw2x" with MCU "kinetis".

   text	   data	    bss	    dec	    hex	filename
   9308	    116	   2552	  11976	   2ec8	/data/riotbuild/riotbase/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf
/home/francisco/workspace/RIOT/dist/tools/openocd/openocd.sh flash /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf
### Flashing Target ###
/home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf is not locked.
Open On-Chip Debugger 0.10.0+dev-00703-g92bb76a4-dirty (2019-07-19-14:27)
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: 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 34321 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: 0x0000073c msp: 0x1fffc200
auto erase enabled
Info : Kinetis MK21DN512xxx5 detected: 2 flash blocks
Info : 2 PFlash banks: 512k total
wrote 10240 bytes from file /home/francisco/workspace/RIOT/examples/hello-world/bin/pba-d-01-kw2x/hello-world.elf in 0.388035s (25.771 KiB/s)
34 bytes written at address 0x20000000
downloaded 34 bytes in 0.004030s (8.239 KiB/s)
target halted due to breakpoint, current mode: Thread 
xPSR: 0x01000000 pc: 0x20000020 msp: 0x1fffc200
verified 9424 bytes in 0.375950s (24.480 KiB/s)
Info : MDM: Chip is unsecured. Continuing.
shutdown command invoked
Done flashing

@fjmolinas fjmolinas added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Sep 23, 2019
Copy link
Contributor

@fjmolinas fjmolinas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was able to reproduce the testing procedure, change make sense. ACK

@fjmolinas fjmolinas merged commit 3d26979 into RIOT-OS:master Sep 23, 2019
@cladmi
Copy link
Contributor Author

cladmi commented Sep 23, 2019

Thank you for the review :)

@cladmi cladmi deleted the pr/pba-d-01-kw2x/do_not_use_OPENOCD_ADAPTER_INIT branch September 23, 2019 09:57
@kb2ma kb2ma added this to the Release 2019.10 milestone Sep 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: boards Area: Board ports Area: build system Area: Build system CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants