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