forked from bandtank/Xmega_Bootloader
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
427 lines (394 loc) · 11.6 KB
/
makefile
File metadata and controls
427 lines (394 loc) · 11.6 KB
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
###############################################################################
# Makefile for the project Xmega_Bootloader
###############################################################################
## General Flags
PROJECT = Xmega_Bootloader
###############################################################################
# User modification section
###############################################################################
# Choose one of the following MCUs:
# If you have a different MCU, you will have to define these values:
# Name in makefile Name in ioxxxx.h
# --------------------------- -----------------------------
# BOOT_SECTION_START_IN_BYTES BOOT_SECTION_START
# BOOT_PAGE_SIZE BOOT_SECTION_PAGE_SIZE
# APP_PAGE_SIZE APP_SECTION_PAGE_SIZE
#
# You can find these files in the include path for your compiler. Examples:
# 1) Winavr: C:\WinAVR-20100110\avr\include\avr\ioxxxx.h
# 2) Atmel 3.4.2: C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR8 GCC\
# Native\3.4.2.1002\avr8-gnu-toolchain\avr\include\avr\ioxxxx.h
# MCU = atxmega8e5
# MCU = atxmega16a4
# MCU = atxmega16a4u
# MCU = atxmega16c4
# MCU = atxmega16d4
# MCU = atxmega16e5
# MCU = atxmega32a4
# MCU = atxmega32a4u
# MCU = atxmega32c3
# MCU = atxmega32c4
# MCU = atxmega32d3
# MCU = atxmega32d4
# MCU = atxmega32e5
# MCU = atxmega64a1
# MCU = atxmega64a1u
# MCU = atxmega64a3
# MCU = atxmega64a3u
# MCU = atxmega64a4u
# MCU = atxmega64b1
# MCU = atxmega64b3
# MCU = atxmega64c3
# MCU = atxmega64d3
# MCU = atxmega64d4
# MCU = atxmega128a1
# MCU = atxmega128a1u
# MCU = atxmega128a3
# MCU = atxmega128a3u
# MCU = atxmega128a4u
# MCU = atxmega128b1
# MCU = atxmega128b3
# MCU = atxmega128c3
# MCU = atxmega128d3
MCU = atxmega128d4
# MCU = atxmega192a3
# MCU = atxmega192a3u
# MCU = atxmega192c3
# MCU = atxmega192d3
# MCU = atxmega256a3
# MCU = atxmega256a3b
# MCU = atxmega256a3bu
# MCU = atxmega256a3u
# MCU = atxmega256c3
# MCU = atxmega256d3
# MCU = atxmega384c3
# MCU = atxmega384d3
# Choose a baud rate for the UART.
# If you need a baud rate that is not listed in this makefile, you must add
# new configuration statements in config.macros.h. Remember, Xmegas start-up
# with a 2MHz clock.
BAUD_RATE = 9600
# BAUD_RATE = 38400
# BAUD_RATE = 57600
# BAUD_RATE = 115200
# Specify a pin to check for entry into the bootloader. The notation is
# PORT,PIN. For example, if you wanted to use PIN 3 on PORTC, you would set
# the option as C,3. Then specifiy the logic value required to enable the
# bootloader code (1 = enable the bootloader if the pin is VCC, 0 = enable
# the bootloader if the pin is GND).
#
# IEEE:
# PD7: SWITCH SW801 A0
# PD6: SWITCH SW801 A1
# PD5: SWITCH SW801 A2
# use PD5 when its 1 activate bootloader
BOOTLOADER_PIN = D,5
BOOTLOADER_PIN_ON = 1
# Specify a pin to control an LED. The notation is PORT,PIN. For example, if
# you wanted to use PIN 6 on PORTA, you would set the option as A,6. Then
# specifiy the logic value required to enable the LED (1 = output VCC to turn
# on the LED, 0 = output GND to turn on the LED).
#
# IEEE: PD4: AMC CARD SD 7_DET
#
LED_PIN = D,4
LED_ON = 1
# Specify which UART to use with PORT,NUM notation. For example, UART1 on
# PORTD would be D,1.
#
# IEEE PORTC: PC2/PC3
#
UART = C,0
###############################################################################
# End user modification section
###############################################################################
## Set configuration options based on MCU model
ifeq ($(MCU), atxmega8e5)
BOOT_SECTION_START_IN_BYTES = 0x2000
BOOT_PAGE_SIZE = 128
APP_PAGE_SIZE = 128
endif
ifeq ($(MCU), atxmega16a4)
BOOT_SECTION_START_IN_BYTES = 0x4000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega16a4u)
BOOT_SECTION_START_IN_BYTES = 0x4000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega16c4)
BOOT_SECTION_START_IN_BYTES = 0x4000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega16d4)
BOOT_SECTION_START_IN_BYTES = 0x4000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega16e5)
BOOT_SECTION_START_IN_BYTES = 0x4000
BOOT_PAGE_SIZE = 128
APP_PAGE_SIZE = 128
endif
ifeq ($(MCU), atxmega32a4)
BOOT_SECTION_START_IN_BYTES = 0x8000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega32a4u)
BOOT_SECTION_START_IN_BYTES = 0x8000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega32c3)
BOOT_SECTION_START_IN_BYTES = 0x8000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega32c4)
BOOT_SECTION_START_IN_BYTES = 0x8000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega32d3)
BOOT_SECTION_START_IN_BYTES = 0x8000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega32d4)
BOOT_SECTION_START_IN_BYTES = 0x8000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega32e5)
BOOT_SECTION_START_IN_BYTES = 0x8000
BOOT_PAGE_SIZE = 128
APP_PAGE_SIZE = 128
endif
ifeq ($(MCU), atxmega64a1)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64a1u)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64a3)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64a3u)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64a4u)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64b1)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64b3)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64c3)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64d3)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega64d4)
BOOT_SECTION_START_IN_BYTES = 0x10000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega128a1)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega128a1u)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega128a3)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega128a3u)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega128a4u)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega128b1)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega128b3)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega128c3)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega128d3)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega128d4)
BOOT_SECTION_START_IN_BYTES = 0x20000
BOOT_PAGE_SIZE = 256
APP_PAGE_SIZE = 256
endif
ifeq ($(MCU), atxmega192a3)
BOOT_SECTION_START_IN_BYTES = 0x30000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega192a3u)
BOOT_SECTION_START_IN_BYTES = 0x30000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega192c3)
BOOT_SECTION_START_IN_BYTES = 0x30000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega192d3)
BOOT_SECTION_START_IN_BYTES = 0x30000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega256a3)
BOOT_SECTION_START_IN_BYTES = 0x40000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega256a3b)
BOOT_SECTION_START_IN_BYTES = 0x40000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega256a3bu)
BOOT_SECTION_START_IN_BYTES = 0x40000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega256a3u)
BOOT_SECTION_START_IN_BYTES = 0x40000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega256c3)
BOOT_SECTION_START_IN_BYTES = 0x40000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega256d3)
BOOT_SECTION_START_IN_BYTES = 0x40000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega384c3)
BOOT_SECTION_START_IN_BYTES = 0x60000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
ifeq ($(MCU), atxmega384d3)
BOOT_SECTION_START_IN_BYTES = 0x60000
BOOT_PAGE_SIZE = 512
APP_PAGE_SIZE = 512
endif
TARGET = $(PROJECT).elf
TARGET_BASE = $(PROJECT)
CC = avr-gcc
CPP = avr-g++
## Compile options common for all C compilation units.
CFLAGS += -mmcu=$(MCU) -Wall -gdwarf-2 -std=gnu99 -DF_CPU=2000000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -DBOOT_PAGE_SIZE=$(BOOT_PAGE_SIZE) -DAPP_PAGE_SIZE=$(APP_PAGE_SIZE) -DMCU=$(MCU) -DBAUD_RATE=$(BAUD_RATE) -DMY_UART=$(UART) -DENTER_BOOTLOADER_PIN=$(BOOTLOADER_PIN) -DLED_PIN=$(LED_PIN) -DLED_ON=$(LED_ON) -DBOOTLOADER_PIN_EN=$(BOOTLOADER_PIN_ON)
CFLAGS += -MD -MP -MT $(*F).o
## Assembly specific flags
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = -mmcu=$(MCU)
LDFLAGS += -Wl,-Map=$(PROJECT).map
LDFLAGS += -Wl,-section-start=.text=$(BOOT_SECTION_START_IN_BYTES)
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Objects that must be built in order to link
OBJECTS = eeprom_driver.o $(PROJECT).o serial.o sp_driver.o CCP_Write.o
## Objects explicitly added by the user
LINKONLYOBJECTS =
## Build
all: $(TARGET) $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss
# Uncomment if you want sizebefore and size after to execute
#all: sizebefore $(TARGET) $(PROJECT).hex $(PROJECT).eep sizeafter $(PROJECT).lss
eeprom_driver.o: eeprom_driver.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
$(PROJECT).o: $(PROJECT).c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
serial.o: serial.c
$(CC) $(INCLUDES) $(CFLAGS) -c $<
sp_driver.o: sp_driver.s
$(CC) $(INCLUDES) $(ASMFLAGS) -c $<
CCP_Write.o: CCP_Write.s
$(CC) $(INCLUDES) $(ASMFLAGS) -c $<
##Link
$(TARGET): $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
%.hex: $(TARGET)
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(TARGET)
avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lss: $(TARGET)
avr-objdump -h -S $< > $@
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) $(PROJECT).elf $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss $(PROJECT).map $(PROJECT).d
## Other dependencies
# Display size of file.
FORMAT = ihex
SIZE = avr-size
MSG_SIZE_BEFORE = Size before:
MSG_SIZE_AFTER = Size after:
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET_BASE).hex
ELFSIZE = $(SIZE) -A $(TARGET_BASE).elf
sizebefore:
@if test -f $(TARGET); then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
echo; fi
sizeafter:
@if test -f $(TARGET); then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
echo; fi