From 0d59e7dc6e6883c3ab560e4e2cd0f0af4ff07b46 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Jul 2020 17:03:15 +0200 Subject: [PATCH 1/5] makefiles/tools/openocd-adapters: default to SWD, but make it configurable --- makefiles/tools/openocd-adapters/dap.inc.mk | 4 ++++ makefiles/tools/openocd-adapters/iotlab.inc.mk | 3 +++ makefiles/tools/openocd-adapters/jlink.inc.mk | 4 ++++ makefiles/tools/openocd-adapters/mulle.inc.mk | 3 +++ makefiles/tools/openocd-adapters/raspi.inc.mk | 6 ++++-- makefiles/tools/openocd-adapters/stlink.inc.mk | 14 ++++++++++---- makefiles/tools/openocd-adapters/sysfs_gpio.inc.mk | 4 +++- makefiles/tools/openocd.inc.mk | 1 + 8 files changed, 32 insertions(+), 7 deletions(-) diff --git a/makefiles/tools/openocd-adapters/dap.inc.mk b/makefiles/tools/openocd-adapters/dap.inc.mk index e3a2c691a5..fbb85ced66 100644 --- a/makefiles/tools/openocd-adapters/dap.inc.mk +++ b/makefiles/tools/openocd-adapters/dap.inc.mk @@ -1,5 +1,9 @@ # CMSIS DAP debug adapter OPENOCD_ADAPTER_INIT ?= -c 'source [find interface/cmsis-dap.cfg]' + +# default to SWD +OPENOCD_TRANSPORT ?= swd + # Add serial matching command, only if DEBUG_ADAPTER_ID was specified ifneq (,$(DEBUG_ADAPTER_ID)) OPENOCD_ADAPTER_INIT += -c 'cmsis_dap_serial $(DEBUG_ADAPTER_ID)' diff --git a/makefiles/tools/openocd-adapters/iotlab.inc.mk b/makefiles/tools/openocd-adapters/iotlab.inc.mk index dfd77d4e00..3e4b8ed13b 100644 --- a/makefiles/tools/openocd-adapters/iotlab.inc.mk +++ b/makefiles/tools/openocd-adapters/iotlab.inc.mk @@ -1,6 +1,9 @@ # iotlab-usb debug adapter OPENOCD_ADAPTER_INIT ?= -c 'source [find interface/ftdi/iotlab-usb.cfg]' +# default to SWD +OPENOCD_TRANSPORT ?= swd + # Add serial matching command, only if DEBUG_ADAPTER_ID was specified ifneq (,$(DEBUG_ADAPTER_ID)) OPENOCD_ADAPTER_INIT += -c 'ftdi_serial $(DEBUG_ADAPTER_ID)' diff --git a/makefiles/tools/openocd-adapters/jlink.inc.mk b/makefiles/tools/openocd-adapters/jlink.inc.mk index ce7137fbc0..b073a153e8 100644 --- a/makefiles/tools/openocd-adapters/jlink.inc.mk +++ b/makefiles/tools/openocd-adapters/jlink.inc.mk @@ -1,5 +1,9 @@ # Segger J-Link debug adapter OPENOCD_ADAPTER_INIT ?= -c 'source [find interface/jlink.cfg]' + +# default to SWD +OPENOCD_TRANSPORT ?= swd + # Add serial matching command, only if DEBUG_ADAPTER_ID was specified ifneq (,$(DEBUG_ADAPTER_ID)) OPENOCD_ADAPTER_INIT += -c 'jlink serial $(DEBUG_ADAPTER_ID)' diff --git a/makefiles/tools/openocd-adapters/mulle.inc.mk b/makefiles/tools/openocd-adapters/mulle.inc.mk index 347d83a17c..e7e7fc017d 100644 --- a/makefiles/tools/openocd-adapters/mulle.inc.mk +++ b/makefiles/tools/openocd-adapters/mulle.inc.mk @@ -26,6 +26,9 @@ PROGRAMMER_VERSION ?= 0.70 OPENOCD_ADAPTER_INIT ?= -f '$(RIOTBASE)/boards/mulle/dist/openocd/mulle-programmer-$(PROGRAMMER_VERSION).cfg' +# Default to SWD +OPENOCD_TRANSPORT ?= swd + # Add serial matching command, only if DEBUG_ADAPTER_ID was specified ifneq (,$(DEBUG_ADAPTER_ID)) OPENOCD_ADAPTER_INIT += -c 'ftdi_serial $(DEBUG_ADAPTER_ID)' diff --git a/makefiles/tools/openocd-adapters/raspi.inc.mk b/makefiles/tools/openocd-adapters/raspi.inc.mk index 0a996378b5..6891e588ca 100644 --- a/makefiles/tools/openocd-adapters/raspi.inc.mk +++ b/makefiles/tools/openocd-adapters/raspi.inc.mk @@ -29,8 +29,10 @@ OPENOCD_ADAPTER_INIT ?= \ -c 'bcm2835gpio_peripheral_base $(PERIPH_BASE)' \ -c 'bcm2835gpio_speed_coeffs $(SPEED_COEFF) $(SPEED_OFFSET)' \ -c 'bcm2835gpio_swd_nums $(SWCLK_PIN ) $(SWDIO_PIN)' \ - -c 'bcm2835gpio_srst_num $(SRST_PIN)' \ - -c 'transport select swd' + -c 'bcm2835gpio_srst_num $(SRST_PIN)' + +# Default to SWD +OPENOCD_TRANSPORT ?= swd # bcm2835gpio needs access to /dev/mem export OPENOCD ?= sudo -E openocd diff --git a/makefiles/tools/openocd-adapters/stlink.inc.mk b/makefiles/tools/openocd-adapters/stlink.inc.mk index 8ab05f56fc..19ba25d8b9 100644 --- a/makefiles/tools/openocd-adapters/stlink.inc.mk +++ b/makefiles/tools/openocd-adapters/stlink.inc.mk @@ -3,15 +3,21 @@ STLINK_VERSION ?= 2-1 # Use STLINK_VERSION to select which stlink version is used -OPENOCD_ADAPTER_INIT ?= \ - -c 'source [find interface/stlink-v$(STLINK_VERSION).cfg]' \ - -c 'transport select hla_swd' +OPENOCD_ADAPTER_INIT ?= -c 'source [find interface/stlink-v$(STLINK_VERSION).cfg]' + +# If swd / jtag is selected by the board, prefix it with hla_ +ifneq (,$(filter swd jtag,$(OPENOCD_TRANSPORT))) + OPENOCD_TRANSPORT := hla_$(OPENOCD_TRANSPORT) +endif + +# All ST-Link adapters support hla_swd, so use that for simplicity +OPENOCD_TRANSPORT ?= hla_swd + # Add serial matching command, only if DEBUG_ADAPTER_ID was specified ifneq (,$(DEBUG_ADAPTER_ID)) OPENOCD_ADAPTER_INIT += -c 'hla_serial $(DEBUG_ADAPTER_ID)' endif - # Some stlink clones cannot signal reset properly, # In this case, use SRST=none ifneq (,$(SRST)) diff --git a/makefiles/tools/openocd-adapters/sysfs_gpio.inc.mk b/makefiles/tools/openocd-adapters/sysfs_gpio.inc.mk index 8a221832a5..c63c273c58 100644 --- a/makefiles/tools/openocd-adapters/sysfs_gpio.inc.mk +++ b/makefiles/tools/openocd-adapters/sysfs_gpio.inc.mk @@ -6,8 +6,10 @@ SRST_PIN ?= 16 OPENOCD_ADAPTER_INIT ?= \ -c 'interface sysfsgpio' \ - -c 'transport select swd' \ -c 'sysfsgpio_swd_nums $(SWCLK_PIN) $(SWDIO_PIN)' \ -c 'sysfsgpio_srst_num $(SRST_PIN)' \ -c 'adapter_nsrst_delay 100' \ -c 'adapter_nsrst_assert_width 100' + +# default to SWD +OPENOCD_TRANSPORT ?= swd diff --git a/makefiles/tools/openocd.inc.mk b/makefiles/tools/openocd.inc.mk index 945dbcc3d1..25ce37915b 100644 --- a/makefiles/tools/openocd.inc.mk +++ b/makefiles/tools/openocd.inc.mk @@ -11,6 +11,7 @@ RESET_FLAGS ?= reset ifneq (,$(DEBUG_ADAPTER)) include $(RIOTMAKE)/tools/openocd-adapters/$(DEBUG_ADAPTER).inc.mk + OPENOCD_ADAPTER_INIT += -c 'transport select $(OPENOCD_TRANSPORT)' endif OPENOCD_CONFIG ?= $(BOARDDIR)/dist/openocd.cfg From 37a10de671f86be96e5b13083c8d0397e0186e0a Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Jul 2020 17:14:33 +0200 Subject: [PATCH 2/5] boards/frdm: remove transport selection from openocd.cfg --- boards/common/frdm/dist/openocd-klx.cfg | 3 --- 1 file changed, 3 deletions(-) diff --git a/boards/common/frdm/dist/openocd-klx.cfg b/boards/common/frdm/dist/openocd-klx.cfg index 47a447b7b8..591f171f37 100644 --- a/boards/common/frdm/dist/openocd-klx.cfg +++ b/boards/common/frdm/dist/openocd-klx.cfg @@ -10,9 +10,6 @@ # CMSIS-DAP (DAPLink) compatible OpenSDA firmware binary images can be found at: # http://www.nxp.com/opensda -# Kinetis L only supports SWD -transport select swd - # Kinetis L series CPUs source [find target/klx.cfg] From d06b26dfd81056a9807cd92b02664857cf1a0fcd Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Jul 2020 17:16:03 +0200 Subject: [PATCH 3/5] boards/common/nrf52: remove transport selection from openocd.cfg --- boards/common/nrf52/dist/openocd.cfg | 2 -- 1 file changed, 2 deletions(-) diff --git a/boards/common/nrf52/dist/openocd.cfg b/boards/common/nrf52/dist/openocd.cfg index 75659d4ab3..fb1632de46 100644 --- a/boards/common/nrf52/dist/openocd.cfg +++ b/boards/common/nrf52/dist/openocd.cfg @@ -1,3 +1 @@ -transport select swd - source [find target/nrf52.cfg] From eceb84f9c0acbc7f439e1a0c0c76be1aa281fe20 Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Thu, 9 Jul 2020 17:17:04 +0200 Subject: [PATCH 4/5] boards/mcb2388: remove transport selection from openocd.cfg --- boards/mcb2388/Makefile.include | 1 + boards/mcb2388/dist/openocd.cfg | 2 -- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/boards/mcb2388/Makefile.include b/boards/mcb2388/Makefile.include index d6451f48e1..03862334e0 100644 --- a/boards/mcb2388/Makefile.include +++ b/boards/mcb2388/Makefile.include @@ -3,6 +3,7 @@ DEBUG_ADAPTER ?= dap PROGRAMMER ?= openocd JLINK_DEVICE := LPC2388 +OPENOCD_TRANSPORT := jtag include $(RIOTBOARD)/common/msba2/Makefile.include include $(RIOTMAKE)/tools/openocd.inc.mk diff --git a/boards/mcb2388/dist/openocd.cfg b/boards/mcb2388/dist/openocd.cfg index ddf203c14a..7251c54749 100644 --- a/boards/mcb2388/dist/openocd.cfg +++ b/boards/mcb2388/dist/openocd.cfg @@ -1,5 +1,3 @@ -transport select jtag - source [find target/lpc2xxx.cfg] # parameters: # - core_freq_khz - frequency of core in kHz during flashing, usually equal to connected crystal or internal oscillator, e.g. 12000 From 8f1d32bb2d4ee4a6bcfbb58b6bd359882bd984dd Mon Sep 17 00:00:00 2001 From: Benjamin Valentin Date: Fri, 10 Jul 2020 12:01:33 +0200 Subject: [PATCH 5/5] boards/common/nrf52: add note about ST-LINKV2 as programmer --- boards/common/nrf52/doc.txt | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/boards/common/nrf52/doc.txt b/boards/common/nrf52/doc.txt index 332c538f4b..f6625c2fb1 100644 --- a/boards/common/nrf52/doc.txt +++ b/boards/common/nrf52/doc.txt @@ -25,4 +25,10 @@ To flash the board with OpenOCD, use the `PROGRAMMER` variable: PROGRAMMER=openocd make BOARD= -C examples/hello-world flash ``` +It is also possible to use the SWD interface of a ST-LINK/V2 in-circuit +debugger/programmer with OpenOCD to flash a nrf52 board: +``` + PROGRAMMER=openocd DEBUG_ADAPTER=stlink make BOARD= -C examples/hello-world flash +``` + */