Subversion Repositories FlightCtrl

Rev

Rev 1544 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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