-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
50 lines (37 loc) · 1.25 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
# List all source files to be compiled; separate with space
SOURCE_FILES := main.c
# Set this flag to "yes" (no quotes) to use JTAG; otherwise ISP (SPI) is used
PROGRAM_WITH_JTAG := yes
# Feel free to ignore anything below this line
PROGRAMMER := atmelice_isp
ifeq ($(PROGRAM_WITH_JTAG), yes)
PROGRAMMER := atmelice
endif
BUILD_DIR := build
TARGET_CPU := atmega162
TARGET_DEVICE := m162
CC := avr-gcc
CFLAGS := -O -std=c11 -mmcu=$(TARGET_CPU)
OBJECT_FILES = $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)
.DEFAULT_GOAL := $(BUILD_DIR)/main.hex
$(BUILD_DIR):
mkdir $(BUILD_DIR)
$(BUILD_DIR)/%.o: %.c | $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/main.hex: $(OBJECT_FILES) | $(BUILD_DIR)
$(CC) $(CFLAGS) $(OBJECT_FILES) -o $(BUILD_DIR)/a.out
avr-objcopy -j .text -j .data -O ihex $(BUILD_DIR)/a.out $(BUILD_DIR)/main.hex
.PHONY: flash
flash: $(BUILD_DIR)/main.hex
avrdude -p $(TARGET_DEVICE) -c $(PROGRAMMER) -U flash:w:$(BUILD_DIR)/main.hex:i
.PHONY: fuse
fuse:
avrdude -p $(TARGET_DEVICE) -c $(PROGRAMMER) -U efuse:w:0xff:m
avrdude -p $(TARGET_DEVICE) -c $(PROGRAMMER) -U hfuse:w:0x19:m
avrdude -p $(TARGET_DEVICE) -c $(PROGRAMMER) -U lfuse:w:0xfd:m
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: erase
erase:
avrdude -p $(TARGET_DEVICE) -c $(PROGRAMMER) -e