summaryrefslogtreecommitdiffstats
path: root/Makefile
blob: 721f452006cfaece8314fb522a9e057aa41ee763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
PROG=main

DEFINES =
DEFINES += -DSWI_DISABLE0
#DEFINES += -DBOARD_PCA10028
DEFINES += -DBOARD_BLE400
DEFINES += -DSOFTDEVICE_PRESENT
DEFINES += -DNRF51
DEFINES += -D__HEAP_SIZE=0
DEFINES += -DS130
DEFINES += -DBLE_STACK_SUPPORT_REQD
DEFINES += -DBSP_DEFINES_ONLY

CFLAGS=-Os
LDFLAGS=
ASFLAGS=
INCLUDES=

SDK=sdk-9.0.0

SDKCSRCS= \
	libraries/util/app_error.c \
	libraries/scheduler/app_scheduler.c \
	libraries/timer/app_timer.c \
	libraries/timer/app_timer_appsh.c \
	libraries/bootloader_dfu/bootloader.c \
	libraries/bootloader_dfu/bootloader_settings.c \
	libraries/bootloader_dfu/bootloader_util.c \
	libraries/crc16/crc16.c \
	libraries/bootloader_dfu/dfu_dual_bank.c \
	libraries/bootloader_dfu/dfu_init_template.c \
	libraries/bootloader_dfu/dfu_transport_ble.c \
	libraries/hci/hci_mem_pool.c \
	libraries/util/nrf_assert.c \
	drivers_nrf/hal/nrf_delay.c \
	drivers_nrf/pstorage/pstorage_raw.c \
	ble/common/ble_advdata.c \
	ble/common/ble_conn_params.c \
	ble/ble_services/ble_dfu/ble_dfu.c \
	ble/common/ble_srv_common.c \
	toolchain/system_nrf51.c \
	softdevice/common/softdevice_handler/softdevice_handler.c \
	softdevice/common/softdevice_handler/softdevice_handler_appsh.c \

SDKSSRCS  = toolchain/gcc/gcc_startup_nrf51.s


CSRCS = \
	dfu_ble_svc.c \
	main.c 


SOFTDEVICE=${SDK}/sdk/softdevice/s130/hex/s130_softdevice.hex

LINKER_SCRIPT=dfu_gcc_nrf51.ld #sdk/toolchain/gcc/s130.ld

INCLUDES += -Isdk-config -I${SDK} -I.
#INCLUDES += -Iconfig

OOCD=openocd
OOCD_CFG=openocd.cfg


CROSS=arm-none-eabi-
CC       		:= $(CROSS)gcc
AS       		:= $(CROSS)as
AR       		:= $(CROSS)ar
LD       		:= $(CROSS)ld
NM       		:= $(CROSS)nm
OBJDUMP  		:= $(CROSS)objdump
OBJCOPY  		:= $(CROSS)objcopy
SIZE    		:= $(CROSS)size
GDB	    		:= $(CROSS)gdb


CFLAGS += -mcpu=cortex-m0
CFLAGS += -mthumb -mabi=aapcs --std=gnu99
CFLAGS += -Wall -Werror -Os
CFLAGS += -mfloat-abi=soft
# keep every function in separate section. This will allow linker to dump unused functions
CFLAGS += -ffunction-sections -fdata-sections -fno-strict-aliasing
CFLAGS += -fno-builtin --short-enums

# keep every function in separate section. This will allow linker to dump unused functions
LDFLAGS += -Xlinker -Map=$(PROG).map
LDFLAGS += -mthumb -mabi=aapcs -L${SDK} -T$(LINKER_SCRIPT)
LDFLAGS += -mcpu=cortex-m0
# let linker to dump unused sections
LDFLAGS += -Wl,--gc-sections
# use newlib in nano version
#LDFLAGS += --specs=nano.specs -lc -lnosys
LIBS += -lc -lnosys

# Assembler flags
ASFLAGS += -x assembler-with-cpp

CPPFLAGS=$(DEFINES) $(INCLUDES)


OBJS=${CSRCS:%.c=%.o} ${SDKCSRCS:%.c=${SDK}/sdk/%.o} ${SDKSSRCS:%.s=${SDK}/sdk/%.o}

default: ${PROG}.bin ${PROG}.hex 

clean:
	/bin/rm -f ${OBJS} ${PROG} ${PROG}.bin ${PROG}.hex

${PROG}:${OBJS}
	$(CC) $(LDFLAGS) $(CFLAGS) $(OBJS) $(LIBS) -o $@
	$(SIZE) $@

%.bin:%
	$(OBJCOPY) -O binary $< $@
%.hex:%
	$(OBJCOPY) -O ihex $< $@


twongle.o:twongle.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<

%.o:%.c
	$(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
	
%.o:%.s
	$(CC) $(CPPFLAGS) $(ASFLAGS) -c -o $@ $<


flash: ${PROG}.hex
	${OOCD} -f ${OOCD_CFG} \
		-c "init" -c "reset init" \
		-c "flash write_image erase $<" \
		-c "reset" \
		-c "shutdown"



flash_softdevice: ${SOFTDEVICE}
	${OOCD} -f ${OOCD_CFG} \
		-c "init" -c "reset init" \
		-c "nrf51 mass_erase"  \
		-c "flash write_image erase $<" \
		-c "reset" \
		-c "shutdown"

flashall: ${SOFTDEVICE} ${PROG}.hex
	${OOCD} -f ${OOCD_CFG} \
		-c "init" -c "reset init" \
		-c "nrf51 mass_erase"  \
		-c "flash write_image ${SOFTDEVICE}" \
		-c "flash write_image ${PROG}.hex" \
		-c "reset" \
		-c "shutdown"


ds:
	$(OOCD) -f $(OOCD_CFG)

debug: ${PROG}
	${GDB} -x gdb.script ${PROG}



#flash: $(MAKECMDGOALS)
#	@echo Flashing: $(OUTPUT_BINARY_DIRECTORY)/$<.hex
#	nrfjprog --reset --program $(OUTPUT_BINARY_DIRECTORY)/$<.hex
#
### Flash softdevice
#flash_softdevice: 
#	@echo Flashing: s130_softdevice.hex
#	nrfjprog --reset --program softdevice/s130/hex/s130_softdevice.hex