Subversion Repositories FlightCtrl

Rev

Rev 1922 | Rev 2102 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1922 Rev 2099
1
#--------------------------------------------------------------------
1
#--------------------------------------------------------------------
2
# MCU name
2
# MCU name
3
MCU = atmega644
3
MCU = atmega644p
4
F_CPU = 20000000
4
F_CPU = 20000000
5
QUARZ = 20MHZ
5
QUARZ = 20MHZ
6
 
6
 
7
#-------------------------------------------------------------------
7
#-------------------------------------------------------------------
8
VERSION_MAJOR    =  0
8
VERSION_MAJOR    =  0
9
VERSION_MINOR    =  0
9
VERSION_MINOR    =  0
10
VERSION_PATCH    =  0
10
VERSION_PATCH    =  0
11
 
11
 
12
VERSION_SERIAL_MAJOR = 10	# Serial Protocol Major Version
12
VERSION_SERIAL_MAJOR = 10	# Serial Protocol Major Version
13
VERSION_SERIAL_MINOR = 1	# Serial Protocol Minor Version
13
VERSION_SERIAL_MINOR = 1	# Serial Protocol Minor Version
14
NC_SPI_COMPATIBLE =    6  	# SPI Protocol Version
14
NC_SPI_COMPATIBLE =    6  	# SPI Protocol Version
15
 
-
 
16
GYRO=ENC-03_FC1.3
-
 
17
GYRO_HW_NAME=ENC
-
 
18
GYRO_HW_FACTOR=1.304f
-
 
19
GYRO_PITCHROLL_CORRECTION=1.0f
-
 
20
GYRO_YAW_CORRECTION=1.0f
-
 
21
 
15
 
22
# Set up for cross axis gyros. Factors increased by sqrt(2).
16
# Set up for cross axis gyros. Factors increased by sqrt(2).
23
#GYRO=ADXRS610_FC2.0
17
#GYRO=ADXRS610_FC2.0
24
#GYRO_HW_NAME=ADXR
18
#GYRO_HW_NAME=ADXR
25
#GYRO_HW_FACTOR="(1.2288f * 1.4142)"
19
#GYRO_HW_FACTOR="(1.2288f * 1.4142)"
26
#GYRO_PITCHROLL_CORRECTION=1.0f
-
 
27
#GYRO_YAW_CORRECTION=1.0f
20
#GYRO_CORRECTION=1.0f
28
 
21
 
29
#GYRO=invenSense
22
GYRO=invenSense
30
#GYRO_HW_NAME=Isense
23
GYRO_HW_NAME=Isense
31
#GYRO_HW_FACTOR=0.6827f
-
 
32
#GYRO_PITCHROLL_CORRECTION=1.0f
24
GYRO_HW_FACTOR=0.6827f
33
#GYRO_YAW_CORRECTION=1.0f
25
GYRO_CORRECTION=1.0f
34
 
26
 
35
#-------------------------------------------------------------------
27
#-------------------------------------------------------------------
36
# get SVN revision
28
# get SVN revision
37
REV=0001
29
REV=0001
38
#$(shell sh -c "cat .svn/entries | sed -n '4p'")
30
#$(shell sh -c "cat .svn/entries | sed -n '4p'")
39
 
31
 
40
ifeq ($(MCU), atmega644)
32
ifeq ($(MCU), atmega644)
41
 FUSE_SETTINGS = -u -U lfuse:w:0xff:m -U hfuse:w:0xdf:m
33
 FUSE_SETTINGS = -u -U lfuse:w:0xff:m -U hfuse:w:0xdf:m
42
 HEX_NAME = MEGA644_$(GYRO)
34
 HEX_NAME = MEGA644_$(GYRO)
43
endif
35
endif
44
 
36
 
45
ifeq ($(MCU), atmega644p)
37
ifeq ($(MCU), atmega644p)
46
 FUSE_SETTINGS = -u -U lfuse:w:0xff:m -U hfuse:w:0xdf:m
38
 FUSE_SETTINGS = -u -U lfuse:w:0xff:m -U hfuse:w:0xdf:m
47
 HEX_NAME = MEGA644p_$(GYRO)
39
 HEX_NAME = MEGA644p_$(GYRO)
48
endif
40
endif
49
 
41
 
