Subversion Repositories FlightCtrl

Rev

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

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