-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
105 lines (84 loc) · 2.74 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
###############################################################################
# Makefile for the project can485_canopen_slave
###############################################################################
## General Flags
PROJECT = can485_canopen_slave
MCU = at90can128
TARGET = AVR
CC = avr-gcc
SRC = canfestival/src
DRV = canfestival/drivers/AVR
ARDUINO_ROOT = C:/arduino
COM_PORT = com6
## Options common to compile, link and assembly rules
COMMON = -mmcu=$(MCU)
## Compile options common for all C compilation units.
CFLAGS = $(COMMON)
CFLAGS += -Wall -gdwarf-2 -Os -fsigned-char -fpack-struct
CFLAGS += -MD -MP -MT $(*F).o -MF dep/$(@F).d
## Assembly specific flags
ASMFLAGS = $(COMMON)
ASMFLAGS += $(CFLAGS)
ASMFLAGS += -x assembler-with-cpp -Wa,-gdwarf2
## Linker flags
LDFLAGS = $(COMMON)
LDFLAGS += -Wl,-Map=$(PROJECT).map
## Intel Hex file production flags
HEX_FLASH_FLAGS = -R .eeprom
HEX_EEPROM_FLAGS = -j .eeprom
HEX_EEPROM_FLAGS += --set-section-flags=.eeprom="alloc,load"
HEX_EEPROM_FLAGS += --change-section-lma .eeprom=0 --no-change-warnings
## Include Directories
INCLUDES = -I"canfestival/include" -I"canfestival/include/AVR" -I"."
## Objects that must be built in order to link
OBJECTS = $(DRV)/can_AVR.o\
$(DRV)/timer_AVR.o\
$(SRC)/dcf.o\
$(SRC)/timer.o\
$(SRC)/emcy.o\
$(SRC)/lifegrd.o\
$(SRC)/lss.o\
$(SRC)/nmtMaster.o\
$(SRC)/nmtSlave.o\
$(SRC)/objacces.o\
$(SRC)/pdo.o\
$(SRC)/sdo.o\
$(SRC)/states.o\
$(SRC)/sync.o\
ObjDict.o\
uart.o\
main.o
## Build
all: $(PROJECT).elf $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss size
## Compile
%.o: %.c
# @echo " "
@echo "---------------------------------------------------------------------------"
@echo "**Compiling $< -> $@"
# @echo "*********************************************"
$(CC) $(INCLUDES) $(CFLAGS) -c $<
# $(CC) $(INCLUDES) $(CFLAGS) -c -o $@ $<
##Link
$(PROJECT).elf: $(OBJECTS)
# @echo " "
@echo "---------------------------------------------------------------------------"
@echo "**Linking : $@"
# @echo "*********************************************"
$(CC) $(LDFLAGS) $(LIBDIRS) $(LIBS) $(^F) -o $@
%.hex: $(PROJECT).elf
avr-objcopy -O ihex $(HEX_FLASH_FLAGS) $< $@
%.eep: $(PROJECT).elf
-avr-objcopy $(HEX_EEPROM_FLAGS) -O ihex $< $@ || exit 0
%.lss: $(PROJECT).elf
avr-objdump -h -S $< > $@
size: $(PROJECT).elf
@echo
@avr-size -C --mcu=${MCU} $(PROJECT).elf
## Clean target
.PHONY: clean
clean:
-rm -rf *.o $(PROJECT).elf dep/* $(PROJECT).hex $(PROJECT).eep $(PROJECT).lss $(PROJECT).map
## Other dependencies
-include $(shell mkdir dep 2>/dev/null) $(wildcard dep/*)
upload:
$(ARDUINO_ROOT)\hardware\tools\avr\bin\avrdude.exe -p c128 -C $(ARDUINO_ROOT)\hardware\tools\avr\etc\avrdude.conf -c arduino -P $(COM_PORT) -Uflash:w:"$(PROJECT).hex":i