forked from openmv/openmv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·323 lines (268 loc) · 8.46 KB
/
Makefile
File metadata and controls
executable file
·323 lines (268 loc) · 8.46 KB
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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# This file is part of the OpenMV project.
#
# Copyright (c) 2013-2024 Ibrahim Abdelkader <iabdalkader@openmv.io>
# Copyright (c) 2013-2024 Kwabena W. Agyeman <kwagyeman@openmv.io>
#
# This work is licensed under the MIT license, see the file LICENSE for details.
#
# Top level Makefile
# Set verbosity
ifeq ($(V), 1)
export Q =
else
export Q = @
MAKEFLAGS += --silent
endif
# Debug configuration
DEBUGGER ?= JLINK
# Dummy target to run sdk/clean
ifeq ($(TARGET),)
ifeq ($(filter sdk clean,$(MAKECMDGOALS)),)
$(error Invalid or no TARGET specified)
else
TARGET=OPENMV4
endif
endif
# OpenMV SDK configuration
SDK_VERSION = 1.1.0
SDK_DIR ?= $(HOME)/openmv-sdk-$(SDK_VERSION)
SDK_STAMP = $(SDK_DIR)/sdk.version
# Check if the SDK is downloaded
ifeq ($(filter sdk clean,$(MAKECMDGOALS)),)
ifeq ($(wildcard $(SDK_STAMP)),)
$(error OpenMV SDK not found. Run 'make sdk' to install it.)
else
SDK_INSTALLED := $(shell cat $(SDK_STAMP))
ifneq ($(SDK_INSTALLED),$(SDK_VERSION))
$(error OpenMV SDK version mismatch. Run 'make sdk'.)
endif
endif
endif
# Targets
export OPENMV ?= openmv
export FIRMWARE ?= firmware
OMV_DEBUG_ELF ?= $(FIRMWARE)
export BOOTLOADER ?= bootloader
# Commands (use := to avoid repeated expansion overhead in parallel builds)
export CC := $(Q)arm-none-eabi-gcc
export CLANG := $(Q)clang
export CXX := $(Q)arm-none-eabi-g++
export AS := $(Q)arm-none-eabi-as
export LD := $(Q)arm-none-eabi-ld
export AR := $(Q)arm-none-eabi-ar
export RM := $(Q)rm
export CPP := $(Q)arm-none-eabi-cpp
export SIZE := $(Q)arm-none-eabi-size
export STRIP := $(Q)arm-none-eabi-strip -s
export OBJCOPY := $(Q)arm-none-eabi-objcopy
export OBJDUMP := $(Q)arm-none-eabi-objdump
export PYTHON := $(Q)python3
export MKDIR := $(Q)mkdir
export ECHO := $(Q)@echo
export MAKE := $(Q)make
export CAT := $(Q)cat
export MKROMFS := mkromfs.py
export MACHINE := $(shell uname -m)
# Directories
export TOP_DIR:=$(shell pwd)
export BUILD:=$(TOP_DIR)/build
export TOOLS_DIR:=$(TOP_DIR)/tools
export FW_DIR:=$(BUILD)/bin
export BOOT_DIR=boot
export PORTS_DIR=ports
export CUBEAI_DIR=cubeai
export CMSIS_DIR=lib/cmsis
export MICROPY_DIR=lib/micropython
export NEMA_DIR=drivers/nema
export LIBPDM_DIR=lib/libpdm
export TENSORFLOW_DIR=lib/tflm
export COMMON_DIR=common
export CYW4343_FW_DIR=drivers/cyw4343/firmware/
export OMV_BOARD_CONFIG_DIR:=$(TOP_DIR)/boards/$(TARGET)/
export OMV_LIB_DIR:=$(TOP_DIR)/scripts/libraries
export FROZEN_MANIFEST:=$(OMV_BOARD_CONFIG_DIR)/manifest.py
# Prepend SDK bin directories to PATH.
STEDGEAI_CORE = $(wildcard $(SDK_DIR)/stedgeai/[0-9]*)
STEDGEAI_UTIL = Utilities/$(if $(filter Darwin,$(shell uname -s)),macarm,linux)
export PATH := $(SDK_DIR)/gcc/bin:$(SDK_DIR)/llvm/bin:$(SDK_DIR)/cmake/bin:$(SDK_DIR)/python/bin:$(SDK_DIR)/stcubeprog/bin:$(STEDGEAI_CORE)/$(STEDGEAI_UTIL):$(SDK_DIR)/fvp/bin:$(PATH)
# Debugging/Optimization
ifeq ($(DEBUG), 1)
ROM_TEXT_COMPRESSION = 0
CFLAGS += -Og -ggdb3
else
DEBUG=0
ROM_TEXT_COMPRESSION = 1
CFLAGS += -O2 -DNDEBUG
USERMOD_OPT = -O2
MPY_CFLAGS += -DMICROPY_ROM_TEXT_COMPRESSION=1
endif
# Enable debug printf
ifeq ($(DEBUG_PRINTF), 1)
CFLAGS += -DOMV_DEBUG_PRINTF
endif
# Enable stack protection
ifeq ($(STACK_PROTECTOR), 1)
CFLAGS += -fstack-protector-all -DSTACK_PROTECTOR
endif
# Enable debug printf
ifeq ($(FB_ALLOC_STATS), 1)
CFLAGS += -DFB_ALLOC_STATS
endif
# Enable timing for some functions.
ifeq ($(PROFILE_ENABLE), 1)
$(info ===================================)
$(info ======= Profiling Enabled =======)
$(info ===================================)
# Enable profiling in IRQ context (default: enabled)
PROFILE_IRQ ?= 0
# Default profiler hash table size (must be power of 2)
ifeq ($(PROFILE_HASH),)
PROFILE_HASH=256
endif
CFLAGS += -DOMV_PROFILER_ENABLE=1
CFLAGS += -DOMV_PROFILER_HASH_SIZE=$(PROFILE_HASH)
CFLAGS += -DOMV_PROFILER_IRQ_ENABLE=$(PROFILE_IRQ)
CFLAGS += -finstrument-functions-exclude-file-list=lib/cmsis,lib/stm32,/lib/mimxrt,lib/alif,simd.h
endif
# Include OpenMV board config first to set the port.
include $(OMV_BOARD_CONFIG_DIR)/omv_boardconfig.mk
# Include MicroPython board config.
#include $(MP_BOARD_CONFIG_DIR)/mpconfigboard.mk
# Additional qstr definitions for OpenMV
#OMV_SRC_QSTR := $(wildcard $(TOP_DIR)/modules/*.c)
export OMV_PORT_DIR:=$(TOP_DIR)/ports/$(PORT)
export MP_BOARD_CONFIG_DIR:=$(TOP_DIR)/$(MICROPY_DIR)/ports/$(PORT)/boards/$(TARGET)/
# The following command line args are passed to MicroPython's top Makefile.
MPY_MKARGS = PORT=$(PORT) BOARD=$(TARGET) DEBUG=$(DEBUG) MICROPY_MANIFEST_OMV_LIB_DIR=$(OMV_LIB_DIR)\
FROZEN_MANIFEST=$(FROZEN_MANIFEST) OMV_SRC_QSTR="$(OMV_SRC_QSTR)"\
MICROPY_ROM_TEXT_COMPRESSION=$(ROM_TEXT_COMPRESSION) USER_C_MODULES=$(TOP_DIR)
# Check GCC toolchain version.
ifeq ($(CPU),cortex-m55)
include $(TOP_DIR)/common/check_toolchain.mk
endif
# Configure additional built-in modules. Note must define both the CFLAGS and the Make command line args.
ifeq ($(MICROPY_PY_CSI), 1)
MPY_CFLAGS += -DMICROPY_PY_CSI=1
MPY_MKARGS += MICROPY_PY_CSI=1
endif
ifeq ($(MICROPY_PY_CSI_NG), 1)
MPY_CFLAGS += -DMICROPY_PY_CSI_NG=1
MPY_MKARGS += MICROPY_PY_CSI_NG=1
endif
ifeq ($(MICROPY_PY_PROTOCOL), 1)
MPY_CFLAGS += -DMICROPY_PY_PROTOCOL=1
MPY_MKARGS += MICROPY_PY_PROTOCOL=1
endif
ifeq ($(MICROPY_PY_FIR), 1)
MPY_CFLAGS += -DMICROPY_PY_FIR=1
MPY_MKARGS += MICROPY_PY_FIR=1
endif
ifeq ($(MICROPY_PY_WINC1500), 1)
MPY_CFLAGS += -DMICROPY_PY_WINC1500=1
MPY_MKARGS += MICROPY_PY_WINC1500=1
MPY_PENDSV_ENTRIES += PENDSV_DISPATCH_WINC,
endif
ifeq ($(MICROPY_PY_IMU), 1)
MPY_CFLAGS += -DMICROPY_PY_IMU=1
MPY_MKARGS += MICROPY_PY_IMU=1
endif
ifeq ($(MICROPY_PY_CRC), 1)
MPY_CFLAGS += -DMICROPY_PY_CRC=1
MPY_MKARGS += MICROPY_PY_CRC=1
endif
ifeq ($(MICROPY_PY_BTREE), 1)
MPY_CFLAGS += -DMICROPY_PY_BTREE=1
MPY_MKARGS += MICROPY_PY_BTREE=1
endif
ifeq ($(MICROPY_PY_TOF), 1)
MPY_CFLAGS += -DMICROPY_PY_TOF=1
MPY_MKARGS += MICROPY_PY_TOF=1
endif
ifeq ($(MICROPY_PY_ULAB), 1)
MPY_CFLAGS += -DMICROPY_PY_ULAB=1
MPY_CFLAGS += -DULAB_CONFIG_FILE="\"$(OMV_BOARD_CONFIG_DIR)/ulab_config.h\""
MPY_MKARGS += MICROPY_PY_ULAB=1
endif
ifeq ($(MICROPY_PY_AUDIO), 1)
MPY_CFLAGS += -DMICROPY_PY_AUDIO=1
MPY_MKARGS += MICROPY_PY_AUDIO=1
endif
ifeq ($(MICROPY_PY_DISPLAY), 1)
MPY_CFLAGS += -DMICROPY_PY_DISPLAY=1
MPY_MKARGS += MICROPY_PY_DISPLAY=1
endif
ifeq ($(MICROPY_PY_TV), 1)
MPY_CFLAGS += -DMICROPY_PY_TV=1
MPY_MKARGS += MICROPY_PY_TV=1
endif
ifeq ($(CUBEAI), 1)
MPY_CFLAGS += -DMICROPY_PY_CUBEAI=1
MPY_MKARGS += MICROPY_PY_CUBEAI=1
endif
ifeq ($(MICROPY_PY_ML), 1)
MPY_CFLAGS += -DMICROPY_PY_ML=1
MPY_MKARGS += MICROPY_PY_ML=1
endif
ifeq ($(MICROPY_PY_ML_TFLM), 1)
MPY_CFLAGS += -DMICROPY_PY_ML_TFLM=1
MPY_MKARGS += MICROPY_PY_ML_TFLM=1
endif
ifeq ($(MICROPY_PY_ML_STAI), 1)
MPY_CFLAGS += -DMICROPY_PY_ML_STAI=1
MPY_MKARGS += MICROPY_PY_ML_STAI=1
endif
ifeq ($(MICROPY_PY_UNITTEST), 1)
MPY_CFLAGS += -DMICROPY_PY_UNITTEST=1
MPY_MKARGS += MICROPY_PY_UNITTEST=1
endif
MPY_PENDSV_ENTRIES := $(shell echo $(MPY_PENDSV_ENTRIES) | tr -d '[:space:]')
MPY_CFLAGS += -DMICROPY_HW_USB_VID=$(OMV_USB_VID)
MPY_CFLAGS += -DMICROPY_HW_USB_PID=$(OMV_USB_PID)
MPY_CFLAGS += -DMICROPY_BOARD_PENDSV_ENTRIES="$(MPY_PENDSV_ENTRIES)"
MPY_CFLAGS += -DMP_CONFIGFILE=\<$(OMV_PORT_DIR)/omv_mpconfigport.h\>
# Include the port Makefile.
include $(OMV_PORT_DIR)/omv_portconfig.mk
# Freeze recursively-expanded variables into simply-expanded ones.
# Without this, make re-evaluates all sub-variable references every
# time it constructs the environment for each recipe fork
CFLAGS := $(CFLAGS)
LDFLAGS := $(LDFLAGS)
MPY_CFLAGS := $(MPY_CFLAGS)
MPY_MKARGS := $(MPY_MKARGS)
AFLAGS := $(AFLAGS)
TOP_DIR := $(TOP_DIR)
BUILD := $(BUILD)
TOOLS_DIR := $(TOOLS_DIR)
FW_DIR := $(FW_DIR)
OMV_BOARD_CONFIG_DIR := $(OMV_BOARD_CONFIG_DIR)
OMV_PORT_DIR := $(OMV_PORT_DIR)
MP_BOARD_CONFIG_DIR := $(MP_BOARD_CONFIG_DIR)
OMV_LIB_DIR := $(OMV_LIB_DIR)
FROZEN_MANIFEST := $(FROZEN_MANIFEST)
# Export variables for sub-make.
export PORT
export MCU
export TARGET
export CFLAGS
export AFLAGS
export LDFLAGS
export MPY_CFLAGS
export MPY_MKARGS
export USERMOD_OPT
clean:
$(RM) -fr $(BUILD)
size:
ifeq ($(OMV_ENABLE_BL), 1)
$(SIZE) --format=SysV $(FW_DIR)/$(BOOTLOADER).elf
endif
$(SIZE) --format=SysV $(FW_DIR)/$(FIRMWARE).elf
.PHONY: sdk
sdk:
$(Q)bash -c "source tools/ci.sh && ci_install_sdk"
submodules:
$(MAKE) -C $(MICROPY_DIR)/ports/$(PORT) BOARD=$(TARGET) submodules
debug: $(ROMFS_IMAGE)
ifeq ($(DEBUGGER),NONE)
$(error This target does not support debugging)
endif
gdbrunner $(DEBUGGER) $(OMV_$(DEBUGGER)_ARGS) $(FW_DIR)/$(OMV_DEBUG_ELF).elf