-
Notifications
You must be signed in to change notification settings - Fork 1
/
Makefile
148 lines (125 loc) · 5.41 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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# msp430fr-firmware-gcc-skeleton
#
# Please read the README.md file
#
# License: The code is released under the MIT license
#
# Copyright (c) 2020, 0xebef
# build type: release or debug
ifndef config
config=release
endif
# paths
GCC_PATH := /opt/msp430-gcc
COMPILER_PATH := $(GCC_PATH)/bin
# microcontroller model
MCU := msp430fr6989
# device, same as microcontroller model but in uppercase
DEVICE := MSP430FR6989
# global definitions
DEFINES := -D__$(DEVICE)__ -DAUTHOR=0xebef
# toolchain
CC := $(COMPILER_PATH)/msp430-elf-gcc
LD := $(COMPILER_PATH)/msp430-elf-ld
AR := $(COMPILER_PATH)/msp430-elf-ar
AS := $(COMPILER_PATH)/msp430-elf-gcc
GASP := $(COMPILER_PATH)/msp430-elf-gasp
GDB := $(COMPILER_PATH)/msp430-elf-gdb
NM := $(COMPILER_PATH)/msp430-elf-nm
OBJCOPY := $(COMPILER_PATH)/msp430-elf-objcopy
OBJDUMP := $(COMPILER_PATH)/msp430-elf-objdump
RANLIB := $(COMPILER_PATH)/msp430-elf-ranlib
STRIP := $(COMPILER_PATH)/msp430-elf-strip
SIZE := $(COMPILER_PATH)/msp430-elf-size
READELF := $(COMPILER_PATH)/msp430-elf-readelf
MAKETXT := srec_cat
CP := cp -p
RM := rm -f
MV := mv
TEST := test
MSPDEBUG := LD_LIBRARY_PATH=/opt/energia/hardware/tools/DSLite/DebugServer/drivers mspdebug tilib -d /dev/ttyACM0
# include directories
GCC_INC_DIR := $(GCC_PATH)/msp430-elf/include
HW_INC_DIR := $(GCC_PATH)/include
INC_DIR := inc
DRV_INC_DIR := lib/driverlib
# source directories
SRC_DIR := src
DRV_SRC_DIR := lib/driverlib/MSP430FR5xx_6xx
# source files
SRC := $(wildcard $(SRC_DIR)/*.c)
DRV_SRC := $(wildcard $(DRV_SRC_DIR)/*.c)
# target
ifeq ($(config),release)
BUILD_DIR=build/release
else
BUILD_DIR=build/debug
endif
OBJ_DIR := $(BUILD_DIR)/obj
BIN_DIR := $(BUILD_DIR)/bin
TARGET := $(BIN_DIR)/app
ELF := $(TARGET).elf
# compiler flags
ifeq ($(config),release)
OPTIMFLAGS = -Os
else
OPTIMFLAGS = -Og -g
endif
DRV_FLAGS := -Wno-missing-field-initializers -Wno-int-to-pointer-cast -Wno-parentheses
#MEMMODEL_FLAGS := -mlarge -muse-lower-region-prefix -mdata-region=lower -mcode-region=upper
#MEMMODEL_FLAGS := -mlarge -mdata-region=either -mcode-region=either
#MEMMODEL_FLAGS := -mlarge -mdata-region=upper -mcode-region=upper
MEMMODEL_FLAGS := -mlarge -mdata-region=upper -mcode-region=either
COMMON_FLAGS := -MD -mmcu=$(MCU) $(DEFINES) $(OPTIMFLAGS) -mhwmult=f5series -mrelax $(MEMMODEL_FLAGS) \
-ffunction-sections -fdata-sections -fno-strict-aliasing \
-I $(GCC_INC_DIR) \
-I $(HW_INC_DIR) -L $(HW_INC_DIR) \
-I $(INC_DIR) \
-I $(DRV_INC_DIR)
CFLAGS := $(COMMON_FLAGS) -c -Wall -Wextra -Werror -Wshadow -Wformat -Wformat-security -Wno-unused-function -Wno-unused-parameter -Wno-unused-but-set-variable -Wundef -std=gnu99
ASFLAGS := $(COMMON_FLAGS) -x assembler-with-cpp -Wa,-gstabs
LDFLAGS := $(COMMON_FLAGS) -T $(HW_INC_DIR)/$(MCU).ld -Wl,--gc-sections -Wl,--cref -Wl,-Map=$(TARGET).map
LIBS := -l gcc -l c -l m
# attempt to create the output directories
ifneq ($(BUILD_DIR),)
$(shell [ -d $(BUILD_DIR) ] || mkdir -p $(BUILD_DIR))
$(shell [ -d $(OBJ_DIR) ] || mkdir -p $(OBJ_DIR))
$(shell [ -d $(OBJ_DIR)/$(SRC_DIR) ] || mkdir -p $(OBJ_DIR)/$(SRC_DIR))
$(shell [ -d $(OBJ_DIR)/$(DRV_SRC_DIR) ] || mkdir -p $(OBJ_DIR)/$(DRV_SRC_DIR))
$(shell [ -d $(BIN_DIR) ] || mkdir -p $(BIN_DIR))
endif
# Object files
OBJS := $(patsubst %.c,$(OBJ_DIR)/$(SRC_DIR)/%.o,$(notdir $(SRC))) \
$(patsubst %.c,$(OBJ_DIR)/$(DRV_SRC_DIR)/%.o,$(notdir $(DRV_SRC))) \
$(patsubst %.c,$(OBJ_DIR)/$(DRV_SRC_DIR)/%.o,$(notdir $(DRV_SRC)))
# Dependancies
DEPS := $(OBJS:.o=.d)
# Rules
.PHONY: all
all: $(ELF)
$(ELF) : $(OBJS)
$(TEST) -f $@ && $(RM) $@ || true
$(CC) $(LDFLAGS) $^ $(LIBS) -o $@
$(TEST) -f $@ && $(SIZE) $@ && $(OBJDUMP) -h $@ || true
$(TEST) -f [email protected] && $(RM) [email protected] || true
ifeq ($(config),debug)
$(TEST) -f $@ && $(SIZE) $@ && $(OBJDUMP) -D -S $@ > [email protected] || true
endif
$(OBJ_DIR)/$(SRC_DIR)/%.o : $(SRC_DIR)/%.c
$(CC) $(CFLAGS) $< -o $@
$(OBJ_DIR)/$(DRV_SRC_DIR)/%.o : $(DRV_SRC_DIR)/%.c
$(CC) $(CFLAGS) $(DRV_FLAGS) $< -o $@
.PHONY: clean
clean:
$(RM) -r $(OBJ_DIR)
$(RM) -r $(BIN_DIR)
.PHONY: flash
flash:
$(MSPDEBUG) "erase" "load $(ELF)" "exit"
.PHONY: restart
restart:
$(MSPDEBUG) "exit"
.PHONY: test
test:
echo "test"
-include $(DEPS)