50
# Output format. (can be srec, ihex, binary)
42
# Output format. (can be srec, ihex, binary)
51
FORMAT = ihex
43
FORMAT = ihex
52
 
44
 
53
# Target file name (without extension).
45
# Target file name (without extension).
54
 
46
 
55
TARGET = Flight-Ctrl_Fixedwing_$(HEX_NAME)
47
TARGET = Flight-Ctrl_Fixedwing_$(HEX_NAME)
56
 
48
 
57
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
49
# Optimization level, can be [0, 1, 2, 3, s]. 0 turns off optimization.
58
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
50
# (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
59
OPT = 2
51
OPT = 2
60
#OPT = s
52
#OPT = s
61
 
53
 
62
##########################################################################################################
54
##########################################################################################################
63
# List C source files here. (C dependencies are automatically generated.)
55
# List C source files here. (C dependencies are automatically generated.)
64
SRC = main.c uart0.c timer0.c timer2.c analog.c output.c controlMixer.c 
56
SRC = main.c uart0.c timer0.c timer2.c analog.c output.c controlMixer.c 
65
SRC += dongfangMath.c twimaster.c rc.c attitude.c flight.c 
57
SRC += rc.c failsafeControl.c attitude.c flight.c  printf_P.c commands.c
66
SRC += eeprom.c configuration.c externalControl.c commands.c $(GYRO).c
58
SRC += eeprom.c configuration.c externalControl.c $(GYRO).c
67
 
59
 
68
##########################################################################################################
60
##########################################################################################################
69
 
61
 
70
# List Assembler source files here.
62
# List Assembler source files here.
71
# Make them always end in a capital .S.  Files ending in a lowercase .s
63
# Make them always end in a capital .S.  Files ending in a lowercase .s
72
# will not be considered source files but generated files (assembler
64
# will not be considered source files but generated files (assembler
73
# output from the compiler), and will be deleted upon "make clean"!
65
# output from the compiler), and will be deleted upon "make clean"!
74
# Even though the DOS/Win* filesystem matches both .s and .S the same,
66
# Even though the DOS/Win* filesystem matches both .s and .S the same,
75
# it will preserve the spelling of the filenames, and gcc itself does
67
# it will preserve the spelling of the filenames, and gcc itself does
76
# care about how the name is spelled on its command-line.
68
# care about how the name is spelled on its command-line.
77
ASRC = 
69
ASRC = 
78
 
70
 
79
# List any extra directories to look for include files here.
71
# List any extra directories to look for include files here.
80
#     Each directory must be seperated by a space.
72
#     Each directory must be seperated by a space.
81
EXTRAINCDIRS = 
73
EXTRAINCDIRS = 
82
 
74
 
83
 
75
 
84
# Optional compiler flags.
76
# Optional compiler flags.
85
#  -g:        generate debugging information (for GDB, or for COFF conversion)
77
#  -g:        generate debugging information (for GDB, or for COFF conversion)
86
#  -O*:       optimization level
78
#  -O*:       optimization level
87
#  -f...:     tuning, see gcc manual and avr-libc documentation
79
#  -f...:     tuning, see gcc manual and avr-libc documentation
88
#  -Wall...:  warning level
80
#  -Wall...:  warning level
89
#  -Wa,...:   tell GCC to pass this to the assembler.
81
#  -Wa,...:   tell GCC to pass this to the assembler.
90
#    -ahlms:  create assembler listing
82
#    -ahlms:  create assembler listing
91
CFLAGS = -O$(OPT) \
83
CFLAGS = -O$(OPT) \
92
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
84
-funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums \
93
-Wall -Wstrict-prototypes \
85
-Wall -Wstrict-prototypes \
94
-DGYRO=$(GYRO) \
86
-DGYRO=$(GYRO) \
95
-Wa,-adhlns=$(<:.c=.lst) \
87
-Wa,-adhlns=$(<:.c=.lst) \
96
$(patsubst %,-I%,$(EXTRAINCDIRS))
88
$(patsubst %,-I%,$(EXTRAINCDIRS))
97
 
89
 
98
 
90
 
