-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
40 lines (29 loc) · 834 Bytes
/
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
MCU = atmega328p
F_CPU = 16000000UL
CC = avr-gcc
CFLAGS = -mmcu=$(MCU) -DF_CPU=$(F_CPU) -Os
SRC_DIR = src
DELAY_DIR = $(SRC_DIR)/delay
USART_DIR = $(SRC_DIR)/usart
TIMER_DIR = $(SRC_DIR)/timer
SRCS = $(SRC_DIR)/main.c \
$(DELAY_DIR)/delay.c \
$(USART_DIR)/usart.c \
$(TIMER_DIR)/timer.c
OBJS = $(SRCS:.c=.o)
TARGET = main.hex
AVRDUDE_PROGRAMMER = arduino
AVRDUDE_PORT = /dev/cu.usbserial-2110 # Update this for your system
AVRDUDE_BAUD = 115200
AVRDUDE_MCU = $(MCU)
all: $(TARGET)
%.o: %.c
$(CC) $(CFLAGS) -c $< -o $@
main.elf: $(OBJS)
$(CC) $(CFLAGS) -o $@ $(OBJS)
$(TARGET): main.elf
avr-objcopy -O ihex -R .eeprom $< $@
upload: $(TARGET)
avrdude -c $(AVRDUDE_PROGRAMMER) -p $(AVRDUDE_MCU) -P $(AVRDUDE_PORT) -b $(AVRDUDE_BAUD) -U flash:w:$(TARGET)
clean:
rm -f $(OBJS) main.elf $(TARGET)