[4b06930] | 1 | # Name: Makefile
|
---|
| 2 | # Project: USBaspLoader
|
---|
| 3 | # Author: Christian Starkjohann
|
---|
| 4 | # Creation Date: 2007-12-10
|
---|
| 5 | # Tabsize: 4
|
---|
| 6 | # Copyright: (c) 2007 by OBJECTIVE DEVELOPMENT Software GmbH
|
---|
| 7 | # License: GNU GPL v2 (see License.txt)
|
---|
| 8 | # This Revision: $Id: Makefile 728 2009-03-20 09:03:16Z cs $
|
---|
| 9 |
|
---|
| 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
|
---|
| 16 |
|
---|
| 17 | F_CPU = 16000000
|
---|
| 18 | DEVICE = atmega8
|
---|
| 19 | BOOTLOADER_ADDRESS = 0x1800
|
---|
| 20 | FUSEOPT = $(FUSEOPT_8)
|
---|
| 21 | LOCKOPT = -U lock:w:0x2f:m
|
---|
| 22 |
|
---|
| 23 | PROGRAMMER = -c usbasp
|
---|
| 24 | # PROGRAMMER contains AVRDUDE options to address your programmer
|
---|
| 25 |
|
---|
| 26 | FUSEOPT_8 = -U hfuse:w:0xc0:m -U lfuse:w:0x9f:m
|
---|
| 27 | FUSEOPT_88 = -U hfuse:w:0xd6:m -U lfuse:w:0xdf:m -U efuse:w:0x00:m
|
---|
| 28 | FUSEOPT_168 = -U hfuse:w:0xd6:m -U lfuse:w:0xdf:m -U efuse:w:0x00:m
|
---|
| 29 | # You may have to change the order of these -U commands.
|
---|
| 30 |
|
---|
| 31 | #---------------------------------------------------------------------
|
---|
| 32 | # ATMega8
|
---|
| 33 | #---------------------------------------------------------------------
|
---|
| 34 | # Fuse high byte:
|
---|
| 35 | # 0xc0 = 1 1 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
|
---|
| 36 | # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
|
---|
| 37 | # | | | | | +-------- BOOTSZ1
|
---|
| 38 | # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
|
---|
| 39 | # | | | +-------------- CKOPT (full output swing)
|
---|
| 40 | # | | +---------------- SPIEN (allow serial programming)
|
---|
| 41 | # | +------------------ WDTON (WDT not always on)
|
---|
| 42 | # +-------------------- RSTDISBL (reset pin is enabled)
|
---|
| 43 | # Fuse low byte:
|
---|
| 44 | # 0x9f = 1 0 0 1 1 1 1 1
|
---|
| 45 | # ^ ^ \ / \--+--/
|
---|
| 46 | # | | | +------- CKSEL 3..0 (external >8M crystal)
|
---|
| 47 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
|
---|
| 48 | # | +------------------ BODEN (BrownOut Detector enabled)
|
---|
| 49 | # +-------------------- BODLEVEL (2.7V)
|
---|
| 50 | #---------------------------------------------------------------------
|
---|
| 51 | # ATMega88, ATMega168
|
---|
| 52 | #---------------------------------------------------------------------
|
---|
| 53 | # Fuse extended byte:
|
---|
| 54 | # 0x00 = 0 0 0 0 0 0 0 0 <-- BOOTRST (boot reset vector at 0x1800)
|
---|
| 55 | # \+/
|
---|
| 56 | # +------- BOOTSZ (00 = 2k bytes)
|
---|
| 57 | # Fuse high byte:
|
---|
| 58 | # 0xd6 = 1 1 0 1 0 1 1 0
|
---|
| 59 | # ^ ^ ^ ^ ^ \-+-/
|
---|
| 60 | # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
|
---|
| 61 | # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
|
---|
| 62 | # | | | +-------------- WDTON (if 0: watchdog always on)
|
---|
| 63 | # | | +---------------- SPIEN (allow serial programming)
|
---|
| 64 | # | +------------------ DWEN (debug wire enable)
|
---|
| 65 | # +-------------------- RSTDISBL (reset pin is enabled)
|
---|
| 66 | # Fuse low byte:
|
---|
| 67 | # 0xdf = 1 1 0 1 1 1 1 1
|
---|
| 68 | # ^ ^ \ / \--+--/
|
---|
| 69 | # | | | +------- CKSEL 3..0 (external >8M crystal)
|
---|
| 70 | # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
|
---|
| 71 | # | +------------------ CKOUT (if 0: Clock output enabled)
|
---|
| 72 | # +-------------------- CKDIV8 (if 0: divide by 8)
|
---|
| 73 |
|
---|
| 74 |
|
---|
| 75 | ###############################################################################
|
---|
| 76 |
|
---|
| 77 | # Tools:
|
---|
| 78 | AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
|
---|
| 79 | CC = avr-gcc
|
---|
| 80 |
|
---|
| 81 | # Options:
|
---|
| 82 | DEFINES = #-DDEBUG_LEVEL=1
|
---|
| 83 | CFLAGS = -Wall -Os -I. -mmcu=$(DEVICE) -DF_CPU=$(F_CPU) $(DEFINES)
|
---|
| 84 | LDFLAGS = -Wl,--section-start=.text=$(BOOTLOADER_ADDRESS)
|
---|
| 85 |
|
---|
| 86 | OBJECTS = usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o
|
---|
| 87 |
|
---|
| 88 | # symbolic targets:
|
---|
| 89 | all: main.hex
|
---|
| 90 |
|
---|
| 91 | .c.o:
|
---|
| 92 | $(CC) $(CFLAGS) -c $< -o $@
|
---|
| 93 |
|
---|
| 94 | .S.o:
|
---|
| 95 | $(CC) $(CFLAGS) -x assembler-with-cpp -c $< -o $@
|
---|
| 96 | # "-x assembler-with-cpp" should not be necessary since this is the default
|
---|
| 97 | # file type for the .S (with capital S) extension. However, upper case
|
---|
| 98 | # characters are not always preserved on Windows. To ensure WinAVR
|
---|
| 99 | # compatibility define the file type manually.
|
---|
| 100 |
|
---|
| 101 | .c.s:
|
---|
| 102 | $(CC) $(CFLAGS) -S $< -o $@
|
---|
| 103 |
|
---|
| 104 | flash: all
|
---|
| 105 | $(AVRDUDE) -U flash:w:main.hex:i
|
---|
| 106 |
|
---|
| 107 | readflash:
|
---|
| 108 | $(AVRDUDE) -U flash:r:read.hex:i
|
---|
| 109 |
|
---|
| 110 | fuse:
|
---|
| 111 | $(AVRDUDE) $(FUSEOPT)
|
---|
| 112 |
|
---|
| 113 | lock:
|
---|
| 114 | $(AVRDUDE) $(LOCKOPT)
|
---|
| 115 |
|
---|
| 116 | read_fuses:
|
---|
| 117 | $(UISP) --rd_fuses
|
---|
| 118 |
|
---|
| 119 | clean:
|
---|
| 120 | rm -f main.hex main.bin *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
|
---|
| 121 |
|
---|
| 122 | # file targets:
|
---|
| 123 | main.bin: $(OBJECTS)
|
---|
| 124 | $(CC) $(CFLAGS) -o main.bin $(OBJECTS) $(LDFLAGS)
|
---|
| 125 |
|
---|
| 126 | main.hex: main.bin
|
---|
| 127 | rm -f main.hex main.eep.hex
|
---|
| 128 | avr-objcopy -j .text -j .data -O ihex main.bin main.hex
|
---|
| 129 | avr-size main.hex
|
---|
| 130 |
|
---|
| 131 | disasm: main.bin
|
---|
| 132 | avr-objdump -d main.bin
|
---|
| 133 |
|
---|
| 134 | cpp:
|
---|
| 135 | $(CC) $(CFLAGS) -E main.c
|
---|
| 136 |
|
---|
| 137 | # Special rules for generating hex files for various devices and clock speeds
|
---|
| 138 | ALLHEXFILES = hexfiles/mega8_12mhz.hex hexfiles/mega8_15mhz.hex hexfiles/mega8_16mhz.hex \
|
---|
| 139 | hexfiles/mega88_12mhz.hex hexfiles/mega88_15mhz.hex hexfiles/mega88_16mhz.hex hexfiles/mega88_20mhz.hex\
|
---|
| 140 | hexfiles/mega168_12mhz.hex hexfiles/mega168_15mhz.hex hexfiles/mega168_16mhz.hex hexfiles/mega168_20mhz.hex
|
---|
| 141 |
|
---|
| 142 | allhexfiles: $(ALLHEXFILES)
|
---|
| 143 | $(MAKE) clean
|
---|
| 144 | avr-size hexfiles/*.hex
|
---|
| 145 |
|
---|
| 146 | $(ALLHEXFILES):
|
---|
| 147 | @[ -d hexfiles ] || mkdir hexfiles
|
---|
| 148 | @device=`echo $@ | sed -e 's|.*/mega||g' -e 's|_.*||g'`; \
|
---|
| 149 | clock=`echo $@ | sed -e 's|.*_||g' -e 's|mhz.*||g'`; \
|
---|
| 150 | addr=`echo $$device | sed -e 's/\([0-9]\)8/\1/g' | awk '{printf("%x", ($$1 - 2) * 1024)}'`; \
|
---|
| 151 | echo "### Make with F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr"; \
|
---|
| 152 | $(MAKE) clean; \
|
---|
| 153 | $(MAKE) main.hex F_CPU=$${clock}000000 DEVICE=atmega$$device BOOTLOADER_ADDRESS=$$addr DEFINES=-DUSE_AUTOCONFIG=1
|
---|
| 154 | mv main.hex $@
|
---|