99
# Set a "language standard" compiler flag.
91
# Set a "language standard" compiler flag.
100
#   Unremark just one line below to set the language standard to use.
92
#   Unremark just one line below to set the language standard to use.
101
#   gnu99 = C99 + GNU extensions. See GCC manual for more information.
93
#   gnu99 = C99 + GNU extensions. See GCC manual for more information.
102
#CFLAGS += -std=c89
94
#CFLAGS += -std=c89
103
#CFLAGS += -std=gnu89
95
#CFLAGS += -std=gnu89
104
#CFLAGS += -std=c99
96
#CFLAGS += -std=c99
105
CFLAGS += -std=gnu99
97
CFLAGS += -std=gnu99
106
 
98
 
107
CFLAGS += -DF_CPU=$(F_CPU) -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_PATCH=$(VERSION_PATCH) -DVERSION_SERIAL_MAJOR=$(VERSION_SERIAL_MAJOR) -DVERSION_SERIAL_MINOR=$(VERSION_SERIAL_MINOR) -DNC_SPI_COMPATIBLE=$(NC_SPI_COMPATIBLE) -DGYRO_HW_NAME=${GYRO_HW_NAME} -DGYRO_HW_FACTOR=${GYRO_HW_FACTOR} -DGYRO_PITCHROLL_CORRECTION=${GYRO_PITCHROLL_CORRECTION} -DGYRO_YAW_CORRECTION=${GYRO_YAW_CORRECTION}
99
CFLAGS += -DF_CPU=$(F_CPU) -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DVERSION_PATCH=$(VERSION_PATCH) -DVERSION_SERIAL_MAJOR=$(VERSION_SERIAL_MAJOR) -DVERSION_SERIAL_MINOR=$(VERSION_SERIAL_MINOR) -DNC_SPI_COMPATIBLE=$(NC_SPI_COMPATIBLE) -DGYRO_HW_NAME=${GYRO_HW_NAME} -DGYRO_HW_FACTOR=${GYRO_HW_FACTOR} -DGYRO_CORRECTION=${GYRO_CORRECTION}
108
 
100
 
109
# Optional assembler flags.
101
# Optional assembler flags.
110
#  -Wa,...:   tell GCC to pass this to the assembler.
102
#  -Wa,...:   tell GCC to pass this to the assembler.
111
#  -ahlms:    create listing
103
#  -ahlms:    create listing
112
#  -gstabs:   have the assembler create line number information; note that
104
#  -gstabs:   have the assembler create line number information; note that
113
#             for use in COFF files, additional information about filenames
105
#             for use in COFF files, additional information about filenames
114
#             and function names needs to be present in the assembler source
106
#             and function names needs to be present in the assembler source
115
#             files -- see avr-libc docs [FIXME: not yet described there]
107
#             files -- see avr-libc docs [FIXME: not yet described there]
116
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
108
ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs 
117
 
109
 
118
# Optional linker flags.
110
# Optional linker flags.
119
#  -Wl,...:   tell GCC to pass this to linker.
111
#  -Wl,...:   tell GCC to pass this to linker.
120
#  -Map:      create map file
112
#  -Map:      create map file
121
#  --cref:    add cross reference to  map file
113
#  --cref:    add cross reference to  map file
122
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
114
LDFLAGS = -Wl,-Map=$(TARGET).map,--cref
123
 
115
 
124
# Additional libraries
116
# Additional libraries
125
 
117
 
126
# Minimalistic printf version
118
# Minimalistic printf version
127
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
119
#LDFLAGS += -Wl,-u,vfprintf -lprintf_min
128
 
120
 
129
# Floating point printf version (requires -lm below)
121
# Floating point printf version (requires -lm below)
130
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
122
#LDFLAGS += -Wl,-u,vfprintf -lprintf_flt
131
 
123
 
132
# -lm = math library
124
# -lm = math library
133
LDFLAGS += -lm
125
LDFLAGS += -lm
134
 
126
 
135
 
127
 
136
##LDFLAGS += -T./linkerfile/avr5.x
128
##LDFLAGS += -T./linkerfile/avr5.x
137
 
129
 
138
 
130
 
139
# Programming support using avrdude. Settings and variables.
131
# Programming support using avrdude. Settings and variables.
140
 
132
 
