diff options
author | sprhawk <hongbo@yang.me> | 2014-08-29 01:48:19 +0800 |
---|---|---|
committer | sprhawk <hongbo@yang.me> | 2014-08-29 01:48:19 +0800 |
commit | 214951cc8d485e826ec52a381b8e50f0e75aafa1 (patch) | |
tree | e86687a76367eae29bd6fe1328a12eea937d7054 | |
download | nrf51822-posix-build-scripts-214951cc8d485e826ec52a381b8e50f0e75aafa1.tar.gz nrf51822-posix-build-scripts-214951cc8d485e826ec52a381b8e50f0e75aafa1.tar.bz2 nrf51822-posix-build-scripts-214951cc8d485e826ec52a381b8e50f0e75aafa1.tar.xz nrf51822-posix-build-scripts-214951cc8d485e826ec52a381b8e50f0e75aafa1.zip |
modified from nordic nRF51 SDK
-rw-r--r-- | Makefile.common | 209 | ||||
-rw-r--r-- | Makefile.posix | 4 | ||||
-rw-r--r-- | Makefile.template | 22 | ||||
-rw-r--r-- | Makefile.windows | 10 | ||||
-rw-r--r-- | gcc_nrf51_blank_xxaa.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_blank_xxab.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_common.ld | 161 | ||||
-rw-r--r-- | gcc_nrf51_s110_xxaa.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_s110_xxab.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_s120_xxaa.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_s120_xxab.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_s210_xxaa.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_s210_xxab.ld | 13 | ||||
-rw-r--r-- | gcc_nrf51_s310_xxaa.ld | 13 | ||||
-rw-r--r-- | gcc_startup_nrf51.s | 270 | ||||
-rw-r--r-- | system_nrf51.c | 121 |
16 files changed, 914 insertions, 0 deletions
diff --git a/Makefile.common b/Makefile.common new file mode 100644 index 0000000..9f81b00 --- /dev/null +++ b/Makefile.common @@ -0,0 +1,209 @@ +DEVICE := NRF51
+DEVICESERIES := nrf51
+
+SDK_INCLUDE_PATH = $(SDK_PATH)/Include/
+SDK_SOURCE_PATH = $(SDK_PATH)/Source/
+# TEMPLATE_PATH += $(SDK_SOURCE_PATH)/templates/gcc/
+OUTPUT_BINARY_DIRECTORY := _build
+
+ifeq ($(OS),Windows_NT)
+include $(TEMPLATE_PATH)Makefile.windows
+else
+include $(TEMPLATE_PATH)Makefile.posix
+endif
+
+ifeq ($(LINKER_SCRIPT),)
+ ifeq ($(USE_SOFTDEVICE), S110)
+ LINKER_SCRIPT = gcc_$(DEVICESERIES)_s110_$(DEVICE_VARIANT).ld
+ OUTPUT_FILENAME := $(OUTPUT_FILENAME)_s110_$(DEVICE_VARIANT)
+ else
+ ifeq ($(USE_SOFTDEVICE), S210)
+ LINKER_SCRIPT = gcc_$(DEVICESERIES)_s210_$(DEVICE_VARIANT).ld
+ OUTPUT_FILENAME := $(OUTPUT_FILENAME)_s210_$(DEVICE_VARIANT)
+ else
+ LINKER_SCRIPT = gcc_$(DEVICESERIES)_blank_$(DEVICE_VARIANT).ld
+ OUTPUT_FILENAME := $(OUTPUT_FILENAME)_$(DEVICE_VARIANT)
+ endif
+ endif
+else
+# Use externally defined settings
+endif
+
+CPU := cortex-m0
+
+# Toolchain commands
+JLINK := JLinkExe -Device nrf51822 -speed 100 -if swd
+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"
+
+MK := mkdir
+RM := rm -rf
+
+OBJECT_DIRECTORY := _build
+LISTING_DIRECTORY := _build
+
+C_SOURCE_FILES += system_$(DEVICESERIES).c
+ASSEMBLER_SOURCE_FILES += gcc_startup_$(DEVICESERIES).s
+
+# Linker flags
+#LDFLAGS += -L"$(GNU_INSTALL_ROOT)/arm-none-eabi/lib/armv6-m"
+#LDFLAGS += -L"$(GNU_INSTALL_ROOT)/lib/gcc/arm-none-eabi/$(GNU_VERSION)/armv6-m"
+LDFLAGS += -Xlinker -Map=$(LISTING_DIRECTORY)/$(OUTPUT_FILENAME).map
+LDFLAGS += -mcpu=$(CPU) -mthumb -mabi=aapcs -L $(TEMPLATE_PATH) -T$(LINKER_SCRIPT)
+
+# Compiler flags
+CFLAGS += -mcpu=$(CPU) -mthumb -mabi=aapcs -D$(DEVICE) -D$(BOARD) -D$(TARGET_CHIP) --std=gnu99
+CFLAGS += -Wall -Werror
+CFLAGS += -mfloat-abi=soft
+
+# Assembler flags
+ASMFLAGS += -x assembler-with-cpp
+
+INCLUDEPATHS += -I"$(SDK_PATH)Include"
+INCLUDEPATHS += -I"$(SDK_PATH)Include/gcc"
+INCLUDEPATHS += -I"$(SDK_PATH)Include/ext_sensors"
+
+# Sorting removes duplicates
+BUILD_DIRECTORIES := $(sort $(OBJECT_DIRECTORY) $(OUTPUT_BINARY_DIRECTORY) $(LISTING_DIRECTORY) )
+
+####################################################################
+# Rules #
+####################################################################
+
+C_SOURCE_FILENAMES = $(notdir $(C_SOURCE_FILES) )
+ASSEMBLER_SOURCE_FILENAMES = $(notdir $(ASSEMBLER_SOURCE_FILES) )
+
+# Make a list of source paths
+C_SOURCE_PATHS += $(SDK_SOURCE_PATH) $(TEMPLATE_PATH) $(wildcard $(SDK_SOURCE_PATH)*/) $(wildcard $(SDK_SOURCE_PATH)ext_sensors/*/) $(wildcard $(SDK_SOURCE_PATH)ble/*/) $(BUILD_SCRIPTS_PATH)
+ASSEMBLER_SOURCE_PATHS = $(SDK_SOURCE_PATH) $(TEMPLATE_PATH) $(wildcard $(SDK_SOURCE_PATH)*/) $(BUILD_SCRIPTS_PATH)
+
+C_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(C_SOURCE_FILENAMES:.c=.o) )
+ASSEMBLER_OBJECTS = $(addprefix $(OBJECT_DIRECTORY)/, $(ASSEMBLER_SOURCE_FILENAMES:.s=.o) )
+
+# Set source lookup paths
+vpath %.c $(C_SOURCE_PATHS)
+vpath %.s $(ASSEMBLER_SOURCE_PATHS)
+
+# Include automatically previously generated dependencies
+-include $(addprefix $(OBJECT_DIRECTORY)/, $(COBJS:.o=.d))
+
+### Targets
+debug: CFLAGS += -DDEBUG -g3 -O0
+debug: ASMFLAGS += -DDEBUG -g3 -O0
+debug: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
+
+.PHONY: release
+release: clean
+release: CFLAGS += -DNDEBUG -O3
+release: ASMFLAGS += -DNDEBUG -O3
+release: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
+
+echostuff:
+ @echo C_OBJECTS: [$(C_OBJECTS)]
+ @echo C_SOURCE_FILES: [$(C_SOURCE_FILES)]
+ @echo C_SOURCE_PATHS: [$(C_SOURCE_PATHS)]
+
+## Create build directories
+$(BUILD_DIRECTORIES):
+ $(MK) $@
+
+## Create objects from C source files
+$(OBJECT_DIRECTORY)/%.o: %.c
+# Build header dependencies
+ $(CC) $(CFLAGS) $(INCLUDEPATHS) -M $< -MF "$(@:.o=.d)" -MT $@
+# Do the actual compilation
+ $(CC) $(CFLAGS) $(INCLUDEPATHS) -c -o $@ $<
+
+## Assemble .s files
+$(OBJECT_DIRECTORY)/%.o: %.s
+ $(CC) $(ASMFLAGS) $(INCLUDEPATHS) -c -o $@ $<
+
+## Link C and assembler objects to an .out file
+$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out: $(BUILD_DIRECTORIES) $(C_OBJECTS) $(ASSEMBLER_OBJECTS) $(LIBRARIES)
+ $(CC) $(LDFLAGS) $(C_OBJECTS) $(ASSEMBLER_OBJECTS) $(LIBRARIES) -o $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
+
+## Create binary .bin file from the .out file
+$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
+ $(OBJCOPY) -O binary $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
+
+## Create binary .hex file from the .out file
+$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex: $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out
+ $(OBJCOPY) -O ihex $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).out $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).hex
+
+## Default build target
+.PHONY: all
+all: clean release
+
+clean:
+ $(RM) $(OUTPUT_BINARY_DIRECTORY)
+
+
+$(OUTPUT_BINARY_DIRECTORY)/erase_all.jlink : $(BUILD_DIRECTORIES)
+ echo " \
+r \n\
+h \n\
+w4 0x4001e504,2 # enable erase all \n\
+w4 0x4001e50c,1 # start erasing \n\
+sleep 1000 \n\
+r \n\
+qc \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)/flash_softdevice.jlink: $(BUILD_DIRECTORIES)
+ echo " \n\
+r \n\
+h \n\
+w4 0x4001e504,2 # enable erase \n\
+w4 0x4001e50c,1 # start erasing all \n\
+sleep 1000 \n\
+w4 0x10001000, 0x14000 \n\
+w4 0x4001e504,1 \n\
+loadbin \"$(SOFTDEVICE_BIN_PATH)\", 0x0 \n\
+r \n\
+qc \n\
+" > $(OUTPUT_BINARY_DIRECTORY)/flash_softdevice.jlink
+
+flash_softdevice: $(OUTPUT_BINARY_DIRECTORY)/flash_softdevice.jlink
+ $(JLINK) -CommanderScript $(OUTPUT_BINARY_DIRECTORY)/flash_softdevice.jlink; [ "$$?" -eq 1 ]
+
+$(OUTPUT_BINARY_DIRECTORY)/flash.jlink: $(BUILD_DIRECTORIES) $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin
+ echo " \n\
+r \n\
+h \n\
+w4 0x4001e504,2 # enable erase \n\
+" > $(OUTPUT_BINARY_DIRECTORY)/flash.jlink
+ binsize=`stat -f %z $(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin`; \
+ starthexaddr=0x14000; \
+ startaddr=`printf "%d" $$starthexaddr`; \
+ page=0; \
+ while [ $$binsize -gt 0 ]; \
+ do \
+ echo "w4 0x4001e508, $$starthexaddr # start erasing code region 1 page $$page\n" >> $(OUTPUT_BINARY_DIRECTORY)/flash.jlink ; \
+ binsize=`expr $$binsize - 1024`; \
+ page=`expr $$page + 1`; \
+ startaddr=`expr $$startaddr + 1024`; \
+ starthexaddr=`printf "0x%x" $$startaddr`; \
+ done
+ echo "sleep 1000 \n\
+r \n\
+w4 0x4001e504,1 # enable write \n\
+loadbin \"$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin\", 0x14000 \n\
+verifybin \"$(OUTPUT_BINARY_DIRECTORY)/$(OUTPUT_FILENAME).bin\", 0x14000 \n\
+r \n\
+g \n\
+qc \n\
+" >> $(OUTPUT_BINARY_DIRECTORY)/flash.jlink
+
+flash: $(OUTPUT_BINARY_DIRECTORY)/flash.jlink
+ $(JLINK) -CommanderScript $(OUTPUT_BINARY_DIRECTORY)/flash.jlink; [ "$$?" -eq 1 ]
+
+.PHONY: erase_all flash_softdevice flash
diff --git a/Makefile.posix b/Makefile.posix new file mode 100644 index 0000000..a690373 --- /dev/null +++ b/Makefile.posix @@ -0,0 +1,4 @@ +GNU_INSTALL_ROOT := $(HOME)Developer/prjs/embeded/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 new file mode 100644 index 0000000..32bb590 --- /dev/null +++ b/Makefile.template @@ -0,0 +1,22 @@ +TARGET_CHIP := NRF51822_QFAA_CA
+BOARD := BOARD_PCA10001
+
+#Uncomment correct line if you have s110 programmed on the chip.
+DEVICE_VARIANT := xxaa
+#DEVICE_VARIANT := xxab
+
+USE_SOFTDEVICE := s110
+#USE_SOFTDEVICE := s210
+
+HOME = /Users/hongbo.yang/
+SDK_PATH = $(HOME)Developer/prjs/embeded/nrf/nrf51_sdk_v6_0_0_43681/nrf51822/
+SOFTDEVICE_BIN_PATH = $(HOME)Developer/prjs/embeded/nrf/s110_nrf51822_7.0.0/s110_nrf51822_7.0.0_softdevice.hex
+BUILD_SCRIPTS_PATH = $(HOME)Developer/prjs/embeded/prjs/nrf51822/build_scripts/
+TEMPLATE_PATH = $(BUILD_SCRIPTS_PATH)
+
+C_SOURCE_FILES += main.c
+
+OUTPUT_FILENAME := main
+
+include $(TEMPLATE_PATH)Makefile.common
+
diff --git a/Makefile.windows b/Makefile.windows new file mode 100644 index 0000000..ed8d0c4 --- /dev/null +++ b/Makefile.windows @@ -0,0 +1,10 @@ +ifeq ($(findstring 86, $(ProgramFiles)), )
+ PROGFILES := C:/Program Files
+else
+ PROGFILES := C:/Program Files (x86)
+endif
+
+GNU_INSTALL_ROOT := $(PROGFILES)/GNU Tools ARM Embedded/4.7 2013q1
+GNU_VERSION := 4.7.3
+GNU_PREFIX := arm-none-eabi
+
diff --git a/gcc_nrf51_blank_xxaa.ld b/gcc_nrf51_blank_xxaa.ld new file mode 100644 index 0000000..8b8a07f --- /dev/null +++ b/gcc_nrf51_blank_xxaa.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x40000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x4000 +}
+
+
+INCLUDE "gcc_nrf51_common.ld"
diff --git a/gcc_nrf51_blank_xxab.ld b/gcc_nrf51_blank_xxab.ld new file mode 100644 index 0000000..bdfeb6b --- /dev/null +++ b/gcc_nrf51_blank_xxab.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys) + +MEMORY +{ + FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 0x20000 + RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 0x4000 +}
+
+
+INCLUDE "gcc_nrf51_common.ld" diff --git a/gcc_nrf51_common.ld b/gcc_nrf51_common.ld new file mode 100644 index 0000000..708130b --- /dev/null +++ b/gcc_nrf51_common.ld @@ -0,0 +1,161 @@ +/* Linker script for Nordic Semiconductor nRF5 devices + * + * Version: Sourcery G++ 4.5-1 + * Support: https://support.codesourcery.com/GNUToolchain/ + * + * Copyright (c) 2007, 2008, 2009, 2010 CodeSourcery, Inc. + * + * The authors hereby grant permission to use, copy, modify, distribute, + * and license this software and its documentation for any purpose, provided + * that existing copyright notices are retained in all copies and that this + * notice is included verbatim in any distributions. No written agreement, + * license, or royalty fee is required for any of the authorized uses. + * Modifications to this software may be copyrighted by their authors + * and need not follow the licensing terms described here, provided that + * the new terms are clearly indicated on the first page of each file where + * they apply. + */ +OUTPUT_FORMAT ("elf32-littlearm", "elf32-bigarm", "elf32-littlearm") + +/* Linker script to place sections and symbol values. Should be used together + * with other linker script that defines memory regions FLASH and RAM. + * It references following symbols, which must be defined in code: + * Reset_Handler : Entry of reset handler + * + * It defines following symbols, which code can use without definition: + * __exidx_start + * __exidx_end + * __etext + * __data_start__ + * __preinit_array_start + * __preinit_array_end + * __init_array_start + * __init_array_end + * __fini_array_start + * __fini_array_end + * __data_end__ + * __bss_start__ + * __bss_end__ + * __end__ + * end + * __HeapLimit + * __StackLimit + * __StackTop + * __stack + */ +ENTRY(Reset_Handler) + +SECTIONS +{ + .text : + { + KEEP(*(.Vectors)) + *(.text*) + + KEEP(*(.init)) + KEEP(*(.fini)) + + /* .ctors */ + *crtbegin.o(.ctors) + *crtbegin?.o(.ctors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .ctors) + *(SORT(.ctors.*)) + *(.ctors) + + /* .dtors */ + *crtbegin.o(.dtors) + *crtbegin?.o(.dtors) + *(EXCLUDE_FILE(*crtend?.o *crtend.o) .dtors) + *(SORT(.dtors.*)) + *(.dtors) + + *(.rodata*) + + *(.eh_frame*) + } > FLASH + + + .ARM.extab : + { + *(.ARM.extab* .gnu.linkonce.armextab.*) + } > FLASH + + __exidx_start = .; + .ARM.exidx : + { + *(.ARM.exidx* .gnu.linkonce.armexidx.*) + } > FLASH + __exidx_end = .; + + __etext = .; + + .data : AT (__etext) + { + __data_start__ = .; + *(vtable) + *(.data*) + + . = ALIGN(4); + /* preinit data */ + PROVIDE_HIDDEN (__preinit_array_start = .); + *(.preinit_array) + PROVIDE_HIDDEN (__preinit_array_end = .); + + . = ALIGN(4); + /* init data */ + PROVIDE_HIDDEN (__init_array_start = .); + *(SORT(.init_array.*)) + *(.init_array) + PROVIDE_HIDDEN (__init_array_end = .); + + + . = ALIGN(4); + /* finit data */ + PROVIDE_HIDDEN (__fini_array_start = .); + *(SORT(.fini_array.*)) + *(.fini_array) + PROVIDE_HIDDEN (__fini_array_end = .); + + *(.jcr) + . = ALIGN(4); + /* All data end */ + __data_end__ = .; + + } > RAM + + .bss : + { + . = ALIGN(4); + __bss_start__ = .; + *(.bss*) + *(COMMON) + . = ALIGN(4); + __bss_end__ = .; + } > RAM + + .heap (COPY): + { + __end__ = .; + end = __end__; + *(.heap*) + __HeapLimit = .; + } > RAM + + /* .stack_dummy section doesn't contains any symbols. It is only + * used for linker to calculate size of stack sections, and assign + * values to stack symbols later */ + .stack_dummy (COPY): + { + *(.stack*) + } > RAM + + /* Set stack top to end of RAM, and stack limit move down by + * size of stack_dummy section */ + __StackTop = ORIGIN(RAM) + LENGTH(RAM); + __StackLimit = __StackTop - SIZEOF(.stack_dummy); + PROVIDE(__stack = __StackTop); + + /* Check if data + heap + stack exceeds RAM limit */ + ASSERT(__StackLimit >= __HeapLimit, "region RAM overflowed with stack") +} + diff --git a/gcc_nrf51_s110_xxaa.ld b/gcc_nrf51_s110_xxaa.ld new file mode 100644 index 0000000..0534ddc --- /dev/null +++ b/gcc_nrf51_s110_xxaa.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00016000, LENGTH = 0x2A000
+ RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000
+}
+
+
+INCLUDE "gcc_nrf51_common.ld"
diff --git a/gcc_nrf51_s110_xxab.ld b/gcc_nrf51_s110_xxab.ld new file mode 100644 index 0000000..fe6ef7f --- /dev/null +++ b/gcc_nrf51_s110_xxab.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.)
+GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00016000, LENGTH = 0xA000
+ RAM (rwx) : ORIGIN = 0x20002000, LENGTH = 0x2000
+}
+
+
+INCLUDE "gcc_nrf51_common.ld"
diff --git a/gcc_nrf51_s120_xxaa.ld b/gcc_nrf51_s120_xxaa.ld new file mode 100644 index 0000000..4e67b02 --- /dev/null +++ b/gcc_nrf51_s120_xxaa.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.) +GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00018000, LENGTH = 0x28000
+ RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0x1800
+}
+
+
+INCLUDE "gcc_nrf51_common.ld"
diff --git a/gcc_nrf51_s120_xxab.ld b/gcc_nrf51_s120_xxab.ld new file mode 100644 index 0000000..a03afba --- /dev/null +++ b/gcc_nrf51_s120_xxab.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.)
+GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00018000, LENGTH = 0x8000
+ RAM (rwx) : ORIGIN = 0x20002800, LENGTH = 0x1800
+}
+
+
+INCLUDE "gcc_nrf51_common.ld"
diff --git a/gcc_nrf51_s210_xxaa.ld b/gcc_nrf51_s210_xxaa.ld new file mode 100644 index 0000000..b42738a --- /dev/null +++ b/gcc_nrf51_s210_xxaa.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.)
+GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x0000C000, LENGTH = 0x34000
+ RAM (rwx) : ORIGIN = 0x20000900, LENGTH = 0x3700
+}
+
+
+INCLUDE "gcc_nrf51_common.ld"
\ No newline at end of file diff --git a/gcc_nrf51_s210_xxab.ld b/gcc_nrf51_s210_xxab.ld new file mode 100644 index 0000000..1c46cb1 --- /dev/null +++ b/gcc_nrf51_s210_xxab.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.)
+GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x0000C000, LENGTH = 0x14000
+ RAM (rwx) : ORIGIN = 0x20000900, LENGTH = 0x3700
+}
+
+
+INCLUDE "gcc_nrf51_common.ld"
\ No newline at end of file diff --git a/gcc_nrf51_s310_xxaa.ld b/gcc_nrf51_s310_xxaa.ld new file mode 100644 index 0000000..479bfee --- /dev/null +++ b/gcc_nrf51_s310_xxaa.ld @@ -0,0 +1,13 @@ +/* Linker script to configure memory regions. */
+
+SEARCH_DIR(.)
+GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00020000, LENGTH = 0x20000
+ RAM (rwx) : ORIGIN = 0x20002400, LENGTH = 0x1C00
+}
+
+
+INCLUDE "gcc_nrf51_common.ld"
\ No newline at end of file diff --git a/gcc_startup_nrf51.s b/gcc_startup_nrf51.s new file mode 100644 index 0000000..89f0a6e --- /dev/null +++ b/gcc_startup_nrf51.s @@ -0,0 +1,270 @@ +/*
+Copyright (c) 2013, Nordic Semiconductor ASA
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions are met:
+
+* Redistributions of source code must retain the above copyright notice, this
+ list of conditions and the following disclaimer.
+
+* Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+
+* Neither the name of Nordic Semiconductor ASA nor the names of its
+ contributors may be used to endorse or promote products derived from
+ this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+*/
+
+/*
+NOTE: Template files (including this one) are application specific and therefore
+expected to be copied into the application project folder prior to its use!
+*/
+
+ .syntax unified
+ .arch armv6-m
+
+ .section .stack
+ .align 3
+#ifdef __STACK_SIZE
+ .equ Stack_Size, __STACK_SIZE
+#else
+ .equ Stack_Size, 2048
+#endif
+ .globl __StackTop
+ .globl __StackLimit
+__StackLimit:
+ .space Stack_Size
+ .size __StackLimit, . - __StackLimit
+__StackTop:
+ .size __StackTop, . - __StackTop
+
+ .section .heap
+ .align 3
+#ifdef __HEAP_SIZE
+ .equ Heap_Size, __HEAP_SIZE
+#else
+ .equ Heap_Size, 2048
+#endif
+ .globl __HeapBase
+ .globl __HeapLimit
+__HeapBase:
+ .if Heap_Size
+ .space Heap_Size
+ .endif
+ .size __HeapBase, . - __HeapBase
+__HeapLimit:
+ .size __HeapLimit, . - __HeapLimit
+
+ .section .Vectors
+ .align 2
+ .globl __Vectors
+__Vectors:
+ .long __StackTop /* Top of Stack */
+ .long Reset_Handler /* Reset Handler */
+ .long NMI_Handler /* NMI Handler */
+ .long HardFault_Handler /* Hard Fault Handler */
+ .long 0 /* Reserved */
+ .long 0 /* Reserved */
+ .long 0 /* Reserved */
+ .long 0 /* Reserved */
+ .long 0 /* Reserved */
+ .long 0 /* Reserved */
+ .long 0 /* Reserved */
+ .long SVC_Handler /* SVCall Handler */
+ .long 0 /* Reserved */
+ .long 0 /* Reserved */
+ .long PendSV_Handler /* PendSV Handler */
+ .long SysTick_Handler /* SysTick Handler */
+
+ /* External Interrupts */
+ .long POWER_CLOCK_IRQHandler /*POWER_CLOCK */
+ .long RADIO_IRQHandler /*RADIO */
+ .long UART0_IRQHandler /*UART0 */
+ .long SPI0_TWI0_IRQHandler /*SPI0_TWI0 */
+ .long SPI1_TWI1_IRQHandler /*SPI1_TWI1 */
+ .long 0 /*Reserved */
+ .long GPIOTE_IRQHandler /*GPIOTE */
+ .long ADC_IRQHandler /*ADC */
+ .long TIMER0_IRQHandler /*TIMER0 */
+ .long TIMER1_IRQHandler /*TIMER1 */
+ .long TIMER2_IRQHandler /*TIMER2 */
+ .long RTC0_IRQHandler /*RTC0 */
+ .long TEMP_IRQHandler /*TEMP */
+ .long RNG_IRQHandler /*RNG */
+ .long ECB_IRQHandler /*ECB */
+ .long CCM_AAR_IRQHandler /*CCM_AAR */
+ .long WDT_IRQHandler /*WDT */
+ .long RTC1_IRQHandler /*RTC1 */
+ .long QDEC_IRQHandler /*QDEC */
+ .long LPCOMP_IRQHandler /*LPCOMP */
+ .long SWI0_IRQHandler /*SWI0 */
+ .long SWI1_IRQHandler /*SWI1 */
+ .long SWI2_IRQHandler /*SWI2 */
+ .long SWI3_IRQHandler /*SWI3 */
+ .long SWI4_IRQHandler /*SWI4 */
+ .long SWI5_IRQHandler /*SWI5 */
+ .long 0 /*Reserved */
+ .long 0 /*Reserved */
+ .long 0 /*Reserved */
+ .long 0 /*Reserved */
+ .long 0 /*Reserved */
+ .long 0 /*Reserved */
+
+
+ .size __Vectors, . - __Vectors
+
+/* Reset Handler */
+
+ .equ NRF_POWER_RAMON_ADDRESS, 0x40000524
+ .equ NRF_POWER_RAMONB_ADDRESS, 0x40000554
+ .equ NRF_POWER_RAMONx_RAMxON_ONMODE_Msk, 0x3
+
+ .text
+ .thumb
+ .thumb_func
+ .align 1
+ .globl Reset_Handler
+ .type Reset_Handler, %function
+Reset_Handler:
+ .fnstart
+
+/* Make sure ALL RAM banks are powered on */
+ MOVS R1, #NRF_POWER_RAMONx_RAMxON_ONMODE_Msk
+
+ LDR R0, =NRF_POWER_RAMON_ADDRESS
+ LDR R2, [R0]
+ ORRS R2, R1
+ STR R2, [R0]
+
+ LDR R0, =NRF_POWER_RAMONB_ADDRESS
+ LDR R2, [R0]
+ ORRS R2, R1
+ STR R2, [R0]
+
+
+/* Loop to copy data from read only memory to RAM. The ranges
+ * of copy from/to are specified by following symbols evaluated in
+ * linker script.
+ * __etext: End of code section, i.e., begin of data sections to copy from.
+ * __data_start__/__data_end__: RAM address range that data should be
+ * copied to. Both must be aligned to 4 bytes boundary. */
+
+ ldr r1, =__etext
+ ldr r2, =__data_start__
+ ldr r3, =__data_end__
+
+ subs r3, r2
+ ble .LC0
+
+.LC1:
+ subs r3, 4
+ ldr r0, [r1,r3]
+ str r0, [r2,r3]
+ bgt .LC1
+.LC0:
+
+ LDR R0, =SystemInit
+ BLX R0
+ LDR R0, =_start
+ BX R0
+
+ .pool
+ .cantunwind
+ .fnend
+ .size Reset_Handler,.-Reset_Handler
+
+ .section ".text"
+
+
+/* Dummy Exception Handlers (infinite loops which can be modified) */
+
+ .weak NMI_Handler
+ .type NMI_Handler, %function
+NMI_Handler:
+ B .
+ .size NMI_Handler, . - NMI_Handler
+
+
+ .weak HardFault_Handler
+ .type HardFault_Handler, %function
+HardFault_Handler:
+ B .
+ .size HardFault_Handler, . - HardFault_Handler
+
+
+ .weak SVC_Handler
+ .type SVC_Handler, %function
+SVC_Handler:
+ B .
+ .size SVC_Handler, . - SVC_Handler
+
+
+ .weak PendSV_Handler
+ .type PendSV_Handler, %function
+PendSV_Handler:
+ B .
+ .size PendSV_Handler, . - PendSV_Handler
+
+
+ .weak SysTick_Handler
+ .type SysTick_Handler, %function
+SysTick_Handler:
+ B .
+ .size SysTick_Handler, . - SysTick_Handler
+
+
+/* IRQ Handlers */
+
+ .globl Default_Handler
+ .type Default_Handler, %function
+Default_Handler:
+ B .
+ .size Default_Handler, . - Default_Handler
+
+ .macro IRQ handler
+ .weak \handler
+ .set \handler, Default_Handler
+ .endm
+
+ IRQ POWER_CLOCK_IRQHandler
+ IRQ RADIO_IRQHandler
+ IRQ UART0_IRQHandler
+ IRQ SPI0_TWI0_IRQHandler
+ IRQ SPI1_TWI1_IRQHandler
+ IRQ GPIOTE_IRQHandler
+ IRQ ADC_IRQHandler
+ IRQ TIMER0_IRQHandler
+ IRQ TIMER1_IRQHandler
+ IRQ TIMER2_IRQHandler
+ IRQ RTC0_IRQHandler
+ IRQ TEMP_IRQHandler
+ IRQ RNG_IRQHandler
+ IRQ ECB_IRQHandler
+ IRQ CCM_AAR_IRQHandler
+ IRQ WDT_IRQHandler
+ IRQ RTC1_IRQHandler
+ IRQ QDEC_IRQHandler
+ IRQ LPCOMP_IRQHandler
+ IRQ SWI0_IRQHandler
+ IRQ SWI1_IRQHandler
+ IRQ SWI2_IRQHandler
+ IRQ SWI3_IRQHandler
+ IRQ SWI4_IRQHandler
+ IRQ SWI5_IRQHandler
+
+
+ .end
+
diff --git a/system_nrf51.c b/system_nrf51.c new file mode 100644 index 0000000..a3f1d4e --- /dev/null +++ b/system_nrf51.c @@ -0,0 +1,121 @@ +/* Copyright (c) 2013, Nordic Semiconductor ASA
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions are met:
+ *
+ * * Redistributions of source code must retain the above copyright notice, this
+ * list of conditions and the following disclaimer.
+ *
+ * * Redistributions in binary form must reproduce the above copyright notice,
+ * this list of conditions and the following disclaimer in the documentation
+ * and/or other materials provided with the distribution.
+ *
+ * * Neither the name of Nordic Semiconductor ASA nor the names of its
+ * contributors may be used to endorse or promote products derived from
+ * this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
+ * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
+ * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ */
+
+/* NOTE: Template files (including this one) are application specific and therefore expected to
+ be copied into the application project folder prior to its use! */
+
+#include <stdint.h>
+#include <stdbool.h>
+#include "nrf.h"
+#include "system_nrf51.h"
+
+/*lint ++flb "Enter library region" */
+
+
+#define __SYSTEM_CLOCK (16000000UL) /*!< nRF51 devices use a fixed System Clock Frequency of 16MHz */
+
+static bool is_manual_peripheral_setup_needed(void);
+static bool is_disabled_in_debug_needed(void);
+
+
+#if defined ( __CC_ARM )
+ uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
+#elif defined ( __ICCARM__ )
+ __root uint32_t SystemCoreClock = __SYSTEM_CLOCK;
+#elif defined ( __GNUC__ )
+ uint32_t SystemCoreClock __attribute__((used)) = __SYSTEM_CLOCK;
+#endif
+
+void SystemCoreClockUpdate(void)
+{
+ SystemCoreClock = __SYSTEM_CLOCK;
+}
+
+void SystemInit(void)
+{
+ /* If desired, switch off the unused RAM to lower consumption by the use of RAMON register.
+ It can also be done in the application main() function. */
+
+ /* Prepare the peripherals for use as indicated by the PAN 26 "System: Manual setup is required
+ to enable the use of peripherals" found at Product Anomaly document for your device found at
+ https://www.nordicsemi.com/. The side effect of executing these instructions in the devices
+ that do not need it is that the new peripherals in the second generation devices (LPCOMP for
+ example) will not be available. */
+ if (is_manual_peripheral_setup_needed())
+ {
+ *(uint32_t volatile *)0x40000504 = 0xC007FFDF;
+ *(uint32_t volatile *)0x40006C18 = 0x00008000;
+ }
+
+ /* Disable PROTENSET registers under debug, as indicated by PAN 59 "MPU: Reset value of DISABLEINDEBUG
+ register is incorrect" found at Product Anomaly document four your device found at
+ https://www.nordicsemi.com/. There is no side effect of using these instruction if not needed. */
+ if (is_disabled_in_debug_needed())
+ {
+ NRF_MPU->DISABLEINDEBUG = MPU_DISABLEINDEBUG_DISABLEINDEBUG_Disabled << MPU_DISABLEINDEBUG_DISABLEINDEBUG_Pos;
+ }
+}
+
+
+static bool is_manual_peripheral_setup_needed(void)
+{
+ if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
+ {
+ if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x00) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
+ {
+ return true;
+ }
+ if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x10) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
+ {
+ return true;
+ }
+ if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x30) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+static bool is_disabled_in_debug_needed(void)
+{
+ if ((((*(uint32_t *)0xF0000FE0) & 0x000000FF) == 0x1) && (((*(uint32_t *)0xF0000FE4) & 0x0000000F) == 0x0))
+ {
+ if ((((*(uint32_t *)0xF0000FE8) & 0x000000F0) == 0x40) && (((*(uint32_t *)0xF0000FEC) & 0x000000F0) == 0x0))
+ {
+ return true;
+ }
+ }
+
+ return false;
+}
+
+/*lint --flb "Leave library region" */
|