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