141
# Programming hardware: alf avr910 avrisp bascom bsd 
133
# Programming hardware: alf avr910 avrisp bascom bsd 
142
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
134
# dt006 pavr picoweb pony-stk200 sp12 stk200 stk500
143
#
135
#
144
# Type: avrdude -c ?
136
# Type: avrdude -c ?
145
# to get a full listing.
137
# to get a full listing.
146
#
138
#
147
#AVRDUDE_PROGRAMMER = dt006
139
#AVRDUDE_PROGRAMMER = dt006
148
#AVRDUDE_PROGRAMMER = stk200
140
#AVRDUDE_PROGRAMMER = stk200
149
#AVRDUDE_PROGRAMMER = ponyser
141
#AVRDUDE_PROGRAMMER = ponyser
150
#AVRDUDE_PROGRAMMER = avrispv2
142
#AVRDUDE_PROGRAMMER = avrispv2
151
AVRDUDE_PROGRAMMER = usbtiny
143
AVRDUDE_PROGRAMMER = usbtiny
152
 
144
 
153
#falls Ponyser ausgewaehlt wird, muss sich unsere avrdude-Configdatei im Bin-Verzeichnis des Compilers befinden
145
#falls Ponyser ausgewaehlt wird, muss sich unsere avrdude-Configdatei im Bin-Verzeichnis des Compilers befinden
154
 
146
 
155
#AVRDUDE_PORT = com1    # programmer connected to serial device
147
#AVRDUDE_PORT = com1    # programmer connected to serial device
156
#AVRDUDE_PORT = lpt1    # programmer connected to parallel port
148
#AVRDUDE_PORT = lpt1    # programmer connected to parallel port
157
AVRDUDE_PORT = usb # programmer connected to USB
149
AVRDUDE_PORT = usb # programmer connected to USB
158
 
150
 
159
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex 
151
#AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex 
160
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_SETTINGS)
152
AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex $(FUSE_SETTINGS)
161
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
153
#AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
162
 
154
 
163
#avrdude -c avrispv2 -P usb -p m32 -U flash:w:blink.hex
155
#avrdude -c avrispv2 -P usb -p m32 -U flash:w:blink.hex
164
AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) -B 1 -F
156
AVRDUDE_FLAGS = -p $(MCU) -c $(AVRDUDE_PROGRAMMER) -B 1 -F
165
 
157
 
166
# Uncomment the following if you want avrdude's erase cycle counter.
158
# Uncomment the following if you want avrdude's erase cycle counter.
167
# Note that this counter needs to be initialized first using -Yn,
159
# Note that this counter needs to be initialized first using -Yn,
168
# see avrdude manual.
160
# see avrdude manual.
169
#AVRDUDE_ERASE += -y
161
#AVRDUDE_ERASE += -y
170
 
162
 
171
# Uncomment the following if you do /not/ wish a verification to be
163
# Uncomment the following if you do /not/ wish a verification to be
172
# performed after programming the device.
164
# performed after programming the device.
173
AVRDUDE_FLAGS += -V
165
AVRDUDE_FLAGS += -V
174
 
166
 
175
# Increase verbosity level.  Please use this when submitting bug
167
# Increase verbosity level.  Please use this when submitting bug
176
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
168
# reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> 
177
# to submit bug reports.
169
# to submit bug reports.
178
#AVRDUDE_FLAGS += -v -v
170
#AVRDUDE_FLAGS += -v -v
179
 
171
 
180
# ---------------------------------------------------------------------------
172
# ---------------------------------------------------------------------------
181
# Define directories, if needed.
173
# Define directories, if needed.
182
DIRAVR = c:/winavr
174
DIRAVR = c:/winavr
183
DIRAVRBIN = $(DIRAVR)/bin
175
DIRAVRBIN = $(DIRAVR)/bin
184
DIRAVRUTILS = $(DIRAVR)/utils/bin
176
DIRAVRUTILS = $(DIRAVR)/utils/bin
185
DIRINC = .
177
DIRINC = .
186
DIRLIB = $(DIRAVR)/avr/lib
178
DIRLIB = $(DIRAVR)/avr/lib
187
 
179
 
188
 
180
 
189
# Define programs and commands.
181
# Define programs and commands.
190
SHELL = sh
182
SHELL = sh
191
 
183
 
192
CC = avr-gcc
184
CC = avr-gcc
193
 
185
 
194
OBJCOPY = avr-objcopy
186
OBJCOPY = avr-objcopy
195
OBJDUMP = avr-objdump
187
OBJDUMP = avr-objdump
196
SIZE = avr-size
188
SIZE = avr-size
197
 
189
 
