1export PATH := $(MAKEFILE_DIR)/downloads/gcc_embedded/bin/:$(PATH) 2TARGET_ARCH := cortex-m4 3TARGET_TOOLCHAIN_PREFIX := arm-none-eabi- 4TARGET_TOOLCHAIN_ROOT := $(TENSORFLOW_ROOT)$(MAKEFILE_DIR)/downloads/gcc_embedded/bin/ 5# Download the Ambiq Apollo3 SDK and set this variable to find the header 6# files: 7APOLLO3_SDK := $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST) 8# Need a pointer to the GNU ARM toolchain for crtbegin.o for the fp functions 9# with the hard interfaces. 10GCC_ARM := $(MAKEFILE_DIR)/downloads/gcc_embedded/ 11 12DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/arm_gcc_download.sh ${MAKEFILE_DIR}/downloads) 13ifneq ($(DOWNLOAD_RESULT), SUCCESS) 14 $(error Something went wrong with the GCC download: $(DOWNLOAD_RESULT)) 15endif 16 17$(eval $(call add_third_party_download,$(AM_SDK_URL),$(AM_SDK_MD5),$(AM_SDK_DEST),patch_am_sdk)) 18 19DOWNLOAD_RESULT := $(shell $(MAKEFILE_DIR)/ext_libs/cmsis_download.sh ${MAKEFILE_DIR}/downloads) 20ifneq ($(DOWNLOAD_RESULT), SUCCESS) 21 $(error Something went wrong with the CMSIS download: $(DOWNLOAD_RESULT)) 22endif 23 24ifeq ($(findstring sparkfun,$(TARGET)), sparkfun) 25 $(eval $(call add_third_party_download,$(SF_BSPS_URL),$(SF_BSPS_MD5),$(AM_SDK_DEST)/$(SF_BSPS_DEST),)) 26 # Make sure that we download the full Ambiq SDK before the SparkFun BSPs. 27$(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST)/$(SF_BSPS_DEST): $(MAKEFILE_DIR)/downloads/$(AM_SDK_DEST) 28endif 29 30PLATFORM_FLAGS = \ 31 -DPART_apollo3 \ 32 -DAM_PACKAGE_BGA \ 33 -DAM_PART_APOLLO3 \ 34 -DGEMMLOWP_ALLOW_SLOW_SCALAR_FALLBACK \ 35 -DTF_LITE_STATIC_MEMORY \ 36 -DTF_LITE_MCU_DEBUG_LOG \ 37 -D __FPU_PRESENT=1 \ 38 -DARM_MATH_CM4 \ 39 -fmessage-length=0 \ 40 -fno-unwind-tables \ 41 -ffunction-sections \ 42 -fdata-sections \ 43 -funsigned-char \ 44 -MMD \ 45 -mcpu=cortex-m4 \ 46 -mthumb \ 47 -mfpu=fpv4-sp-d16 \ 48 -mfloat-abi=hard \ 49 -Wvla \ 50 -Wall \ 51 -Wextra \ 52 -Wno-implicit-fallthrough \ 53 -Wno-missing-field-initializers \ 54 -Wno-return-type \ 55 -Wno-sign-compare \ 56 -Wno-strict-aliasing \ 57 -Wno-type-limits \ 58 -Wno-unused-function \ 59 -Wno-unused-parameter \ 60 -fno-delete-null-pointer-checks \ 61 -fomit-frame-pointer \ 62 -nostdlib \ 63 -ggdb \ 64 -O3 65 66CXXFLAGS += \ 67 $(PLATFORM_FLAGS) \ 68 -fno-use-cxa-atexit 69 70CCFLAGS += $(PLATFORM_FLAGS) \ 71 -Wno-int-conversion 72 73LDFLAGS += \ 74 -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard \ 75 -nostartfiles -static \ 76 -Wl,--gc-sections -Wl,--entry,Reset_Handler \ 77 -Wl,--start-group -lm -lc -lgcc -Wl,--end-group \ 78 -fno-exceptions \ 79 -nostdlib --specs=nano.specs -t -lstdc++ -lc -lnosys -lm \ 80 -Wl,-T,$(TENSORFLOW_ROOT)$(APOLLO3_SDK)/boards/apollo3_evb/examples/hello_world/gcc_patched/apollo3evb.ld \ 81 -Wl,-Map=$(TENSORFLOW_ROOT)$(MAKEFILE_DIR)/gen/$(TARGET).map,--cref 82BUILD_TYPE := micro 83ifeq ($(TARGET), apollo3evb) 84 BOARD_BSP_PATH := $(APOLLO3_SDK)/boards/apollo3_evb/bsp 85endif 86ifeq ($(findstring sparkfun,$(TARGET)), sparkfun) 87 BOARD_BSP_PATH := $(APOLLO3_SDK)/$(SF_BSPS_DEST)/$(subst sparkfun_,,$(TARGET))/bsp 88 INCLUDES+= \ 89 -I$(APOLLO3_SDK)/$(SF_BSPS_DEST)/common/third_party/hm01b0 90endif 91MICROLITE_LIBS := \ 92 $(BOARD_BSP_PATH)/gcc/bin/libam_bsp.a \ 93 $(APOLLO3_SDK)/mcu/apollo3/hal/gcc/bin/libam_hal.a \ 94 $(GCC_ARM)/lib/gcc/arm-none-eabi/10.2.1/thumb/v7e-m+fp/hard/crtbegin.o \ 95 -lm 96INCLUDES += \ 97 -isystem$(MAKEFILE_DIR)/downloads/cmsis/CMSIS/Core/Include/ \ 98 -isystem$(MAKEFILE_DIR)/downloads/cmsis/CMSIS/DSP/Include/ \ 99 -I$(GCC_ARM)/arm-none-eabi/ \ 100 -I$(APOLLO3_SDK)/mcu/apollo3/ \ 101 -I$(APOLLO3_SDK)/mcu/apollo3/regs \ 102 -I$(APOLLO3_SDK)/mcu/apollo3/hal \ 103 -I$(APOLLO3_SDK)/CMSIS/AmbiqMicro/Include/ \ 104 -I$(BOARD_BSP_PATH) \ 105 -I$(APOLLO3_SDK)/devices/ \ 106 -I$(APOLLO3_SDK)/utils/ \ 107 108 109# The startup_gcc.c file is an altered version of the examples/hello_world/gcc/startup_gcc.c 110# file from Ambiq: 111# - Increase the stack size from 1k to 20k 112# - Change the application entry call from main() to _main() 113# The am_*.c files should be copied from the Ambiq Apollo3 SDK 114# _main.c contains application and target specific initialization, like 115# setting clock speed, default uart setups, etc. and an implementation 116# of the DebugLog interfaces. 117MICROLITE_CC_SRCS += \ 118 $(APOLLO3_SDK)/boards/apollo3_evb/examples/hello_world/gcc_patched/startup_gcc.c \ 119 $(APOLLO3_SDK)/utils/am_util_delay.c \ 120 $(APOLLO3_SDK)/utils/am_util_faultisr.c \ 121 $(APOLLO3_SDK)/utils/am_util_id.c \ 122 $(APOLLO3_SDK)/utils/am_util_stdio.c \ 123 $(APOLLO3_SDK)/devices/am_devices_led.c 124 125CMSIS_SRC_DIR := $(MAKEFILE_DIR)/downloads/cmsis/CMSIS/DSP/Source 126THIRD_PARTY_CC_SRCS := \ 127$(CMSIS_SRC_DIR)/BasicMathFunctions/arm_dot_prod_q15.c \ 128$(CMSIS_SRC_DIR)/BasicMathFunctions/arm_mult_q15.c \ 129$(CMSIS_SRC_DIR)/TransformFunctions/arm_rfft_init_q15.c \ 130$(CMSIS_SRC_DIR)/TransformFunctions/arm_rfft_q15.c \ 131$(CMSIS_SRC_DIR)/TransformFunctions/arm_bitreversal2.c \ 132$(CMSIS_SRC_DIR)/TransformFunctions/arm_cfft_q15.c \ 133$(CMSIS_SRC_DIR)/TransformFunctions/arm_cfft_radix4_q15.c \ 134$(CMSIS_SRC_DIR)/CommonTables/arm_const_structs.c \ 135$(CMSIS_SRC_DIR)/CommonTables/arm_common_tables.c \ 136$(CMSIS_SRC_DIR)/StatisticsFunctions/arm_mean_q15.c \ 137$(CMSIS_SRC_DIR)/StatisticsFunctions/arm_max_q7.c 138 139MICRO_SPEECH_TEST_SRCS += \ 140 $(AP3_MICRO_DIR)/_main.c 141 142TEST_SCRIPT := tensorflow/lite/micro/testing/test_apollo3evb_binary.sh 143# These are tests that don't currently work on the Apollo3 board. 144EXCLUDED_TESTS := \ 145 tensorflow/lite/micro/micro_interpreter_test.cc \ 146 tensorflow/lite/micro/simple_tensor_allocator_test.cc 147MICROLITE_TEST_SRCS := $(filter-out $(EXCLUDED_TESTS), $(MICROLITE_TEST_SRCS)) 148