annotate Makefile @ 306:848b0fe159d2

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