198
# Programming support using avrdude.
190
# Programming support using avrdude.
199
AVRDUDE = avrdude
191
AVRDUDE = avrdude
200
 
192
 
201
REMOVE = rm -f
193
REMOVE = rm -f
202
COPY = cp
194
COPY = cp
203
 
195
 
204
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
196
HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
205
ELFSIZE = $(SIZE) -A $(TARGET).elf
197
ELFSIZE = $(SIZE) -A $(TARGET).elf
206
 
198
 
207
# Define Messages
199
# Define Messages
208
# English
200
# English
209
MSG_ERRORS_NONE = Errors: none
201
MSG_ERRORS_NONE = Errors: none
210
MSG_BEGIN = -------- begin --------
202
MSG_BEGIN = -------- begin --------
211
MSG_END = --------  end  --------
203
MSG_END = --------  end  --------
212
MSG_SIZE_BEFORE = Size before: 
204
MSG_SIZE_BEFORE = Size before: 
213
MSG_SIZE_AFTER = Size after:
205
MSG_SIZE_AFTER = Size after:
214
MSG_COFF = Converting to AVR COFF:
206
MSG_COFF = Converting to AVR COFF:
215
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
207
MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
216
MSG_FLASH = Creating load file for Flash:
208
MSG_FLASH = Creating load file for Flash:
217
MSG_EEPROM = Creating load file for EEPROM:
209
MSG_EEPROM = Creating load file for EEPROM:
218
MSG_EXTENDED_LISTING = Creating Extended Listing:
210
MSG_EXTENDED_LISTING = Creating Extended Listing:
219
MSG_SYMBOL_TABLE = Creating Symbol Table:
211
MSG_SYMBOL_TABLE = Creating Symbol Table:
220
MSG_LINKING = Linking:
212
MSG_LINKING = Linking:
221
MSG_COMPILING = Compiling:
213
MSG_COMPILING = Compiling:
222
MSG_ASSEMBLING = Assembling:
214
MSG_ASSEMBLING = Assembling:
223
MSG_CLEANING = Cleaning project:
215
MSG_CLEANING = Cleaning project:
224
 
216
 
225
 
217
 
226
# Define all object files.
218
# Define all object files.
227
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
219
OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) 
228
 
220
 
229
# Define all listing files.
221
# Define all listing files.
230
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
222
LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
231
 
223
 
232
# Combine all necessary flags and optional flags.
224
# Combine all necessary flags and optional flags.
233
# Add target processor to flags.
225
# Add target processor to flags.
234
#ALL_CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. $(CFLAGS)
226
#ALL_CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -I. $(CFLAGS)
235
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
227
ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
236
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
228
ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
237
 
229
 
238
 
230
 
239
# Default target.
231
# Default target.
240
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
232
all: begin gccversion sizebefore $(TARGET).elf $(TARGET).hex $(TARGET).eep \
241
	$(TARGET).lss $(TARGET).sym sizeafter finished end
233
	$(TARGET).lss $(TARGET).sym sizeafter finished end
242
 
234
 
243
 
235
 
244
# Eye candy.
236
# Eye candy.
245
# AVR Studio 3.x does not check make's exit code but relies on
237
# AVR Studio 3.x does not check make's exit code but relies on
246
# the following magic strings to be generated by the compile job.
238
# the following magic strings to be generated by the compile job.
247
begin:
239
begin:
248
	@echo
240
	@echo
249
	@echo $(MSG_BEGIN)
241
	@echo $(MSG_BEGIN)
250
 
242
 
251
finished:
243
finished:
252
	@echo $(MSG_ERRORS_NONE)
244
	@echo $(MSG_ERRORS_NONE)
253
 
245
 
254
end:
246
end:
255
	@echo $(MSG_END)
247
	@echo $(MSG_END)
256
	@echo
248
	@echo
257
 
249
 
258
 
250
 
259
# Display size of file.
251
# Display size of file.
260
sizebefore:
252
sizebefore:
261
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
253
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi
262
 
254
 
263
sizeafter:
255
sizeafter:
264
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
256
	@if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi
265
 
257
 
266
 
258
 
267
 
259
 
268
# Display compiler version information.
260
# Display compiler version information.
269
gccversion : 
261
gccversion : 
270
	@$(CC) --version
262
	@$(CC) --version
271
 
263
 
