Merge pull request #38175 from sensiml:features/gen_projects

PiperOrigin-RevId: 315725889
Change-Id: Iba207060ed8416133c3d67564d3d744a43e37708
This commit is contained in:
TensorFlower Gardener 2020-06-10 11:22:20 -07:00
commit d3271b9d21
4 changed files with 60 additions and 10 deletions

View File

@ -6,6 +6,10 @@ endif
TENSORFLOW_ROOT :=
MAKEFILE_DIR := tensorflow/lite/micro/tools/make
# Override this on make command line to to parse thirdy party downloads during project generation
# make -f tensorflow/lite/micro/tools/make/Makefile PARSE_THIRD_PARTY=true TARGET=apollo3evb generate_hello_world_make_project
PARSE_THIRD_PARTY :=
# Pull in some convenience functions.
include $(MAKEFILE_DIR)/helper_functions.inc

View File

@ -419,6 +419,9 @@ endef
# 3 - C/C++ header files needed for the test.
# Calling eval on the output will create the targets that you need.
define microlite_test
ifeq (,$(findstring _test, $(1)))
$(eval $(call generate_project_third_party_parsing))
endif
$(1)_LOCAL_SRCS := $(2)
$(1)_LOCAL_SRCS := $$(call specialize,$$($(1)_LOCAL_SRCS))
ALL_SRCS += $$($(1)_LOCAL_SRCS)
@ -472,3 +475,39 @@ endef
# 1 - Starting path
# 2 - File pattern, e.g: *.h
recursive_find = $(wildcard $(1)$(2)) $(foreach dir,$(wildcard $(1)*),$(call recursive_find,$(dir)/,$(2)))
# Modifies the Makefile to include all third party Srcs so that generate
# projects will create a Makefile that can be immediatley compiled without
# modification
define generate_project_third_party_parsing
ifeq ($$(PARSE_THIRD_PARTY), true)
# Get generated src includes with update path to third party
THIRD_PARTY_CC_SRCS += $$(filter $$(MAKEFILE_DIR)/downloads/%, $$(MICROLITE_CC_SRCS))
MICROLITE_CC_SRCS := $$(filter-out $$(THIRD_PARTY_CC_SRCS), $$(MICROLITE_CC_SRCS))
THIRD_PARTY_CC_SRCS := $$(sort $$(patsubst $$(MAKEFILE_DIR)/downloads/%, third_party/%, $$(THIRD_PARTY_CC_SRCS)))
# Get generated project includes from the includes with update path to third_party
GENERATED_PROJECT_INCLUDES += $$(filter -I$$(MAKEFILE_DIR)/downloads/%, $$(INCLUDES))
GENERATED_PROJECT_INCLUDES := $$(patsubst -I$$(MAKEFILE_DIR)/downloads/%, -Ithird_party/%, $$(GENERATED_PROJECT_INCLUDES))
GENERATED_PROJECT_INCLUDES += $$(filter -isystem$$(MAKEFILE_DIR)/downloads/%, $$(INCLUDES))
GENERATED_PROJECT_INCLUDES := $$(sort $$(patsubst -isystem$$(MAKEFILE_DIR)/downloads/%, -isystemthird_party/%, $$(GENERATED_PROJECT_INCLUDES)))
# We dont copy the libraries, we just want to make sure we link to them correctly.
MICROLITE_LIBS := $$(sort $$(patsubst $$(MAKEFILE_DIR)/downloads/%, $$(TENSORFLOW_ROOT)$$(MAKEFILE_DIR)/downloads/%, $$(MICROLITE_LIBS)))
LDFLAGS := $$(sort $$(patsubst $$(MAKEFILE_DIR)/downloads/%, $$(TENSORFLOW_ROOT)$$(MAKEFILE_DIR)/downloads/%, $$(LDFLAGS)))
# Copy all third party headers that are mentioned in includes
THIRD_PARTY_CC_HDRS += $$(filter $$(MAKEFILE_DIR)/downloads/%, $$(MICROLITE_CC_HDRS))
MICROLITE_CC_HDRS:= $$(sort $$(filter-out $$(THIRD_PARTY_CC_HDRS), $$(MICROLITE_CC_HDRS)))
THIRD_PARTY_CC_HDRS := $$(sort $$(patsubst $$(MAKEFILE_DIR)/downloads/%, third_party/%, $$(THIRD_PARTY_CC_HDRS)))
# Copy all third party headers that are mentioned in includes
INCLUDE_HDRS := $$(wildcard $$(addsuffix /*.h,$$(filter $$(MAKEFILE_DIR)/downloads/%, $$(patsubst -I%,%,$$(INCLUDES)))))
INCLUDE_HDRS += $$(wildcard $$(addsuffix /*.h,$$(filter $$(MAKEFILE_DIR)/downloads/%, $$(patsubst -isystem%,%,$$(INCLUDES)))))
INCLUDE_HDRS := $$(sort $$(INCLUDE_HDRS))
THIRD_PARTY_CC_HDRS += $ $$(sort $(patsubst $$(MAKEFILE_DIR)/downloads/%, third_party/%, $$(INCLUDE_HDRS)))
endif
endef

View File

@ -6,6 +6,7 @@ ifeq ($(TARGET),$(filter $(TARGET),\
export PATH := $(MAKEFILE_DIR)/downloads/gcc_embedded/bin/:$(PATH)
TARGET_ARCH := cortex-m4
TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
TARGET_TOOLCHAIN_ROOT := $(TENSORFLOW_ROOT)$(MAKEFILE_DIR)/downloads/gcc_embedded/bin/
# Download the Ambiq Apollo3 SDK and set this variable to find the header
# files:
APOLLO3_SDK := $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST)
@ -77,8 +78,8 @@ $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST)/$(SF_BSPS_DEST): $(MAKEFILE_DIR)/downlo
-Wl,--start-group -lm -lc -lgcc -Wl,--end-group \
-fno-exceptions \
-nostdlib --specs=nano.specs -t -lstdc++ -lc -lnosys -lm \
-Wl,-T,$(APOLLO3_SDK)/boards/apollo3_evb/examples/hello_world/gcc_patched/apollo3evb.ld \
-Wl,-Map=$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref
-Wl,-T,$(TENSORFLOW_ROOT)$(APOLLO3_SDK)/boards/apollo3_evb/examples/hello_world/gcc_patched/apollo3evb.ld \
-Wl,-Map=$(TENSORFLOW_ROOT)$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref
BUILD_TYPE := micro
ifeq ($(TARGET), apollo3evb)
BOARD_BSP_PATH := $(APOLLO3_SDK)/boards/apollo3_evb/bsp
@ -98,10 +99,13 @@ $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST)/$(SF_BSPS_DEST): $(MAKEFILE_DIR)/downlo
-isystem$(MAKEFILE_DIR)/downloads/cmsis/CMSIS/DSP/Include/ \
-I$(GCC_ARM)/arm-none-eabi/ \
-I$(APOLLO3_SDK)/mcu/apollo3/ \
-I$(APOLLO3_SDK)/mcu/apollo3/regs \
-I$(APOLLO3_SDK)/mcu/apollo3/hal \
-I$(APOLLO3_SDK)/CMSIS/AmbiqMicro/Include/ \
-I$(BOARD_BSP_PATH) \
-I$(APOLLO3_SDK)/devices/ \
-I$(APOLLO3_SDK)/utils/
-I$(APOLLO3_SDK)/utils/ \
# The startup_gcc.c file is an altered version of the examples/hello_world/gcc/startup_gcc.c
# file from Ambiq:
@ -120,7 +124,7 @@ $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST)/$(SF_BSPS_DEST): $(MAKEFILE_DIR)/downlo
$(APOLLO3_SDK)/devices/am_devices_led.c
CMSIS_SRC_DIR := $(MAKEFILE_DIR)/downloads/cmsis/CMSIS/DSP/Source
CMSIS_SRCS := \
THIRD_PARTY_CC_SRCS := \
$(CMSIS_SRC_DIR)/BasicMathFunctions/arm_mult_q15.c \
$(CMSIS_SRC_DIR)/TransformFunctions/arm_rfft_init_q15.c \
$(CMSIS_SRC_DIR)/TransformFunctions/arm_rfft_q15.c \
@ -141,4 +145,4 @@ $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST)/$(SF_BSPS_DEST): $(MAKEFILE_DIR)/downlo
tensorflow/lite/micro/simple_tensor_allocator_test.cc
MICROLITE_TEST_SRCS := $(filter-out $(EXCLUDED_TESTS), $(MICROLITE_TEST_SRCS))
endif
endif

View File

@ -3,6 +3,7 @@ ifeq ($(TARGET), stm32f4)
export PATH := $(MAKEFILE_DIR)/downloads/gcc_embedded/bin/:$(PATH)
TARGET_ARCH := cortex-m4
TARGET_TOOLCHAIN_PREFIX := arm-none-eabi-
TARGET_TOOLCHAIN_ROOT := $(TENSORFLOW_ROOT)$(MAKEFILE_DIR)/downloads/gcc_embedded/bin/
$(eval $(call add_third_party_download,$(GCC_EMBEDDED_URL),$(GCC_EMBEDDED_MD5),gcc_embedded,))
$(eval $(call add_third_party_download,$(CMSIS_URL),$(CMSIS_MD5),cmsis,))
@ -41,20 +42,21 @@ ifeq ($(TARGET), stm32f4)
CCFLAGS += $(PLATFORM_FLAGS)
LDFLAGS += \
--specs=nosys.specs \
-T $(MAKEFILE_DIR)/targets/stm32f4/stm32f4.lds \
-Wl,-Map=$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref \
-T ${TENSORFLOW_ROOT}$(MAKEFILE_DIR)/targets/stm32f4/stm32f4.lds \
-Wl,-Map=${TENSORFLOW_ROOT}$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref \
-Wl,--gc-sections
BUILD_TYPE := micro
MICROLITE_LIBS := \
-lm
INCLUDES += \
-isystem$(MAKEFILE_DIR)/downloads/cmsis/CMSIS/Core/Include/ \
-I$(MAKEFILE_DIR)/downloads/stm32_bare_lib/include
MICROLITE_CC_SRCS += \
-I$(MAKEFILE_DIR)/downloads/stm32_bare_lib/include/
THIRD_PARTY_CC_SRCS += \
$(wildcard $(MAKEFILE_DIR)/downloads/stm32_bare_lib/source/*.c) \
$(wildcard $(MAKEFILE_DIR)/downloads/stm32_bare_lib/source/*.cc)
EXCLUDED_SRCS := \
$(MAKEFILE_DIR)/downloads/stm32_bare_lib/source/debug_log.c
THIRD_PARTY_CC_SRCS := $(filter-out $(EXCLUDED_SRCS), $(THIRD_PARTY_CC_SRCS))
MICROLITE_CC_SRCS := $(filter-out $(EXCLUDED_SRCS), $(MICROLITE_CC_SRCS))
TEST_SCRIPT := tensorflow/lite/micro/testing/test_stm32f4_binary.sh
# TODO, non working tests.. the micro_speech example partly works
@ -86,7 +88,8 @@ ifeq ($(TARGET), stm32f4)
tensorflow/lite/micro/examples/person_detection_experimental/Makefile.inc \
tensorflow/lite/micro/examples/mobilenet_v2/Makefile.inc \
tensorflow/lite/micro/examples/micro_speech/Makefile.inc \
tensorflow/lite/micro/examples/ds_cnn_l/Makefile.inc
tensorflow/lite/micro/examples/ds_cnn_l/Makefile.inc \
tensorflow/lite/micro/examples/image_recognition_experimental/Makefile.inc
MICRO_LITE_EXAMPLE_TESTS := $(filter-out $(EXCLUDED_EXAMPLE_TESTS), $(MICRO_LITE_EXAMPLE_TESTS))
# These are microcontroller-specific rules for converting the ELF output