From c798dce98042e7e43cddcedada0aebacb79973d2 Mon Sep 17 00:00:00 2001
From: Prithvi Raj Narendra <prithvirajnarendra@gmail.com>
Date: Fri, 28 Jul 2017 01:42:29 +0530
Subject: [PATCH 1/2] Adds support to choose between JLINK and BMP as
 programmers

The targets of flash, flash_softdevice and erase work based
on what the variable DEBUGGER is set as: JLINK or BMP.
---
 .../bluey_1.0/s132/armgcc/Makefile            | 36 +++++++++++++++----
 1 file changed, 29 insertions(+), 7 deletions(-)

diff --git a/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile b/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile
index a454072..cfbe371 100755
--- a/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile
+++ b/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile
@@ -1,6 +1,10 @@
 PROJECT_NAME     := ble_app_beacon_pca10040_s132
 TARGETS          := nrf52832_xxaa
 OUTPUT_DIRECTORY := _build
+DEBUGGER         := JLINK
+#Install ARM GCC compiler
+#https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa
+GDB              := arm-none-eabi-gdb
 
 SDK_ROOT := ../../../../../../..
 PROJ_DIR := ../../..
@@ -236,15 +240,33 @@ $(foreach target, $(TARGETS), $(call define_target, $(target)))
 
 # Flash the program
 flash: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
-	@echo Flashing: $<
-	nrfjprog --program $< -f nrf52 --sectorerase
-	nrfjprog --reset -f nrf52
+	@echo Flashing: $<; \
+	if [ "$(DEBUGGER)" = "JLINK" ]; then \
+		~/Desktop/nrfjprog/nrfjprog --program $< -f nrf52 --sectorerase; \
+		~/Desktop/nrfjprog/nrfjprog --reset -f nrf52; \
+	elif [ "$(DEBUGGER)" = "BMP" ]; then \
+		$(GDB) -q -ex 'target extended-remote /dev/ttyBmpGdb' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'compare-sections' -ex 'detach' -ex 'quit' $<; \
+	else\
+		echo "Use the DEBUGGER variable to specify the debugger to be used for uploading"; \
+	fi
 
 # Flash softdevice
 flash_softdevice:
-	@echo Flashing: s132_nrf52_3.0.0_softdevice.hex
-	nrfjprog --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex -f nrf52 --sectorerase
-	nrfjprog --reset -f nrf52
+	@echo Flashing: s132_nrf52_3.0.0_softdevice.hex; \
+	if [ "$(DEBUGGER)" = "JLINK" ]; then\
+		~/Desktop/nrfjprog/nrfjprog --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex -f nrf52 --sectorerase; \
+		~/Desktop/nrfjprog/nrfjprog --reset -f nrf52; \
+	elif [ "$(DEBUGGER)" = "BMP" ]; then \
+		$(GDB) -q -ex 'target extended-remote /dev/ttyBmpGdb' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'compare-sections' -ex 'detach' -ex 'quit' $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex; \
+	else \
+		echo "Use the DEBUGGER variable to specify the debugger to be used for uploading"; \
+	fi
 
 erase:
-	nrfjprog --eraseall -f nrf52
+	@if [ "$(DEBUGGER)" = "JLINK" ]; then\
+		~/Desktop/nrfjprog/nrfjprog --eraseall -f nrf52; \
+	elif [ "$(DEBUGGER)" = "BMP" ]; then \
+		$(GDB) -q -ex 'target extended-remote /dev/ttyBmpGdb' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'mon erase_mass' -ex 'detach' -ex 'quit'; \
+	else\
+		echo "Use the DEBUGGER variable to specify the debugger to be used for the erase all operation"; \
+	fi

From dcd5ddf4fffa75f97ecc4ade3c41da374bcdd25d Mon Sep 17 00:00:00 2001
From: Prithvi Raj Narendra <prithvirajnarendra@gmail.com>
Date: Fri, 18 Aug 2017 20:26:30 +0530
Subject: [PATCH 2/2] Adds Makefile variable for BMP port and nrfjprog path

This commit removes the hardcoding of the BMP port to /dev/ttyBmpGdb
so that people using other OS apart from Linux can set it appropriately.
---
 .../bluey_1.0/s132/armgcc/Makefile            | 34 +++++++++++++------
 1 file changed, 24 insertions(+), 10 deletions(-)

