-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
58 lines (43 loc) · 1.36 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
## General Flags
PROJECT = encoder-modbus
MCU = attiny2313
TARGET = encoder-modbus
BAUDRATE = 38400
# Fuses for external oscillator 16Mhz
F_CPU = 12000000UL
LFUSE = 0xFF
HFUSE = 0xCF
# Toolchain
CC=avr-gcc
OBJCOPY=avr-objcopy
AVRDUDE=avrdude -P /dev/ttyUSB0
MODPOLL=mbpoll -p none /dev/ttyUSB1 -b $(BAUDRATE)
COMMON = -mmcu=$(MCU)
## Compile options common for all C compilation units.
CFLAGS = $(COMMON) -std=gnu99
CFLAGS += -Wall -gstabs -DBAUD=$(BAUDRATE) -DF_CPU=$(F_CPU) -Os -Wall -Wstrict-prototypes -fno-exceptions -ffunction-sections -fdata-sections
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += -x assembler-with-cpp -Wa,-gstabs
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -w -Os -g -flto -Wl,-Map=$(TARGET).map,--cref -Wl,--gc-sections
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom
SOURCES = main.c interrupts.c crc.c modbus.c
OBJECTS = $(SOURCES:.c=.o)
## Build
all: $(TARGET).elf $(TARGET).hex
flash: $(TARGET).hex
$(AVRDUDE) -p $(MCU) -c stk500 -v -b 115200 -e -U flash:w:$(TARGET).hex:i -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m
poll:
$(MODPOLL) -m rtu -a 0x85 -c 6 -t 3 -l 100 -o 5 -R -P none
##Link
$(TARGET).elf: $(OBJECTS)
$(CC) $(LDFLAGS) $(OBJECTS) $(LIBDIRS) $(LIBS) -o $(TARGET).elf
%.hex: $(TARGET).elf
$(OBJCOPY) -O ihex $(HEX_FLASH_FLAGS) $< $@
.o: $(SOURCES)
$(CC) $(INCLUDES) $(CFLAGS) -c $<
clean:
rm -f *.o