beautify interfacing maschinecode
[pub/USBaspLoader.git] / firmware / Makefile
1 # Name: Makefile
2 # Project: USBaspLoader
3 # Author: Christian Starkjohann
4 # Creation Date: 2007-12-10
5 # Author: Stephan Bärwolf
6 # Improvement Date: 2012-07-31
7 # Tabsize: 4
8 # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
9 # License: GNU GPL v2 (see License.txt)
10
11 ###############################################################################
12 # Configure the following variables according to your AVR.
13 # Program the device with
14 # make fuse # to set the clock generator, boot section size etc.
15 # make flash # to load the boot loader into flash
16 # make lock # to protect the boot loader from overwriting
17
18 F_CPU = 16000000
19 DEVICE = atmega8
20
21 # BOOTLOADER_ADDRESS is 1800 for 8k devices, 3800 for 16k and 7800 for 32k.
22 BOOTLOADER_ADDRESS = 1800
23
24 # PROGRAMMER contains AVRDUDE options to address your programmer
25 # PROGRAMMER = -c pony-stk200
26 PROGRAMMER = -c usbasp
27
28 # since USBaspLoader supports HAVE_BLB11_SOFTW_LOCKBIT...
29 LOCKOPT = -U lock:w:0x3f:m
30 FUSEOPT = $(FUSEOPT_8)
31
32
33 # standard atmega8 needs BODLEVEL to be programed, since it is a 5V device
34 # you may also want to UNprogram SUT1 to get a SLOWER bootup (lfuse then would be 0x3f)
35 FUSEOPT_8 = -U hfuse:w:0xc0:m -U lfuse:w:0x1f:m
36
37 FUSEOPT_88 = -U hfuse:w:0xd6:m -U lfuse:w:0xdf:m -U efuse:w:0x00:m
38 FUSEOPT_168 = -U hfuse:w:0xd6:m -U lfuse:w:0xdf:m -U efuse:w:0x00:m
39 FUSEOPT_328 = -U lfuse:w:0xf7:m -U hfuse:w:0xda:m -U efuse:w:0x03:m
40 # You may have to change the order of these -U commands.
41
42 #---------------------------------------------------------------------
43 # ATMega8
44 #---------------------------------------------------------------------
45 # Fuse high byte:
46 # 0xc0 = 1 1 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
47 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
48 # | | | | | +-------- BOOTSZ1
49 # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
50 # | | | +-------------- CKOPT (full output swing)
51 # | | +---------------- SPIEN (allow serial programming)
52 # | +------------------ WDTON (WDT not always on)
53 # +-------------------- RSTDISBL (reset pin is enabled)
54 # Fuse low byte:
55 # 0x9f = 1 0 0 1 1 1 1 1
56 # ^ ^ \ / \--+--/
57 # | | | +------- CKSEL 3..0 (external >8M crystal)
58 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
59 # | +------------------ BODEN (BrownOut Detector enabled)
60 # +-------------------- BODLEVEL (2.7V)
61 #---------------------------------------------------------------------
62 # ATMega88, ATMega168
63 #---------------------------------------------------------------------
64 # Fuse extended byte:
65 # 0x00 = 0 0 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
66 # \+/
67 # +------- BOOTSZ (00 = 2k bytes)
68 # Fuse high byte:
69 # 0xd6 = 1 1 0 1 0 1 1 0
70 # ^ ^ ^ ^ ^ \-+-/
71 # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
72 # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
73 # | | | +-------------- WDTON (if 0: watchdog always on)
74 # | | +---------------- SPIEN (allow serial programming)
75 # | +------------------ DWEN (debug wire enable)
76 # +-------------------- RSTDISBL (reset pin is enabled)
77 # Fuse low byte:
78 # 0xdf = 1 1 0 1 1 1 1 1
79 # ^ ^ \ / \--+--/
80 # | | | +------- CKSEL 3..0 (external >8M crystal)
81 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
82 # | +------------------ CKOUT (if 0: Clock output enabled)
83 # +-------------------- CKDIV8 (if 0: divide by 8)
84 #---------------------------------------------------------------------
85 # ATMega328P
86 #---------------------------------------------------------------------
87 # Fuse extended byte:
88 # 0x03 = - - - - - 0 1 1
89 # \-+-/
90 # +------ BODLEVEL 0..2 (011 = 4.3V)
91 # Fuse high byte:
92 # 0xda = 1 1 0 1 1 0 1 0 <-- BOOTRST (0 = jump to bootloader at start)
93 # ^ ^ ^ ^ ^ \+/
94 # | | | | | +------- BOOTSZ 0..1 (01 = 2KB starting at 0x7800)
95 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
96 # | | | +-------------- WDTON (1 = watchdog disabled at start)
97 # | | +---------------- SPIEN (0 = allow serial programming)
98 # | +------------------ DWEN (1 = debug wire disable)
99 # +-------------------- RSTDISBL (1 = reset pin is enabled)
100 # Fuse low byte:
101 # 0xf7 = 1 1 1 1 0 1 1 1
102 # ^ ^ \ / \--+--/
103 # | | | +------- CKSEL 3..0 (0111 = external full-swing crystal)
104 # | | +--------------- SUT 1..0 (11 = startup time 16K CK/14K + 65ms)
105 # | +------------------ CKOUT (1 = clock output disabled)
106 # +-------------------- CKDIV8 (1 = do not divide clock by 8)
107
108
109 ###############################################################################
110
111 # Tools:
112 AVRDUDE = @echo avrdude $(PROGRAMMER) -p $(DEVICE)
113 CC = avr-gcc
114
115 # Options:
116 DEFINES = #-DDEBUG_LEVEL=2
117 # Remove the -fno-* options when you use gcc 3, it does not understand them
118 CFLAGS = -Wall -Os -fno-move-loop-invariants -fno-tree-scev-cprop -fno-inline-small-functions -I. -mmcu=$(DEVICE) -DBOOTLOADER_ADDRESS=0x$(BOOTLOADER_ADDRESS) -DF_CPU=$(F_CPU) $(DEFINES)
119 LDFLAGS = -Wl,--relax,--gc-sections -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS)
120
121 OBJECTS = usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
122
123 # symbolic targets:
124 all: main.hex
125
126 install: main.hex
127 cp -Rvp main.hex ./hexfiles/usbasploader.hex
128
129 .c.o:
130 $(CC) $(CFLAGS) -c $< -o $@
131
132 .S.o:
133 $(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@
134 # "-x assembler-with-cpp" should not be necessary since this is the default
135 # file type for the .S (with capital S) extension. However, upper case
136 # characters are not always preserved on Windows. To ensure WinAVR
137 # compatibility define the file type manually.
138
139 .c.s:
140 $(CC) $(CFLAGS) -S $< -o $@
141
142 flash: all
143 $(AVRDUDE) -U flash:w:main.hex:i
144
145 readflash:
146 $(AVRDUDE) -U flash:r:read.hex:i
147
148 fuse:
149 $(AVRDUDE) $(FUSEOPT)
150
151 lock:
152 $(AVRDUDE) $(LOCKOPT)
153
154 read_fuses:
155 $(UISP) --rd_fuses
156
157 deepclean: clean
158 rm -f *~
159
160 clean:
161 rm -f main.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
162
163 # file targets:
164 main.bin: $(OBJECTS)
165 $(CC) $(CFLAGS) -o main.bin $(OBJECTS) $(LDFLAGS)
166
167 main.hex: main.bin
168 rm -f main.hex main.eep.hex
169 avr-objcopy -j .text -j .data -O ihex main.bin main.hex
170 avr-size main.bin
171
172 disasm: main.bin
173 avr-objdump -d main.bin
174
175 cpp:
176 $(CC) $(CFLAGS) -E main.c
177
178 # Special rules for generating hex files for various devices and clock speeds
179 ALLHEXFILES = hexfiles/mega8_12mhz.hex hexfiles/mega8_15mhz.hex hexfiles/mega8_16mhz.hex \
180 hexfiles/mega88_12mhz.hex hexfiles/mega88_15mhz.hex hexfiles/mega88_16mhz.hex hexfiles/mega88_20mhz.hex\
181 hexfiles/mega168_12mhz.hex hexfiles/mega168_15mhz.hex hexfiles/mega168_16mhz.hex hexfiles/mega168_20mhz.hex\
182 hexfiles/mega328p_12mhz.hex hexfiles/mega328p_15mhz.hex hexfiles/mega328p_16mhz.hex hexfiles/mega328p_20mhz.hex
183
184 allhexfiles: $(ALLHEXFILES)
185 $(MAKE) clean
186 avr-size hexfiles/*.hex
187
188 $(ALLHEXFILES):
189 @[ -d hexfiles ] || mkdir hexfiles
190 @device=`echo $@ | sed -e 's|.*/mega||g' -e 's|_.*||g'`; \
191 clock=`echo $@ | sed -e 's|.*_||g' -e 's|mhz.*||g'`; \
192 addr=`echo $$device | sed -e 's/\([0-9]\)8/\1/g' | awk '{printf("%x", ($$1 - 2) * 1024)}'`; \
193 echo "### Make with F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr"; \
194 $(MAKE) clean; \
195 $(MAKE) main.hex F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr DEFINES=-DUSE_AUTOCONFIG=1
196 mv main.hex $@