diff --git a/boards/common/nrf52/Makefile.include b/boards/common/nrf52/Makefile.include index 8e17d28b28b1..dfd99b916bb3 100644 --- a/boards/common/nrf52/Makefile.include +++ b/boards/common/nrf52/Makefile.include @@ -18,8 +18,12 @@ else PROGRAMMER ?= openocd endif -# 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. +# Setup OpenOCD for flashing. The nRF52 series is supported from OpenOCD v0.11 +# onwards. OPENOCD_DEBUG_ADAPTER ?= jlink OPENOCD_CONFIG = $(RIOTBOARD)/common/nrf52/dist/openocd.cfg + +# From Build Code Fxx and later, the nRF52 device is automatically locked after +# a power cycle and has to be recovered with a separate command after the +# initialization. Otherwise the Flash can not be accessed. +OPENOCD_POST_INIT_CMDS = -c 'nrf52_recover' diff --git a/dist/tools/openocd/openocd.sh b/dist/tools/openocd/openocd.sh index ebe73da4f558..5ea5d4072233 100755 --- a/dist/tools/openocd/openocd.sh +++ b/dist/tools/openocd/openocd.sh @@ -346,6 +346,7 @@ do_flash() { -c 'telnet_port 0' \ -c 'gdb_port 0' \ -c 'init' \ + ${OPENOCD_POST_INIT_CMDS} \ -c 'targets' \ ${OPENOCD_CMD_RESET_HALT} \ ${OPENOCD_PRE_FLASH_CMDS} \ diff --git a/makefiles/tools/openocd.inc.mk b/makefiles/tools/openocd.inc.mk index 4d01fb017477..f3b4599889d7 100644 --- a/makefiles/tools/openocd.inc.mk +++ b/makefiles/tools/openocd.inc.mk @@ -34,6 +34,12 @@ $(call target-export-variables,$(OPENOCD_TARGETS),OPENOCD_CORE) # Export OPENOCD_ADAPTER_INIT to required targets $(call target-export-variables,$(OPENOCD_TARGETS),OPENOCD_ADAPTER_INIT) +# Export OPENOCD_EXTRA_INIT to required targets +$(call target-export-variables,$(OPENOCD_TARGETS),OPENOCD_EXTRA_INIT) + +# Export OPENOCD_EXTRA_RESET_INIT to required targets +$(call target-export-variables,$(OPENOCD_TARGETS),OPENOCD_EXTRA_RESET_INIT) + # Export OPENOCD_RESET_USE_CONNECT_ASSERT_SRST to required targets $(call target-export-variables,$(OPENOCD_TARGETS),OPENOCD_RESET_USE_CONNECT_ASSERT_SRST) @@ -67,6 +73,11 @@ ifneq (,$(IMAGE_OFFSET)) $(call target-export-variables,$(OPENOCD_FLASH_TARGETS),IMAGE_OFFSET) endif +ifneq (,$(OPENOCD_POST_INIT_CMDS)) + # Export OPENOCD_POST_INIT_CMDS only to the flash/flash-only target + $(call target-export-variables,$(OPENOCD_FLASH_TARGETS),OPENOCD_POST_INIT_CMDS) +endif + ifneq (,$(OPENOCD_PRE_VERIFY_CMDS)) # Export OPENOCD_PRE_VERIFY_CMDS only to the flash/flash-only target $(call target-export-variables,$(OPENOCD_FLASH_TARGETS),OPENOCD_PRE_VERIFY_CMDS)