Project

General

Profile

Revision 16

Added template file.

View differences:

trunk/code/projects/template/main.c
1
#include <dragonfly_lib.h>
2

  
3
int main(void)
4
{
5
	dragonfly_init(ALL_ON);
6
	return 0;
7
}
8

  
trunk/code/projects/template/Makefile
1
########Update This Section########
2
#
3
#
4

  
5
# Relative path to the root directory (containing lib directory)
6
COLONYROOT = ../../..
7

  
8
# Target file name (without extension).
9
TARGET = template
10

  
11
# Uncomment this to use the wireless library
12
# USE_WIRELESS = 1
13

  
14
#
15
#
16
###################################
17

  
18
# Hey Emacs, this is a -*- makefile -*-
19
#----------------------------------------------------------------------------
20
# WinAVR Makefile Template written by Eric B. Weddington, J?rg Wunsch, et al.
21
#
22
# Released to the Public Domain
23
#
24
# Additional material for this makefile was written by:
25
# Peter Fleury
26
# Tim Henigan
27
# Colin O'Flynn
28
# Reiner Patommel
29
# Markus Pfaff
30
# Sander Pool
31
# Frederik Rouleau
32
#
33
#----------------------------------------------------------------------------
34
# On command line:
35
#
36
# make all = Make software.
37
#
38
# make clean = Clean out built project files.
39
#
40
# make coff = Convert ELF to AVR COFF.
41
#
42
# make extcoff = Convert ELF to AVR Extended COFF.
43
#
44
# make program = Download the hex file to the device, using avrdude.
45
#                Please customize the avrdude settings below first!
46
#
47
# make debug = Start either simulavr or avarice as specified for debugging, 
48
#              with avr-gdb or avr-insight as the front end for debugging.
49
#
50
# make filename.s = Just compile filename.c into the assembler code only.
51
#
52
# make filename.i = Create a preprocessed source file for use in submitting
53
#                   bug reports to the GCC project.
54
#
55
# To rebuild project do "make clean" then "make all".
56
#----------------------------------------------------------------------------
57

  
58
#if you want your code to work on the Firefly++ and not Firefly+
59
#then add the -DFFPP line to CDEFS
60
CDEFS = 
61
#-DFFPP
62

  
63
# MCU name
64
MCU = atmega128
65

  
66
# Processor frequency.
67
#     This will define a symbol, F_CPU, in all source code files equal to the 
68
#     processor frequency. You can then use this symbol in your source code to 
69
#     calculate timings. Do NOT tack on a 'UL' at the end, this will be done
70
#     automatically to create a 32-bit value in your source code.
71
F_CPU = 8000000
72

  
73
# Output format. (can be srec, ihex, binary)
74
FORMAT = ihex
75

  
76
# List C source files here. (C dependencies are automatically generated.)
77
SRC = $(wildcard *.c)
78

  
79
# List Assembler source files here.
80
#     Make them always end in a capital .S.  Files ending in a lowercase .s
81
#     will not be considered source files but generated files (assembler
82
#     output from the compiler), and will be deleted upon "make clean"!
83
#     Even though the DOS/Win* filesystem matches both .s and .S the same,
84
#     it will preserve the spelling of the filenames, and gcc itself does
85
#     care about how the name is spelled on its command-line.
86
ASRC = 
87

  
88
# Optimization level, can be [0, 1, 2, 3, s]. 
89
#     0 = turn off optimization. s = optimize for size.
90
#     (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
91
OPT = s
92

  
93
# Debugging format.
94
#     Native formats for AVR-GCC's -g are dwarf-2 [default] or stabs.
95
#     AVR Studio 4.10 requires dwarf-2.
96
#     AVR [Extended] COFF format requires stabs, plus an avr-objcopy run.
97
DEBUG =
98

  
99
# Compiler flag to set the C Standard level.
100
#     c89   = "ANSI" C
101
#     gnu89 = c89 plus GCC extensions
102
#     c99   = ISO C99 standard (not yet fully implemented)
103
#     gnu99 = c99 plus GCC extensions
104
CSTANDARD = -std=gnu99
105

  
106
# Place -D or -U options here
107
CDEFS += -DF_CPU=$(F_CPU)UL 
108
CDEFS += -DFFP
109
# for wireless library
110
ifdef USE_WIRELESS
111
	CDEFS += -DROBOT
112
endif
113

  
114
# Place -I, -L options here
115
CINCS = -I$(COLONYROOT)/code/lib/include/libdragonfly 
116
CINCS += -L$(COLONYROOT)/code/lib/bin
117
ifdef USE_WIRELESS
118
	CINCS += -I$(COLONYROOT)/code/lib/include/libwireless
