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