3 F_CPU = 18000000 # in Hz
4 FUSE_L = 0xd7# see below for fuse values for particular devices
7 #AVRDUDE = avrdude -c stk500 -B 2 -p $(DEVICE) -P /dev/ttyACM0 # edit this line for your programmer
8 AVRDUDE = avrdude -c avrispmkII -B 10 -p $(DEVICE) -P usb # edit this line for your programmer
10 CFLAGS = -Iusbdrv -I. -DDEBUG_LEVEL=0
11 OBJECTS = usbdrv/usbdrv.o usbdrv/usbdrvasm.o usbdrv/oddebug.o main.o snes.o
13 COMPILE = avr-gcc -Wall -Os -DF_CPU=$(F_CPU) $(CFLAGS) -mmcu=$(DEVICE)
15 ##############################################################################
16 # Fuse values for particular devices
17 ##############################################################################
18 # If your device is not listed here, go to
19 # http://palmavr.sourceforge.net/cgi-bin/fc.cgi
20 # and choose options for external crystal clock and no clock divider
22 ################################## ATMega8 ##################################
23 # ATMega8 FUSE_L (Fuse low byte):
24 # 0x9f = 1 0 0 1 1 1 1 1
26 # | | | +------- CKSEL 3..0 (external >8M crystal)
27 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
28 # | +------------------ BODEN (BrownOut Detector enabled)
29 # +-------------------- BODLEVEL (2.7V)
30 # ATMega8 FUSE_H (Fuse high byte):
31 # 0xc9 = 1 1 0 0 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
32 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
33 # | | | | | +-------- BOOTSZ1
34 # | | | | + --------- EESAVE (don't preserve EEPROM over chip erase)
35 # | | | +-------------- CKOPT (full output swing)
36 # | | +---------------- SPIEN (allow serial programming)
37 # | +------------------ WDTON (WDT not always on)
38 # +-------------------- RSTDISBL (reset pin is enabled)
40 ############################## ATMega48/88/168 ##############################
41 # ATMega*8 FUSE_L (Fuse low byte):
42 # 0xdf = 1 1 0 1 1 1 1 1
44 # | | | +------- CKSEL 3..0 (external >8M crystal)
45 # | | +--------------- SUT 1..0 (crystal osc, BOD enabled)
46 # | +------------------ CKOUT (if 0: Clock output enabled)
47 # +-------------------- CKDIV8 (if 0: divide by 8)
48 # ATMega*8 FUSE_H (Fuse high byte):
49 # 0xde = 1 1 0 1 1 1 1 0
51 # | | | | | +------ BODLEVEL 0..2 (110 = 1.8 V)
52 # | | | | + --------- EESAVE (preserve EEPROM over chip erase)
53 # | | | +-------------- WDTON (if 0: watchdog always on)
54 # | | +---------------- SPIEN (allow serial programming)
55 # | +------------------ DWEN (debug wire enable)
56 # +-------------------- RSTDISBL (reset pin is enabled)
58 ############################## ATTiny25/45/85 ###############################
59 # ATMega*5 FUSE_L (Fuse low byte):
60 # 0xef = 1 1 1 0 1 1 1 1
62 # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
63 # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
64 # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
65 # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
66 # ATMega*5 FUSE_H (Fuse high byte):
67 # 0xdd = 1 1 0 1 1 1 0 1
69 # | | | | | +------ BODLEVEL 2..0 (brownout trigger level -> 2.7V)
70 # | | | | +---------- EESAVE (preserve EEPROM on Chip Erase -> not preserved)
71 # | | | +-------------- WDTON (watchdog timer always on -> disable)
72 # | | +---------------- SPIEN (enable serial programming -> enabled)
73 # | +------------------ DWEN (debug wire enable)
74 # +-------------------- RSTDISBL (disable external reset -> enabled)
76 ################################ ATTiny2313 #################################
77 # ATTiny2313 FUSE_L (Fuse low byte):
78 # 0xef = 1 1 1 0 1 1 1 1
80 # | | | +------- CKSEL 3..0 (clock selection -> crystal @ 12 MHz)
81 # | | +--------------- SUT 1..0 (BOD enabled, fast rising power)
82 # | +------------------ CKOUT (clock output on CKOUT pin -> disabled)
83 # +-------------------- CKDIV8 (divide clock by 8 -> don't divide)
84 # ATTiny2313 FUSE_H (Fuse high byte):
85 # 0xdb = 1 1 0 1 1 0 1 1
87 # | | | | | +---- RSTDISBL (disable external reset -> enabled)
88 # | | | | +-------- BODLEVEL 2..0 (brownout trigger level -> 2.7V)
89 # | | | +-------------- WDTON (watchdog timer always on -> disable)
90 # | | +---------------- SPIEN (enable serial programming -> enabled)
91 # | +------------------ EESAVE (preserve EEPROM on Chip Erase -> not preserved)
92 # +-------------------- DWEN (debug wire enable)
98 @echo "This Makefile has no default rule. Use one of the following:"
99 @echo "make hex ....... to build main.hex"
100 @echo "make program ... to flash fuses and firmware"
101 @echo "make fuse ...... to flash the fuses"
102 @echo "make flash ..... to flash the firmware (use this on metaboard)"
103 @echo "make clean ..... to delete objects and hex file"
107 # rule for programming fuse bits:
109 @[ "$(FUSE_H)" != "" -a "$(FUSE_L)" != "" ] || \
110 { echo "*** Edit Makefile and choose values for FUSE_L and FUSE_H!"; exit 1; }
111 $(AVRDUDE) -U hfuse:w:$(FUSE_H):m -U lfuse:w:$(FUSE_L):m
113 # rule for uploading firmware:
115 $(AVRDUDE) -U flash:w:main.hex:i
120 # rule for deleting dependent files (those which can be built by Make):
122 rm -f main.hex main.lst main.obj main.cof main.list main.map main.eep.hex main.elf *.o usbdrv/*.o main.s usbdrv/oddebug.s usbdrv/usbdrv.s
124 # Generic rule for compiling C files:
126 $(COMPILE) -c $< -o $@
128 # Generic rule for assembling Assembler source files:
130 $(COMPILE) -x assembler-with-cpp -c $< -o $@
131 # "-x assembler-with-cpp" should not be necessary since this is the default
132 # file type for the .S (with capital S) extension. However, upper case
133 # characters are not always preserved on Windows. To ensure WinAVR
134 # compatibility define the file type manually.
136 # Generic rule for compiling C to assembler, used for debugging only.
138 $(COMPILE) -S $< -o $@
142 main.elf: $(OBJECTS) # usbdrv dependency only needed because we copy it
143 $(COMPILE) -o main.elf $(OBJECTS)
146 rm -f main.hex main.eep.hex
147 avr-objcopy -j .text -j .data -O ihex main.elf main.hex
153 avr-objdump -d main.elf