119
endif
120

  
121
#---------------- Compiler Options ----------------
122
#  -g*:          generate debugging information
123
#  -O*:          optimization level
124
#  -f...:        tuning, see GCC manual and avr-libc documentation
125
#  -Wall...:     warning level
126
#  -Wa,...:      tell GCC to pass this to the assembler.
127
#    -adhlns...: create assembler listing
128
CFLAGS =
129
# CFLAGS = -g$(DEBUG)
130
CFLAGS += $(CDEFS) $(CINCS)
131
CFLAGS += -O$(OPT)
132
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
133
CFLAGS += -Wall -Wstrict-prototypes
134
CFLAGS += -Wa,-adhlns=$(<:.c=.lst)
135
CFLAGS += $(CSTANDARD)
136

  
137
#---------------- Assembler Options ----------------
138
#  -Wa,...:   tell GCC to pass this to the assembler.
139
#  -ahlms:    create listing
140
#  -gstabs:   have the assembler create line number information; note that
141
#             for use in COFF files, additional information about filenames
142
#             and function names needs to be present in the assembler source
143
#             files -- see avr-libc docs [FIXME: not yet described there]
144
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
145

  
146

  
147
#---------------- Library Options ----------------
148
# Minimalistic printf version
149
PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
150

  
151
# Floating point printf version (requires MATH_LIB = -lm below)
152
PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
153

  
154
# If this is left blank, then it will use the Standard printf version.
155
PRINTF_LIB = 
156
#PRINTF_LIB = $(PRINTF_LIB_MIN)
157
#PRINTF_LIB = $(PRINTF_LIB_FLOAT)
158

  
159

  
160
# Minimalistic scanf version
161
SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
162

  
163
# Floating point + %[ scanf version (requires MATH_LIB = -lm below)
164
SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
165

  
166
# If this is left blank, then it will use the Standard scanf version.
167
SCANF_LIB = 
168
#SCANF_LIB = $(SCANF_LIB_MIN)
169
#SCANF_LIB = $(SCANF_LIB_FLOAT)
170

  
171
MATH_LIB = -lm
172

  
173
#---------------- External Memory Options ----------------
174

  
175
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
176
# used for variables (.data/.bss) and heap (malloc()).
177
#EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff
178

  
179
# 64 KB of external RAM, starting after internal RAM (ATmega128!),
180
# only used for heap (malloc()).
181
#EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
182

  
183
EXTMEMOPTS =
184

  
185
#---------------- Linker Options ----------------
186
#  -Wl,...:     tell GCC to pass this to linker.
187
#    -Map:      create map file
188
#    --cref:    add cross reference to  map file
189
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
190
LDFLAGS += $(EXTMEMOPTS)
191
LDFLAGS += $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
192
ifdef USE_WIRELESS
193
	LDFLAGS += -lwireless
