summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaudio Takahasi <claudio.takahasi@gmail.com>2013-12-20 13:31:19 -0300
committerClaudio Takahasi <claudio.takahasi@gmail.com>2013-12-23 11:36:34 -0300
commit44754fa78bdb7c92ea241b3dbdfb83dfcf8d80de (patch)
treea1daf4226c9024220df6958366f3a69c16a26408
parentb13593e244243acf27c72b40cfeee325e98f3ce8 (diff)
build: Add Makefile per example
This patch changes the build system creating one Makefile for each project.
-rw-r--r--Makefile.am21
-rw-r--r--Makefile.nrf41
-rw-r--r--acinclude.m46
-rwxr-xr-xbootstrap-configure.nrf2
l---------configure.ac1
-rw-r--r--configure.nrf6
-rw-r--r--examples/helloworld/Makefile.am40
-rw-r--r--platform/nrf51822/Makefile.am13
-rw-r--r--platform/nrf51822/gcc_nrf51_blank_xxaa.ld11
-rw-r--r--platform/nrf51822/gcc_startup_nrf51.s239
-rw-r--r--platform/nrf51822/system_nrf51.c85
-rw-r--r--stack/Makefile.am10
12 files changed, 422 insertions, 53 deletions
diff --git a/Makefile.am b/Makefile.am
index 1e6b70b..65beabc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,16 +1,21 @@
AM_MAKEFLAGS = --no-print-directory
-AM_CPPFLAGS =
-
-STACK_SOURCE_FILES = stack/ll.c stack/bci.c
-
-STACK_OBJECT_FILES = $(STACK_SOURCE_FILES:.c=.o)
-
-AM_CPPFLAGS += -Istack
+MAINTAINERCLEANFILES =
if PLATFORM_NRF
-include Makefile.nrf
+SUBDIRS = stack platform/nrf51822 examples/helloworld
endif
if PLATFORM_UBERTOOTH
include Makefile.ubertooth
endif
+
+MAINTAINERCLEANFILES += Makefile.in \
+ aclocal.m4 \
+ configure \
+ config.h \
+ ltmain.sh \
+ autom4te.cache \
+ stamp-h1
+
+clean-local:
+ $(RM) -rf $(MAINTAINERCLEANFILES)
diff --git a/Makefile.nrf b/Makefile.nrf
deleted file mode 100644
index 8a8cb18..0000000
--- a/Makefile.nrf
+++ /dev/null
@@ -1,41 +0,0 @@
-PLATFORM_SOURCE_FILES = $(SDK_DIR)/Nordic/nrf51822/Source/templates/system_nrf51.c
-PLATFORM_ASM_FILES = $(SDK_DIR)/Nordic/nrf51822/Source/templates/gcc/gcc_startup_nrf51.s
-PROJECT_SOURCE_FILES = examples/helloworld/main.c
-
-AM_CPPFLAGS += -I$(SDK_DIR)/Nordic/nrf51822/Include
-AM_CPPFLAGS += -I$(SDK_DIR)/Nordic/nrf51822/Include/gcc
-
-LDFLAGS += -T$(SDK_DIR)/Nordic/nrf51822/Source/templates/gcc/gcc_nrf51_blank_xxaa.ld
-LDFLAGS += -L$(SDK_DIR)/Nordic/nrf51822/Source/templates/gcc
-LDFLAGS += -mabi=aapcs --specs=nano.specs -Xlinker -Map=$(BUILD_DIR)/nrf.map
-
-PLATFORM_OBJECT_FILES = $(PLATFORM_SOURCE_FILES:.c=.o)
-ASM_OBJECT_FILES = $(PLATFORM_ASM_FILES:.s=.o)
-PROJECT_OBJECT_FILES = $(PROJECT_SOURCE_FILES:.c=.o)
-
-all: $(BUILD_DIR) $(BUILD_DIR)/helloworld.bin
-
-$(BUILD_DIR)/helloworld.bin: $(BUILD_DIR)/helloworld.out
- $(OBJCOPY) -Obinary $(BUILD_DIR)/helloworld.out $@
-
-$(BUILD_DIR)/helloworld.out: $(PROJECT_OBJECT_FILES) $(STACK_OBJECT_FILES) \
- $(PLATFORM_OBJECT_FILES) $(ASM_OBJECT_FILES)
- $(CC) $(LDFLAGS) $(ASM_OBJECT_FILES) $(PROJECT_OBJECT_FILES) \
- $(PLATFORM_OBJECT_FILES) $(STACK_OBJECT_FILES) -o $@
- $(OBJDUMP) -h $(BUILD_DIR)/helloworld.out
-
-# Build object files from C source files
-%.o: %.c
- $(CC) -c $(CFLAGS) $(AM_CPPFLAGS) $(AM_CPPFLAGS) -o $@ $<
-
-# Build object files from ASM source files
-%.o: %.s
- $(CC) -c $(ASMFLAGS) $(AM_CPPFLAGS) -o $@ $<
-
-$(BUILD_DIR):
- mkdir $@
-
-clean:
- rm -rf $(BUILD_DIR) *.log
- rm $(PROJECT_OBJECT_FILES) $(PLATFORM_OBJECT_FILES) \
- $(ASM_OBJECT_FILES) $(STACK_OBJECT_FILES)
diff --git a/acinclude.m4 b/acinclude.m4
index 2a3340a..db1d58a 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -50,8 +50,12 @@ AC_DEFUN([AC_ARG_BLESTACK], [
[Select target platform]), [platform_val=${withval}])
if (test "${platform_val}" == "nrf"); then
- AM_CONDITIONAL(PLATFORM_NRF, true)
AM_CONDITIONAL(PLATFORM_UBERTOOTH, false)
+ AM_CONDITIONAL(PLATFORM_NRF, true)
+ AM_CONDITIONAL(NRF51, true)
+ AM_CONDITIONAL(NRF51822_QFAA_CA, true)
+ AM_CONDITIONAL(BOARD_PCA10001, true)
+
elif (test "${platform_val}" == "ubertooth"); then
AM_CONDITIONAL(PLATFORM_NRF, false)
AM_CONDITIONAL(PLATFORM_UBERTOOTH, true)
diff --git a/bootstrap-configure.nrf b/bootstrap-configure.nrf
index 606c7e2..636438b 100755
--- a/bootstrap-configure.nrf
+++ b/bootstrap-configure.nrf
@@ -1,6 +1,5 @@
#!/bin/sh
-# environment variables
export CC="arm-none-eabi-gcc"
export LD="arm-none-eabi-ld"
export NM="arm-none-eabi-nm -B"
@@ -12,7 +11,6 @@ export OBJDUMP="arm-none-eabi-objdump"
export CFLAGS="-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -DNRF51 -DNRF51822_QFAA_CA -DBOARD_PCA10001 --std=gnu99"
export ASMFLAGS="-x assembler-with-cpp -D__HEAP_SIZE=0 -D__STACK_SIZE=1024"
-export CROSS_COMPILE=1
if [ -f config.status ]; then
make maintainer-clean
diff --git a/configure.ac b/configure.ac
new file mode 120000
index 0000000..20f7050
--- /dev/null
+++ b/configure.ac
@@ -0,0 +1 @@
+configure.nrf \ No newline at end of file
diff --git a/configure.nrf b/configure.nrf
index eaeb546..43ac3b3 100644
--- a/configure.nrf
+++ b/configure.nrf
@@ -33,4 +33,8 @@ AC_SUBST(TYPE, ${TYPE})
AM_CONFIG_HEADER(config.h)
-AC_OUTPUT(Makefile)
+AC_OUTPUT([ Makefile
+ stack/Makefile
+ platform/nrf51822/Makefile
+ examples/helloworld/Makefile
+])
diff --git a/examples/helloworld/Makefile.am b/examples/helloworld/Makefile.am
new file mode 100644
index 0000000..2e6cc6d
--- /dev/null
+++ b/examples/helloworld/Makefile.am
@@ -0,0 +1,40 @@
+AM_CFLAGS=-mcpu=cortex-m0 -mthumb -mfloat-abi=soft -c
+AM_LDFLAGS=--specs=nano.specs -Xlinker -Map=helloworld.map \
+ -T$(top_builddir)/platform/nrf51822/gcc_nrf51_blank_xxaa.ld \
+ -L$(SDK_DIR)/Nordic/nrf51822/Source/templates/gcc
+
+PLATFORM_LIBS = $(top_builddir)/stack/libblestack.a \
+ $(top_builddir)/platform/nrf51822/libnrf.a
+
+AM_CPPFLAGS=-I$(top_builddir)/platform/nrf51822
+
+HELLO_SOURCE_FILES = main.c
+HELLO_OBJECT_FILES = $(HELLO_SOURCE_FILES:.c=.o)
+
+all: helloworld.bin
+
+helloworld.bin: helloworld.out
+ $(OBJCOPY) -Obinary helloworld.out $@
+
+helloworld.out: $(HELLO_OBJECT_FILES)
+
+ $(CC) $(AM_LDFLAGS) $(HELLO_OBJECT_FILES) $(PLATFORM_LIBS) -o $@
+
+ $(OBJDUMP) -h helloworld.out
+
+# Build object files from C source files
+%.o: %.c
+ $(CC) -c $(CFLAGS) $(AM_CPPFLAGS) -o $@ $<
+
+# Build object files from ASM source files
+%.o: %.s
+ $(CC) -c $(ASMFLAGS) $(AM_CPPFLAGS) -o $@ $<
+
+MAINTAINERCLEANFILES = Makefile.in \
+ helloworld.bin \
+ helloworld.out \
+ helloworld.map
+
+clean-local:
+ $(RM) -rf $(MAINTAINERCLEANFILES)
+ $(RM) *.o
diff --git a/platform/nrf51822/Makefile.am b/platform/nrf51822/Makefile.am
new file mode 100644
index 0000000..c391381
--- /dev/null
+++ b/platform/nrf51822/Makefile.am
@@ -0,0 +1,13 @@
+noinst_LIBRARIES = libnrf.a
+
+AM_CPPFLAGS =-I$(SDK_DIR)/Nordic/nrf51822/Include
+AM_CPPFLAGS += -I$(SDK_DIR)/Nordic/nrf51822/Include/gcc
+
+libnrf_a_SOURCES = system_nrf51.c gcc_startup_nrf51.s
+
+MAINTAINERCLEANFILES = Makefile.in
+
+clean-local:
+ $(RM) -rf $(MAINTAINERCLEANFILES)
+ $(RM) *.o
+ $(RM) -rf .deps
diff --git a/platform/nrf51822/gcc_nrf51_blank_xxaa.ld b/platform/nrf51822/gcc_nrf51_blank_xxaa.ld
new file mode 100644
index 0000000..2127b3f
--- /dev/null
+++ b/platform/nrf51822/gcc_nrf51_blank_xxaa.ld
@@ -0,0 +1,11 @@
+/* Linker script to configure memory regions. */
+SEARCH_DIR(.)
+GROUP(-lgcc -lc -lnosys)
+
+MEMORY
+{
+ FLASH (rx) : ORIGIN = 0x00000000, LENGTH = 256K
+ RAM (rwx) : ORIGIN = 0x20000000, LENGTH = 16K
+}
+
+INCLUDE "gcc_nrf51_common.ld"
diff --git a/platform/nrf51822/gcc_startup_nrf51.s b/platform/nrf51822/gcc_startup_nrf51.s
new file mode 100644
index 0000000..3bf36ac
--- /dev/null
+++ b/platform/nrf51822/gcc_startup_nrf51.s
@@ -0,0 +1,239 @@
+/*
+Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
+
+The information contained herein is property of Nordic Semiconductor ASA.
+Terms and conditions of usage are described in detail in NORDIC
+SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+
+Licensees are granted free, non-transferable use of the information. NO
+WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+the file.
+*/
+
+ .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_COMP_IRQHandler /*LPCOMP_COMP */
+ .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_RAMON_RAMxON_ONMODE_Msk, 0xF
+
+ .text
+ .thumb
+ .thumb_func
+ .align 1
+ .globl Reset_Handler
+ .type Reset_Handler, %function
+Reset_Handler:
+ .fnstart
+
+/* Make sure ALL RAM banks are powered on */
+ LDR R0, =NRF_POWER_RAMON_ADDRESS
+ LDR R2, [R0]
+ MOVS R1, #NRF_POWER_RAMON_RAMxON_ONMODE_Msk
+ 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_COMP_IRQHandler
+ IRQ SWI0_IRQHandler
+ IRQ SWI1_IRQHandler
+ IRQ SWI2_IRQHandler
+ IRQ SWI3_IRQHandler
+ IRQ SWI4_IRQHandler
+ IRQ SWI5_IRQHandler
+
+
+ .end
+
diff --git a/platform/nrf51822/system_nrf51.c b/platform/nrf51822/system_nrf51.c
new file mode 100644
index 0000000..e02ad4a
--- /dev/null
+++ b/platform/nrf51822/system_nrf51.c
@@ -0,0 +1,85 @@
+/* Copyright (c) 2009 Nordic Semiconductor. All Rights Reserved.
+ *
+ * The information contained herein is property of Nordic Semiconductor ASA.
+ * Terms and conditions of usage are described in detail in NORDIC
+ * SEMICONDUCTOR STANDARD SOFTWARE LICENSE AGREEMENT.
+ *
+ * Licensees are granted free, non-transferable use of the information. NO
+ * WARRANTY of ANY KIND is provided. This heading must NOT be removed from
+ * the file.
+ *
+ */
+
+
+/**
+A template file for system_device.c is provided by ARM but adapted by the
+silicon vendor to match their actual device. As a minimum requirement this file
+must provide a device specific system configuration function and a global
+variable that contains the system frequency. It configures the device and
+initializes typically the oscillator (PLL) that is part of the microcontroller
+device.
+*/
+
+#include <stdint.h>
+#include "nrf.h"
+#include "system_nrf51.h"
+
+/*lint ++flb "Enter library region" */
+
+#define __SYSTEM_CLOCK (__XTAL)
+
+/**
+ System Core Clock Frequency (Core Clock).
+
+ Contains the system core clock which is the system clock frequency supplied
+ to the SysTick timer and the processor core clock. This variable can be used
+ by the user application to setup the SysTick timer or configure other
+ parameters. It may also be used by debugger to query the frequency of the
+ debug timer or configure the trace clock speed. SystemCoreClock is
+ initialized with a correct predefined value.
+
+ The compiler must be configured to avoid the removal of this variable in case
+ that the application program is not using it. It is important for debug
+ systems that the variable is physically present in memory so that it can be
+ examined to configure the debugger.
+*/
+uint32_t SystemCoreClock = __SYSTEM_CLOCK;
+
+/**
+ Sets up the microcontroller system.
+
+ Typically this function configures the oscillator (PLL) that is part of the
+ microcontroller device. For systems with variable clock speed it also updates
+ the variable SystemCoreClock. SystemInit is called from startup_device file
+ before entering main() function.
+*/
+void SystemInit (void)
+{
+ /* If desired, switch off the unused RAM to lower consumption by the use of RAMON register */
+
+ /* Prepare the peripherals for use as indicated by the PAN 27 "System: Manual setup is required
+ to enable the use of peripherals" found at Product Anomaly document version 1.6 found at
+ https://www.nordicsemi.com/eng/Products/Bluetooth-R-low-energy/nRF51822/PAN-028. The MACRO
+ is defined in the nrf.h file depending on the device defined. */
+ #if MANUAL_PERIPHERAL_SETUP_NEEDED == 1
+ *(uint32_t *)0x40000504 = 0xC007FFDF;
+ *(uint32_t *)0x40006C18 = 0x00008000;
+ #endif /* MANUAL_PERIPHERAL_SETUP_NEEDED */
+ #ifndef MANUAL_PERIPHERAL_SETUP_NEEDED
+ #error "Make sure you are using latest nrf.h header file."
+ #endif /* MANUAL_PERIPHERAL_SETUP_NEEDED not defined */
+}
+
+/**
+ Updates the variable SystemCoreClock and must be called whenever the core
+ clock is changed during program execution.
+
+ SystemCoreClockUpdate() evaluates the clock register settings and calculates
+ the current core clock.
+*/
+void SystemCoreClockUpdate (void)
+{
+ SystemCoreClock = __SYSTEM_CLOCK;
+}
+
+/*lint --flb "Leave library region" */
diff --git a/stack/Makefile.am b/stack/Makefile.am
new file mode 100644
index 0000000..d7a18cf
--- /dev/null
+++ b/stack/Makefile.am
@@ -0,0 +1,10 @@
+noinst_LIBRARIES = libblestack.a
+libblestack_a_SOURCES = ll.c \
+ bci.c
+
+MAINTAINERCLEANFILES = Makefile.in
+
+clean-local:
+ $(RM) -rf $(MAINTAINERCLEANFILES)
+ $(RM) *.o
+ $(RM) -rf .deps