3471 |
miho |
1 |
# |
|
|
2 |
# Makefile for usbasp |
|
|
3 |
# 20061119 Thomas Fischl original |
|
|
4 |
# 20061120 Hanns-Konrad Unger help: and TARGET=atmega48 added |
3472 |
miho |
5 |
# 20140209 Milan Horkel added automatic built for more targets |
3471 |
miho |
6 |
|
3472 |
miho |
7 |
ALL_TARGETS=atmega8 atmega88 |
3471 |
miho |
8 |
|
3472 |
miho |
9 |
# Default target |
|
|
10 |
# -------------- |
3471 |
miho |
11 |
|
3472 |
miho |
12 |
ifndef $(TARGET) |
|
|
13 |
TARGET=atmega88 |
|
|
14 |
endif |
|
|
15 |
|
|
|
16 |
|
|
|
17 |
# Define target dependent constants |
|
|
18 |
# --------------------------------- |
|
|
19 |
|
|
|
20 |
ifeq ($(TARGET), atmega8) |
3488 |
miho |
21 |
HFUSE=0xC9 |
|
|
22 |
LFUSE=0x9F |
3472 |
miho |
23 |
endif |
|
|
24 |
|
3488 |
miho |
25 |
ifeq ($(TARGET), atmega88) |
|
|
26 |
EFUSE=0xF9 |
|
|
27 |
HFUSE=0xDE |
|
|
28 |
LFUSE=0xD7 |
3472 |
miho |
29 |
endif |
|
|
30 |
|
|
|
31 |
|
3471 |
miho |
32 |
# ISP=bsd PORT=/dev/parport0 |
|
|
33 |
# ISP=ponyser PORT=/dev/ttyS1 |
|
|
34 |
# ISP=stk500 PORT=/dev/ttyS1 |
|
|
35 |
# ISP=usbasp PORT=/dev/usb/ttyUSB0 |
|
|
36 |
# ISP=stk500v2 PORT=/dev/ttyUSB0 |
|
|
37 |
ISP=usbasp |
|
|
38 |
PORT=/dev/usb/ttyUSB0 |
|
|
39 |
|
|
|
40 |
help: |
|
|
41 |
@echo "Usage: make same as make help" |
|
|
42 |
@echo " make help same as make" |
3472 |
miho |
43 |
@echo " make all build HEX for all target CPUs" |
|
|
44 |
@echo " make hex create HEX for default target CPU" |
3471 |
miho |
45 |
@echo " make clean remove redundant data" |
3472 |
miho |
46 |
@echo " make disasm create listing" |
|
|
47 |
@echo " make flash upload HEX into flash (for default target CPU)" |
|
|
48 |
@echo " make fuses program fuses (for default target CPU)" |
3471 |
miho |
49 |
@echo " make avrdude test avrdude" |
|
|
50 |
@echo "Current values:" |
|
|
51 |
@echo " TARGET=${TARGET}" |
|
|
52 |
@echo " LFUSE=${LFUSE}" |
|
|
53 |
@echo " HFUSE=${HFUSE}" |
|
|
54 |
@echo " CLOCK=12000000" |
|
|
55 |
@echo " ISP=${ISP}" |
|
|
56 |
@echo " PORT=${PORT}" |
|
|
57 |
|
|
|
58 |
COMPILE = avr-gcc -Wall -O2 -Iusbdrv -I. -mmcu=$(TARGET) # -DDEBUG_LEVEL=2 |
|
|
59 |
|
|
|
60 |
OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o isp.o clock.o tpi.o main.o |
|
|
61 |
|
|
|
62 |
.c.o: |
|
|
63 |
$(COMPILE) -c $< -o $@ |
|
|
64 |
#-Wa,-ahlms=$<.lst |
|
|
65 |
|
|
|
66 |
.S.o: |
|
|
67 |
$(COMPILE) -x assembler-with-cpp -c $< -o $@ |
|
|
68 |
# "-x assembler-with-cpp" should not be necessary since this is the default |
|
|
69 |
# file type for the .S (with capital S) extension. However, upper case |
|
|
70 |
# characters are not always preserved on Windows. To ensure WinAVR |
|
|
71 |
# compatibility define the file type manually. |
|
|
72 |
|
|
|
73 |
.c.s: |
|
|
74 |
$(COMPILE) -S $< -o $@ |
|
|
75 |
|
3472 |
miho |
76 |
cleantmp: |
|
|
77 |
rm -f usbasp.lst usbasp.obj usbasp.cof usbasp.list usbasp.map usbasp.bin *.o main.s usbdrv/*.o |
3471 |
miho |
78 |
|
3472 |
miho |
79 |
clean: cleantmp |
|
|
80 |
rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex |
|
|
81 |
|
3471 |
miho |
82 |
# file targets: |
3472 |
miho |
83 |
usbasp.bin: $(OBJECTS) |
|
|
84 |
$(COMPILE) -o usbasp.bin $(OBJECTS) -Wl,-Map,usbasp.map |
3471 |
miho |
85 |
|
3472 |
miho |
86 |
usbasp.hex: usbasp_$(TARGET).hex |
|
|
87 |
|
|
|
88 |
usbasp_$(TARGET).hex: usbasp.bin |
|
|
89 |
rm -f usbasp_$(TARGET).hex usbasp_$(TARGET).eep.hex |
|
|
90 |
avr-objcopy -j .text -j .data -O ihex usbasp.bin $@ |
|
|
91 |
# ./checksize usbasp.bin |
3471 |
miho |
92 |
# do the checksize script as our last action to allow successful compilation |
|
|
93 |
# on Windows with WinAVR where the Unix commands will fail. |
|
|
94 |
|
3472 |
miho |
95 |
disasm: usbasp.bin |
|
|
96 |
avr-objdump -d usbasp.bin |
3471 |
miho |
97 |
|
|
|
98 |
cpp: |
|
|
99 |
$(COMPILE) -E main.c |
|
|
100 |
|
|
|
101 |
flash: |
3472 |
miho |
102 |
avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -U flash:w:usbasp.hex |
3471 |
miho |
103 |
|
|
|
104 |
fuses: |
|
|
105 |
avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -u -U hfuse:w:$(HFUSE):m -U lfuse:w:$(LFUSE):m |
|
|
106 |
|
|
|
107 |
avrdude: |
|
|
108 |
avrdude -c ${ISP} -p ${TARGET} -P ${PORT} -v |
|
|
109 |
|
3488 |
miho |
110 |
# Fuse atmega8 |
|
|
111 |
# ------------ |
3471 |
miho |
112 |
# Fuse atmega8 high byte HFUSE: |
3488 |
miho |
113 |
# 0xD9 = 1 1 0 1 1 0 0 1 = Factory Default Value |
|
|
114 |
# 0xC9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000) |
3471 |
miho |
115 |
# ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0 |
|
|
116 |
# | | | | | +-------- BOOTSZ1 |
|
|
117 |
# | | | | + --------- EESAVE (don't preserve EEPROM over chip erase) |
|
|
118 |
# | | | +-------------- CKOPT (full output swing) |
|
|
119 |
# | | +---------------- SPIEN (allow serial programming) |
|
|
120 |
# | +------------------ WDTON (WDT not always on) |
|
|
121 |
# +-------------------- RSTDISBL (reset pin is enabled) |
|
|
122 |
# Fuse atmega8 low byte LFUSE: |
3488 |
miho |
123 |
# 0xE1 = 1 1 1 0 0 0 0 1 = Factory Default Value |
|
|
124 |
# 0x9F = 1 0 0 1 1 1 1 1 |
3471 |
miho |
125 |
# ^ ^ \ / \--+--/ |
|
|
126 |
# | | | +------- CKSEL 3..0 (external >8M crystal) |
|
|
127 |
# | | +--------------- SUT 1..0 (crystal osc, BOD enabled) |
|
|
128 |
# | +------------------ BODEN (BrownOut Detector enabled) |
|
|
129 |
# +-------------------- BODLEVEL (2.7V) |
|
|
130 |
# |
3488 |
miho |
131 |
# Fuse atmega88 |
|
|
132 |
# ------------- |
|
|
133 |
# Fuse atmega88 extended byte: |
|
|
134 |
# 0xF9 = 1 1 1 1 1 0 0 1 = Factory Default Value (default value is used) |
|
|
135 |
# 0xF9 = 1 1 1 1 1 0 0 1 <-- BOOTRST (select vetor) |
|
|
136 |
# \+/ |
|
|
137 |
# +----- BOOTSZ1..0 (Select Boot Size) |
|
|
138 |
# Fuse high byte: |
|
|
139 |
# 0xDF 1 1 0 1 1 1 1 1 = Factory Default Value (default value may be used) |
|
|
140 |
# 0xDE = 1 1 0 1 1 1 1 0 |
3471 |
miho |
141 |
# ^ ^ ^ ^ ^ \-+-/ |
3488 |
miho |
142 |
# | | | | | +------ BODLEVEL (1.7-2.0V) |
|
|
143 |
# | | | | +---------- EESAVE (don't preserve EEPROM over chip erase) |
3471 |
miho |
144 |
# | | | +-------------- WDTON (WDT not always on) |
3488 |
miho |
145 |
# | | +---------------- SPIEN (allow serial programming)!!! |
|
|
146 |
# | +------------------ DWEN (debug wire not enabled) |
|
|
147 |
# +-------------------- RSTDISBL (reset pin is not disabled) |
|
|
148 |
# Fuse low byte: |
|
|
149 |
# 0x62 0 1 1 0 0 0 1 0 = Factory Default Value (must be programmed to use xosc) |
|
|
150 |
# 0xD7 = 1 1 0 1 0 1 1 1 |
3471 |
miho |
151 |
# ^ ^ \ / \--+--/ |
3488 |
miho |
152 |
# | | | +------- CKSEL 3..0 (full swing xosc, BOD enabled) |
|
|
153 |
# | | +--------------- SUT 1..0 (startup timer - see CKSEL) |
|
|
154 |
# | +------------------ CKOUT (clock output is not enabled) |
|
|
155 |
# +-------------------- CLKDIV8 (clock divider is not enabled) |
3471 |
miho |
156 |
|
|
|
157 |
|
3488 |
miho |
158 |
|
3471 |
miho |
159 |
SERIAL = `echo /dev/tty.USA19QI*` |
|
|
160 |
UISP = uisp -dprog=$S -dserial=$(SERIAL) -dpart=auto |
|
|
161 |
# The two lines above are for "uisp" and the AVR910 serial programmer connected |
|
|
162 |
# to a Keyspan USB to serial converter to a Mac running Mac OS X. |
|
|
163 |
# Choose your favorite programmer and interface. |
|
|
164 |
|
|
|
165 |
uisp: all |
|
|
166 |
$(UISP) --erase |
3472 |
miho |
167 |
$(UISP) --upload --verify if=usbasp_$(TARGET).hex |
3471 |
miho |
168 |
|
3472 |
miho |
169 |
# Execute these steps for each target CPU |
|
|
170 |
# Do not remove empty line in this definition! |
|
|
171 |
define EXEC |
|
|
172 |
rm -f usbasp_$(1).hex |
|
|
173 |
make TARGET=$(1) cleantmp |
|
|
174 |
make TARGET=$(1) usbasp_$(1).hex |
|
|
175 |
|
|
|
176 |
endef |
|
|
177 |
|
|
|
178 |
ALL: |
|
|
179 |
@$(foreach III,$(ALL_TARGETS),$(call EXEC,$(III))) |
|
|
180 |
@make cleantmp |