2 # Project: USBaspLoader
3 # Author: Christian Starkjohann
4 # Creation Date: 2007-12-10
6 # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
7 # License: GNU GPL v2 (see License.txt)
9 ###############################################################################
10 # Configure the following variables according to your AVR.
11 # Program the device with
12 # make fuse # to set the clock generator, boot section size etc.
13 # make flash # to load the boot loader into flash
14 # make lock # to protect the boot loader from overwriting
19 # BOOTLOADER_ADDRESS is 1800 for 8k devices, 3800 for 16k and 7800 for 32k.
20 BOOTLOADER_ADDRESS
= 1800
22 # PROGRAMMER contains AVRDUDE options to address your programmer
23 # PROGRAMMER = -c pony-stk200
24 PROGRAMMER
= -c usbasp
26 # since USBaspLoader supports HAVE_BLB11_SOFTW_LOCKBIT...
27 LOCKOPT
= -U lock
:w
:0x3f:m
28 FUSEOPT
= $(FUSEOPT_8
)
31 # standard atmega8 needs BODLEVEL to be programed, since it is a 5V device
32 # you may also want to UNprogram SUT1 to get a SLOWER bootup (lfuse then would be 0x3f)
33 FUSEOPT_8
= -U hfuse
:w
:0xc0:m
-U lfuse
:w
:0x1f:m
35 FUSEOPT_88
= -U hfuse
:w
:0xd6:m
-U lfuse
:w
:0xdf:m
-U efuse
:w
:0x00:m
36 FUSEOPT_168
= -U hfuse
:w
:0xd6:m
-U lfuse
:w
:0xdf:m
-U efuse
:w
:0x00:m
37 FUSEOPT_328
= -U lfuse
:w
:0xf7:m
-U hfuse
:w
:0xda:m
-U efuse
:w
:0x03:m
38 # You may have to change the order of these -U commands.
40 #---------------------------------------------------------------------
42 #---------------------------------------------------------------------
44 # 0xc0 = 1 1 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
45 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
46 # | | | | | +-------- BOOTSZ1
47 # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
48 # | | | +-------------- CKOPT (full output swing)
49 # | | +---------------- SPIEN (allow serial programming)
50 # | +------------------ WDTON (WDT not always on)
51 # +-------------------- RSTDISBL (reset pin is enabled)
53 # 0x9f = 1 0 0 1 1 1 1 1
55 # | | | +------- CKSEL 3..0 (external >8M crystal)
56 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
57 # | +------------------ BODEN (BrownOut Detector enabled)
58 # +-------------------- BODLEVEL (2.7V)
59 #---------------------------------------------------------------------
61 #---------------------------------------------------------------------
63 # 0x00 = 0 0 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
65 # +------- BOOTSZ (00 = 2k bytes)
67 # 0xd6 = 1 1 0 1 0 1 1 0
69 # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
70 # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
71 # | | | +-------------- WDTON (if 0: watchdog always on)
72 # | | +---------------- SPIEN (allow serial programming)
73 # | +------------------ DWEN (debug wire enable)
74 # +-------------------- RSTDISBL (reset pin is enabled)
76 # 0xdf = 1 1 0 1 1 1 1 1
78 # | | | +------- CKSEL 3..0 (external >8M crystal)
79 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
80 # | +------------------ CKOUT (if 0: Clock output enabled)
81 # +-------------------- CKDIV8 (if 0: divide by 8)
82 #---------------------------------------------------------------------
84 #---------------------------------------------------------------------
86 # 0x03 = - - - - - 0 1 1
88 # +------ BODLEVEL 0..2 (011 = 4.3V)
90 # 0xda = 1 1 0 1 1 0 1 0 <-- BOOTRST (0 = jump to bootloader at start)
92 # | | | | | +------- BOOTSZ 0..1 (01 = 2KB starting at 0x7800)
93 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
94 # | | | +-------------- WDTON (1 = watchdog disabled at start)
95 # | | +---------------- SPIEN (0 = allow serial programming)
96 # | +------------------ DWEN (1 = debug wire disable)
97 # +-------------------- RSTDISBL (1 = reset pin is enabled)
99 # 0xf7 = 1 1 1 1 0 1 1 1
101 # | | | +------- CKSEL 3..0 (0111 = external full-swing crystal)
102 # | | +--------------- SUT 1..0 (11 = startup time 16K CK/14K + 65ms)
103 # | +------------------ CKOUT (1 = clock output disabled)
104 # +-------------------- CKDIV8 (1 = do not divide clock by 8)
107 ###############################################################################
110 AVRDUDE
= @echo avrdude
$(PROGRAMMER
) -p
$(DEVICE
)
114 DEFINES
= #-DDEBUG_LEVEL=2
115 # Remove the -fno-* options when you use gcc 3, it does not understand them
116 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
)
117 LDFLAGS
= -Wl
,--relax
,--gc-sections
-Wl
,--section-start
=.text
=$(BOOTLOADER_ADDRESS
)
119 OBJECTS
= usbdrv
/usbdrvasm.o usbdrv
/oddebug.o main.o
125 $(CC
) $(CFLAGS
) -c
$< -o
$@
128 $(CC
) $(CFLAGS
) -x assembler-with-cpp
-c
$< -o
$@
129 # "-x assembler-with-cpp" should not be necessary since this is the default
130 # file type for the .S (with capital S) extension. However, upper case
131 # characters are not always preserved on Windows. To ensure WinAVR
132 # compatibility define the file type manually.
135 $(CC
) $(CFLAGS
) -S
$< -o
$@
138 $(AVRDUDE
) -U flash
:w
:main.hex
:i
141 $(AVRDUDE
) -U flash
:r
:read.hex
:i
144 $(AVRDUDE
) $(FUSEOPT
)
147 $(AVRDUDE
) $(LOCKOPT
)
156 rm -f main.hex main.bin
*.o usbdrv
/*.o main.s usbdrv
/oddebug.s usbdrv
/usbdrv.s
160 $(CC
) $(CFLAGS
) -o main.bin
$(OBJECTS
) $(LDFLAGS
)
163 rm -f main.hex main.eep.hex
164 avr-objcopy
-j .text
-j .data
-O ihex main.bin main.hex
168 avr-objdump
-d main.bin
171 $(CC
) $(CFLAGS
) -E main.c
173 # Special rules for generating hex files for various devices and clock speeds
174 ALLHEXFILES
= hexfiles
/mega8_12mhz.hex hexfiles
/mega8_15mhz.hex hexfiles
/mega8_16mhz.hex \
175 hexfiles
/mega88_12mhz.hex hexfiles
/mega88_15mhz.hex hexfiles
/mega88_16mhz.hex hexfiles
/mega88_20mhz.hex\
176 hexfiles
/mega168_12mhz.hex hexfiles
/mega168_15mhz.hex hexfiles
/mega168_16mhz.hex hexfiles
/mega168_20mhz.hex\
177 hexfiles
/mega328p_12mhz.hex hexfiles
/mega328p_15mhz.hex hexfiles
/mega328p_16mhz.hex hexfiles
/mega328p_20mhz.hex
179 allhexfiles
: $(ALLHEXFILES
)
181 avr-size hexfiles
/*.hex
184 @
[ -d hexfiles
] || mkdir hexfiles
185 @device
=`echo $@ | sed -e 's|.*/mega||g' -e 's|_.*||g'`; \
186 clock
=`echo $@ | sed -e 's|.*_||g' -e 's|mhz.*||g'`; \
187 addr
=`echo $$device | sed -e 's/\([0-9]\)8/\1/g' | awk '{printf("%x", ($$1 - 2) * 1024)}'`; \
188 echo
"### Make with F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr"; \
190 $(MAKE
) main.hex F_CPU
=$${clock}000000 DEVICE
=atmega
$$device BOOTLOADER_ADDRESS
=$$addr DEFINES
=-DUSE_AUTOCONFIG
=1