]> defiant.homedns.org Git - ros_wild_thumper.git/blob - avr/motor_ctrl/Makefile
avr: increase clk to 8MHz
[ros_wild_thumper.git] / avr / motor_ctrl / Makefile
1 # Hey Emacs, this is a -*- makefile -*-\r
2 #\r
3 # WinAVR makefile written by Eric B. Weddington, Jörg Wunsch, et al.\r
4 # Released to the Public Domain\r
5 # Please read the make user manual!\r
6 #\r
7 # Additional material for this makefile was submitted by:\r
8 #  Tim Henigan\r
9 #  Peter Fleury\r
10 #  Reiner Patommel\r
11 #  Sander Pool\r
12 #  Frederik Rouleau\r
13 #  Markus Pfaff\r
14 #\r
15 # On command line:\r
16 #\r
17 # make all = Make software.\r
18 #\r
19 # make clean = Clean out built project files.\r
20 #\r
21 # make coff = Convert ELF to AVR COFF (for use with AVR Studio 3.x or VMLAB).\r
22 #\r
23 # make extcoff = Convert ELF to AVR Extended COFF (for use with AVR Studio\r
24 #                4.07 or greater).\r
25 #\r
26 # make program = Download the hex file to the device, using avrdude.  Please\r
27 #                customize the avrdude settings below first!\r
28 #\r
29 # make filename.s = Just compile filename.c into the assembler code only\r
30 #\r
31 # To rebuild project do "make clean" then "make all".\r
32 #\r
33 \r
34 # mth 2004/09 \r
35 # Differences from WinAVR 20040720 sample:\r
36 # - DEPFLAGS according to Eric Weddingtion's fix (avrfreaks/gcc-forum)\r
37 # - F_OSC Define in CFLAGS and AFLAGS\r
38 \r
39 \r
40 # MCU name\r
41 MCU = atmega32\r
42 \r
43 # Main Oscillator Frequency\r
44 # This is only used to define F_OSC in all assembler and c-sources.\r
45 F_OSC = 3686400\r
46 \r
47 # Output format. (can be srec, ihex, binary)\r
48 FORMAT = ihex\r
49 \r
50 # Target file name (without extension).\r
51 TARGET = main\r
52 \r
53 \r
54 # List C source files here. (C dependencies are automatically generated.)\r
55 SRC = $(TARGET).c uart.c\r
56 \r
57 \r
58 # List Assembler source files here.\r
59 # Make them always end in a capital .S.  Files ending in a lowercase .s\r
60 # will not be considered source files but generated files (assembler\r
61 # output from the compiler), and will be deleted upon "make clean"!\r
62 # Even though the DOS/Win* filesystem matches both .s and .S the same,\r
63 # it will preserve the spelling of the filenames, and gcc itself does\r
64 # care about how the name is spelled on its command-line.\r
65 ASRC = \r
66 \r
67 \r
68 \r
69 # Optimization level, can be [0, 1, 2, 3, s]. \r
70 # 0 = turn off optimization. s = optimize for size.\r
71 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)\r
72 OPT = s\r
73 \r
74 # Debugging format.\r
75 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.\r
76 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.\r
77 DEBUG = stabs\r
78 #DEBUG = dwarf-2\r
79 \r
80 # List any extra directories to look for include files here.\r
81 #     Each directory must be seperated by a space.\r
82 EXTRAINCDIRS = \r
83 \r
84 \r
85 # Compiler flag to set the C Standard level.\r
86 # c89   - "ANSI" C\r
87 # gnu89 - c89 plus GCC extensions\r
88 # c99   - ISO C99 standard (not yet fully implemented)\r
89 # gnu99 - c99 plus GCC extensions\r
90 CSTANDARD = -std=gnu99\r
91 \r
92 # Place -D or -U options here\r
93 CDEFS = -DF_CPU=8000000\r
94 \r
95 # Place -I options here\r
96 CINCS = -Ii2c/\r
97 \r
98 \r
99 # Compiler flags.\r
100 #  -g*:          generate debugging information\r
101 #  -O*:          optimization level\r
102 #  -f...:        tuning, see GCC manual and avr-libc documentation\r
103 #  -Wall...:     warning level\r
104 #  -Wa,...:      tell GCC to pass this to the assembler.\r
105 #    -adhlns...: create assembler listing\r
106 CFLAGS = -g$(DEBUG)\r
107 CFLAGS += $(CDEFS) $(CINCS)\r
108 CFLAGS += -O$(OPT)\r
109 CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums\r
110 CFLAGS += -Wall -Wstrict-prototypes\r
111 CFLAGS += -Wa,-adhlns=$(<:.c=.lst)\r
112 CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))\r
113 CFLAGS += $(CSTANDARD)\r
114 CFLAGS += -DF_OSC=$(F_OSC)\r
115 \r
116 \r
117 \r
118 # Assembler flags.\r
119 #  -Wa,...:   tell GCC to pass this to the assembler.\r
120 #  -ahlms:    create listing\r
121 #  -gstabs:   have the assembler create line number information; note that\r
122 #             for use in COFF files, additional information about filenames\r
123 #             and function names needs to be present in the assembler source\r
124 #             files -- see avr-libc docs [FIXME: not yet described there]\r
125 ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs \r
126 ASFLAGS += -DF_OSC=$(F_OSC)\r
127 \r
128 \r
129 #Additional libraries.\r
130 \r
131 # Minimalistic printf version\r
132 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min\r
133 \r
134 # Floating point printf version (requires MATH_LIB = -lm below)\r
135 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt -lm\r
136 \r
137 PRINTF_LIB = \r
138 \r
139 # Minimalistic scanf version\r
140 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min\r
141 \r
142 # Floating point + %[ scanf version (requires MATH_LIB = -lm below)\r
143 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt\r
144 \r
145 SCANF_LIB = \r
146 \r
147 MATH_LIB = -lm\r
148 \r
149 # External memory options\r
150 \r
151 # 64 KB of external RAM, starting after internal RAM (ATmega128!),\r
152 # used for variables (.data/.bss) and heap (malloc()).\r
153 #EXTMEMOPTS = -Wl,-Tdata=0x801100,--defsym=__heap_end=0x80ffff\r
154 \r
155 # 64 KB of external RAM, starting after internal RAM (ATmega128!),\r
156 # only used for heap (malloc()).\r
157 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff\r
158 \r
159 EXTMEMOPTS =\r
160 \r
161 # Linker flags.\r
162 #  -Wl,...:     tell GCC to pass this to linker.\r
163 #    -Map:      create map file\r
164 #    --cref:    add cross reference to  map file\r
165 LDFLAGS = -Wl,-Map=$(TARGET).map,--cref\r
166 LDFLAGS += $(EXTMEMOPTS)\r
167 LDFLAGS += $(PRINTF_LIB_MIN) $(SCANF_LIB) $(MATH_LIB)\r
168 \r
169 \r
170 \r
171 \r
172 # Programming support using avrdude. Settings and variables.\r
173 \r
174 # Programming hardware: alf avr910 avrisp bascom bsd \r
175 # dt006 pavr picoweb pony-stk200 sp12 stk200 stk500\r
176 #\r
177 # Type: avrdude -c ?\r
178 # to get a full listing.\r
179 #\r
180 #AVRDUDE_PROGRAMMER = avr911\r
181 AVRDUDE_PROGRAMMER = avrisp2\r
182 \r
183 # com1 = serial port. Use lpt1 to connect to parallel port.\r
184 #AVRDUDE_PORT = /dev/ttyUSB0    # programmer connected to serial device\r
185 AVRDUDE_PORT = usb    # programmer connected to serial device\r
186 \r
187 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex\r
188 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep\r
189 \r
190 \r
191 # Uncomment the following if you want avrdude's erase cycle counter.\r
192 # Note that this counter needs to be initialized first using -Yn,\r
193 # see avrdude manual.\r
194 #AVRDUDE_ERASE_COUNTER = -y\r
195 \r
196 # Uncomment the following if you do /not/ wish a verification to be\r
197 # performed after programming the device.\r
198 #AVRDUDE_NO_VERIFY = -V\r
199 \r
200 # Increase verbosity level.  Please use this when submitting bug\r
201 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude> \r
202 # to submit bug reports.\r
203 #AVRDUDE_VERBOSE = -v -v\r
204 \r
205 AVRDUDE_FLAGS = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)\r
206 AVRDUDE_FLAGS += $(AVRDUDE_NO_VERIFY)\r
207 AVRDUDE_FLAGS += $(AVRDUDE_VERBOSE)\r
208 AVRDUDE_FLAGS += $(AVRDUDE_ERASE_COUNTER)\r
209 \r
210 \r
211 \r
212 # ---------------------------------------------------------------------------\r
213 \r
214 # Define directories, if needed.\r
215 DIRAVR = c:/winavr\r
216 DIRAVRBIN = $(DIRAVR)/bin\r
217 DIRAVRUTILS = $(DIRAVR)/utils/bin\r
218 DIRINC = .\r
219 DIRLIB = $(DIRAVR)/avr/lib\r
220 \r
221 \r
222 # Define programs and commands.\r
223 SHELL = sh\r
224 CC = avr-gcc\r
225 OBJCOPY = avr-objcopy\r
226 OBJDUMP = avr-objdump\r
227 SIZE = avr-size\r
228 NM = avr-nm\r
229 AVRDUDE = avrdude\r
230 REMOVE = rm -f\r
231 COPY = cp\r
232 \r
233 \r
234 \r
235 \r
236 # Define Messages\r
237 # English\r
238 MSG_ERRORS_NONE = Errors: none\r
239 MSG_BEGIN = -------- begin --------\r
240 MSG_END = --------  end  --------\r
241 MSG_SIZE_BEFORE = Size before: \r
242 MSG_SIZE_AFTER = Size after:\r
243 MSG_COFF = Converting to AVR COFF:\r
244 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:\r
245 MSG_FLASH = Creating load file for Flash:\r
246 MSG_EEPROM = Creating load file for EEPROM:\r
247 MSG_EXTENDED_LISTING = Creating Extended Listing:\r
248 MSG_SYMBOL_TABLE = Creating Symbol Table:\r
249 MSG_LINKING = Linking:\r
250 MSG_COMPILING = Compiling:\r
251 MSG_ASSEMBLING = Assembling:\r
252 MSG_CLEANING = Cleaning project:\r
253 \r
254 \r
255 \r
256 \r
257 # Define all object files.\r
258 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o) \r
259 \r
260 # Define all listing files.\r
261 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)\r
262 \r
263 \r
264 # Compiler flags to generate dependency files.\r
265 ### GENDEPFLAGS = -Wp,-M,-MP,-MT,$(*F).o,-MF,.dep/$(@F).d\r
266 GENDEPFLAGS = -MD -MP -MF .dep/$(@F).d\r
267 \r
268 # Combine all necessary flags and optional flags.\r
269 # Add target processor to flags.\r
270 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS) $(GENDEPFLAGS)\r
271 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)\r
272 \r
273 \r
274 \r
275 \r
276 \r
277 # Default target.\r
278 all: begin gccversion sizebefore build sizeafter finished end\r
279 \r
280 build: elf hex eep lss sym\r
281 \r
282 elf: $(TARGET).elf\r
283 hex: $(TARGET).hex\r
284 eep: $(TARGET).eep\r
285 lss: $(TARGET).lss \r
286 sym: $(TARGET).sym\r
287 \r
288 \r
289 \r
290 # Eye candy.\r
291 # AVR Studio 3.x does not check make's exit code but relies on\r
292 # the following magic strings to be generated by the compile job.\r
293 begin:\r
294         @echo\r
295         @echo $(MSG_BEGIN)\r
296 \r
297 finished:\r
298         @echo $(MSG_ERRORS_NONE)\r
299 \r
300 end:\r
301         @echo $(MSG_END)\r
302         @echo\r
303 \r
304 \r
305 # Display size of file.\r
306 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex\r
307 ELFSIZE = $(SIZE) -A $(TARGET).elf\r
308 sizebefore:\r
309         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_BEFORE); $(ELFSIZE); echo; fi\r
310 \r
311 sizeafter:\r
312         @if [ -f $(TARGET).elf ]; then echo; echo $(MSG_SIZE_AFTER); $(ELFSIZE); echo; fi\r
313 \r
314 \r
315 \r
316 # Display compiler version information.\r
317 gccversion : \r
318         @$(CC) --version\r
319 \r
320 \r
321 \r
322 # Program the device.  \r
323 program: $(TARGET).hex $(TARGET).eep\r
324         $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)\r
325 \r
326 \r
327 \r
328 \r
329 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.\r
330 COFFCONVERT=$(OBJCOPY) --debugging \\r
331 --change-section-address .data-0x800000 \\r
332 --change-section-address .bss-0x800000 \\r
333 --change-section-address .noinit-0x800000 \\r
334 --change-section-address .eeprom-0x810000 \r
335 \r
336 \r
337 coff: $(TARGET).elf\r
338         @echo\r
339         @echo $(MSG_COFF) $(TARGET).cof\r
340         $(COFFCONVERT) -O coff-avr $< $(TARGET).cof\r
341 \r
342 \r
343 extcoff: $(TARGET).elf\r
344         @echo\r
345         @echo $(MSG_EXTENDED_COFF) $(TARGET).cof\r
346         $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof\r
347 \r
348 \r
349 \r
350 # Create final output files (.hex, .eep) from ELF output file.\r
351 %.hex: %.elf\r
352         @echo\r
353         @echo $(MSG_FLASH) $@\r
354         $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@\r
355 \r
356 %.eep: %.elf\r
357         @echo\r
358         @echo $(MSG_EEPROM) $@\r
359         -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \\r
360         --change-section-lma .eeprom=0 -O $(FORMAT) $< $@\r
361 \r
362 # Create extended listing file from ELF output file.\r
363 %.lss: %.elf\r
364         @echo\r
365         @echo $(MSG_EXTENDED_LISTING) $@\r
366         $(OBJDUMP) -h -S $< > $@\r
367 \r
368 # Create a symbol table from ELF output file.\r
369 %.sym: %.elf\r
370         @echo\r
371         @echo $(MSG_SYMBOL_TABLE) $@\r
372         $(NM) -n $< > $@\r
373 \r
374 \r
375 \r
376 # Link: create ELF output file from object files.\r
377 .SECONDARY : $(TARGET).elf\r
378 .PRECIOUS : $(OBJ)\r
379 %.elf: $(OBJ)\r
380         @echo\r
381         @echo $(MSG_LINKING) $@\r
382         $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)\r
383 \r
384 \r
385 # Compile: create object files from C source files.\r
386 %.o : %.c\r
387         @echo\r
388         @echo $(MSG_COMPILING) $<\r
389         $(CC) -c $(ALL_CFLAGS) $< -o $@ \r
390 \r
391 \r
392 # Compile: create assembler files from C source files.\r
393 %.s : %.c\r
394         $(CC) -S $(ALL_CFLAGS) $< -o $@\r
395 \r
396 \r
397 # Assemble: create object files from assembler source files.\r
398 %.o : %.S\r
399         @echo\r
400         @echo $(MSG_ASSEMBLING) $<\r
401         $(CC) -c $(ALL_ASFLAGS) $< -o $@\r
402 \r
403 \r
404 \r
405 # Target: clean project.\r
406 clean: begin clean_list finished end\r
407 \r
408 clean_list :\r
409         @echo\r
410         @echo $(MSG_CLEANING)\r
411         $(REMOVE) $(TARGET).hex\r
412         $(REMOVE) $(TARGET).eep\r
413         $(REMOVE) $(TARGET).obj\r
414         $(REMOVE) $(TARGET).cof\r
415         $(REMOVE) $(TARGET).elf\r
416         $(REMOVE) $(TARGET).map\r
417         $(REMOVE) $(TARGET).obj\r
418         $(REMOVE) $(TARGET).a90\r
419         $(REMOVE) $(TARGET).sym\r
420         $(REMOVE) $(TARGET).lnk\r
421         $(REMOVE) $(TARGET).lss\r
422         $(REMOVE) $(OBJ)\r
423         $(REMOVE) $(LST)\r
424         $(REMOVE) $(SRC:.c=.s)\r
425         $(REMOVE) $(SRC:.c=.d)\r
426         $(REMOVE) .dep/*\r
427 \r
428 \r
429 \r
430 # Include the dependency files.\r
431 -include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)\r
432 \r
433 \r
434 # Listing of phony targets.\r
435 .PHONY : all begin finish end sizebefore sizeafter gccversion \\r
436 build elf hex eep lss sym coff extcoff \\r
437 clean clean_list program\r
438 \r