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)
8 # This Revision: $Id: Makefile 798 2010-07-27 17:29:28Z cs $
10 ###############################################################################
11 # Configure the following variables according to your AVR.
12 # Program the device with
13 # make fuse # to set the clock generator, boot section size etc.
14 # make flash # to load the boot loader into flash
15 # 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
21 FUSEOPT
= $(FUSEOPT_8
)
22 LOCKOPT
= -U lock
:w
:0x2f:m
24 PROGRAMMER
= -c pony-stk200
25 # PROGRAMMER contains AVRDUDE options to address your programmer
27 FUSEOPT_8
= -U hfuse
:w
:0xc0:m
-U lfuse
:w
:0x9f:m
28 FUSEOPT_88
= -U hfuse
:w
:0xd6:m
-U lfuse
:w
:0xdf:m
-U efuse
:w
:0x00:m
29 FUSEOPT_168
= -U hfuse
:w
:0xd6:m
-U lfuse
:w
:0xdf:m
-U efuse
:w
:0x00:m
30 FUSEOPT_328
= -U lfuse
:w
:0xf7:m
-U hfuse
:w
:0xda:m
-U efuse
:w
:0x03:m
31 # You may have to change the order of these -U commands.
33 #---------------------------------------------------------------------
35 #---------------------------------------------------------------------
37 # 0xc0 = 1 1 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
38 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
39 # | | | | | +-------- BOOTSZ1
40 # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
41 # | | | +-------------- CKOPT (full output swing)
42 # | | +---------------- SPIEN (allow serial programming)
43 # | +------------------ WDTON (WDT not always on)
44 # +-------------------- RSTDISBL (reset pin is enabled)
46 # 0x9f = 1 0 0 1 1 1 1 1
48 # | | | +------- CKSEL 3..0 (external >8M crystal)
49 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
50 # | +------------------ BODEN (BrownOut Detector enabled)
51 # +-------------------- BODLEVEL (2.7V)
52 #---------------------------------------------------------------------
54 #---------------------------------------------------------------------
56 # 0x00 = 0 0 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
58 # +------- BOOTSZ (00 = 2k bytes)
60 # 0xd6 = 1 1 0 1 0 1 1 0
62 # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
63 # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
64 # | | | +-------------- WDTON (if 0: watchdog always on)
65 # | | +---------------- SPIEN (allow serial programming)
66 # | +------------------ DWEN (debug wire enable)
67 # +-------------------- RSTDISBL (reset pin is enabled)
69 # 0xdf = 1 1 0 1 1 1 1 1
71 # | | | +------- CKSEL 3..0 (external >8M crystal)
72 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
73 # | +------------------ CKOUT (if 0: Clock output enabled)
74 # +-------------------- CKDIV8 (if 0: divide by 8)
75 #---------------------------------------------------------------------
77 #---------------------------------------------------------------------
79 # 0x03 = - - - - - 0 1 1
81 # +------ BODLEVEL 0..2 (011 = 4.3V)
83 # 0xda = 1 1 0 1 1 0 1 0 <-- BOOTRST (0 = jump to bootloader at start)
85 # | | | | | +------- BOOTSZ 0..1 (01 = 2KB starting at 0x7800)
86 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
87 # | | | +-------------- WDTON (1 = watchdog disabled at start)
88 # | | +---------------- SPIEN (0 = allow serial programming)
89 # | +------------------ DWEN (1 = debug wire disable)
90 # +-------------------- RSTDISBL (1 = reset pin is enabled)
92 # 0xf7 = 1 1 1 1 0 1 1 1
94 # | | | +------- CKSEL 3..0 (0111 = external full-swing crystal)
95 # | | +--------------- SUT 1..0 (11 = startup time 16K CK/14K + 65ms)
96 # | +------------------ CKOUT (1 = clock output disabled)
97 # +-------------------- CKDIV8 (1 = do not divide clock by 8)
100 ###############################################################################
103 AVRDUDE
= @echo avrdude
$(PROGRAMMER
) -p
$(DEVICE
)
107 DEFINES
= #-DDEBUG_LEVEL=2
108 # Remove the -fno-* options when you use gcc 3, it does not understand them
109 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
)
110 LDFLAGS
= -Wl
,--relax
,--gc-sections
-Wl
,--section-start
=.text
=$(BOOTLOADER_ADDRESS
)
112 OBJECTS
= usbdrv
/usbdrvasm.o usbdrv
/oddebug.o main.o
118 $(CC
) $(CFLAGS
) -c
$< -o
$@
121 $(CC
) $(CFLAGS
) -x assembler-with-cpp
-c
$< -o
$@
122 # "-x assembler-with-cpp" should not be necessary since this is the default
123 # file type for the .S (with capital S) extension. However, upper case
124 # characters are not always preserved on Windows. To ensure WinAVR
125 # compatibility define the file type manually.
128 $(CC
) $(CFLAGS
) -S
$< -o
$@
131 $(AVRDUDE
) -U flash
:w
:main.hex
:i
134 $(AVRDUDE
) -U flash
:r
:read.hex
:i
137 $(AVRDUDE
) $(FUSEOPT
)
140 $(AVRDUDE
) $(LOCKOPT
)
149 rm -f main.hex main.bin
*.o usbdrv
/*.o main.s usbdrv
/oddebug.s usbdrv
/usbdrv.s
153 $(CC
) $(CFLAGS
) -o main.bin
$(OBJECTS
) $(LDFLAGS
)
156 rm -f main.hex main.eep.hex
157 avr-objcopy
-j .text
-j .data
-O ihex main.bin main.hex
161 avr-objdump
-d main.bin
164 $(CC
) $(CFLAGS
) -E main.c
166 # Special rules for generating hex files for various devices and clock speeds
167 ALLHEXFILES
= hexfiles
/mega8_12mhz.hex hexfiles
/mega8_15mhz.hex hexfiles
/mega8_16mhz.hex \
168 hexfiles
/mega88_12mhz.hex hexfiles
/mega88_15mhz.hex hexfiles
/mega88_16mhz.hex hexfiles
/mega88_20mhz.hex\
169 hexfiles
/mega168_12mhz.hex hexfiles
/mega168_15mhz.hex hexfiles
/mega168_16mhz.hex hexfiles
/mega168_20mhz.hex\
170 hexfiles
/mega328p_12mhz.hex hexfiles
/mega328p_15mhz.hex hexfiles
/mega328p_16mhz.hex hexfiles
/mega328p_20mhz.hex
172 allhexfiles
: $(ALLHEXFILES
)
174 avr-size hexfiles
/*.hex
177 @
[ -d hexfiles
] || mkdir hexfiles
178 @device
=`echo $@ | sed -e 's|.*/mega||g' -e 's|_.*||g'`; \
179 clock
=`echo $@ | sed -e 's|.*_||g' -e 's|mhz.*||g'`; \
180 addr
=`echo $$device | sed -e 's/\([0-9]\)8/\1/g' | awk '{printf("%x", ($$1 - 2) * 1024)}'`; \
181 echo
"### Make with F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr"; \
183 $(MAKE
) main.hex F_CPU
=$${clock}000000 DEVICE
=atmega
$$device BOOTLOADER_ADDRESS
=$$addr DEFINES
=-DUSE_AUTOCONFIG
=1