194
endif
195
LDFLAGS += -ldragonfly
196

  
197

  
198

  
199
#---------------- Programming Options (avrdude) ----------------
200

  
201
# Programming hardware: alf avr910 avrisp bascom bsd 
202
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
203
#
204
# Type: avrdude -c ?
205
# to get a full listing.
206
#
207
AVRDUDE_PROGRAMMER = avrisp
208

  
209
# com1 = serial port. Use lpt1 to connect to parallel port.
210
AVRDUDE_PORT = com4
211
# programmer connected to serial device
212

  
213
AVRDUDE_WRITE_FLASH = -b 57600 -U flash:w:$(TARGET).hex
214
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
215

  
216

  
217
# Uncomment the following if you want avrdude's erase cycle counter.
218
# Note that this counter needs to be initialized first using -Yn,
219
# see avrdude manual.
220
#AVRDUDE_ERASE_COUNTER = -y
221

  
222
# Uncomment the following if you do /not/ wish a verification to be
223
# performed after programming the device.
224
#AVRDUDE_NO_VERIFY = -V
225

  
226
# Increase verbosity level.  Please use this when submitting bug
227
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
228
# to submit bug reports.
229
#AVRDUDE_VERBOSE = -v -v
230

  
231
AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
232
AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)
233
AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)
234
AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)
235

  
236
#don't check for device signature
237
AVRDUDE_FLAGS += -F
238

  
239

  
240

  
241
#---------------- Debugging Options ----------------
242

  
243
# For simulavr only - target MCU frequency.
244
DEBUG_MFREQ = $(F_CPU)
245

  
246
# Set the DEBUG_UI to either gdb or insight.
247
# DEBUG_UI = gdb
248
DEBUG_UI = insight
249

  
250
# Set the debugging back-end to either avarice, simulavr.
251
DEBUG_BACKEND = avarice
252
#DEBUG_BACKEND = simulavr
253

  
254
# GDB Init Filename.
255
GDBINIT_FILE = __avr_gdbinit
256

  
257
# When using avarice settings for the JTAG
258
JTAG_DEV = /dev/com1
259

  
260
# Debugging port used to communicate between GDB / avarice / simulavr.
261
DEBUG_PORT = 4242
262

  
263
# Debugging host used to communicate between GDB / avarice / simulavr, normally
264
#     just set to localhost unless doing some sort of crazy debugging when 
265
#     avarice is running on a different computer.
266
DEBUG_HOST = localhost
267

  
268

  
269

  
270
#============================================================================
271

  
272

  
273
# Define programs and commands.
274
SHELL = sh
275
CC = avr-gcc
276
OBJCOPY = avr-objcopy
277
OBJDUMP = avr-objdump
278
SIZE = avr-size
279
NM = avr-nm
280
AVRDUDE = avrdude
281
REMOVE = rm -f
282
REMOVEDIR = rm -rf
283
COPY = cp
284
WINSHELL = cmd
285

  
286

  
287
# Define Messages
288
# English
289
MSG_ERRORS_NONE = Errors: none
290
MSG_BEGIN = -------- begin --------
291
MSG_END = --------  end  --------
292
MSG_SIZE_BEFORE = Size before: 
293
MSG_SIZE_AFTER = Size after:
294
MSG_COFF = Converting to AVR COFF:
295
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
296
MSG_FLASH = Creating load file for Flash:
297
MSG_EEPROM = Creating load file for EEPROM:
298
MSG_EXTENDED_LISTING = Creating Extended Listing:
299
MSG_SYMBOL_TABLE = Creating Symbol Table:
300
MSG_LINKING = Linking:
301
MSG_COMPILING = Compiling:
302
MSG_ASSEMBLING = Assembling:
303
MSG_CLEANING = Cleaning project:
304

  
305

  
306

  
307

  
308
# Define all object files.
309
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
310

  
311
# Define all listing files.
312
LST = $(SRC:.c=.lst) $(ASRC:.S=.lst) 
313

  
314

  
315
# Compiler flags to generate dependency files.
316
GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d
317

  
318

  
319
# Combine all necessary flags and optional flags.
320
# Add target processor to flags.
321
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)
322
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
323

  
324

  
325

  
326

  
327

  
328
# Default target.
329
all: begin gccversion sizebefore build sizeafter end
330

  
331
build: elf hex eep lss sym
332

  
333
elf: $(TARGET).elf
334
hex: $(TARGET).hex
335
eep: $(TARGET).eep
336
lss: $(TARGET).lss 
337
sym: $(TARGET).sym
338

  
339

  
340

  
341
# Eye candy.
342
# AVR Studio 3.x does not check make's exit code but relies on
343
# the following magic strings to be generated by the compile job.
344
begin:
345
	@echo
346
	@echo $(MSG_BEGIN)
347

  
348
end:
349
	@echo $(MSG_END)
350
	@echo
351

  
352

  
353
# Display size of file.
354
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
355
ELFSIZE = $(SIZE) -A $(TARGET).elf
356
AVRMEM = avr-mem.sh $(TARGET).elf $(MCU)
357

  
358
sizebefore:
359
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); \
360
	$(AVRMEM) 2>/dev/null; echo; fi
361

  
362
sizeafter:
363
	@if test -f $(TARGET).elf; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); \
364
	$(AVRMEM) 2>/dev/null; echo; fi
365

  
366

  
367

  
368
# Display compiler version information.
369
gccversion : 
370
	@$(CC) --version
371

  
372

  
373

  
374
# Program the device.  
375
program: $(TARGET).hex $(TARGET).eep
376
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
377

  
378

  
379
# Generate avr-gdb config/init file which does the following:
380
#     define the reset signal, load the target file, connect to target, and set 
381
#     a breakpoint at main().
382
gdb-config: 
383
	@$(REMOVE) $(GDBINIT_FILE)
384
	@echo define reset >> $(GDBINIT_FILE)
385
	@echo SIGNAL SIGHUP >> $(GDBINIT_FILE)
386
	@echo end >> $(GDBINIT_FILE)
387
	@echo file $(TARGET).elf >> $(GDBINIT_FILE)
388
	@echo target remote $(DEBUG_HOST):$(DEBUG_PORT)  >> $(GDBINIT_FILE)