272
 
264
 
273
# Convert ELF to COFF for use in debugging / simulating in
265
# Convert ELF to COFF for use in debugging / simulating in
274
# AVR Studio or VMLAB.
266
# AVR Studio or VMLAB.
275
COFFCONVERT=$(OBJCOPY) --debugging \
267
COFFCONVERT=$(OBJCOPY) --debugging \
276
	--change-section-address .data-0x800000 \
268
	--change-section-address .data-0x800000 \
277
	--change-section-address .bss-0x800000 \
269
	--change-section-address .bss-0x800000 \
278
	--change-section-address .noinit-0x800000 \
270
	--change-section-address .noinit-0x800000 \
279
	--change-section-address .eeprom-0x810000 
271
	--change-section-address .eeprom-0x810000 
280
 
272
 
281
 
273
 
282
coff: $(TARGET).elf
274
coff: $(TARGET).elf
283
	@echo
275
	@echo
284
	@echo $(MSG_COFF) $(TARGET).cof
276
	@echo $(MSG_COFF) $(TARGET).cof
285
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
277
	$(COFFCONVERT) -O coff-avr $< $(TARGET).cof
286
 
278
 
287
 
279
 
288
extcoff: $(TARGET).elf
280
extcoff: $(TARGET).elf
289
	@echo
281
	@echo
290
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
282
	@echo $(MSG_EXTENDED_COFF) $(TARGET).cof
