2 # Project: USBaspLoader 
   3 # Author: Christian Starkjohann 
   4 # Creation Date: 2007-12-10 
   5 # Author: Stephan Bärwolf 
   6 # Improvement Date: 2012-07-31 
   8 # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH 
   9 # License: GNU GPL v2 (see License.txt) 
  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 
  21 # BOOTLOADER_ADDRESS is 1800 for 8k devices, 3800 for 16k and 7800 for 32k. 
  22 BOOTLOADER_ADDRESS 
= 1800 
  24 # PROGRAMMER contains AVRDUDE options to address your programmer 
  25 # PROGRAMMER = -c pony-stk200 
  26 PROGRAMMER 
= -c usbasp
 
  28 #  since USBaspLoader supports HAVE_BLB11_SOFTW_LOCKBIT... 
  29 LOCKOPT 
= -U lock
:w
:0x3f:m
 
  30 FUSEOPT 
= $(FUSEOPT_8
) 
  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
 
  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. 
  42 #--------------------------------------------------------------------- 
  44 #--------------------------------------------------------------------- 
  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) 
  55 # 0x9f = 1 0 0 1   1 1 1 1 
  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 #--------------------------------------------------------------------- 
  63 #--------------------------------------------------------------------- 
  65 # 0x00 = 0 0 0 0   0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800) 
  67 #                     +------- BOOTSZ (00 = 2k bytes) 
  69 # 0xd6 = 1 1 0 1   0 1 1 0 
  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) 
  78 # 0xdf = 1 1 0 1   1 1 1 1 
  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 #--------------------------------------------------------------------- 
  86 #--------------------------------------------------------------------- 
  88 # 0x03 = - - - -   - 0 1 1 
  90 #                      +------ BODLEVEL 0..2 (011 = 4.3V) 
  92 # 0xda = 1 1 0 1   1 0 1 0 <-- BOOTRST (0 = jump to bootloader at start) 
  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) 
 101 # 0xf7 = 1 1 1 1   0 1 1 1 
 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) 
 109 ############################################################################### 
 112 AVRDUDE 
= @echo avrdude 
$(PROGRAMMER
) -p 
$(DEVICE
) 
 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
) 
 121 OBJECTS 
=  usbdrv
/usbdrvasm.o usbdrv
/oddebug.o main.o
 
 127         cp 
-Rvp main.hex .
/hexfiles
/usbasploader.hex
 
 130         $(CC
) $(CFLAGS
) -c 
$< -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. 
 140         $(CC
) $(CFLAGS
) -S 
$< -o 
$@
 
 143         $(AVRDUDE
) -U flash
:w
:main.hex
:i
 
 146         $(AVRDUDE
) -U flash
:r
:read.hex
:i
 
 149         $(AVRDUDE
) $(FUSEOPT
) 
 152         $(AVRDUDE
) $(LOCKOPT
) 
 161         rm -f main.hex main.bin 
*.o usbdrv
/*.o main.s usbdrv
/oddebug.s usbdrv
/usbdrv.s
 
 165         $(CC
) $(CFLAGS
) -o main.bin 
$(OBJECTS
) $(LDFLAGS
) 
 168         rm -f main.hex main.eep.hex
 
 169         avr-objcopy 
-j .text 
-j .data 
-O ihex main.bin main.hex
 
 173         avr-objdump 
-d main.bin
 
 176         $(CC
) $(CFLAGS
) -E main.c
 
 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
 
 184 allhexfiles
: $(ALLHEXFILES
) 
 186         avr-size hexfiles
/*.hex
 
 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"; \
 
 195         $(MAKE
) main.hex F_CPU
=$${clock}000000 DEVICE
=atmega
$$device BOOTLOADER_ADDRESS
=$$addr DEFINES
=-DUSE_AUTOCONFIG
=1