├── .gitignore ├── LICENSE ├── README.md ├── examples └── pca10001 │ ├── blinky_example │ └── pure-gcc │ │ └── Makefile │ └── s110 │ ├── ble_app_hrs │ └── pure-gcc │ │ └── Makefile │ └── ble_app_proximity │ └── pure-gcc │ └── Makefile └── template ├── Makefile ├── Makefile.posix ├── Makefile.windows ├── gcc_nrf51_blank.ld ├── gcc_nrf51_common.ld ├── gcc_nrf51_s110.ld ├── gcc_nrf51_s120.ld ├── gcc_nrf51_s210.ld ├── gcc_nrf51_s310.ld └── startup_nrf51.s /.gitignore: -------------------------------------------------------------------------------- 1 | *.swp 2 | *~ 3 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2013, hlnd 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without modification, 5 | are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, this 11 | list of conditions and the following disclaimer in the documentation and/or 12 | other materials provided with the distribution. 13 | 14 | * Neither the name of the {organization} nor the names of its 15 | contributors may be used to endorse or promote products derived from 16 | this software without specific prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 19 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 20 | WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR 22 | ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 23 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 24 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 25 | ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 27 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | nrf51-pure-gcc-setup 2 | ==================== 3 | 4 | A simple and cross-platform GCC setup for nRF51 development. I've developed 5 | it on Linux, but should also work fine on OS X and on Windows. Beware that 6 | neither of those are regularly used by me, though. Feel free to submit a 7 | pull request if you find something that doesn't work. 8 | 9 | This was started (long) before the official SDK got GCC support, but I've kept 10 | maintaining it, since I don't really like the official Makefiles... 11 | 12 | The currently supported SDK version is 6.0.0. Support for some other versions 13 | are available as branches. 14 | 15 | Usage 16 | ----- 17 | Make a pure-gcc subfolder in your project folder (i.e. alongside the 18 | arm/gcc/iar folders from the SDK) and copy an example Makefile from the 19 | examples/ folder into it. Make sure that the SDK_PATH and TEMPLATE_PATH points 20 | towards your nRF51 SDK installation and the template/ subfolder of your clone 21 | of this repository respectively. 22 | 23 | Project options 24 | --------------- 25 | All source files, if they are in the application folder (../ from the 26 | Makefile) or somewhere in the SDK should be possible to include directly, 27 | without a path. If you want to add some other path to the search paths, add it 28 | to LIBRARY_PATHS (header files) or SOURCE_PATHS. 29 | 30 | Make sure that the USE_SOFTDEVICE variable is set to whichever softdevice is 31 | currently programmed on your board, lowercase. The value is directly used in 32 | paths, so if it's uppercase, you'll most likely end up with files not being 33 | found, at least on OS X/Linux. Currently S110, S120, S210 and S310 should be 34 | supported, although only S110 have been well-tested. 35 | 36 | If you use the boards.h file, make sure that the BOARD define is set 37 | to the board you're currently using. 38 | 39 | If you have multiple J-Links connected to your system, you should 40 | set the SEGGER_SERIAL variable to the serial number of your J-Link, so that 41 | the programming Just Works (tm). It seems Segger on Linux isn't capable of 42 | giving you a selection of J-Links, as on Windows. 43 | 44 | If you want to use the GDB functionality with multiple J-Links, you should 45 | make sure that all projects have a unique GDB port number defined in their 46 | project Makefile. 47 | 48 | You can override most of the defines from the other Makefiles by setting them 49 | in your project file, since most of them use ?=. 50 | 51 | Targets 52 | ------- 53 | Most of the targets provided should be self explanatory, but some may use some 54 | extra explanation: 55 | 56 | ### erase-all: 57 | Does an erase all of a chip. 58 | 59 | ### recover: 60 | Provides equal functionality to that of nrfjprog / nRFgo Studio on Windows. 61 | 62 | ### flash-softdevice SOFTDEVICE=$(PATH_TO_SOFTDEVICE_WITHOUT_SPACES) 63 | Can be used to flash a softdevice to a chip. The path to the softdevice hex 64 | needs to be without spaces, due to Make limitations. 65 | 66 | ### startdebug: 67 | Starts a J-Link GDB Server in a separate terminal window, and then GDB 68 | also in a separate window. If you change the code, you can then make directly 69 | from gdb, and do load to run the new code. 70 | 71 | 72 | -------------------------------------------------------------------------------- /examples/pca10001/blinky_example/pure-gcc/Makefile: -------------------------------------------------------------------------------- 1 | # List all source files the application uses. 2 | APPLICATION_SRCS = $(notdir $(wildcard ../*.c)) nrf_delay.c 3 | # Use shell to find name of root folder. Possible but horrible to do in make. 4 | PROJECT_NAME = $(shell basename "$(realpath ../)") 5 | 6 | DEVICE = NRF51 7 | BOARD = BOARD_PCA10001 8 | #SEGGER_SERIAL = 9 | 10 | #USE_SOFTDEVICE = s110 11 | 12 | SDK_PATH = $(HOME)/Projects/nrf51/nrf51822/ 13 | TEMPLATE_PATH = $(HOME)/Projects/nrf51-pure-gcc-setup/template/ 14 | 15 | CFLAGS = -Os 16 | 17 | GDB_PORT_NUMBER = 2331 18 | 19 | include $(TEMPLATE_PATH)Makefile 20 | -------------------------------------------------------------------------------- /examples/pca10001/s110/ble_app_hrs/pure-gcc/Makefile: -------------------------------------------------------------------------------- 1 | # List all source files the application uses. 2 | APPLICATION_SRCS = $(notdir $(wildcard ../*.c)) 3 | APPLICATION_SRCS += app_gpiote.c 4 | APPLICATION_SRCS += app_button.c 5 | APPLICATION_SRCS += app_timer.c 6 | APPLICATION_SRCS += app_trace.c 7 | APPLICATION_SRCS += ble_advdata.c 8 | APPLICATION_SRCS += ble_conn_params.c 9 | APPLICATION_SRCS += pstorage.c 10 | APPLICATION_SRCS += device_manager_peripheral.c 11 | APPLICATION_SRCS += ble_bas.c 12 | APPLICATION_SRCS += ble_dis.c 13 | APPLICATION_SRCS += ble_hrs.c 14 | APPLICATION_SRCS += ble_srv_common.c 15 | APPLICATION_SRCS += crc16.c 16 | APPLICATION_SRCS += softdevice_handler.c 17 | 18 | PROJECT_NAME = $(shell basename "$(realpath ../)") 19 | 20 | DEVICE = NRF51 21 | BOARD = BOARD_PCA10001 22 | #SEGGER_SERIAL = 23 | 24 | USE_SOFTDEVICE = s110 25 | 26 | SDK_PATH = $(HOME)/Projects/nrf51-sdk-6.0.0/nrf51822/ 27 | TEMPLATE_PATH = $(HOME)/Projects/nrf51-pure-gcc-setup/template/ 28 | 29 | CFLAGS = -Os 30 | 31 | GDB_PORT_NUMBER = 2331 32 | 33 | include $(TEMPLATE_PATH)Makefile 34 | -------------------------------------------------------------------------------- /examples/pca10001/s110/ble_app_proximity/pure-gcc/Makefile: -------------------------------------------------------------------------------- 1 | # List all source files the application uses. 2 | APPLICATION_SRCS = $(notdir $(wildcard ../*.c)) 3 | APPLICATION_SRCS += app_gpiote.c 4 | APPLICATION_SRCS += app_button.c 5 | APPLICATION_SRCS += app_timer.c 6 | APPLICATION_SRCS += ble_advdata.c 7 | APPLICATION_SRCS += ble_conn_params.c 8 | APPLICATION_SRCS += pstorage.c 9 | APPLICATION_SRCS += device_manager_peripheral.c 10 | APPLICATION_SRCS += ble_bas.c 11 | APPLICATION_SRCS += ble_ias.c 12 | APPLICATION_SRCS += ble_ias_c.c 13 | APPLICATION_SRCS += ble_lls.c 14 | APPLICATION_SRCS += ble_tps.c 15 | APPLICATION_SRCS += ble_srv_common.c 16 | APPLICATION_SRCS += crc16.c 17 | APPLICATION_SRCS += softdevice_handler.c 18 | APPLICATION_SRCS += ble_debug_assert_handler.c 19 | APPLICATION_SRCS += ble_error_log.c 20 | 21 | PROJECT_NAME = ble_app_proximity 22 | 23 | DEVICE = NRF51 24 | BOARD = BOARD_PCA10001 25 | #SEGGER_SERIAL = 26 | 27 | USE_SOFTDEVICE = s110 28 | 29 | SDK_PATH = ../../../../../ 30 | TEMPLATE_PATH = c:/temp/nrf51-pure-gcc-setup/template/ 31 | 32 | CFLAGS = -Os 33 | 34 | GDB_PORT_NUMBER = 2331 35 | 36 | include $(TEMPLATE_PATH)Makefile 37 | -------------------------------------------------------------------------------- /template/Makefile: -------------------------------------------------------------------------------- 1 | TOOLCHAIN_PREFIX ?= arm-none-eabi 2 | 3 | AS = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-as 4 | CC = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gcc 5 | LD = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gcc 6 | OBJCOPY = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-objcopy 7 | OBJDUMP = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-objdump 8 | SIZE = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-size 9 | GDB = $(TOOLCHAIN_PATH)$(TOOLCHAIN_PREFIX)-gdb 10 | 11 | START_CODE ?= startup_nrf51.s 12 | SYSTEM_FILE ?= system_nrf51.c 13 | 14 | SDK_INCLUDE_PATH += $(SDK_PATH)Include/ 15 | SDK_SOURCE_PATH += $(SDK_PATH)Source/ 16 | CMSIS_INCLUDE_PATH += $(SDK_PATH)Include/gcc 17 | 18 | LIBRARY_PATHS += ../ 19 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH) 20 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)sdk/ 21 | SOURCE_PATHS += ../ $(SDK_SOURCE_PATH) $(TEMPLATE_PATH) $(wildcard $(SDK_SOURCE_PATH)*/) 22 | 23 | ifeq ($(USE_SOFTDEVICE), s110) 24 | USE_BLE = 1 25 | endif 26 | 27 | ifeq ($(USE_SOFTDEVICE), s120) 28 | USE_BLE = 1 29 | endif 30 | 31 | ifeq ($(USE_SOFTDEVICE), s210) 32 | USE_ANT = 1 33 | endif 34 | 35 | ifeq ($(USE_SOFTDEVICE), s310) 36 | USE_BLE = 1 37 | USE_ANT = 1 38 | endif 39 | 40 | ifdef USE_BLE 41 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)ble/ 42 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)ble/ble_services/ 43 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)ble/device_manager/ 44 | SOURCE_PATHS += $(SDK_SOURCE_PATH)ble/ble_services/ 45 | SOURCE_PATHS += $(SDK_SOURCE_PATH)ble/device_manager/ 46 | CFLAGS += -DBLE_STACK_SUPPORT_REQD 47 | endif 48 | 49 | ifdef USE_ANT 50 | CFLAGS += -DANT_STACK_SUPPORT_REQD 51 | endif 52 | 53 | ifdef USE_SOFTDEVICE 54 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)$(USE_SOFTDEVICE) 55 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)app_common/ 56 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)sd_common/ 57 | else 58 | USE_SOFTDEVICE = blank 59 | endif 60 | 61 | LINKER_SCRIPT ?= gcc_nrf51_$(USE_SOFTDEVICE).ld 62 | OUTPUT_NAME ?= $(addsuffix _$(USE_SOFTDEVICE), $(PROJECT_NAME)) 63 | 64 | ifdef USE_EXT_SENSORS 65 | LIBRARY_PATHS += $(SDK_INCLUDE_PATH)ext_sensors/ 66 | SOURCE_PATHS += $(wildcard $(SDK_SOURCE_PATH)ext_sensors/*/) 67 | endif 68 | 69 | LIBRARY_INCLUDES = $(addprefix -I,$(LIBRARY_PATHS)) 70 | CMSIS_INCLUDE = $(addprefix -I,$(CMSIS_INCLUDE_PATH)) 71 | 72 | VPATH = $(SOURCE_PATHS) 73 | 74 | OUTPUT_PATH = _build/ 75 | 76 | CPUFLAGS = -mthumb -mcpu=cortex-m0 -march=armv6-m 77 | CFLAGS += -std=gnu99 -c $(CPUFLAGS) -Wall -D$(DEVICE) -D$(BOARD) $(CMSIS_INCLUDE) $(LIBRARY_INCLUDES) -MD 78 | LDFLAGS += $(CPUFLAGS) -L $(TEMPLATE_PATH) -T $(LINKER_SCRIPT) -Wl,-Map=$(OUTPUT_PATH)$(OUTPUT_NAME).Map 79 | 80 | HEX = $(OUTPUT_PATH)$(OUTPUT_NAME).hex 81 | ELF = $(OUTPUT_PATH)$(OUTPUT_NAME).elf 82 | BIN = $(OUTPUT_PATH)$(OUTPUT_NAME).bin 83 | 84 | SRCS = $(SYSTEM_FILE) $(notdir $(APPLICATION_SRCS)) 85 | OBJS = $(addprefix $(OUTPUT_PATH), $(SRCS:.c=.o)) $(addprefix $(OUTPUT_PATH),$(APPLICATION_LIBS)) 86 | DEPS = $(addprefix $(OUTPUT_PATH), $(SRCS:.c=.d)) 87 | SRCS_AS = $(START_CODE) 88 | OBJS_AS = $(addprefix $(OUTPUT_PATH), $(SRCS_AS:.s=.os)) 89 | 90 | JLINK_OPTIONS = -device nrf51822 -if swd -speed 1000 91 | 92 | all: $(OBJS) $(OBJS_AS) $(HEX) 93 | 94 | rebuild: clean all 95 | 96 | ifeq ($(OS),Windows_NT) 97 | include $(TEMPLATE_PATH)Makefile.windows 98 | else 99 | include $(TEMPLATE_PATH)Makefile.posix 100 | endif 101 | 102 | $(HEX): $(OBJS) $(OBJS_AS) 103 | $(LD) $(LDFLAGS) $(OBJS_AS) $(OBJS) -o $(ELF) 104 | $(OBJCOPY) -Oihex $(ELF) $(HEX) 105 | $(OBJCOPY) -Obinary $(ELF) $(BIN) 106 | $(SIZE) $(ELF) 107 | 108 | size: $(ELF) 109 | $(SIZE) $(ELF) 110 | 111 | $(OUTPUT_PATH)%.o: %.c 112 | $(MAKE_BUILD_FOLDER) 113 | $(CC) $(LDFLAGS) $(CFLAGS) $< -o $@ 114 | 115 | $(OUTPUT_PATH)%.os: %.s 116 | $(MAKE_BUILD_FOLDER) 117 | $(AS) $< -o $@ 118 | 119 | -include $(DEPS) 120 | 121 | .PHONY: all clean rebuild size 122 | -------------------------------------------------------------------------------- /template/Makefile.posix: -------------------------------------------------------------------------------- 1 | # Set toolchain path if arm-none-eabi- binaries are not in user path 2 | # TOOLCHAIN_PATH ?= 3 | TERMINAL ?= gnome-terminal -e 4 | 5 | FLASH_START_ADDRESS = $(shell $(OBJDUMP) -h $(ELF) -j .text | grep .text | awk '{print $$4}') 6 | 7 | ifdef SEGGER_SERIAL 8 | JLINKEXE_OPTION = -SelectEmuBySn $(SEGGER_SERIAL) 9 | JLINKGDBSERVER_OPTION = -select USB=$(SEGGER_SERIAL) 10 | endif 11 | 12 | MAKE_BUILD_FOLDER = mkdir -p $(OUTPUT_PATH) 13 | 14 | JLINK = -JLinkExe $(JLINK_OPTIONS) $(JLINKEXE_OPTION) 15 | JLINKGDBSERVER = JLinkGDBServer $(JLINK_OPTIONS) $(JLINKGDBSERVER_OPTION) 16 | 17 | SOFTDEVICE_OUTPUT = $(OUTPUT_PATH)$(notdir $(SOFTDEVICE)) 18 | 19 | clean: 20 | rm -rf $(OUTPUT_PATH) 21 | rm -f *.jlink 22 | rm -f JLink.log 23 | rm -f .gdbinit 24 | 25 | flash: all flash.jlink 26 | $(JLINK) flash.jlink 27 | 28 | flash.jlink: 29 | printf "r\nloadbin $(BIN) $(FLASH_START_ADDRESS)\nr\ng\nexit\n" > flash.jlink 30 | 31 | flash-softdevice: erase-all flash-softdevice.jlink 32 | ifndef SOFTDEVICE 33 | $(error "You need to set the SOFTDEVICE command-line parameter to a path (without spaces) to the softdevice hex-file") 34 | endif 35 | 36 | $(OBJCOPY) -Iihex -Obinary $(SOFTDEVICE) $(SOFTDEVICE_OUTPUT:.hex=.bin) 37 | $(JLINK) flash-softdevice.jlink 38 | 39 | flash-softdevice.jlink: 40 | # Write to NVMC to enable write. Write mainpart, write UICR. Assumes device is erased. 41 | printf "w4 4001e504 1\nloadbin \"$(SOFTDEVICE_OUTPUT:.hex=.bin)\" 0\nr\ng\nexit\n" > flash-softdevice.jlink 42 | 43 | recover: recover.jlink erase-all.jlink pin-reset.jlink 44 | $(JLINK) recover.jlink 45 | $(JLINK) erase-all.jlink 46 | $(JLINK) pin-reset.jlink 47 | 48 | recover.jlink: 49 | printf "si 0\nt0\nsleep 1\ntck1\nsleep 1\nt1\nsleep 2\nt0\nsleep 2\nt1\nsleep 2\nt0\nsleep 2\nt1\nsleep 2\nt0\nsleep 2\nt1\nsleep 2\nt0\nsleep 2\nt1\nsleep 2\nt0\nsleep 2\nt1\nsleep 2\nt0\nsleep 2\nt1\nsleep 2\ntck0\nsleep 100\nsi 1\nr\nexit\n" > recover.jlink 50 | 51 | pin-reset.jlink: 52 | printf "w4 40000544 1\nr\nexit\n" > pin-reset.jlink 53 | 54 | pin-reset: pin-reset.jlink 55 | $(JLINK) pin-reset.jlink 56 | 57 | reset: reset.jlink 58 | $(JLINK) reset.jlink 59 | 60 | reset.jlink: 61 | printf "r\ng\nexit\n" > reset.jlink 62 | 63 | erase-all: erase-all.jlink 64 | $(JLINK) erase-all.jlink 65 | 66 | erase-all.jlink: 67 | # Write to NVMC to enable erase, do erase all, wait for completion. reset 68 | printf "w4 4001e504 2\nw4 4001e50c 1\nsleep 100\nr\nexit\n" > erase-all.jlink 69 | 70 | startdebug: debug-gdbinit 71 | $(TERMINAL) "$(JLINKGDBSERVER) -port $(GDB_PORT_NUMBER)" 72 | sleep 1 73 | $(TERMINAL) "$(GDB) $(ELF)" 74 | 75 | debug-gdbinit: 76 | printf "target remote localhost:$(GDB_PORT_NUMBER)\nbreak main\n" > .gdbinit 77 | 78 | .PHONY: flash flash-softdevice erase-all startdebug 79 | -------------------------------------------------------------------------------- /template/Makefile.windows: -------------------------------------------------------------------------------- 1 | TOOLCHAIN_PATH = "c:\Program Files (x86)\GNU Tools ARM Embedded\4.8 2013q4\bin\" 2 | JLINK_PATH = "C:\Program Files (x86)\SEGGER\JLinkARM_V480\" 3 | 4 | MAKE_BUILD_FOLDER = if not exist $(OUTPUT_PATH:/=\\) mkdir $(OUTPUT_PATH:/=\\) 5 | 6 | # Make GDB server die after one run. 7 | JLINKGDBSERVER_OPTION = -s 8 | 9 | ifdef SEGGER_SERIAL 10 | NRFJPROG_OPTIONS = --snr $(SEGGER_SERIAL) 11 | JLINKGDBSERVER_OPTION += -select USB=$(SEGGER_SERIAL) 12 | endif 13 | 14 | NRFJPROG = nrfjprog $(NRFJPROG_OPTIONS) 15 | 16 | clean: 17 | if exist .\$(OUTPUT_PATH:/=\\) rmdir /Q /S $(OUTPUT_PATH:/=) 18 | if exist *.jlink del /q *.jlink 19 | if exist JLink.log del /q JLink.log 20 | if exist .gdbinit del /q .gdbinit 21 | 22 | $(OUTPUT_PATH): 23 | if not exist .\$(OUTPUT_PATH:/=\\) md $(OUTPUT_PATH) 24 | 25 | flash: 26 | $(NRFJPROG) --program $(HEX) -r 27 | 28 | flash-softdevice: 29 | ifndef SOFTDEVICE 30 | $(error "You need to set the SOFTDEVICE command-line parameter to a path (without spaces) to the softdevice hex-file") 31 | endif 32 | $(NRFJPROG) -e --programs "$(SOFTDEVICE)" 33 | 34 | recover: 35 | $(NRFJPROG) --recover 36 | 37 | pin-reset: 38 | $(NRFJPROG) --pinreset 39 | 40 | reset: 41 | $(NRFJPROG) --reset 42 | 43 | startdebug: debug-gdbinit 44 | start /D $(JLINK_PATH) JLinkGDBServer $(JLINKGDBSERVER_OPTION) $(JLINK_OPTIONS) -port $(GDB_PORT_NUMBER) 45 | timeout /t 1 46 | $(GDB) $(ELF) -x gdbinit 47 | 48 | debug-gdbinit: 49 | @(echo target remote localhost:$(GDB_PORT_NUMBER) & echo break main) > gdbinit 50 | 51 | .PHONY: clean flash startdebug debug-gdbinit 52 | -------------------------------------------------------------------------------- /template/gcc_nrf51_blank.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | MEMORY 3 | { 4 | FLASH (rx) : ORIGIN = 0x0, LENGTH = 0x40000 /* 256k */ 5 | RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x4000 /* 16k */ 6 | } 7 | INCLUDE "gcc_nrf51_common.ld" 8 | -------------------------------------------------------------------------------- /template/gcc_nrf51_common.ld: -------------------------------------------------------------------------------- 1 | /* Library configurations */ 2 | GROUP(libgcc.a libc.a libm.a libnosys.a) 3 | 4 | /* Linker script to place sections and symbol values. Should be used together 5 | * with other linker script that defines memory regions FLASH and RAM. 6 | * It references following symbols, which must be defined in code: 7 | * Reset_Handler : Entry of reset handler 8 | * 9 | * It defines following symbols, which code can use without definition: 10 | * __exidx_start 11 | * __exidx_end 12 | * __etext 13 | * __data_start__ 14 | * __preinit_array_start 15 | * __preinit_array_end 16 | * __init_array_start 17 | * __init_array_end 18 | * __fini_array_start 19 | * __fini_array_end 20 | * __data_end__ 21 | * __bss_start__ 22 | * __bss_end__ 23 | * __end__ 24 | * end 25 | * __HeapLimit 26 | * __StackLimit 27 | * __StackTop 28 | * __stack 29 | */ 30 | ENTRY(Reset_Handler) 31 | 32 | SECTIONS 33 | { 34 | .text : 35 | { 36 | KEEP(*(.isr_vector)) 37 | *(.text*) 38 | 39 | KEEP(*(.init)) 40 | KEEP(*(.fini)) 41 | 42 | /* .ctors */ 43 | *crtbegin.o(.ctors) 44 | *crtbegin?.o(.ctors) 45 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) 46 | *(SORT(.ctors.*)) 47 | *(.ctors) 48 | 49 | /* .dtors */ 50 | *crtbegin.o(.dtors) 51 | *crtbegin?.o(.dtors) 52 | *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) 53 | *(SORT(.dtors.*)) 54 | *(.dtors) 55 | 56 | *(.rodata*) 57 | 58 | KEEP(*(.eh_frame*)) 59 | } > FLASH 60 | 61 | .ARM.extab : 62 | { 63 | *(.ARM.extab* .gnu.linkonce.armextab.*) 64 | } > FLASH 65 | 66 | __exidx_start = .; 67 | .ARM.exidx : 68 | { 69 | *(.ARM.exidx* .gnu.linkonce.armexidx.*) 70 | } > FLASH 71 | __exidx_end = .; 72 | 73 | __etext = .; 74 | 75 | .data : AT (__etext) 76 | { 77 | __data_start__ = .; 78 | *(vtable) 79 | *(.data*) 80 | 81 | . = ALIGN(4); 82 | /* preinit data */ 83 | PROVIDE (__preinit_array_start = .); 84 | *(.preinit_array) 85 | PROVIDE (__preinit_array_end = .); 86 | 87 | . = ALIGN(4); 88 | /* init data */ 89 | PROVIDE (__init_array_start = .); 90 | *(SORT(.init_array.*)) 91 | *(.init_array) 92 | PROVIDE (__init_array_end = .); 93 | 94 | 95 | . = ALIGN(4); 96 | /* finit data */ 97 | PROVIDE (__fini_array_start = .); 98 | *(SORT(.fini_array.*)) 99 | *(.fini_array) 100 | PROVIDE (__fini_array_end = .); 101 | 102 | . = ALIGN(4); 103 | /* All data end */ 104 | __data_end__ = .; 105 | 106 | } > RAM 107 | 108 | .bss : 109 | { 110 | __bss_start__ = .; 111 | *(.bss*) 112 | *(COMMON) 113 | __bss_end__ = .; 114 | } > RAM 115 | 116 | .heap : 117 | { 118 | __end__ = .; 119 | end = __end__; 120 | *(.heap*) 121 | __HeapLimit = .; 122 | } > RAM 123 | 124 | /* .stack_dummy section doesn't contains any symbols. It is only 125 | * used for linker to calculate size of stack sections, and assign 126 | * values to stack symbols later */ 127 | .stack_dummy : 128 | { 129 | *(.stack) 130 | } > RAM 131 | 132 | /* Set stack top to end of RAM, and stack limit move down by 133 | * size of stack_dummy section */ 134 | __StackTop = ORIGIN(RAM) + LENGTH(RAM); 135 | __StackLimit = __StackTop - SIZEOF(.stack_dummy); 136 | PROVIDE(__stack = __StackTop); 137 | 138 | /* Check if data + heap + stack exceeds RAM limit */ 139 | ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") 140 | } 141 | -------------------------------------------------------------------------------- /template/gcc_nrf51_s110.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | MEMORY 3 | { 4 | FLASH (rx) : ORIGIN = 0x0 + 88K, LENGTH = 256K - 88K /* 88 kB is taken by S110, rest for app. */ 5 | RAM (rwx) : ORIGIN = 0x20000000 + 8K, LENGTH = 16K - 8K /* 8 kB is taken by S110, 8 kB for app. */ 6 | } 7 | INCLUDE "gcc_nrf51_common.ld" 8 | -------------------------------------------------------------------------------- /template/gcc_nrf51_s120.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | MEMORY 3 | { 4 | FLASH (rx) : ORIGIN = 0x18000, LENGTH = 0x27000 /* 96 kB is taken by S120, 160 kB for app. */ 5 | RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0x1800 /* 10 kB is taken by S120, 6 kB for app. */ 6 | } 7 | INCLUDE "gcc_nrf51_common.ld" 8 | -------------------------------------------------------------------------------- /template/gcc_nrf51_s210.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | MEMORY 3 | { 4 | FLASH (rx) : ORIGIN = 0xC000, LENGTH = 0x34000 /* 48 kB is taken by S210, 80 kB for app. */ 5 | RAM (rwx) : ORIGIN = 0x20000900, LENGTH = 0x3700 /* 2.25 kB is taken by S210, 13.75 kB for app. */ 6 | } 7 | INCLUDE "gcc_nrf51_common.ld" 8 | -------------------------------------------------------------------------------- /template/gcc_nrf51_s310.ld: -------------------------------------------------------------------------------- 1 | /* Linker script to configure memory regions. */ 2 | MEMORY 3 | { 4 | FLASH (rx) : ORIGIN = 0x20000, LENGTH = 0x20000 /* 128 kB is taken by S310, 128 kB for app. */ 5 | RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0x1800 /* 10 kB is taken by S310, 6 kB for app. */ 6 | } 7 | INCLUDE "gcc_nrf51_common.ld" 8 | -------------------------------------------------------------------------------- /template/startup_nrf51.s: -------------------------------------------------------------------------------- 1 | /* File: startup_ARMCM0.S 2 | * Purpose: startup file for Cortex-M0 devices. Should use with 3 | * GCC for ARM Embedded Processors 4 | * Version: V1.2 5 | * Date: 15 Nov 2011 6 | * 7 | * Copyright (c) 2011, ARM Limited 8 | * All rights reserved. 9 | * 10 | * Redistribution and use in source and binary forms, with or without 11 | * modification, are permitted provided that the following conditions are met: 12 | * Redistributions of source code must retain the above copyright 13 | notice, this list of conditions and the following disclaimer. 14 | * Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | * Neither the name of the ARM Limited nor the 18 | names of its contributors may be used to endorse or promote products 19 | derived from this software without specific prior written permission. 20 | * 21 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 22 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 23 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 24 | * DISCLAIMED. IN NO EVENT SHALL ARM LIMITED BE LIABLE FOR ANY 25 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 26 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 27 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 28 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 29 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 | */ 32 | .syntax unified 33 | .arch armv6-m 34 | 35 | .section .stack 36 | .align 3 37 | #ifdef __STACK_SIZE 38 | .equ Stack_Size, __STACK_SIZE 39 | #else 40 | .equ Stack_Size, 0xc00 41 | #endif 42 | .globl __StackTop 43 | .globl __StackLimit 44 | __StackLimit: 45 | .space Stack_Size 46 | .size __StackLimit, . - __StackLimit 47 | __StackTop: 48 | .size __StackTop, . - __StackTop 49 | 50 | .section .heap 51 | .align 3 52 | #ifdef __HEAP_SIZE 53 | .equ Heap_Size, __HEAP_SIZE 54 | #else 55 | .equ Heap_Size, 0x100 56 | #endif 57 | .globl __HeapBase 58 | .globl __HeapLimit 59 | __HeapBase: 60 | .space Heap_Size 61 | .size __HeapBase, . - __HeapBase 62 | __HeapLimit: 63 | .size __HeapLimit, . - __HeapLimit 64 | 65 | .section .isr_vector 66 | .align 2 67 | .globl __Vectors 68 | __Vectors: 69 | .long __StackTop /* Top of Stack */ 70 | .long Reset_Handler /* Reset Handler */ 71 | .long NMI_Handler /* NMI Handler */ 72 | .long HardFault_Handler /* Hard Fault Handler */ 73 | .long 0 /* Reserved */ 74 | .long 0 /* Reserved */ 75 | .long 0 /* Reserved */ 76 | .long 0 /* Reserved */ 77 | .long 0 /* Reserved */ 78 | .long 0 /* Reserved */ 79 | .long 0 /* Reserved */ 80 | .long SVC_Handler /* SVCall Handler */ 81 | .long 0 /* Reserved */ 82 | .long 0 /* Reserved */ 83 | .long PendSV_Handler /* PendSV Handler */ 84 | .long SysTick_Handler /* SysTick Handler */ 85 | 86 | /* External interrupts */ 87 | .long POWER_CLOCK_IRQHandler /* POWER_CLOCK */ 88 | .long RADIO_IRQHandler /* RADIO */ 89 | .long UART0_IRQHandler /* UART0 */ 90 | .long SPI0_TWI0_IRQHandler /* SPI0_TWI0 */ 91 | .long SPI1_TWI1_IRQHandler /* SPI1_TWI1 */ 92 | .long 0 /* Reserved */ 93 | .long GPIOTE_IRQHandler /* GPIOTE */ 94 | .long ADC_IRQHandler /* ADC */ 95 | .long TIMER0_IRQHandler /* TIMER0 */ 96 | .long TIMER1_IRQHandler /* TIMER1 */ 97 | .long TIMER2_IRQHandler /* TIMER2 */ 98 | .long RTC0_IRQHandler /* RTC0 */ 99 | .long TEMP_IRQHandler /* TEMP */ 100 | .long RNG_IRQHandler /* RNG */ 101 | .long ECB_IRQHandler /* ECB */ 102 | .long CCM_AAR_IRQHandler /* CCM_AAR */ 103 | .long WDT_IRQHandler /* WDT */ 104 | .long RTC1_IRQHandler /* RTC1 */ 105 | .long QDEC_IRQHandler /* QDEC */ 106 | .long 0 /* Reserved */ 107 | .long SWI0_IRQHandler /* SWI0 */ 108 | .long SWI1_IRQHandler /* SWI1 */ 109 | .long SWI2_IRQHandler /* SWI2 */ 110 | .long SWI3_IRQHandler /* SWI3 */ 111 | .long SWI4_IRQHandler /* SWI4 */ 112 | .long SWI5_IRQHandler /* SWI5 */ 113 | .long 0 /* Reserved */ 114 | .long 0 /* Reserved */ 115 | .long 0 /* Reserved */ 116 | .long 0 /* Reserved */ 117 | .long 0 /* Reserved */ 118 | .long 0 /* Reserved */ 119 | 120 | .size __Vectors, . - __Vectors 121 | 122 | .text 123 | .thumb 124 | .thumb_func 125 | .align 2 126 | .globl Reset_Handler 127 | .type Reset_Handler, %function 128 | Reset_Handler: 129 | .equ NRF_POWER_RAMON_ADDRESS, 0x40000524 130 | .equ NRF_POWER_RAMON_RAM1ON_ONMODE_Msk, 0x3 131 | ldr r0, =NRF_POWER_RAMON_ADDRESS 132 | ldr r2, [r0] 133 | movs r1, #NRF_POWER_RAMON_RAM1ON_ONMODE_Msk 134 | orrs r2, r1 135 | str r2, [r0] 136 | 137 | /* Loop to copy data from read only memory to RAM. The ranges 138 | * of copy from/to are specified by following symbols evaluated in 139 | * linker script. 140 | * __etext: End of code section, i.e., begin of data sections to copy from. 141 | * __data_start__/__data_end__: RAM address range that data should be 142 | * copied to. Both must be aligned to 4 bytes boundary. */ 143 | ldr r1, =__etext 144 | ldr r2, =__data_start__ 145 | ldr r3, =__data_end__ 146 | 147 | subs r3, r2 148 | ble .flash_to_ram_loop_end 149 | 150 | movs r4, 0 151 | .flash_to_ram_loop: 152 | ldr r0, [r1,r4] 153 | str r0, [r2,r4] 154 | adds r4, 4 155 | cmp r4, r3 156 | blt .flash_to_ram_loop 157 | .flash_to_ram_loop_end: 158 | ldr r0, =SystemInit 159 | blx r0 160 | ldr r0, =_start 161 | bx r0 162 | .pool 163 | .size Reset_Handler, . - Reset_Handler 164 | 165 | /* Macro to define default handlers. Default handler 166 | * will be weak symbol and just dead loops. They can be 167 | * overwritten by other handlers */ 168 | .macro def_default_handler handler_name 169 | .align 1 170 | .thumb_func 171 | .weak \handler_name 172 | .type \handler_name, %function 173 | \handler_name : 174 | b . 175 | .size \handler_name, . - \handler_name 176 | .endm 177 | 178 | def_default_handler NMI_Handler 179 | def_default_handler HardFault_Handler 180 | def_default_handler SVC_Handler 181 | def_default_handler PendSV_Handler 182 | def_default_handler SysTick_Handler 183 | def_default_handler Default_Handler 184 | def_default_handler POWER_CLOCK_IRQHandler 185 | def_default_handler RADIO_IRQHandler 186 | def_default_handler UART0_IRQHandler 187 | def_default_handler SPI0_TWI0_IRQHandler 188 | def_default_handler SPI1_TWI1_IRQHandler 189 | def_default_handler GPIOTE_IRQHandler 190 | def_default_handler ADC_IRQHandler 191 | def_default_handler TIMER0_IRQHandler 192 | def_default_handler TIMER1_IRQHandler 193 | def_default_handler TIMER2_IRQHandler 194 | def_default_handler RTC0_IRQHandler 195 | def_default_handler TEMP_IRQHandler 196 | def_default_handler RNG_IRQHandler 197 | def_default_handler ECB_IRQHandler 198 | def_default_handler CCM_AAR_IRQHandler 199 | def_default_handler WDT_IRQHandler 200 | def_default_handler RTC1_IRQHandler 201 | def_default_handler QDEC_IRQHandler 202 | def_default_handler SWI0_IRQHandler 203 | def_default_handler SWI1_IRQHandler 204 | def_default_handler SWI2_IRQHandler 205 | def_default_handler SWI3_IRQHandler 206 | def_default_handler SWI4_IRQHandler 207 | def_default_handler SWI5_IRQHandler 208 | 209 | .weak DEF_IRQHandler 210 | .set DEF_IRQHandler, Default_Handler 211 | 212 | .end 213 | --------------------------------------------------------------------------------