]> git.defcon.no Git - avrfbosd/blob - Makefile
Updated to support bootloader programming w/Optiboot.
[avrfbosd] / Makefile
1 # Hey Emacs, this is a -*- makefile -*-
2
3 # AVR-GCC Makefile template, derived from the WinAVR template (which
4 # is public domain), believed to be neutral to any flavor of "make"
5 # (GNU make, BSD make, SysV make)
6 #
7 # Adaptations by Jon Langseth <jon.langseth AT lilug.no>
8 # This modified template is placed in the public domain like the original.
9 #
10
11 #AVRDUDE_PROGRAMMER = usbasp
12 AVRDUDE_PROGRAMMER = usbtiny
13 AVRDUDE_PORT = usb
14
15 AVRDUDE_BL_PROGRAMMER = arduino
16 AVRDUDE_BL_PORT = COM3
17 AVRDUDE_BL_SPEED = 115200
18
19 # Target name and MCU setup -------------------------------------------------
20
21 TARGET = fbosd
22
23 MCU = atmega328p
24
25 # Processor frequency.
26 # This will define a symbol, F_CPU, in all source code files equal to the
27 # processor frequency. You can then use this symbol in your source code to
28 # calculate timings. Do NOT tack on a 'UL' at the end, this will be done
29 # automatically to create a 32-bit value in your source code.
30 # Typical values are:
31 # F_CPU = 1000000
32 # F_CPU = 1843200
33 # F_CPU = 2000000
34 # F_CPU = 3686400
35 # F_CPU = 4000000
36 # F_CPU = 7372800
37 # F_CPU = 8000000
38 # F_CPU = 11059200
39 # F_CPU = 14745600
40 # F_CPU = 16000000
41 # F_CPU = 18432000
42 # F_CPU = 20000000
43
44 # Default settings:
45 #F_CPU = 1000000
46 # Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
47 #FUSE_LOW = 0x62
48 #FUSE_HIGH = 0xD9
49 #FUSE_EXT = 0x7
50
51 # Fancy 20MHz settings:
52 F_CPU = 20000000
53 ## Fuse-bits. Recommended tool: http://www.engbedded.com/fusecalc/
54 FUSE_LOW = 0xAF
55 FUSE_HIGH = 0xD9
56 FUSE_EXT = 0x7
57 FUSE_LOCK = 0x3F
58
59 BL_FUSE_LOW = 0xBF
60 BL_FUSE_HIGH = 0xDE
61 BL_FUSE_EXT = 0x7
62 BL_FUSE_LOCK = 0x2F
63
64 # Source files to compile ---------------------------------------------------
65
66 # List C source files here. (C dependencies are automatically generated.)
67 SRC = $(TARGET).c render.c draw.c
68
69 # List Assembler source files here.
70 # Make them always end in a capital .S.
71 ASRC =
72
73 # Optimization level, can be [0, 1, 2, 3, s].
74 # 0 = turn off optimization. s = optimize for size.
75 # (Note: 3 is not always the best optimization level. See avr-libc FAQ.)
76 OPT = 1
77
78 # Output formats and debug format -------------------------------------------
79
80 # Output format. (can be srec, ihex, binary)
81 FORMAT = ihex
82
83 # Debugging format.
84 # Native formats for AVR-GCC's -g are stabs [default], or dwarf-2.
85 # AVR (extended) COFF requires stabs, plus an avr-objcopy run.
86 DEBUG = dwarf-2
87
88 # Command names (and paths/parameters to them...) ---------------------------
89
90 CC = avr-gcc
91 OBJCOPY = avr-objcopy
92 OBJDUMP = avr-objdump
93 SIZE = avr-size
94 NM = avr-nm
95 AVRDUDE = avrdude
96 REMOVE = rm -f
97 MV = mv -f
98
99 # Compiler flag to set the C Standard level.
100 # c89 - "ANSI" C
101 # gnu89 - c89 plus GCC extensions
102 # c99 - ISO C99 standard (not yet fully implemented)
103 # gnu99 - c99 plus GCC extensions
104 CSTANDARD = -std=gnu99
105
106 # Place -D or -U options here
107 CDEFS = -DF_CPU=$(F_CPU)UL
108
109 # Place -I options here
110 CINCS =
111
112 CFLAGS = -g$(CDEBUG) $(CDEFS) $(CINCS) -O$(OPT) $(CSTANDARD)
113 CFLAGS += -funsigned-char
114 CFLAGS += -funsigned-bitfields
115 CFLAGS += -fpack-struct
116 CFLAGS += -fshort-enums
117 CFLAGS += -Wall
118 CFLAGS += -Wstrict-prototypes
119 #CFLAGS += -mshort-calls
120 #CFLAGS += -fno-unit-at-a-time
121 #CFLAGS += -Wundef
122 #CFLAGS += -Wunreachable-code
123 #CFLAGS += -Wsign-compare
124
125 #ASFLAGS = -Wa,-adhlns=$(<:.S=.lst),-gstabs
126
127
128 #Additional libraries.
129
130 MATH_LIB = -lm
131
132 # Minimalistic printf version
133 PRINTF_LIB_MIN = -Wl,-u,vfprintf -lprintf_min
134
135 # Floating point printf version (requires MATH_LIB = -lm)
136 PRINTF_LIB_FLOAT = -Wl,-u,vfprintf -lprintf_flt
137
138 # If this is left blank, then it will use the Standard printf version.
139 PRINTF_LIB =
140 #PRINTF_LIB = $(PRINTF_LIB_MIN)
141 #PRINTF_LIB = $(PRINTF_LIB_FLOAT)
142
143
144 # Minimalistic scanf version
145 SCANF_LIB_MIN = -Wl,-u,vfscanf -lscanf_min
146
147 # Floating point + %[ scanf version (requires MATH_LIB = -lm)
148 SCANF_LIB_FLOAT = -Wl,-u,vfscanf -lscanf_flt
149
150 # If this is left blank, then it will use the Standard scanf version.
151 SCANF_LIB =
152 #SCANF_LIB = $(SCANF_LIB_MIN)
153 #SCANF_LIB = $(SCANF_LIB_FLOAT)
154
155
156 # External memory options
157
158 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
159 # used for variables (.data/.bss) and heap (malloc()).
160 #EXTMEMOPTS = -Wl,--section-start,.data=0x801100,--defsym=__heap_end=0x80ffff
161
162 # 64 KB of external RAM, starting after internal RAM (ATmega128!),
163 # only used for heap (malloc()).
164 #EXTMEMOPTS = -Wl,--defsym=__heap_start=0x801100,--defsym=__heap_end=0x80ffff
165
166 EXTMEMOPTS =
167
168
169 #LDMAP = $(LDFLAGS) -Wl,-Map=$(TARGET).map,--cref
170 LDFLAGS = $(EXTMEMOPTS) $(LDMAP) $(PRINTF_LIB) $(SCANF_LIB) $(MATH_LIB)
171
172
173 # Programming support using avrdude. Settings and variables.
174
175 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex
176 #AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
177
178
179 # Uncomment the following if you want avrdude's erase cycle counter.
180 # Note that this counter needs to be initialized first using -Yn,
181 # see avrdude manual.
182 #AVRDUDE_ERASE_COUNTER = -y
183
184 # Uncomment the following if you do /not/ wish a verification to be
185 # performed after programming the device.
186 #AVRDUDE_NO_VERIFY = -V
187
188 # Increase verbosity level. Please use this when submitting bug
189 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
190 # to submit bug reports.
191 #AVRDUDE_VERBOSE = -v -v
192
193 AVRDUDE_PROG = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
194 AVRDUDE_FLAGS = $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER)
195
196
197 # Define all object files.
198 OBJ = $(SRC:.c=.o) $(ASRC:.S=.o)
199
200 # Define all listing files.
201 LST = $(ASRC:.S=.lst) $(SRC:.c=.lst)
202
203 # Combine all necessary flags and optional flags.
204 # Add target processor to flags.
205 ALL_CFLAGS = -mmcu=$(MCU) -I. $(CFLAGS)
206 ALL_ASFLAGS = -mmcu=$(MCU) -I. -x assembler-with-cpp $(ASFLAGS)
207
208
209 # Default target.
210 all: build
211
212 build: elf hex eep size
213
214 elf: $(TARGET).elf
215 hex: $(TARGET).hex
216 eep: $(TARGET).eep
217 lss: $(TARGET).lss
218 sym: $(TARGET).sym
219
220 # Display size of file.
221 HEXSIZE = $(SIZE) --target=$(FORMAT) $(TARGET).hex
222 ELFSIZE = $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
223
224 size:
225 @echo
226 $(SIZE) --mcu=$(MCU) --format=avr $(TARGET).elf
227 $(SIZE) --target=$(FORMAT) $(TARGET).hex
228
229 # Program the device.
230 program: $(TARGET).hex $(TARGET).eep
231 $(AVRDUDE) -p $(MCU) $(AVRDUDE_PROG) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) $(AVRDUDE_WRITE_EEPROM)
232
233 bl_program: $(TARGET).hex $(TARGET).eep
234 $(AVRDUDE) -p $(MCU) -c $(AVRDUDE_BL_PROGRAMMER) -P $(AVRDUDE_BL_PORT) -b $(AVRDUDE_BL_SPEED) $(AVRDUDE_NO_VERIFY) $(AVRDUDE_VERBOSE) $(AVRDUDE_ERASE_COUNTER) $(AVRDUDE_WRITE_FLASH)
235
236 # make fuseread can be used to test programmer connectivity, and naturally to verify fuses..
237 fuseread:
238 $(AVRDUDE) -p $(MCU) $(AVRDUDE_PROG) -q -U lfuse:r:-:h -U hfuse:r:-:h -U efuse:r:-:h
239
240 FUSES =
241 ifdef FUSE_EXT
242 FUSES += -U efuse:w:$(FUSE_EXT):m
243 endif
244 FUSES += -U efuse:w:$(FUSE_EXT):m
245 FUSES += -U lfuse:w:$(FUSE_LOW):m
246
247 fusebits: $(TARGET).hex
248 $(AVRDUDE) -p $(MCU) $(AVRDUDE_PROG) $(FUSES)
249
250 lockbits: $(TARGET).hex
251 $(AVRDUDE) -p $(MCU) $(AVRDUDE_PROG) -e -u -U lock:w:$(FUSE_LOCK):m
252
253 bl_fusebits: $(TARGET).hex
254 $(AVRDUDE) -p $(MCU) $(AVRDUDE_PROG) -U efuse:w:$(BL_FUSE_EXT):m -U efuse:w:$(BL_FUSE_EXT):m -U lfuse:w:$(BL_FUSE_LOW):m
255
256 bl_lockbits: $(TARGET).hex
257 $(AVRDUDE)-p $(MCU) $(AVRDUDE_PROG) -e -u -U lock:w:$(BL_FUSE_LOCK):m
258
259 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
260 COFFCONVERT=$(OBJCOPY) --debugging \
261 --change-section-address .data-0x800000 \
262 --change-section-address .bss-0x800000 \
263 --change-section-address .noinit-0x800000 \
264 --change-section-address .eeprom-0x810000
265
266 coff: $(TARGET).elf
267 $(COFFCONVERT) -O coff-avr $(TARGET).elf $(TARGET).cof
268
269
270 extcoff: $(TARGET).elf
271 $(COFFCONVERT) -O coff-ext-avr $(TARGET).elf $(TARGET).cof
272
273
274 .SUFFIXES: .elf .hex .eep .lss .sym
275
276 .elf.hex:
277 $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
278
279 .elf.eep:
280 -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
281 --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
282
283 # Create extended listing file from ELF output file.
284 .elf.lss:
285 $(OBJDUMP) -h -S $< > $@
286
287 # Create a symbol table from ELF output file.
288 .elf.sym:
289 $(NM) -n $< > $@
290
291
292
293 # Link: create ELF output file from object files.
294 $(TARGET).elf: $(OBJ)
295 $(CC) $(ALL_CFLAGS) $(OBJ) --output $@ $(LDFLAGS)
296
297
298 # Compile: create object files from C source files.
299 .c.o:
300 $(CC) -c $(ALL_CFLAGS) $< -o $@
301
302
303 # Compile: create assembler files from C source files.
304 .c.s:
305 $(CC) -S $(ALL_CFLAGS) $< -o $@
306
307
308 # Assemble: create object files from assembler source files.
309 .S.o:
310 $(CC) -c $(ALL_ASFLAGS) $< -o $@
311
312
313
314 # Target: clean project.
315 clean:
316 $(REMOVE) $(TARGET).hex $(TARGET).eep $(TARGET).cof $(TARGET).elf \
317 $(TARGET).map $(TARGET).sym $(TARGET).lss \
318 $(OBJ) $(LST) $(SRC:.c=.s) $(SRC:.c=.d)
319
320 # Name of this Makefile (used for "make depend").
321 MAKEFILE = Makefile
322
323 depend:
324 if grep '^# DO NOT DELETE' $(MAKEFILE) >/dev/null; \
325 then \
326 sed -e '/^# DO NOT DELETE/,$$d' $(MAKEFILE) > \
327 $(MAKEFILE).$$$$ && \
328 $(MV) $(MAKEFILE).$$$$ $(MAKEFILE); \
329 fi
330 echo '# DO NOT DELETE THIS LINE -- make depend depends on it.' \
331 >> $(MAKEFILE); \
332 $(CC) -M -mmcu=$(MCU) $(CDEFS) $(CINCS) $(SRC) $(ASRC) >> $(MAKEFILE)
333
334 .PHONY: all build elf hex eep lss sym program coff extcoff clean depend
335