From 3eb17f56fa3350cd41d60280eeda2d32141a1a89 Mon Sep 17 00:00:00 2001
From: Alexandre Abadie <alexandre.abadie@inria.fr>
Date: Wed, 20 Jun 2018 10:42:38 +0200
Subject: [PATCH] boards/nrf52xxxdk: add openocd as programmer

For the moment openocd doesn't work when softdevice blob module is loaded
---
 boards/common/nrf52/Makefile.include | 24 ++++++++++++++++--------
 boards/common/nrf52/dist/openocd.cfg |  3 +++
 2 files changed, 19 insertions(+), 8 deletions(-)
 create mode 100644 boards/common/nrf52/dist/openocd.cfg

diff --git a/boards/common/nrf52/Makefile.include b/boards/common/nrf52/Makefile.include
index 269a84f145..f8e47e1b57 100644
--- a/boards/common/nrf52/Makefile.include
+++ b/boards/common/nrf52/Makefile.include
@@ -9,24 +9,32 @@ PORT_LINUX ?= /dev/ttyACM0
 PORT_DARWIN ?= $(firstword $(sort $(wildcard /dev/tty.usbmodem*)))
 include $(RIOTMAKE)/tools/serial.inc.mk
 
-# define jlink as default programmer, but overridable
-PROGRAMMER ?= jlink
+# The following configuration is dependencies specific
+# but they are resolved later
+# Hack to know now if 'nordic_softdevice_ble' is used
+include $(RIOTBOARD)/$(BOARD)/Makefile.dep
 
+PROGRAMMER ?= jlink
 ifeq (jlink,$(PROGRAMMER))
   # setup JLink for flashing
   export JLINK_DEVICE := nrf52
 
-  # The following configuration is dependencies specific
-  # but they are resolved later
-  # Hack to know now if 'nordic_softdevice_ble' is used
-  include $(RIOTBOARD)/$(BOARD)/Makefile.dep
-
   # special options when using SoftDevice
   ifneq (,$(filter nordic_softdevice_ble,$(USEPKG)))
     export JLINK_PRE_FLASH := erase\nloadfile $(BINDIR)/softdevice.hex
     export FLASH_ADDR := 0x1f000
     export LINKER_SCRIPT ?= $(RIOTCPU)/$(CPU)/ldscripts/$(CPU_MODEL)_sd.ld
   endif
-
   include $(RIOTMAKE)/tools/jlink.inc.mk
+else ifeq (openocd,$(PROGRAMMER))
+  # setup OpenOCD for flashing. Version 0.10 of OpenOCD doesn't contain support
+  # for nrf52dk and nrf52840dk boards. To use OpenOCD with these a version
+  # build from source (master > 2018, August the 13rd) is required.
+  ifneq (,$(filter nordic_softdevice_ble,$(USEPKG)))
+    # openocd doesn't work (yet) with softdevice
+    $(error Cannot use OpenOCD with nordic_softdevice module)
+  endif
+  export DEBUG_ADAPTER ?= jlink
+  export OPENOCD_CONFIG := $(RIOTBOARD)/common/nrf52/dist/openocd.cfg
+  include $(RIOTMAKE)/tools/openocd.inc.mk
 endif
diff --git a/boards/common/nrf52/dist/openocd.cfg b/boards/common/nrf52/dist/openocd.cfg
new file mode 100644
index 0000000000..75659d4ab3
--- /dev/null
+++ b/boards/common/nrf52/dist/openocd.cfg
@@ -0,0 +1,3 @@
+transport select swd
+
+source [find target/nrf52.cfg]
-- 
GitLab