-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
172 lines (143 loc) · 6.73 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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
include make/helpers.mk
include make/neuralspot_config.mk
include make/neuralspot_toolchain.mk
include make/jlink.mk
include make/ns_for_ei.mk
local_app_name := main
PROJECT := yes_no
# The Model
sources := $(wildcard $(PROJECT)/src/*.c)
sources += $(wildcard $(PROJECT)/src/*.cc)
sources += $(wildcard $(PROJECT)/src/*.cpp)
sources += $(wildcard $(PROJECT)/src/*.s)
sources += $(wildcard $(PROJECT)/src/ns-core/*.c)
sources += $(wildcard $(PROJECT)/src/ns-core/*.cc)
sources += $(wildcard $(PROJECT)/src/ns-core/*.cpp)
sources += $(wildcard $(PROJECT)/src/ns-core/*.s)
# EdgeImpulse Stuff
# Common Code
sources += $(wildcard src/ambiq/*.cpp)
# Per-project EI stuff
sources += $(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/TransformFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/CommonTables/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/BasicMathFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/ComplexMathFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/FastMathFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/SupportFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/MatrixFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/Source/StatisticsFunctions/*.c) \
$(wildcard $(PROJECT)/src/tflite-model/*.cpp) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/dsp/kissfft/*.cpp) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/dsp/dct/*.cpp) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/dsp/memory.cpp) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/porting/posix/*.c*) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/porting/mingw32/*.c*) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/tensorflow/lite/kernels/*.cc) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/tensorflow/lite/kernels/internal/*.cc) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/tensorflow/lite/micro/kernels/*.cc) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/tensorflow/lite/micro/*.cc) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/tensorflow/lite/micro/memory_planner/*.cc) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/tensorflow/lite/core/api/*.cc) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/ActivationFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/BasicMathFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/ConcatenationFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/ConvolutionFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/FullyConnectedFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/NNSupportFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/PoolingFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/ReshapeFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/SoftmaxFunctions/*.c) \
$(wildcard $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Source/SVDFunctions/*.c)
sources += $(PROJECT)/src/edge-impulse-sdk/tensorflow/lite/c/common.c
VPATH+=$(dir $(sources))
targets := $(BINDIR)/$(local_app_name).axf
targets += $(BINDIR)/$(local_app_name).bin
objects = $(call source-to-object,$(sources))
dependencies = $(subst .o,.d,$(objects))
DEFINES += EI_CLASSIFIER_TFLITE_ENABLE_CMSIS_NN=1 # Use CMSIS-NN functions in the SDK
DEFINES += __ARM_FEATURE_DSP=1 # Enable CMSIS-DSP optimized features
DEFINES += TF_LITE_DISABLE_X86_NEON=1
DEFINES += EI_CLASSIFIER_ALLOCATION_STATIC=1
# DEFINES += EIDSP_SIGNAL_C_FN_POINTER=1
# DEFINES += EI_C_LINKAGE=1
DEFINES += STACK_SIZE=4096
# DEFINES += NS_MALLOC_HEAP_SIZE_IN_K=24
# Experiment for hello_ambiq model (still runs out of heap, it's in infinite alloc loop)
# DEFINES += STACK_SIZE=8192
DEFINES += NS_MALLOC_HEAP_SIZE_IN_K=48
LOCAL_INCLUDES += src
LOCAL_INCLUDES += $(PROJECT)/src
LOCAL_INCLUDES += $(PROJECT)/src/ns-core
LOCAL_INCLUDES += $(PROJECT)/src/edge-impulse-sdk/CMSIS/NN/Include/
LOCAL_INCLUDES += $(PROJECT)/src/edge-impulse-sdk/CMSIS/DSP/PrivateInclude/
# split $(objects) to avoid exceeding Windows command line length limit'
objects_tf := $(call FILTER_IN,tensorflow,$(objects))
objects_cmsis := $(call FILTER_IN,CMSIS,$(objects))
objects_rest := $(call FILTER_OUT,tensorflow,$(objects))
objects_rest1 := $(call FILTER_OUT,CMSIS,$(objects_rest))
libs += ../$(BINDIR)/wis_cmsis.a ../$(BINDIR)/wis_tf.a
CFLAGS += $(addprefix -D,$(DEFINES))
CFLAGS += $(addprefix -I $(PROJECT)/includes/,$(INCLUDES))
CFLAGS += $(addprefix -I ,$(LOCAL_INCLUDES))
LINKER_FILE := $(PROJECT)/libs/linker_script.ld
libraries += $(addprefix $(PROJECT)/,$(libs))
all: $(BINDIR) $(objects) $(targets)
.PHONY: clean
clean:
ifeq ($(OS),Windows_NT)
@echo "Windows_NT"
@echo $(Q) $(RM) -rf $(BINDIR)/*
$(Q) $(RM) -rf $(BINDIR)/*
else
$(Q) $(RM) -rf $(BINDIR) $(JLINK_CF)
endif
ifneq "$(MAKECMDGOALS)" "clean"
include $(dependencies)
endif
$(BINDIR):
@mkdir -p $@
$(BINDIR)/%.o: %.cc
@echo " Compiling $(COMPILERNAME) $< to make $@"
@mkdir -p $(@D)
$(Q) $(CC) -c $(CFLAGS) $(CCFLAGS) $< -o $@
$(BINDIR)/%.o: %.cpp
@echo " Compiling $(COMPILERNAME) $< to make $@"
@mkdir -p $(@D)
$(Q) $(CC) -c $(CFLAGS) $(CCFLAGS) $< -o $@
$(BINDIR)/%.o: %.c
@echo " Compiling $(COMPILERNAME) $< to make $@"
@mkdir -p $(@D)
$(Q) $(CC) -c $(CFLAGS) $(CONLY_FLAGS) $< -o $@
$(BINDIR)/%.o: %.s
@echo " Assembling $(COMPILERNAME) $<"
@mkdir -p $(@D)
$(Q) $(CC) -c $(CFLAGS) $< -o $@
$(BINDIR)/$(local_app_name).axf: $(objects)
@echo " Linking $(COMPILERNAME) $@"
@mkdir -p $(@D)
# Break into multiple steps to avoid exceeding Windows command line length limit
$(Q) $(AR) rsc $(BINDIR)/wis_tf.a $(objects_tf)
$(Q) $(AR) rsc $(BINDIR)/wis_cmsis.a $(objects_cmsis)
# $(Q) $(AR) rsc $(BINDIR)/wis_rest1.a $(objects_rest1)
$(Q) $(CC) -Wl,-T,$(LINKER_FILE) -o $@ $(objects_rest1) $(LFLAGS)
$(BINDIR)/$(local_app_name).bin: $(BINDIR)/$(local_app_name).axf
@echo " Copying $(COMPILERNAME) $@..."
@mkdir -p $(@D)
$(Q) $(CP) $(CPFLAGS) $< $@
$(Q) $(OD) $(ODFLAGS) $< > $(BINDIR)/$(local_app_name).lst
# $(Q) $(SIZE) $(objects) $(lib_prebuilt) $< > $(BINDIR)/$(local_app_name).size
$(JLINK_CF):
@echo " Creating JLink command sequence input file..."
$(Q) echo "ExitOnError 1" > $@
$(Q) echo "Reset" >> $@
$(Q) echo "LoadFile $(BINDIR)/$(local_app_name).bin, $(JLINK_PF_ADDR)" >> $@
$(Q) echo "Exit" >> $@
.PHONY: deploy
deploy: $(JLINK_CF)
@echo " Deploying $< to device (ensure JLink USB connected and powered on)..."
$(Q) $(JLINK) $(JLINK_CMD)
.PHONY: view
view:
@echo " Printing SWO output (ensure JLink USB connected and powered on)..."
$(Q) $(JLINK_SWO) $(JLINK_SWO_CMD)
%.d: ;