-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmakefile
More file actions
71 lines (53 loc) · 1.97 KB
/
Copy pathmakefile
File metadata and controls
71 lines (53 loc) · 1.97 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
# List all source files to be compiled; separate with space
SOURCE_FILES := main.c drivers/uart.c drivers/xmem.c utils.c drivers/timer.c drivers/adc.c drivers/io.c drivers/spi.c fonts.c drivers/menu.c drivers/can.c drivers/controller.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
CLOCK := 4915200 # Default clock speed at lab - can
# be overwritten by passing flag
# CLOCK=<speed> to make command
LOG := LOG_LEVEL_CRITICAL # Log level
CC := avr-gcc
CFLAGS := -Iinclude -O -std=c11 -mmcu=$(TARGET_CPU) -ggdb -DF_CPU=$(CLOCK) -DLOG_LEVEL=${LOG}
OBJECT_FILES = $(SOURCE_FILES:%.c=$(BUILD_DIR)/%.o)
.DEFAULT_GOAL := $(BUILD_DIR)/main.hex
$(BUILD_DIR):
mkdir $(BUILD_DIR)
$(BUILD_DIR)/%.o: %.c
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c $< -o $@
$(BUILD_DIR)/a.out: $(OBJECT_FILES) | $(BUILD_DIR)
$(CC) $(CFLAGS) $(OBJECT_FILES) -o $(BUILD_DIR)/a.out
$(BUILD_DIR)/main.hex: $(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
@avr-size -C -x --mcu=$(TARGET_CPU) $(BUILD_DIR)/a.out
.PHONY: ram
ram: $(BUILD_DIR)/a.out
@avr-size -C -x --mcu=$(TARGET_CPU) $(BUILD_DIR)/a.out
.PHONY: clean
clean:
@rm -rf $(BUILD_DIR)
.PHONY: erase
erase:
avrdude -p $(TARGET_DEVICE) -c $(PROGRAMMER) -e
.PHONY: compiledb
compiledb:
@bear -- make
.PHONY: debug
debug:
if pgrep avarice; then pkill avarice; fi
avrdude -p $(TARGET_DEVICE) -c $(PROGRAMMER) -U flash:w:$(BUILD_DIR)/main.hex:i
x-terminal-emulator -e avarice --edbg --ignore-intr :4242
sleep 2
avr-gdb -tui -iex "target remote localhost:4242" $(BUILD_DIR)/a.out
killall -s 9 avarice