diff --git a/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile b/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile
index cfbe371..4496527 100755
--- a/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile
+++ b/code/bluey-beacon/bluey-beacon-nrf52/bluey_1.0/s132/armgcc/Makefile
@@ -1,10 +1,23 @@
 PROJECT_NAME     := ble_app_beacon_pca10040_s132
 TARGETS          := nrf52832_xxaa
 OUTPUT_DIRECTORY := _build
-DEBUGGER         := JLINK
+
+#Either JLINK or BMP
+DEBUGGER         := BMP
+
+ifeq ($(DEBUGGER),JLINK)
+### JLink related stuff ###
+NRFJPROG         := nrfjprog
+endif
+
+ifeq ($(DEBUGGER),BMP)
+### BMP related stuff ###
+# Use relevant port like COM5 in Windows environment
+BMP_PORT         := /dev/ttyBmpGdb
 #Install ARM GCC compiler
-#https://launchpad.net/~team-gcc-arm-embedded/+archive/ubuntu/ppa
+#https://launchpad.net/gcc-arm-embedded/+download
 GDB              := arm-none-eabi-gdb
+endif
 
 SDK_ROOT := ../../../../../../..
 PROJ_DIR := ../../..
@@ -242,10 +255,10 @@ $(foreach target, $(TARGETS), $(call define_target, $(target)))
 flash: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
 	@echo Flashing: $<; \
 	if [ "$(DEBUGGER)" = "JLINK" ]; then \
-		~/Desktop/nrfjprog/nrfjprog --program $< -f nrf52 --sectorerase; \
-		~/Desktop/nrfjprog/nrfjprog --reset -f nrf52; \
+		$(NRFJPROG) --program $< -f nrf52 --sectorerase; \
+		$(NRFJPROG) --reset -f nrf52; \
 	elif [ "$(DEBUGGER)" = "BMP" ]; then \
-		$(GDB) -q -ex 'target extended-remote /dev/ttyBmpGdb' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'compare-sections' -ex 'detach' -ex 'quit' $<; \
+		$(GDB) -q -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'compare-sections' -ex 'detach' -ex 'quit' $<; \
 	else\
 		echo "Use the DEBUGGER variable to specify the debugger to be used for uploading"; \
 	fi
@@ -254,19 +267,20 @@ flash: $(OUTPUT_DIRECTORY)/nrf52832_xxaa.hex
 flash_softdevice:
 	@echo Flashing: s132_nrf52_3.0.0_softdevice.hex; \
 	if [ "$(DEBUGGER)" = "JLINK" ]; then\
-		~/Desktop/nrfjprog/nrfjprog --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex -f nrf52 --sectorerase; \
-		~/Desktop/nrfjprog/nrfjprog --reset -f nrf52; \
+		$(NRFJPROG) --program $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex -f nrf52 --sectorerase; \
+		$(NRFJPROG) --reset -f nrf52; \
 	elif [ "$(DEBUGGER)" = "BMP" ]; then \
-		$(GDB) -q -ex 'target extended-remote /dev/ttyBmpGdb' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'compare-sections' -ex 'detach' -ex 'quit' $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex; \
+		$(GDB) -q -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'load' -ex 'compare-sections' -ex 'detach' -ex 'quit' $(SDK_ROOT)/components/softdevice/s132/hex/s132_nrf52_3.0.0_softdevice.hex; \
 	else \
 		echo "Use the DEBUGGER variable to specify the debugger to be used for uploading"; \
 	fi
 
 erase:
 	@if [ "$(DEBUGGER)" = "JLINK" ]; then\
-		~/Desktop/nrfjprog/nrfjprog --eraseall -f nrf52; \
+		$(NRFJPROG) --eraseall -f nrf52; \
 	elif [ "$(DEBUGGER)" = "BMP" ]; then \
-		$(GDB) -q -ex 'target extended-remote /dev/ttyBmpGdb' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'mon erase_mass' -ex 'detach' -ex 'quit'; \
+		$(GDB) -q -ex 'target extended-remote $(BMP_PORT)' -ex 'monitor swdp_scan' -ex 'attach 1' -ex 'mon erase_mass' -ex 'detach' -ex 'quit'; \
 	else\
 		echo "Use the DEBUGGER variable to specify the debugger to be used for the erase all operation"; \
 	fi
+