1 | # Makefile for this AVR project
|
2 |
|
3 | # make code Compiles the source code
|
4 | # make fuses Program fuses
|
5 | # make program Program flash and eeprom
|
6 |
|
7 | # make list Create generated code listing
|
8 | # make clean Delete all generated files
|
9 |
|
10 | # Programmer hardware settings for avrdude
|
11 | # AVRDUDE_HW = -c avr910 -P /dev/ttyUSB0 -b 115200
|
12 | # AVRDUDE_HW = -c arduino -P COM3 -b 57600
|
13 | AVRDUDE_HW = -c avrispmkII -P usb -B16
|
14 |
|
15 | # Name of the program without extension
|
16 | PRG = HelloWorld
|
17 |
|
18 | # Microcontroller type and clock frequency
|
19 | MCU = attiny2313
|
20 | F_CPU = 1000000
|
21 |
|
22 | # Fuse settings
|
23 | # Comment out if you are using a bootloader (e.g. in case of Arduino)
|
24 | LFUSE = 0x64
|
25 | HFUSE = 0xDF
|
26 | EFUSE = 0xFF
|
27 |
|
28 | # Source files, separated by space.
|
29 | SRC = main.c
|
30 |
|
31 |
|
32 | ###################################################################
|
33 | # You possibly do not need to change settings below this marker
|
34 | ###################################################################
|
35 |
|
36 | # Binaries to be used
|
37 | # You may add the path to them if they are not in the PATH variable.
|
38 | CC = avr-gcc
|
39 | OBJCOPY = avr-objcopy
|
40 | OBJDUMP = avr-objdump
|
41 | AVRDUDE = avrdude
|
42 | AVR_SIZE = avr-size
|
43 |
|
44 | # Do we need to write Eeprom? (yes/no)
|
45 | EEPROM = no
|
46 |
|
47 | # Libraries
|
48 | #LIBS = -L path/to/libraries -llibrary1 -llibrary2
|
49 |
|
50 | # Includes
|
51 | #INCLUDES = -Ipath/to/include/files
|
52 |
|
53 | # Compiler options for all c source files
|
54 | CFLAGS = -std=c99 -Wall -O1 -mmcu=$(MCU) -DF_CPU=$(F_CPU) $(INCLUDES)
|
55 |
|
56 | # Enable map file
|
57 | # LDFLAGS += -Wl,-Map,$(PRG).map
|
58 |
|
59 | # Enable floating-point support in printf
|
60 | #LDFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm
|
61 |
|
62 | # Enable automatic removal of unused functions
|
63 | CFLAGS += -ffunction-sections -fdata-sections
|
64 | LDFLAGS += -Wl,--gc-sections
|
65 |
|
66 | # Collect fuse operations for avrdude
|
67 | ifdef FUSE
|
68 | FUSES += -U fuse:w:$(FUSE):m
|
69 | endif
|
70 | ifdef LFUSE
|
71 | FUSES += -U lfuse:w:$(LFUSE):m
|
72 | endif
|
73 | ifdef HFUSE
|
74 | FUSES += -U hfuse:w:$(HFUSE):m
|
75 | endif
|
76 | ifdef EFUSE
|
77 | FUSES += -U efuse:w:$(EFUSE):m
|
78 | endif
|
79 | ifdef FUSE0
|
80 | FUSES += -U fuse0:w:$(FUSE0):m
|
81 | endif
|
82 | ifdef FUSE1
|
83 | FUSES += -U fuse1:w:$(FUSE1):m
|
84 | endif
|
85 | ifdef FUSE2
|
86 | FUSES += -U fuse2:w:$(FUSE2):m
|
87 | endif
|
88 | ifdef FUSE3
|
89 | FUSES += -U fuse3:w:$(FUSE3):m
|
90 | endif
|
91 | ifdef FUSE4
|
92 | FUSES += -U fuse4:w:$(FUSE4):m
|
93 | endif
|
94 | ifdef FUSE5
|
95 | FUSES += -U fuse5:w:$(FUSE5):m
|
96 | endif
|
97 | ifdef FUSE6
|
98 | FUSES += -U fuse6:w:$(FUSE6):m
|
99 | endif
|
100 | ifdef FUSE7
|
101 | FUSES += -U fuse7:w:$(FUSE7):m
|
102 | endif
|
103 |
|
104 | # Default sections
|
105 | ifeq ($(EEPROM),yes)
|
106 | all: code eeprom
|
107 | else
|
108 | all: code
|
109 | endif
|
110 |
|
111 | # Program code
|
112 | code: $(PRG).hex
|
113 |
|
114 | # Eeprom content
|
115 | eeprom: $(PRG)_eeprom.hex
|
116 |
|
117 | # Generated code listing
|
118 | list: $(PRG).lst
|
119 |
|
120 | # Remove all generated files
|
121 | clean:
|
122 | rm -rf *.o driver/*.o $(PRG).hex $(PRG).elf $(PRG).lst $(PRG).map $(PRG)_eeprom.hex
|
123 |
|
124 | # Program flash memory with or without eeprom
|
125 | ifeq ($(EEPROM),yes)
|
126 | program: code eeprom
|
127 | $(AVRDUDE) -p $(MCU) $(AVRDUDE_HW) -U flash:w:$(PRG).hex:i -U eeprom:w:$(PRG)_eeprom.hex:i
|
128 | else
|
129 | program: code
|
130 | $(AVRDUDE) -p $(MCU) $(AVRDUDE_HW) -U flash:w:$(PRG).hex:i
|
131 | endif
|
132 |
|
133 | # Program fuses
|
134 | fuses:
|
135 | $(AVRDUDE) -p $(MCU) $(AVRDUDE_HW) $(FUSES)
|
136 |
|
137 | $(PRG).elf: $(SRC:.c=.o)
|
138 | $(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)
|
139 | $(AVR_SIZE) $(PRG).elf
|
140 |
|
141 | %.lst: %.elf
|
142 | $(OBJDUMP) -h -S $< > $@
|
143 |
|
144 | %.hex: %.elf
|
145 | $(OBJCOPY) -j .text -j .data -O ihex $< $@
|
146 |
|
147 | %_eeprom.hex: %.elf
|
148 | $(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
|