From bcfa665ebd095aa1c9a13219b421457c72b8a899 Mon Sep 17 00:00:00 2001 From: "Erdem U. Altinyurt" Date: Thu, 4 Sep 2014 05:59:07 +0300 Subject: Merged OpenOCD Flasher scripts + Added GDB functions to OpenOCD + Automatize tasks + bugfixes + readme fixed + others... --- Makefile.common | 116 ++++++++++++++++++++++++++++++--------------- Makefile.posix | 2 +- Makefile.template | 15 ++++-- README.md | 16 ++++--- gcc_nrf51_s110-sd6_xxaa.ld | 10 ---- gcc_nrf51_s110-sd6_xxab.ld | 10 ---- gcc_nrf51_s110-v6_xxaa.ld | 10 ++++ gcc_nrf51_s110-v6_xxab.ld | 10 ++++ 8 files changed, 119 insertions(+), 70 deletions(-) delete mode 100644 gcc_nrf51_s110-sd6_xxaa.ld delete mode 100644 gcc_nrf51_s110-sd6_xxab.ld create mode 100644 gcc_nrf51_s110-v6_xxaa.ld create mode 100644 gcc_nrf51_s110-v6_xxab.ld diff --git a/Makefile.common b/Makefile.common index 9618c57..42782f3 100644 --- a/Makefile.common +++ b/Makefile.common @@ -13,9 +13,9 @@ include $(TEMPLATE_PATH)/Makefile.posix endif ifeq ($(LINKER_SCRIPT),) - ifeq ($(USE_SOFTDEVICE), S110-sd6) - LINKER_SCRIPT = gcc_$(DEVICESERIES)_s110-sd6_$(DEVICE_VARIANT).ld - OUTPUT_FILENAME := $(OUTPUT_FILENAME)_s110-sd6_$(DEVICE_VARIANT) + ifeq ($(USE_SOFTDEVICE), S110-v6) + LINKER_SCRIPT = gcc_$(DEVICESERIES)_s110-v6_$(DEVICE_VARIANT).ld + OUTPUT_FILENAME := $(OUTPUT_FILENAME)_s110-v6_$(DEVICE_VARIANT) STARTADDRESS = 0x14000 else ifeq ($(USE_SOFTDEVICE), S110) @@ -39,17 +39,24 @@ else endif CPU := cortex-m0 - + +#Flasher selection +#FLASHER := JLink +FLASHER := OpenOCD + # Toolchain commands JLINK := JLinkExe -Device nrf51822 -speed 100 -if swd -OPENOCD := /usr/local/bin/openocd -f interface/stlink-v2.cfg -c"transport select hla_swd" -f target/nrf51.cfg +#You need to change openOCD clause depending your dongle. I have stlink-v2 and it's working. Jlink will work if you fetch latest trunk from git. +OPENOCD := /usr/local/bin/openocd -f interface/stlink-v2.cfg -c"transport select hla_swd" -f target/nrf51.cfg +#OPENOCD := /usr/local/bin/openocd -f interface/jlink.cfg -c"transport select swd ; adapter_khz 1000 ; adapter_nsrst_delay 10" -f /home/death/de/nrf51.cfg CC := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gcc" AS := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-as" AR := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ar" -r LD := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-ld" NM := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-nm" -OBJDUMP := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump" -OBJCOPY := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy" +OBJDUMP := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objdump" +OBJCOPY := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-objcopy" +GDB := "$(GNU_INSTALL_ROOT)/bin/$(GNU_PREFIX)-gdb" MK := mkdir RM := rm -rf @@ -97,7 +104,7 @@ INCLUDEPATHS += -I"$(SDK_PATH)/Include/serialization/application/transport" INCLUDEPATHS += -I"$(SDK_PATH)/Include/serialization/application/codecs/common" INCLUDEPATHS += -I"$(SDK_PATH)/Include/serialization/application/codecs/s110/serializers" -ifeq ($(USE_SOFTDEVICE), S110-sd6) +ifeq ($(USE_SOFTDEVICE), S110-v6) INCLUDEPATHS += -I"$(SDK_PATH)/Include/s110" else ifeq ($(USE_SOFTDEVICE), S110) @@ -185,10 +192,56 @@ all: clean debug clean: $(RM) $(OUTPUT_BINARY_DIRECTORY) + +# Create binary file from the softdevice 7 hex file +$(OUTPUT_BINARY_DIRECTORY)/softdevice.bin: $(BUILD_DIRECTORIES) + $(OBJCOPY) -I ihex -O binary $(SOFTDEVICE_HEX_PATH) $(OUTPUT_BINARY_DIRECTORY)/softdevice.bin + +# Create IUCR binary file from the softdevice 6 UICR hex file +$(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin: $(SOFTDEVICE_HEX_PATH) $(BUILD_DIRECTORIES) + $(OBJCOPY) -Iihex -Obinary --only-section .sec3 $< $@ + +# Create binary file from the softdevice 6 hex file +$(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin: $(SOFTDEVICE_HEX_PATH) $(BUILD_DIRECTORIES) + $(OBJCOPY) -Iihex -Obinary --remove-section .sec3 $< $@ + +#OpenOCD Flasher Scripts +ifeq ($(FLASHER), OpenOCD) +flash: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin + $(OPENOCD) -c "program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin $(STARTADDRESS) verify" + +ifeq ($(USE_SOFTDEVICE), S110-v6) +flash_softdevice: $(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin $(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin + $(OPENOCD) -c "init ; reset halt ; nrf51 mass_erase ; sleep 500 ; flash write_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin 0x10001000 ; verify_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin 0x10001000 ; flash write_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin 0x0 ; verify_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin 0; shutdown" +else +flash_softdevice: $(OUTPUT_BINARY_DIRECTORY)/softdevice.bin + $(OPENOCD) -c "init ; reset halt ; nrf51 mass_erase ; sleep 500 ; flash write_image $(OUTPUT_BINARY_DIRECTORY)/softdevice.bin 0x0 ; verify_image $(OUTPUT_BINARY_DIRECTORY)/softdevice.bin 0x0 ; mww 0x4001e504 1 ; mww 0x10001000 $(STARTADDRESS) ; mww 0x4001e504 0 ; shutdown" +endif + +erase_all: + $(OPENOCD) -c "init ; reset halt ; nrf51 mass_erase ; shutdown" + +pinreset: + $(OPENOCD) -c "init ; reset halt ; mww 0x4001e504 2 ; mww 0x40000544 1 ; reset ; shutdown" + +gdbserver: + $(OPENOCD) + +GDB_COMMAND_SCRIPT=$(OUTPUT_BINARY_DIRECTORY)/gdbinit +$(GDB_COMMAND_SCRIPT): debug + echo -e -n "target remote localhost:3333 \n\ + monitor reset halt \n\ + file $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out \n\ + load \n\ + b main \n\ + b app_error_handler \n\ + monitor reset \n\ + continue" > $(GDB_COMMAND_SCRIPT) - +#JLink Flasher Scripts +else $(OUTPUT_BINARY_DIRECTORY)/erase_all.jlink : $(BUILD_DIRECTORIES) - echo " \ + echo " r \n\ h \n\ w4 0x4001e504,2 # enable erase all \n\ @@ -200,14 +253,10 @@ r \n\ q \n\ " \ > $(OUTPUT_BINARY_DIRECTORY)/erase_all.jlink - + erase_all: $(OUTPUT_BINARY_DIRECTORY)/erase_all.jlink $(JLINK) -CommanderScript $(OUTPUT_BINARY_DIRECTORY)/erase_all.jlink; [ "$$?" -eq 1 ] -$(OUTPUT_BINARY_DIRECTORY)/softdevice.bin: $(BUILD_DIRECTORIES) - $(OBJCOPY) -I ihex -O binary $(SOFTDEVICE_HEX_PATH) $(OUTPUT_BINARY_DIRECTORY)/softdevice.bin - endif - $(OUTPUT_BINARY_DIRECTORY)/flash_softdevice.jlink: $(BUILD_DIRECTORIES) echo " \n\ r \n\ @@ -273,15 +322,15 @@ $(OUTPUT_BINARY_DIRECTORY)/pinreset.jlink: $(BUILD_DIRECTORIES) pin-reset: $(OUTPUT_BINARY_DIRECTORY)/pinreset.jlink $(JLINK) -CommanderScript $(OUTPUT_BINARY_DIRECTORY)/pinreset.jlink; [ "$$?" -eq 1 ] - + START_GDB_SERVER_SCRIPT=$(OUTPUT_BINARY_DIRECTORY)/start_gdbserver.sh $(START_GDB_SERVER_SCRIPT): $(BUILD_DIRECTORIES) - echo "JLinkGDBServer -if swd -device nrf51822 -LocalHostOnly" > $(START_GDB_SERVER_SCRIPT) - + echo "JLinkGDBServer -if swd -device nrf51822 -LocalHostOnly" > $(START_GDB_SERVER_SCRIPT) + gdbserver: $(START_GDB_SERVER_SCRIPT) - /bin/sh $(START_GDB_SERVER_SCRIPT) - -GDB_COMMAND_SCRIPT=$(OUTPUT_BINARY_DIRECTORY)/gdbinit + /bin/sh $(START_GDB_SERVER_SCRIPT) + +GDB_COMMAND_SCRIPT=$(OUTPUT_BINARY_DIRECTORY)/gdbinit $(GDB_COMMAND_SCRIPT): debug echo " \n\ target remote localhost:2331 \n\ @@ -292,22 +341,15 @@ $(GDB_COMMAND_SCRIPT): debug b main \n\ b app_error_handler \n\ monitor reset \n\ - continue" >> $(GDB_COMMAND_SCRIPT) + continue" > $(GDB_COMMAND_SCRIPT) + +#end of FLASHER selection +endif gdb: $(GDB_COMMAND_SCRIPT) debug - arm-none-eabi-gdb -x $(GDB_COMMAND_SCRIPT) - -serial: - screen /dev/cu.usbmodem1411 38400 + $(GDB) -x $(GDB_COMMAND_SCRIPT) -openocd_flash: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin - $(OPENOCD) $(OPENOCD_ARGS) -c "program $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin verify $(STARTADDRESS)" - -openocd_flash_softdevice6: $(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin $(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin - $(OPENOCD) -c"init; reset halt; nrf51 mass_erase; flash write_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin 0x10001000; flash write_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin 0; verify_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin 0x10001000; verify_image $(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin 0; reset; shutdown" - -$(OUTPUT_BINARY_DIRECTORY)/softdevice_uicr.bin: $(SOFTDEVICE_HEX_PATH) $(BUILD_DIRECTORIES) - $(OBJCOPY) -Iihex -Obinary --only-section .sec3 $< $@ - -$(OUTPUT_BINARY_DIRECTORY)/softdevice_main.bin: $(SOFTDEVICE_HEX_PATH) $(BUILD_DIRECTORIES) - $(OBJCOPY) -Iihex -Obinary --remove-section .sec3 $< $@ +serial: + screen /dev/ttyUSB1cu.usbmodem1411 38400 + + diff --git a/Makefile.posix b/Makefile.posix index a690373..b9e0b44 100644 --- a/Makefile.posix +++ b/Makefile.posix @@ -1,4 +1,4 @@ -GNU_INSTALL_ROOT := $(HOME)Developer/prjs/embeded/gcc-arm-none-eabi-4_8-2014q2 +GNU_INSTALL_ROOT := /opt/gcc-arm-none-eabi-4_8-2014q2 GNU_VERSION := 4.8.4 GNU_PREFIX := arm-none-eabi diff --git a/Makefile.template b/Makefile.template index 15a1713..134dd16 100644 --- a/Makefile.template +++ b/Makefile.template @@ -6,16 +6,21 @@ DEVICE_VARIANT := xxaa #DEVICE_VARIANT := xxab USE_SOFTDEVICE := S110 +#USE_SOFTDEVICE := S110-v6 #USE_SOFTDEVICE := S120 -#USE_SOFTDEVICE := S110-sd6 -#USE_SOFTDEVICE := S120-sd6 HOME = ~ + +#Not that SDK 5.1.0 does NOT work with SoftDevice 7 +#SDK_PATH = $(HOME)/nRF_SDK_v5.1.0.36092/Nordic/nrf51822 SDK_PATH = $(HOME)/nRF51_SDK_v6.0.0.43681/Nordic/nrf51822 -SOFTDEVICE_HEX_PATH = $(HOME)/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_softdevice.hex -#SOFTDEVICE_HEX_PATH = $(HOME)/s110_nrf51822_6_0_0/s110_nrf51822_6.0.0_softdevice.hex -BUILD_SCRIPTS_PATH = $(HOME)/F2FS/nrf51822-macosx-build-scripts +BUILD_SCRIPTS_PATH = $(HOME)/nrf51822-posix-build-scripts TEMPLATE_PATH = $(BUILD_SCRIPTS_PATH) +ifeq ($(USE_SOFTDEVICE), S110-v6) + SOFTDEVICE_HEX_PATH = /run/media/death/F2FS/s110_nrf51822_6_0_0/s110_nrf51822_6.0.0_softdevice.hex +else + SOFTDEVICE_HEX_PATH = /run/media/death/F2FS/s110_nrf51822_7_0_0/s110_nrf51822_7.0.0_softdevice.hex +endif # CFLAGS += -DBLE_STACK_SUPPORT_REQD # debug: CFLAGS+=-DENABLE_DEBUG_LOG_SUPPORT diff --git a/README.md b/README.md index 4a97d9f..8d3cfd3 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,5 @@ -nrf51822 build script under MacOSX -================================= +nrf51822 build script under Linux and MacOSX +============================================ Usage: 1. make erase_all @@ -12,17 +12,17 @@ Usage: 5. make pin-reset -6. make serial # will start screen as your terminal +6. make serial # will start screen as your terminal. You need to adjust for your terminal program 7. make gdbserver # will start gdbserver (-LocalHostOnly) -8. make gdb # will start gdb and set breakpoint at main then start +8. make gdb # will start gdb and set breakpoint at main and app_error_handler then start Steps: ------ -0. download and extract nRF51-SDK 6.0.0 and s110 softdevice 7.0.0 +0. download and extract nRF51-SDK 6.0.0 (or 5.1.0) and s110 softdevice 7.0.0 (or 6.0.0) -1. install arm-none-eabi-gcc for MacOSX: +1. install arm-none-eabi-gcc for Linux or MacOSX: from: https://launchpad.net/gcc-arm-embedded @@ -42,4 +42,6 @@ Steps: 9. make flash -note[2]: Currently JLink (for MacOSX) v4.90b will not require disabling CDC, highly recommend use that new version, that will allow use GDB and virtual com port simutaneously. OpenOCD users could use openocd_flash and openocd_flash_softdevice6 options after adjusting $OPENOCD command at Makefile.common file. +note[1]: OpenOCD supported (0.9-trunk advised) if you set FLASHER as OpenOCD at Makefile.common file. You also need to adjust $OPENOCD command for your OpenOCD compatible dongle at same file. You can also flash "softdevice 6.0" with OpenOCD flasher. PS: This patch increases OpenOCD speed by 10 ( http://openocd.zylin.com/#/c/2204/ ) + +note[2]: Currently JLink (for MacOSX) v4.90b will not require disabling CDC, highly recommend use that new version, that will allow use GDB and virtual com port simutaneously. diff --git a/gcc_nrf51_s110-sd6_xxaa.ld b/gcc_nrf51_s110-sd6_xxaa.ld deleted file mode 100644 index ac2bf9e..0000000 --- a/gcc_nrf51_s110-sd6_xxaa.ld +++ /dev/null @@ -1,10 +0,0 @@ -/* Linker script to configure memory regions. */ -SEARCH_DIR(.) -GROUP(-lgcc -lc -lnosys) - -MEMORY -{ - FLASH (rx) : ORIGIN = 0x14000, LENGTH = 0x2C000 /* 80 kB is taken by S110, 176 kB available for application. */ - RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */ -} -INCLUDE "gcc_nrf51_common.ld" diff --git a/gcc_nrf51_s110-sd6_xxab.ld b/gcc_nrf51_s110-sd6_xxab.ld deleted file mode 100644 index e59c48d..0000000 --- a/gcc_nrf51_s110-sd6_xxab.ld +++ /dev/null @@ -1,10 +0,0 @@ -/* Linker script to configure memory regions. */ -SEARCH_DIR(.) -GROUP(-lgcc -lc -lnosys) - -MEMORY -{ - FLASH (rx) : ORIGIN = 0x14000, LENGTH = 0xC000 /* 80 kB is taken by S110, 48 kB available for application. */ - RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */ -} -INCLUDE "gcc_nrf51_common.ld" diff --git a/gcc_nrf51_s110-v6_xxaa.ld b/gcc_nrf51_s110-v6_xxaa.ld new file mode 100644 index 0000000..ac2bf9e --- /dev/null +++ b/gcc_nrf51_s110-v6_xxaa.ld @@ -0,0 +1,10 @@ +/* Linker script to configure memory regions. */ +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x14000, LENGTH = 0x2C000 /* 80 kB is taken by S110, 176 kB available for application. */ + RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */ +} +INCLUDE "gcc_nrf51_common.ld" diff --git a/gcc_nrf51_s110-v6_xxab.ld b/gcc_nrf51_s110-v6_xxab.ld new file mode 100644 index 0000000..e59c48d --- /dev/null +++ b/gcc_nrf51_s110-v6_xxab.ld @@ -0,0 +1,10 @@ +/* Linker script to configure memory regions. */ +SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x14000, LENGTH = 0xC000 /* 80 kB is taken by S110, 48 kB available for application. */ + RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000 /* 8 kB, 8 kB is taken by S110. */ +} +INCLUDE "gcc_nrf51_common.ld" -- cgit v1.2.3