389
ifeq ($(DEBUG_BACKEND),simulavr)
390
	@echo load  >> $(GDBINIT_FILE)
391
endif	
392
	@echo break main >> $(GDBINIT_FILE)
393
	
394
debug: gdb-config $(TARGET).elf
395
ifeq ($(DEBUG_BACKEND), avarice)
396
	@echo Starting AVaRICE - Press enter when "waiting to connect" message displays.
397
	@$(WINSHELL) /c start avarice --jtag $(JTAG_DEV) --erase --program --file \
398
	$(TARGET).elf $(DEBUG_HOST):$(DEBUG_PORT)
399
	@$(WINSHELL) /c pause
400
	
401
else
402
	@$(WINSHELL) /c start simulavr --gdbserver --device $(MCU) --clock-freq \
403
	$(DEBUG_MFREQ) --port $(DEBUG_PORT)
404
endif
405
	@$(WINSHELL) /c start avr-$(DEBUG_UI) --command=$(GDBINIT_FILE)
406
	
407

  
408

  
409

  
410
# Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
411
COFFCONVERT=$(OBJCOPY) --debugging \
412
--change-section-address .data-0x800000 \
413
--change-section-address .bss-0x800000 \
414
--change-section-address .noinit-0x800000 \
415
--change-section-address .eeprom-0x810000 
416

  
417

  
418
coff: $(TARGET).elf
419
	@echo
420
	@echo $(MSG_COFF) $(TARGET).cof
421
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
422

  
423

  
424
extcoff: $(TARGET).elf
425
	@echo
426
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
427
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
428

  
429

  
430

  
431
# Create final output files (.hex, .eep) from ELF output file.
432
%.hex: %.elf
433
	@echo
434
	@echo $(MSG_FLASH) $@
435
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
436

  
437
%.eep: %.elf
438
	@echo
439
	@echo $(MSG_EEPROM) $@
440
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
441
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
442

  
443
# Create extended listing file from ELF output file.
444
%.lss: %.elf
445
	@echo
446
	@echo $(MSG_EXTENDED_LISTING) $@
447
	$(OBJDUMP) -h -S $< > $@
448

  
449
# Create a symbol table from ELF output file.
450
%.sym: %.elf
451
	@echo
452
	@echo $(MSG_SYMBOL_TABLE) $@
453
	$(NM) -n $< > $@
454

  
455

  
456

  
457
# Link: create ELF output file from object files.
458
.SECONDARY : $(TARGET).elf
459
.PRECIOUS : $(OBJ)
460
%.elf: $(OBJ)
461
	@echo
462
	@echo $(MSG_LINKING) $@
463
	$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)
464

  
465

  
466
# Compile: create object files from C source files.
467
%.o : %.c
468
	@echo
469
	@echo $(MSG_COMPILING) $<
470
	$(CC) -c $(ALL_CFLAGS) $< -o $@ 
471

  
472

  
473
# Compile: create assembler files from C source files.
474
%.s : %.c
475
	$(CC) -S $(ALL_CFLAGS) $< -o $@
476

  
477

  
478
# Assemble: create object files from assembler source files.
479
%.o : %.S
480
	@echo
481
	@echo $(MSG_ASSEMBLING) $<
482
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
483

  
484
# Create preprocessed source for use in sending a bug report.
485
%.i : %.c
486
	$(CC) -E -mmcu=$(MCU) -I. $(CFLAGS) $< -o $@ 
487

  
488

  
489
# Target: clean project.
490
clean: begin clean_list end
491

  
492
clean_list :
493
	@echo
494
	@echo $(MSG_CLEANING)
495
	$(REMOVE) $(TARGET).hex
496
	$(REMOVE) $(TARGET).eep
497
	$(REMOVE) $(TARGET).cof
498
	$(REMOVE) $(TARGET).elf
499
	$(REMOVE) $(TARGET).map
500
	$(REMOVE) $(TARGET).sym
501
	$(REMOVE) $(TARGET).lss
502
	$(REMOVE) $(OBJ)
503
	$(REMOVE) $(LST)
504
	$(REMOVE) $(SRC:.c=.s)
505
	$(REMOVE) $(SRC:.c=.d)
506
	$(REMOVEDIR) .dep
507

  
508

  
509

  
510
# Include the dependency files.
511
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)
512

  
513

  
514
# Listing of phony targets.
515
.PHONY : all begin finish end sizebefore sizeafter gccversion \
516
build elf hex eep lss sym coff extcoff \
517
clean clean_list program debug gdb-config
518

  

Also available in: Unified diff