-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
71 lines (52 loc) · 1.89 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
TARGET = firmware
TARGET_PLATFORM = Atmel AVR
TARGET_MCU = atmega328p
TARGET_MCU_TAG = m328p
TARGET_CLOCK = 16000000
TARGET_LOADER = avrdude
TARGET_PORT = /dev/ttyUSB0
TARGET_BOARD = arduino
TOOLCHAIN = avr-
SOURCES = main.cpp gpio.cpp assert.cpp
OBJECTS = $(SOURCES:.cpp=.o)
INCLUDES = -I.
OPTIONS = -DF_CPU=$(TARGET_CLOCK) -DWITH_DEBUG=1 -DWITH_ASSERT=1
EFLAGS = -Wall -Wextra -Werror
CXX = $(TOOLCHAIN)g++
CXXFLAGS = -mmcu=$(TARGET_MCU) $(EFLAGS) $(OPTIONS) $(INCLUDES) -Os -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics
LDLIBS =
LDFLAGS = -mmcu=$(TARGET_MCU) $(EFLAGS) -Wl,--gc-sections
LOADER_FLAGS = -C arduino.conf -v -p $(TARGET_MCU_TAG) -c $(TARGET_BOARD) -P $(TARGET_PORT) -b57600
OBJCOPY = $(TOOLCHAIN)objcopy
OBJSIZE = $(TOOLCHAIN)size
# Implicit suffix rules
# ---------------------
.SUFFIXES:
.SUFFIXES: .cpp .o .elf .hex
.cpp.o:
$(CXX) -c $(CXXFLAGS) -o $@ $<
# Build rules
# ---------------------
.PHONY: all clean install
.PHONY: checkfuses burnfuses terminal
all: $(SOURCES) $(TARGET).hex
$(TARGET).hex: $(TARGET).elf
$(OBJCOPY) -O ihex -R .eeprom $(TARGET).elf $(TARGET).hex
$(OBJSIZE) -t $(OBJECTS) $(TARGET).elf $(TARGET).hex
$(TARGET).elf: $(OBJECTS)
$(CXX) $(LDFLAGS) -o $@ $(OBJECTS)
clean:
rm -rf $(OBJECTS) $(TARGET).*
# Install: Write hex to the target device
install: $(TARGET).hex
$(TARGET_LOADER) $(LOADER_FLAGS) -e -U flash:w:$(TARGET).hex
# Terminal: Open a connection with the STK500 terminal.
terminal:
$(TARGET_LOADER) $(LOADER_FLAGS) -t $(FLAGS)
# Fuses: make sure to uncomment the extended fuse byte when needed by the microcontroller.
checkfuses:
$(TARGET_LOADER) $(LOADER_FLAGS) \
-U hfuse:v:$(TARGET_HFUSE):m -U lfuse:v:$(TARGET_LFUSE):m #-U efuse:v:$(TARGET_EFUSE):m
burnfuses:
$(TARGET_LOADER) $(LOADER_FLAGS) \
-U hfuse:w:$(TARGET_HFUSE):m -U lfuse:w:$(TARGET_LFUSE):m #-U efuse:w:$(TARGET_EFUSE):m