-
Notifications
You must be signed in to change notification settings - Fork 19
/
Makefile
72 lines (48 loc) · 1.69 KB
/
Makefile
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
PROJECT=sbus2ppm
MCU = atmega88
MCU_AVRDUDE = atmega88
#full swing, bod 2,7
FUSE_SETTINGS = -U lfuse:w:0xf7:m -U hfuse:w:0xdd:m -U efuse:w:0xf9:m
ifeq ($(OSTYPE),)
OSTYPE = $(shell uname)
endif
ifneq ($(findstring Darwin,$(OSTYPE)),)
USB_DEVICE = /dev/cu.SLAB_USBtoUART
else
USB_DEVICE = /dev/ttyUSB1
endif
#########################################################################
SRC=$(wildcard *.c)
OBJECTS=$(SRC:.c=.o)
DFILES=$(SRC:.c=.d)
HEADERS=$(wildcard *.h)
# Compiler Options
GCFLAGS = -mmcu=$(MCU) -I. -gstabs -DF_CPU=20000000 -O2 -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums -Wall -Wstrict-prototypes -std=gnu99 -MD -MP
#LDFLAGS = -Wl,-Map=pwbl.map,--cref -lm -Wl,--section-start=.text=0x1800
LDFLAGS = -mmcu=$(MCU)
# Compiler Paths
GCC = avr-gcc
REMOVE = rm -f
SIZE = avr-size
OBJCOPY = avr-objcopy
#########################################################################
all: $(PROJECT).hex Makefile stats
$(PROJECT).hex: $(PROJECT).elf Makefile
$(OBJCOPY) -R .eeprom -O ihex $(PROJECT).elf $(PROJECT).hex
$(PROJECT).elf: $(OBJECTS) Makefile
$(GCC) $(LDFLAGS) $(OBJECTS) -o $(PROJECT).elf
stats: $(PROJECT).elf Makefile
$(SIZE) -C --mcu=$(MCU) $(PROJECT).elf
clean:
$(REMOVE) $(OBJECTS)
$(REMOVE) $(PROJECT).hex
$(REMOVE) $(DFILES)
$(REMOVE) $(PROJECT).elf
#########################################################################
%.o: %.c Makefile $(HEADERS)
$(GCC) $(GCFLAGS) -o $@ -c $<
#########################################################################
flash: all
avrdude -F -p $(MCU_AVRDUDE) -P $(USB_DEVICE) -c stk500v2 -U flash:w:$(PROJECT).hex
fuse:
avrdude -F -p $(MCU_AVRDUDE) -P $(USB_DEVICE) -c stk500v2 $(FUSE_SETTINGS)