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