Makefile 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # Licensed to the Apache Software Foundation (ASF) under one
  2. # or more contributor license agreements. See the NOTICE file
  3. # distributed with this work for additional information
  4. # regarding copyright ownership. The ASF licenses this file
  5. # to you under the Apache License, Version 2.0 (the
  6. # "License"); you may not use this file except in compliance
  7. # with the License. You may obtain a copy of the License at
  8. #
  9. # http://www.apache.org/licenses/LICENSE-2.0
  10. #
  11. # Unless required by applicable law or agreed to in writing,
  12. # software distributed under the License is distributed on an
  13. # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  14. # KIND, either express or implied. See the License for the
  15. # specific language governing permissions and limitations
  16. # under the License.
  17. # Makefile to build demo
  18. # Setup build environment
  19. BUILD_DIR := build
  20. ARM_CPU = ARMCM55
  21. ETHOSU_PATH = /opt/arm/ethosu
  22. CMSIS_PATH ?= ${ETHOSU_PATH}/cmsis
  23. ETHOSU_PLATFORM_PATH ?= ${ETHOSU_PATH}/core_platform
  24. STANDALONE_CRT_PATH := $(abspath $(BUILD_DIR))/runtime
  25. CORSTONE_300_PATH = ${ETHOSU_PLATFORM_PATH}/targets/corstone-300
  26. PKG_COMPILE_OPTS = -g -Wall -O2 -Wno-incompatible-pointer-types -Wno-format -mcpu=cortex-m55 -mthumb -mfloat-abi=hard -std=gnu99
  27. CMAKE ?= cmake
  28. CC = arm-none-eabi-gcc
  29. AR = arm-none-eabi-ar
  30. RANLIB = arm-none-eabi-ranlib
  31. PKG_CFLAGS = ${PKG_COMPILE_OPTS} \
  32. -I${STANDALONE_CRT_PATH}/include \
  33. -I${STANDALONE_CRT_PATH}/src/runtime/crt/include \
  34. -I${PWD}/include \
  35. -I${CORSTONE_300_PATH} \
  36. -I${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Include/ \
  37. -I${CMSIS_PATH}/CMSIS/Core/Include \
  38. -I${CMSIS_PATH}/CMSIS/NN/Include \
  39. -I${CMSIS_PATH}/CMSIS/DSP/Include \
  40. -I$(abspath $(BUILD_DIR))/codegen/host/include
  41. CMSIS_NN_CMAKE_FLAGS = -DCMAKE_TOOLCHAIN_FILE=$(abspath $(BUILD_DIR))/../arm-none-eabi-gcc.cmake \
  42. -DTARGET_CPU=cortex-m55 \
  43. -DBUILD_CMSIS_NN_FUNCTIONS=YES
  44. PKG_LDFLAGS = -lm -specs=nosys.specs -static -T corstone300.ld
  45. $(ifeq VERBOSE,1)
  46. QUIET ?=
  47. $(else)
  48. QUIET ?= @
  49. $(endif)
  50. DEMO_MAIN = src/demo_bare_metal.c
  51. CODEGEN_SRCS = $(wildcard $(abspath $(BUILD_DIR))/codegen/host/src/*.c)
  52. CODEGEN_OBJS = $(subst .c,.o,$(CODEGEN_SRCS))
  53. CMSIS_STARTUP_SRCS = $(wildcard ${CMSIS_PATH}/Device/ARM/${ARM_CPU}/Source/*.c)
  54. UART_SRCS = $(wildcard ${CORSTONE_300_PATH}/*.c)
  55. demo: $(BUILD_DIR)/demo
  56. $(BUILD_DIR)/stack_allocator.o: $(STANDALONE_CRT_PATH)/src/runtime/crt/memory/stack_allocator.c
  57. $(QUIET)mkdir -p $(@D)
  58. $(QUIET)$(CC) -c $(PKG_CFLAGS) -o $@ $^
  59. $(BUILD_DIR)/crt_backend_api.o: $(STANDALONE_CRT_PATH)/src/runtime/crt/common/crt_backend_api.c
  60. $(QUIET)mkdir -p $(@D)
  61. $(QUIET)$(CC) -c $(PKG_CFLAGS) -o $@ $^
  62. # Build generated code
  63. $(BUILD_DIR)/libcodegen.a: $(CODEGEN_SRCS)
  64. $(QUIET)cd $(abspath $(BUILD_DIR)/codegen/host/src) && $(CC) -c $(PKG_CFLAGS) $(CODEGEN_SRCS)
  65. $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libcodegen.a) $(CODEGEN_OBJS)
  66. $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libcodegen.a)
  67. # Build CMSIS startup code
  68. ${BUILD_DIR}/libcmsis_startup.a: $(CMSIS_STARTUP_SRCS)
  69. $(QUIET)mkdir -p $(abspath $(BUILD_DIR)/libcmsis_startup)
  70. $(QUIET)cd $(abspath $(BUILD_DIR)/libcmsis_startup) && $(CC) -c $(PKG_CFLAGS) -D${ARM_CPU} $^
  71. $(QUIET)$(AR) -cr $(abspath $(BUILD_DIR)/libcmsis_startup.a) $(abspath $(BUILD_DIR))/libcmsis_startup/*.o
  72. $(QUIET)$(RANLIB) $(abspath $(BUILD_DIR)/libcmsis_startup.a)
  73. CMSIS_SHA_FILE=${CMSIS_PATH}/977abe9849781a2e788b02282986480ff4e25ea6.sha
  74. ifneq ("$(wildcard $(CMSIS_SHA_FILE))","")
  75. ${BUILD_DIR}/cmsis_nn/Source/libcmsis-nn.a:
  76. $(QUIET)mkdir -p $(@D)
  77. $(QUIET)cd $(CMSIS_PATH)/CMSIS/NN && $(CMAKE) -B $(abspath $(BUILD_DIR)/cmsis_nn) $(CMSIS_NN_CMAKE_FLAGS)
  78. $(QUIET)cd $(abspath $(BUILD_DIR)/cmsis_nn) && $(MAKE) all
  79. else
  80. # Build CMSIS-NN
  81. ${BUILD_DIR}/cmsis_nn/Source/SoftmaxFunctions/libCMSISNNSoftmax.a:
  82. $(QUIET)mkdir -p $(@D)
  83. $(QUIET)cd $(CMSIS_PATH)/CMSIS/NN && $(CMAKE) -B $(abspath $(BUILD_DIR)/cmsis_nn) $(CMSIS_NN_CMAKE_FLAGS)
  84. $(QUIET)cd $(abspath $(BUILD_DIR)/cmsis_nn) && $(MAKE) all
  85. endif
  86. # Build demo application
  87. ifneq ("$(wildcard $(CMSIS_SHA_FILE))","")
  88. $(BUILD_DIR)/demo: $(DEMO_MAIN) $(UART_SRCS) $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o \
  89. ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a ${BUILD_DIR}/cmsis_nn/Source/libcmsis-nn.a
  90. $(QUIET)mkdir -p $(@D)
  91. $(QUIET)$(CC) $(PKG_CFLAGS) $(FREERTOS_FLAGS) -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(PKG_LDFLAGS)
  92. else
  93. $(BUILD_DIR)/demo: $(DEMO_MAIN) $(UART_SRCS) $(BUILD_DIR)/stack_allocator.o $(BUILD_DIR)/crt_backend_api.o \
  94. ${BUILD_DIR}/libcodegen.a ${BUILD_DIR}/libcmsis_startup.a \
  95. ${BUILD_DIR}/cmsis_nn/Source/SoftmaxFunctions/libCMSISNNSoftmax.a \
  96. ${BUILD_DIR}/cmsis_nn/Source/FullyConnectedFunctions/libCMSISNNFullyConnected.a \
  97. ${BUILD_DIR}/cmsis_nn/Source/SVDFunctions/libCMSISNNSVDF.a \
  98. ${BUILD_DIR}/cmsis_nn/Source/ReshapeFunctions/libCMSISNNReshape.a \
  99. ${BUILD_DIR}/cmsis_nn/Source/ActivationFunctions/libCMSISNNActivation.a \
  100. ${BUILD_DIR}/cmsis_nn/Source/NNSupportFunctions/libCMSISNNSupport.a \
  101. ${BUILD_DIR}/cmsis_nn/Source/ConcatenationFunctions/libCMSISNNConcatenation.a \
  102. ${BUILD_DIR}/cmsis_nn/Source/BasicMathFunctions/libCMSISNNBasicMaths.a \
  103. ${BUILD_DIR}/cmsis_nn/Source/ConvolutionFunctions/libCMSISNNConvolutions.a \
  104. ${BUILD_DIR}/cmsis_nn/Source/PoolingFunctions/libCMSISNNPooling.a
  105. $(QUIET)mkdir -p $(@D)
  106. $(QUIET)$(CC) $(PKG_CFLAGS) $(FREERTOS_FLAGS) -o $@ -Wl,--whole-archive $^ -Wl,--no-whole-archive $(PKG_LDFLAGS)
  107. endif
  108. clean:
  109. $(QUIET)rm -rf $(BUILD_DIR)/codegen
  110. cleanall:
  111. $(QUIET)rm -rf $(BUILD_DIR)
  112. .SUFFIXES:
  113. .DEFAULT: demo