comparison Makefile @ 0:c8b14b2950b9

Some basic bits
author Matt Johnston <matt@ucc.asn.au>
date Sun, 06 May 2012 23:13:14 +0800
parents
children ab0e30c4b344
comparison
equal deleted inserted replaced
-1:000000000000 0:c8b14b2950b9
1 # Name: Makefile
2 # Author: <insert your name here>
3 # Copyright: <insert your copyright message here>
4 # License: <insert your license reference here>
5
6 # This is a prototype Makefile. Modify it according to your needs.
7 # You should at least check the settings for
8 # DEVICE ....... The AVR device you compile for
9 # CLOCK ........ Target AVR clock rate in Hertz
10 # OBJECTS ...... The object files created from your source files. This list is
11 # usually the same as the list of source files with suffix ".o".
12 # PROGRAMMER ... Options to avrdude which define the hardware you use for
13 # uploading to the AVR and the interface where this hardware
14 # is connected. We recommend that you leave it undefined and
15 # add settings like this to your ~/.avrduderc file:
16 # default_programmer = "stk500v2"
17 # default_serial = "avrdoper"
18 # FUSES ........ Parameters for avrdude to flash the fuses appropriately.
19
20 DEVICE = atmega8
21 CLOCK = 8000000
22 PROGRAMMER = #-c stk500v2 -P avrdoper
23 OBJECTS = main.o
24 FUSES = -U hfuse:w:0xd9:m -U lfuse:w:0x24:m
25
26 # ATMega8 fuse bits used above (fuse bits for other devices are different!):
27 # Example for 8 MHz internal oscillator
28 # Fuse high byte:
29 # 0xd9 = 1 1 0 1 1 0 0 1 <-- BOOTRST (boot reset vector at 0x0000)
30 # ^ ^ ^ ^ ^ ^ ^------ BOOTSZ0
31 # | | | | | +-------- BOOTSZ1
32 # | | | | +---------- EESAVE (set to 0 to preserve EEPROM over chip erase)
33 # | | | +-------------- CKOPT (clock option, depends on oscillator type)
34 # | | +---------------- SPIEN (if set to 1, serial programming is disabled)
35 # | +------------------ WDTON (if set to 0, watchdog is always on)
36 # +-------------------- RSTDISBL (if set to 0, RESET pin is disabled)
37 # Fuse low byte:
38 # 0x24 = 0 0 1 0 0 1 0 0
39 # ^ ^ \ / \--+--/
40 # | | | +------- CKSEL 3..0 (8M internal RC)
41 # | | +--------------- SUT 1..0 (slowly rising power)
42 # | +------------------ BODEN (if 0, brown-out detector is enabled)
43 # +-------------------- BODLEVEL (if 0: 4V, if 1: 2.7V)
44 #
45 # For computing fuse byte values for other devices and options see
46 # the fuse bit calculator at http://www.engbedded.com/fusecalc/
47
48
49 # Tune the lines below only if you know what you are doing:
50
51 AVRDUDE = avrdude $(PROGRAMMER) -p $(DEVICE)
52 COMPILE = avr-gcc -Wall -Os -DF_CPU=$(CLOCK) -mmcu=$(DEVICE) -g
53
54 # symbolic targets:
55 all: main.hex
56
57 .c.o:
58 $(COMPILE) -c $< -o $@
59
60 .S.o:
61 $(COMPILE) -x assembler-with-cpp -c $< -o $@
62 # "-x assembler-with-cpp" should not be necessary since this is the default
63 # file type for the .S (with capital S) extension. However, upper case
64 # characters are not always preserved on Windows. To ensure WinAVR
65 # compatibility define the file type manually.
66
67 .c.s:
68 $(COMPILE) -S $< -o $@
69
70 flash: all
71 $(AVRDUDE) -U flash:w:main.hex:i
72
73 fuse:
74 $(AVRDUDE) $(FUSES)
75
76 # Xcode uses the Makefile targets "", "clean" and "install"
77 install: flash fuse
78
79 # if you use a bootloader, change the command below appropriately:
80 load: all
81 bootloadHID main.hex
82
83 clean:
84 rm -f main.hex main.elf $(OBJECTS)
85
86 # file targets:
87 main.elf: $(OBJECTS)
88 $(COMPILE) -o main.elf $(OBJECTS)
89
90 main.hex: main.elf
91 rm -f main.hex
92 avr-objcopy -j .text -j .data -O ihex main.elf main.hex
93 avr-size --format=avr --mcu=$(DEVICE) main.elf
94 # If you have an EEPROM section, you must also create a hex file for the
95 # EEPROM and add it to the "flash" target.
96
97 # Targets for code debugging and analysis:
98 disasm: main.elf
99 avr-objdump -d main.elf
100
101 cpp:
102 $(COMPILE) -E main.c