From d7be547bc2bcf16918007d86ad06f5ca9e943f95 Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Sat, 24 Dec 2016 19:47:37 +0300 Subject: [PATCH 1/8] feat(Makefile.posix): Add openocd --- make/Makefile.posix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/make/Makefile.posix b/make/Makefile.posix index 8771a797..adeb6d34 100644 --- a/make/Makefile.posix +++ b/make/Makefile.posix @@ -21,6 +21,8 @@ JLINK = -JLinkExe $(JLINK_OPTIONS) $(JLINKEXE_OPTION) JLINKGDBSERVER = JLinkGDBServer $(JLINK_OPTIONS) $(JLINKGDBSERVER_OPTION) JLINKRTTCLIENT = JLinkRTTClient $(JLINK_OPTIONS) $(JLINKRTTCLIENT_OPTION) +OPENOCD = openocd -f interface/stlink-v2.cfg -f target/nrf51.cfg # FIXME nrf51 + SOFTDEVICE_OUTPUT = $(OUTPUT_PATH)$(notdir $(SOFTDEVICE)) clean: clean-bootloader From 369d9fa0450b62b23e7f458b6f52c819a5e12eee Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Sat, 24 Dec 2016 19:48:00 +0300 Subject: [PATCH 2/8] feat(Makefile.posix): Impl {flash,reset,erase-all}.stlinkv2 --- make/Makefile.posix | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/make/Makefile.posix b/make/Makefile.posix index adeb6d34..b66bf0f3 100644 --- a/make/Makefile.posix +++ b/make/Makefile.posix @@ -65,6 +65,9 @@ ifdef ID endif printf "loadfile $(HEX) \nr\ng\nexit\n" >> $(OUTPUT_PATH)flash.jlink +flash.stlinkv2: + $(MAKE_BUILD_FOLDER) + $(OPENOCD) -c 'program $(HEX) verify reset exit' test-softdevice: test-softdevice.jlink ifndef SOFTDEVICE @@ -141,6 +144,10 @@ reset.jlink: $(MAKE_BUILD_FOLDER) printf "r\ng\nexit\n" > $(OUTPUT_PATH)reset.jlink +reset.stlinkv2: + $(MAKE_BUILD_FOLDER) + $(OPENOCD) -c init -c 'reset' -c shutdown + erase-all: erase-all.jlink $(MAKE_BUILD_FOLDER) $(JLINK) $(OUTPUT_PATH)erase-all.jlink @@ -150,6 +157,10 @@ erase-all.jlink: $(MAKE_BUILD_FOLDER) printf "w4 4001e504 2\nw4 4001e50c 1\nsleep 100\nr\nexit\n" > $(OUTPUT_PATH)erase-all.jlink +erase-all.stlinkv2: + $(MAKE_BUILD_FOLDER) + $(OPENOCD) -c init -c 'reset halt' -c 'nrf51 mass_erase' -c 'reset' -c shutdown + from-scratch: all flash.jlink flash-softdevice $(MAKE_BUILD_FOLDER) $(JLINK) $(OUTPUT_PATH)flash.jlink From 4fe9da8bc5ca14b1ade9d27ce48be95155384a1b Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Fri, 10 Feb 2017 15:15:16 +0300 Subject: [PATCH 3/8] feat(Makefile.posix): Impl flash-softdevice.stlinkv2 --- make/Makefile.posix | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/make/Makefile.posix b/make/Makefile.posix index b66bf0f3..14acb274 100644 --- a/make/Makefile.posix +++ b/make/Makefile.posix @@ -105,6 +105,10 @@ flash-softdevice.jlink: $(MAKE_BUILD_FOLDER) printf "w4 4001e504 1\nloadbin \"$(SOFTDEVICE_OUTPUT:.hex=.bin)\" 0\nr\ng\nexit\n" > $(OUTPUT_PATH)flash-softdevice.jlink +flash-softdevice.stlinkv2: + $(MAKE_BUILD_FOLDER) + $(OPENOCD) -c 'program $(SOFTDEVICE) verify reset exit' + flash-bootloader: bootloader flash-bootloader.jlink test-softdevice $(JLINK) $(OUTPUT_PATH)flash-bootloader.jlink From f1107eb3df4abec3ced12f44f7387b169d9c281f Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Fri, 10 Feb 2017 15:54:56 +0300 Subject: [PATCH 4/8] feat(Makefile.posix): Impl {startdebug,debug-gdbinit}.stlinkv2 --- make/Makefile.posix | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/make/Makefile.posix b/make/Makefile.posix index 14acb274..14c16d2f 100644 --- a/make/Makefile.posix +++ b/make/Makefile.posix @@ -169,17 +169,26 @@ from-scratch: all flash.jlink flash-softdevice $(MAKE_BUILD_FOLDER) $(JLINK) $(OUTPUT_PATH)flash.jlink -startdebug: debug-gdbinit +startdebug: startdebug.jlink + +startdebug.jlink: debug-gdbinit.jlink $(TERMINAL) "$(JLINKGDBSERVER) -port $(GDB_PORT_NUMBER)" sleep 1 $(TERMINAL) "$(GDB) $(ELF)" +startdebug.stlinkv2: debug-gdbinit.stlinkv2 + $(GDB) $(ELF) + startrtt: $(TERMINAL) "JLinkExe -device nrf51822 -if swd -speed 1000 -AutoConnect 1" sleep 1 $(TERMINAL) "$(JLINKRTTCLIENT)" -debug-gdbinit: +debug-gdbinit.jlink: printf "target remote localhost:$(GDB_PORT_NUMBER)\nload\nmon reset\nbreak main\n" > .gdbinit +debug-gdbinit.stlinkv2: + printf "target remote | $(OPENOCD) -c 'gdb_port pipe; log_output openocd.log'" > .gdbinit + + .PHONY: flash flash-softdevice erase-all startdebug test-softdevice flash.jlink From e0e21c5a0086e5a85e58efd71b1e4611995e10a2 Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Fri, 10 Feb 2017 16:45:35 +0300 Subject: [PATCH 5/8] feat(Makefile.posix): Impl unitargets: {flash,reset,erase-all,startdebug} Specifying `PROGRAMMER` in a project Makefile is used to change actual commands being invoked. Defaults to jlink. Specific commands like `flash.stlinkv2` remain available. --- make/Makefile.posix | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/make/Makefile.posix b/make/Makefile.posix index 14c16d2f..a778fad5 100644 --- a/make/Makefile.posix +++ b/make/Makefile.posix @@ -34,12 +34,17 @@ clean: clean-bootloader clean-bootloader: rm -rf $(BASE_DIR)/dfu/_build -ifndef ENABLE_WIRELESS_DFU -flash: all flash.jlink test-softdevice - $(JLINK) $(OUTPUT_PATH)flash.jlink +ifeq ($(PROGRAMMER),stlinkv2) + # TODO: DFU support, test-softdevice + flash: all flash.stlinkv2 else -flash: all flash.jlink test-softdevice flash-bootloader - $(JLINK) $(OUTPUT_PATH)flash.jlink + ifndef ENABLE_WIRELESS_DFU + flash: all flash.jlink test-softdevice + $(JLINK) $(OUTPUT_PATH)flash.jlink + else + flash: all flash.jlink test-softdevice flash-bootloader + $(JLINK) $(OUTPUT_PATH)flash.jlink + endif endif @@ -140,9 +145,13 @@ pin-reset: pin-reset.jlink $(MAKE_BUILD_FOLDER) $(JLINK) $(OUTPUT_PATH)pin-reset.jlink +ifeq ($(PROGRAMMER),stlinkv2) +reset: reset.stlinkv2 +else reset: reset.jlink $(MAKE_BUILD_FOLDER) $(JLINK) $(OUTPUT_PATH)reset.jlink +endif reset.jlink: $(MAKE_BUILD_FOLDER) @@ -152,9 +161,13 @@ reset.stlinkv2: $(MAKE_BUILD_FOLDER) $(OPENOCD) -c init -c 'reset' -c shutdown +ifeq ($(PROGRAMMER),stlinkv2) +erase-all: erase-all.stlinkv2 +else erase-all: erase-all.jlink $(MAKE_BUILD_FOLDER) $(JLINK) $(OUTPUT_PATH)erase-all.jlink +endif erase-all.jlink: # Write to NVMC to enable erase, do erase all, wait for completion. reset @@ -169,7 +182,11 @@ from-scratch: all flash.jlink flash-softdevice $(MAKE_BUILD_FOLDER) $(JLINK) $(OUTPUT_PATH)flash.jlink +ifeq ($(PROGRAMMER),stlinkv2) +startdebug: startdebug.stlinkv2 +else startdebug: startdebug.jlink +endif startdebug.jlink: debug-gdbinit.jlink $(TERMINAL) "$(JLINKGDBSERVER) -port $(GDB_PORT_NUMBER)" From db6b60b89ca44cab804ae34bb28133b1cabc42ab Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Fri, 10 Feb 2017 17:05:24 +0300 Subject: [PATCH 6/8] feat(Makefile.posix): Impl unitarget flash-softdevice --- make/Makefile.posix | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/make/Makefile.posix b/make/Makefile.posix index a778fad5..c9d03653 100644 --- a/make/Makefile.posix +++ b/make/Makefile.posix @@ -97,6 +97,9 @@ test-softdevice.jlink: $(MAKE_BUILD_FOLDER) printf "r\nsavebin $(SOFTDEVICE_TEST_FLASH) $(SOFTDEVICE_TEST_ADDR) $(SOFTDEVICE_TEST_LEN)\nexit\n" > $(OUTPUT_PATH)test-softdevice.jlink +ifeq ($(PROGRAMMER),stlinkv2) +flash-softdevice: erase-all flash-softdevice.stlinkv2 +else flash-softdevice: erase-all flash-softdevice.jlink ifndef SOFTDEVICE $(error "You need to set the SOFTDEVICE command-line parameter to a path (without spaces) to the softdevice hex-file") @@ -104,6 +107,7 @@ endif $(MAKE_BUILD_FOLDER) $(OBJCOPY) -Iihex -Obinary $(SOFTDEVICE) $(SOFTDEVICE_OUTPUT:.hex=.bin) $(JLINK) $(OUTPUT_PATH)flash-softdevice.jlink +endif flash-softdevice.jlink: # Write to NVMC to enable write. Write mainpart, write UICR. Assumes device is erased. @@ -111,6 +115,9 @@ flash-softdevice.jlink: printf "w4 4001e504 1\nloadbin \"$(SOFTDEVICE_OUTPUT:.hex=.bin)\" 0\nr\ng\nexit\n" > $(OUTPUT_PATH)flash-softdevice.jlink flash-softdevice.stlinkv2: +ifndef SOFTDEVICE + $(error "You need to set the SOFTDEVICE command-line parameter to a path (without spaces) to the softdevice hex-file") +endif $(MAKE_BUILD_FOLDER) $(OPENOCD) -c 'program $(SOFTDEVICE) verify reset exit' From 91932ac341f05f282e60b70386d581db89c5db3e Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Fri, 10 Feb 2017 17:16:24 +0300 Subject: [PATCH 7/8] refactor(Makefile.posix): DRY $SOFTDEVICE definedness check --- make/Makefile.posix | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/make/Makefile.posix b/make/Makefile.posix index c9d03653..bfe58335 100644 --- a/make/Makefile.posix +++ b/make/Makefile.posix @@ -74,11 +74,17 @@ flash.stlinkv2: $(MAKE_BUILD_FOLDER) $(OPENOCD) -c 'program $(HEX) verify reset exit' -test-softdevice: test-softdevice.jlink ifndef SOFTDEVICE +define softdevice-defined= $(error "You need to set the SOFTDEVICE command-line parameter to a path (without spaces) to the softdevice hex-file") +endef +else +define softdevice-defined= +endef endif +test-softdevice: test-softdevice.jlink $(softdevice-defined) + ifneq ($(SOFTDEVICE_MODEL),blank) $(MAKE_BUILD_FOLDER) @touch $(SOFTDEVICE_TEST_FLASH) @@ -98,12 +104,9 @@ test-softdevice.jlink: printf "r\nsavebin $(SOFTDEVICE_TEST_FLASH) $(SOFTDEVICE_TEST_ADDR) $(SOFTDEVICE_TEST_LEN)\nexit\n" > $(OUTPUT_PATH)test-softdevice.jlink ifeq ($(PROGRAMMER),stlinkv2) -flash-softdevice: erase-all flash-softdevice.stlinkv2 +flash-softdevice: erase-all $(softdevice-defined) flash-softdevice.stlinkv2 else -flash-softdevice: erase-all flash-softdevice.jlink -ifndef SOFTDEVICE - $(error "You need to set the SOFTDEVICE command-line parameter to a path (without spaces) to the softdevice hex-file") -endif +flash-softdevice: erase-all $(softdevice-defined) flash-softdevice.jlink $(MAKE_BUILD_FOLDER) $(OBJCOPY) -Iihex -Obinary $(SOFTDEVICE) $(SOFTDEVICE_OUTPUT:.hex=.bin) $(JLINK) $(OUTPUT_PATH)flash-softdevice.jlink @@ -115,9 +118,6 @@ flash-softdevice.jlink: printf "w4 4001e504 1\nloadbin \"$(SOFTDEVICE_OUTPUT:.hex=.bin)\" 0\nr\ng\nexit\n" > $(OUTPUT_PATH)flash-softdevice.jlink flash-softdevice.stlinkv2: -ifndef SOFTDEVICE - $(error "You need to set the SOFTDEVICE command-line parameter to a path (without spaces) to the softdevice hex-file") -endif $(MAKE_BUILD_FOLDER) $(OPENOCD) -c 'program $(SOFTDEVICE) verify reset exit' From 383f9973aa3b94d36001d284d15d2adf72328004 Mon Sep 17 00:00:00 2001 From: Dmitriy Volkov Date: Fri, 10 Feb 2017 17:30:56 +0300 Subject: [PATCH 8/8] docs(README): Add a section on STLink --- README.md | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 82d1df04..e45dfdbd 100644 --- a/README.md +++ b/README.md @@ -99,7 +99,7 @@ Program a nRF51822 To flash an application to a nRF51822 BLE chip, there is some setup you must do. -1. Install the [`arm-none-eabi-gcc`](https://launchpad.net/gcc-arm-embedded) compiler. +First, install the [`arm-none-eabi-gcc`](https://launchpad.net/gcc-arm-embedded) compiler. On Ubuntu: @@ -107,13 +107,15 @@ you must do. sudo apt-get update sudo apt-get install gcc-arm-embedded -2. Install the JLink [software](https://www.segger.com/jlink-software.html) +### With JLink + +1. Install the JLink [software](https://www.segger.com/jlink-software.html) for your platform. You want the "Software and documentation pack". -3. Acquire a [JLink JTAG programmer](https://www.segger.com/jlink-general-info.html). +2. Acquire a [JLink JTAG programmer](https://www.segger.com/jlink-general-info.html). The "EDU" edition works fine. -4. Program an app! With the JLink box attached to the target board: +3. Program an app! With the JLink box attached to the target board: make flash @@ -122,12 +124,33 @@ The "EDU" edition works fine. make erase-all - See the [make](https://github.com/lab11/nrf5x-base/tree/master/make) folder - for a complete list of commands. +### With STLink/v2 + +1. Install [openocd](http://openocd.org/), an On-Chip Debugging / In-System Programming tool. + + On Ubuntu: + + sudo apt-get install openocd + +2. Get a [STLink/v2 programmer](http://www.st.com/en/development-tools/st-link-v2.html). +There are also popular unofficial versions described [here](http://wiki.sgmk-ssam.ch/wiki/STM32_dev#ST-Link_V2_Programmer) in more detail. + +3. Add `PROGRAMMER = stlinkv2` to your Makefile. + +4. Program an app! With the STLink attached to the target board: + + make flash-softdevice # only necessary the first time, after erase of if you change the softdevice + make flash + + will write the app and softdevice to the nRF51822. You can erase + a chip with: + + make erase-all + + +See the [make](https://github.com/lab11/nrf5x-base/tree/master/make) folder for a complete list of commands. - Most of our boards use a [TagConnect header](http://www.tag-connect.com/TC2030-IDC-NL) - instead of the way-too-large ARM JTAG header. We use [our own](https://github.com/lab11/jtag-tagconnect) - adapter, but Segger also makes [one](https://www.segger.com/jlink-6-pin-needle-adapter.html). +Most of our boards use a [TagConnect header](http://www.tag-connect.com/TC2030-IDC-NL) instead of the way-too-large ARM JTAG header. We use [our own](https://github.com/lab11/jtag-tagconnect) adapter, but Segger also makes [one](https://www.segger.com/jlink-6-pin-needle-adapter.html). Git Submodules