291
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
283
	$(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
292
 
284
 
293
# Program the device.  
285
# Program the device.  
294
program: $(TARGET).hex $(TARGET).eep
286
program: $(TARGET).hex $(TARGET).eep
295
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
287
	$(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
296
 
288
 
297
# Create final output files (.hex, .eep) from ELF output file.
289
# Create final output files (.hex, .eep) from ELF output file.
298
%.hex: %.elf
290
%.hex: %.elf
299
	@echo
291
	@echo
300
	@echo $(MSG_FLASH) $@
292
	@echo $(MSG_FLASH) $@
301
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
293
	$(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
302
 
294
 
303
%.eep: %.elf
295
%.eep: %.elf
304
	@echo
296
	@echo
305
	@echo $(MSG_EEPROM) $@
297
	@echo $(MSG_EEPROM) $@
306
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
298
	-$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
307
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
299
	--change-section-lma .eeprom=0 -O $(FORMAT) $< $@
308
 
300
 
309
# Create extended listing file from ELF output file.
301
# Create extended listing file from ELF output file.
310
%.lss: %.elf
302
%.lss: %.elf
311
	@echo
303
	@echo
312
	@echo $(MSG_EXTENDED_LISTING) $@
304
	@echo $(MSG_EXTENDED_LISTING) $@
313
	$(OBJDUMP) -h -S $< > $@
305
	$(OBJDUMP) -h -S $< > $@
314
 
306
 
315
# Create a symbol table from ELF output file.
307
# Create a symbol table from ELF output file.
316
%.sym: %.elf
308
%.sym: %.elf
317
	@echo
309
	@echo
318
	@echo $(MSG_SYMBOL_TABLE) $@
310
	@echo $(MSG_SYMBOL_TABLE) $@
319
	avr-nm -n $< > $@
311
	avr-nm -n $< > $@
320
 
312
 
321
 
313
 
322
 
314
 
323
# Link: create ELF output file from object files.
315
# Link: create ELF output file from object files.
324
.SECONDARY : $(TARGET).elf
316
.SECONDARY : $(TARGET).elf
325
.PRECIOUS : $(OBJ)
317
.PRECIOUS : $(OBJ)
326
%.elf: $(OBJ)
318
%.elf: $(OBJ)
327
	@echo
319
	@echo
328
	@echo $(MSG_LINKING) $@
320
	@echo $(MSG_LINKING) $@
329
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
321
	$(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
330
 
322
 
331
 
323
 
332
# Compile: create object files from C source files.
324
# Compile: create object files from C source files.
333
%.o : %.c
325
%.o : %.c
334
	@echo
326
	@echo
335
	@echo $(MSG_COMPILING) $<
327
	@echo $(MSG_COMPILING) $<
336
	$(CC) -c $(ALL_CFLAGS) $< -o $@
328
	$(CC) -c $(ALL_CFLAGS) $< -o $@
337
 
329
 
338
 
330
 
339
# Compile: create assembler files from C source files.
331
# Compile: create assembler files from C source files.
340
%.s : %.c
332
%.s : %.c
341
	$(CC) -S $(ALL_CFLAGS) $< -o $@
333
	$(CC) -S $(ALL_CFLAGS) $< -o $@
342
 
334
 
343
 
335
 
344
# Assemble: create object files from assembler source files.
336
# Assemble: create object files from assembler source files.
345
%.o : %.S
337
%.o : %.S
346
	@echo
338
	@echo
347
	@echo $(MSG_ASSEMBLING) $<
339
	@echo $(MSG_ASSEMBLING) $<
348
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
340
	$(CC) -c $(ALL_ASFLAGS) $< -o $@
349
 
341
 
350
 
342
 
351
 
343
 
352
 
344
 
353
 
345
 
354
 
346
 
355
# Target: clean project.
347
# Target: clean project.
356
clean: begin clean_list finished end
348
clean: begin clean_list finished end
357
 
349
 
358
clean_list :
350
clean_list :
359
	@echo
351
	@echo
360
	@echo $(MSG_CLEANING)
352
	@echo $(MSG_CLEANING)
361
#	$(REMOVE) $(TARGET).hex
353
	$(REMOVE) $(TARGET).hex
362
	$(REMOVE) $(TARGET).eep
354
	$(REMOVE) $(TARGET).eep
363
	$(REMOVE) $(TARGET).obj
355
	$(REMOVE) $(TARGET).obj
364
	$(REMOVE) $(TARGET).cof
356
	$(REMOVE) $(TARGET).cof
365
	$(REMOVE) $(TARGET).elf
357
	$(REMOVE) $(TARGET).elf
366
	$(REMOVE) $(TARGET).map
358
	$(REMOVE) $(TARGET).map
367
	$(REMOVE) $(TARGET).obj
359
	$(REMOVE) $(TARGET).obj
368
	$(REMOVE) $(TARGET).a90
360
	$(REMOVE) $(TARGET).a90
369
	$(REMOVE) $(TARGET).sym
361
	$(REMOVE) $(TARGET).sym
370
	$(REMOVE) $(TARGET).lnk
362
	$(REMOVE) $(TARGET).lnk
371
	$(REMOVE) $(TARGET).lss
363
	$(REMOVE) $(TARGET).lss
372
	$(REMOVE) $(OBJ)
364
	$(REMOVE) $(OBJ)
373
	$(REMOVE) $(LST)
365
	$(REMOVE) $(LST)
374
	$(REMOVE) $(SRC:.c=.s)
366
	$(REMOVE) $(SRC:.c=.s)
375
	$(REMOVE) $(SRC:.c=.d)
367
	$(REMOVE) $(SRC:.c=.d)
376
 
368
 
377
 
369
 
378
# Automatically generate C source code dependencies. 
370
# Automatically generate C source code dependencies. 
379
# (Code originally taken from the GNU make user manual and modified 
371
# (Code originally taken from the GNU make user manual and modified 
380
# (See README.txt Credits).)
372
# (See README.txt Credits).)
381
#
373
#
382
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
374
# Note that this will work with sh (bash) and sed that is shipped with WinAVR
383
# (see the SHELL variable defined above).
375
# (see the SHELL variable defined above).
384
# This may not work with other shells or other seds.
376
# This may not work with other shells or other seds.
385
#
377
#
386
%.d: %.c
378
%.d: %.c
387
	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
379
	set -e; $(CC) -MM $(ALL_CFLAGS) $< \
388
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
380
	| sed 's,\(.*\)\.o[ :]*,\1.o \1.d : ,g' > $@; \
389
	[ -s $@ ] || rm -f $@
381
	[ -s $@ ] || rm -f $@
390
 
382
 
391
 
383
 
392
# Remove the '-' if you want to see the dependency files generated.
384
# Remove the '-' if you want to see the dependency files generated.
393
-include $(SRC:.c=.d)
385
-include $(SRC:.c=.d)
394
 
386
 
395
 
387
 
396
 
388
 
397
# Listing of phony targets.
389
# Listing of phony targets.
398
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
390
.PHONY : all begin finish end sizebefore sizeafter gccversion coff extcoff \
399
	clean clean_list program
391
	clean clean_list program
400
 
392