-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMakefile
More file actions
92 lines (70 loc) · 2.59 KB
/
Copy pathMakefile
File metadata and controls
92 lines (70 loc) · 2.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
## General Flags
PROJECT = AVRTestingDevice
MCU = attiny85
BURNMCU = attiny85
BURNPROGRAMMER = buspirate
##PORTPRO = /dev/tty.usbserial-Flashy
PORTPRO = com3
TARGET = output/$(PROJECT).elf
CC = avr-gcc
CCXX = avr-g++
## Flags common to C, ASM, and Linker
COMMON = -mmcu=$(MCU)
## Flags common to C only
CFLAGS = $(COMMON)
CONLYFLAGS = -std=gnu99
CFLAGS += -Wall -gdwarf-2 -DF_CPU=16500000UL -Os -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -ffunction-sections -fdata-sections
CFLAGS += -MD -MP -MT $(*F).o
## Flags common to ASM only
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
ASMFLAGS +=
## Flags common to CPP/CXX only
CXXFLAGS = $(COMMON)
CXXFLAGS += $(CFLAGS)
CXXFLAGS += -std=c99
## Flags common to Linker only
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=output/$(PROJECT).map
LDFLAGS += -Wl,--gc-sections
## Flags for Intel HEX file production
HEX_FLASH_FLAGS = -R .eeprom -R .fuse -R .lock -R .signature
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Include Directories
INCLUDES = -I"."
## Libraries
LIBS = -lm -lc
## Link these object files to be made
OBJECTS = main.o usbdrv.o usbdrvasm.o
## Link objects specified by users
LINKONLYOBJECTS =
## Compile
all: $(TARGET)
main.o: ./main.c
$(CC) $(INCLUDES) $(CFLAGS) $(CONLYFLAGS) -c $<
usbdrv.o: ./usbdrv/usbdrv.c
$(CC) $(INCLUDES) $(CFLAGS) $(CONLYFLAGS) -c $<
usbdrvasm.o: ./usbdrv/usbdrvasm.S
$(CC) $(INCLUDES) $(ASMFLAGS) -c $<
## Link
$(TARGET): $(OBJECTS)
-rm -rf $(TARGET) output/$(PROJECT).map
$(CC) $(LDFLAGS) $(OBJECTS) $(LINKONLYOBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET)
-rm -rf $(OBJECTS) main.d usbdrv.d usbdrvasm.d
-rm -rf output/$(PROJECT).hex output/$(PROJECT).eep output/$(PROJECT).lss
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $(TARGET) output/$(PROJECT).hex
avr-objcopy $(HEX_FLASH_FLAGS) -O ihex $(TARGET) output/$(PROJECT).eep || exit 0
avr-objdump -h -S $(TARGET) >> output/$(PROJECT).lss
@avr-size -C --mcu=${MCU} ${TARGET}
## Program
burn:
avrdude -p $(BURNMCU) -P $(PORTPRO) -c $(BURNPROGRAMMER) -U flash:w:output/$(PROJECT).hex:a
burnfuses:
avrdude -p $(BURNMCU) -c $(BURNPROGRAMMER) -U lfuse:w:0xE1:m -U hfuse:w:0xDF:m -U efuse:w:0xFF:m -U lock:w:0xFF:m
## Clean target
.PHONY: clean
clean:
-rm -rf $(OBJECTS) main.d usbdrv.d usbdrvasm.d output/$(PROJECT).elf output/$(PROJECT).map output/$(PROJECT).lss output/$(PROJECT).hex output/$(PROJECT).eep