blob: 3fe9b1b68b343847d9482eb00ceffc53913f3dca [file] [log] [blame]
alexander3c798932021-03-26 21:42:19 +00001#----------------------------------------------------------------------------
2# Copyright (c) 2021 Arm Limited. All rights reserved.
3# SPDX-License-Identifier: Apache-2.0
4#
5# Licensed under the Apache License, Version 2.0 (the "License");
6# you may not use this file except in compliance with the License.
7# 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, software
12# distributed under the License is distributed on an "AS IS" BASIS,
13# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14# See the License for the specific language governing permissions and
15# limitations under the License.
16#----------------------------------------------------------------------------
17set(CMAKE_INSTALL_PREFIX ${CMAKE_SOURCE_DIR}/build_baremetal)
18set(PLAT_HAL ${CMAKE_CURRENT_SOURCE_DIR}/source/application/hal/platforms/bare-metal)
19
20# If target platform not defined raise an error
21# TARGET_PLATFORM either should have been defined by the user or set to default value mps3
22if (NOT DEFINED TARGET_PLATFORM)
23 message(FATAL_ERROR "Invalid target platform, specify TARGET_PLATFORM=mps3")
24endif ()
25message(STATUS "target platform ${TARGET_PLATFORM}")
26
27set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp)
28if (NOT DEFINED MEM_PROFILES_SRC_DIR)
29 set(MEM_PROFILES_SRC_DIR ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/subsystem-profiles)
30endif()
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010031
alexander3c798932021-03-26 21:42:19 +000032set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_memmap.h.template)
33set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/peripheral_irqs.h.template)
34set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/mem_regions.h.template)
35set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/scripts/cmake/templates/timing_adapter_settings.template)
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +010036set(LINKER_SCRIPT_DIR "${PLAT_HAL}/bsp/mem_layout")
alexander3c798932021-03-26 21:42:19 +000037set(TENSORFLOW_LITE_MICRO_PLATFORM_LIB_NAME "libtensorflow-microlite.a")
38set(TENSORFLOW_LITE_MICRO_FLAG "-DTF_LITE_STATIC_MEMORY")
Cisco Cervelleraf085fa52021-08-02 09:32:07 +010039set(ETHOS_U_NPU_FLAG "-DARM_NPU=1")
alexander3c798932021-03-26 21:42:19 +000040
Cisco Cervelleraf085fa52021-08-02 09:32:07 +010041if (ETHOS_U_NPU_ENABLED)
Isabella Gottardi118f73e2021-09-16 17:54:35 +010042
43 USER_OPTION(ETHOS_U_NPU_ID "Arm Ethos-U NPU IP (U55 or U65)"
44 "U55"
45 STRING)
46
47 if ((ETHOS_U_NPU_ID STREQUAL U55) OR (ETHOS_U_NPU_ID STREQUAL U65))
48 if (ETHOS_U_NPU_ID STREQUAL U55)
49 set(DEFAULT_NPU_MEM_MODE "Shared_Sram")
50 set(DEFAULT_NPU_CONFIG_ID "H128")
51 elseif(ETHOS_U_NPU_ID STREQUAL U65)
52 set(DEFAULT_NPU_MEM_MODE "Dedicated_Sram")
53 set(DEFAULT_NPU_CONFIG_ID "Y256")
54 endif()
55 else ()
56 message(FATAL_ERROR "Non compatible Ethos-U NPU processor ${ETHOS_U_NPU_ID}")
57 endif ()
58
59 USER_OPTION(ETHOS_U_NPU_MEMORY_MODE "Specifies the memory mode used in the Vela command."
60 "${DEFAULT_NPU_MEM_MODE}"
61 STRING)
62
63 if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
64
65 if (ETHOS_U_NPU_ID STREQUAL U55)
66 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
67 else ()
68 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `sram_only` can be used only for Ethos-U55.")
69 endif ()
70
71 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
72 # Shared Sram can be used for Ethos-U55 and Ethos-U65
73 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
74
75 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
76 # Dedicated Sram is used only for Ethos-U65
77 if (ETHOS_U_NPU_ID STREQUAL U65)
78 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM")
79 else ()
80 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode and processor ${ETHOS_U_NPU_MEMORY_MODE} - ${ETHOS_U_NPU_ID}. `dedicated_sram` can be used only for Ethos-U65.")
81 endif ()
82
83 else ()
84 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
85 endif ()
86
87 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${ETHOS_U_NPU_FLAG} ${ETHOS_U_NPU_MEMORY_MODE_FLAG}")
alexander3c798932021-03-26 21:42:19 +000088endif ()
89
90# Set specific flags depending on target platform and subsystem
91if (TARGET_PLATFORM STREQUAL mps3)
92 set(MPS3_PLATFORM_FLAG "-DMPS3_PLATFORM=1")
93
94 # If target platform is mps3 and subsystem not defined raise an error,
95 # TARGET_SUBSYSTEM either should have been defined by the user or set to a default value
96 if (NOT DEFINED TARGET_SUBSYSTEM)
97 message(FATAL_ERROR "Target subsystem for mps3 undefined, "
alexanderd580eee2021-05-04 21:24:22 +010098 "specify -DTARGET_SUBSYSTEM=<sse-300>")
alexander3c798932021-03-26 21:42:19 +000099 endif ()
100
alexanderd580eee2021-05-04 21:24:22 +0100101 if (TARGET_SUBSYSTEM STREQUAL sse-300)
alexander3c798932021-03-26 21:42:19 +0000102 message(STATUS "target subsystem is ${TARGET_SUBSYSTEM}")
103 set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/mps3")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100104 set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}-${TARGET_SUBSYSTEM}")
alexander3c798932021-03-26 21:42:19 +0000105
106 # Include the mem profile definitions specific to our target subsystem
107 include(${MEM_PROFILES_SRC_DIR}/corstone-${TARGET_SUBSYSTEM}.cmake)
108 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} ${MPS3_PLATFORM_FLAG}")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100109
110 # For deployment on the MPS3 FPGA platform, we need to produce
111 # two bin files - one that is loaded into the ITCM, and another
112 # that is loaded into the DDR region.
Kshitij Sisodia69a47452021-07-23 17:43:54 +0100113 set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr")
114 set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin")
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100115 set(MPS3_FPGA_CONFIG "${CMAKE_CURRENT_SOURCE_DIR}/scripts/${TARGET_PLATFORM}/${TARGET_SUBSYSTEM}/images.txt")
alexander3c798932021-03-26 21:42:19 +0000116 else ()
117 message(FATAL_ERROR "Non compatible target subsystem: ${TARGET_SUBSYSTEM}")
118 endif ()
119elseif (TARGET_PLATFORM STREQUAL simple_platform)
Kshitij Sisodia69a47452021-07-23 17:43:54 +0100120 set(BSP_PACKAGE_DIR "${PLAT_HAL}/bsp/bsp-packs/${TARGET_PLATFORM}")
121 set(LINKER_SCRIPT_NAME "${TARGET_PLATFORM}")
alexander3c798932021-03-26 21:42:19 +0000122 include(${MEM_PROFILES_SRC_DIR}/${TARGET_PLATFORM}.cmake)
Kshitij Sisodia69a47452021-07-23 17:43:54 +0100123 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS}")
124 set(LINKER_SECTION_TAGS "*.at_itcm" "*.at_ddr")
125 set(LINKER_OUTPUT_BIN_TAGS "itcm.bin" "ddr.bin")
alexander3c798932021-03-26 21:42:19 +0000126else ()
127 message(FATAL_ERROR "Non compatible target platform ${TARGET_PLATFORM}")
128endif ()
129
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100130# Add link options for the linker script to be used:
131add_linker_script(${LINKER_SCRIPT_DIR} ${LINKER_SCRIPT_NAME})
132
Cisco Cervelleraf085fa52021-08-02 09:32:07 +0100133if (ETHOS_U_NPU_ENABLED)
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100134 if (ETHOS_U_NPU_ID STREQUAL U55)
135 set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u55_high_end.cmake")
136 else ()
137 set(DEFAULT_TA_CONFIG_FILE_PATH "${CMAKE_SCRIPTS_DIR}/timing_adapter/ta_config_u65_high_end.cmake")
138 endif ()
alexander3c798932021-03-26 21:42:19 +0000139 USER_OPTION(TA_CONFIG_FILE "Path to the timing adapter configuration file"
Isabella Gottardi118f73e2021-09-16 17:54:35 +0100140 ${DEFAULT_TA_CONFIG_FILE_PATH}
alexander3c798932021-03-26 21:42:19 +0000141 FILEPATH)
142
143 # must be included after target subsystem CMake file
144 include(${TA_CONFIG_FILE})
145endif()
146
147# Generate the memory map header file from the mem profile cmake included in one of
148# the previous sections
149message(STATUS "Configuring file from ${MEM_PROFILE_TEMPLATE}"
150 ", ${IRQ_PROFILE_TEMPLATE}"
151 " and ${MEM_REGIONS_TEMPLATE}")
152
153configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h")
154configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h")
155configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h")
156configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h")
157
alexander3c798932021-03-26 21:42:19 +0000158message(STATUS "Using BSP package from: ${BSP_PACKAGE_DIR}")
159
160if (DEFINED VERIFY_TEST_OUTPUT)
161 message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}")
162 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DVERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT}")
163endif ()
164
165if (DEFINED LOG_LEVEL)
166 message(STATUS "Setting log level to ${LOG_LEVEL}")
167 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DLOG_LEVEL=${LOG_LEVEL}")
168endif()
169
170if (DEFINED ACTIVATION_BUF_SRAM_SZ)
171 message(STATUS "Maximum SRAM space for activations buffers for this system: ${ACTIVATION_BUF_SRAM_SZ}")
172 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -DACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ}")
173endif()
174
175if (DEFINED ARMCLANG_DEBUG_DWARF_LEVEL)
176 message(STATUS "setting dwarf conformance level to gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}")
177 set(OPTIONAL_FLAGS "${OPTIONAL_FLAGS} -gdwarf-${ARMCLANG_DEBUG_DWARF_LEVEL}")
178endif()
179
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100180set(COMPILER_FLAGS "${TENSORFLOW_LITE_MICRO_FLAG} ${PROFILING_OPT} ${OPTIONAL_FLAGS}")
alexander3c798932021-03-26 21:42:19 +0000181# For some reason, cmake doesn't pass the c++ standard flag, adding it manually
182set(CMAKE_CXX_FLAGS "${COMPILER_FLAGS} -std=c++11" CACHE INTERNAL "")
183set(CMAKE_C_FLAGS "${COMPILER_FLAGS}" CACHE INTERNAL "")
alexander3c798932021-03-26 21:42:19 +0000184set(CMAKE_ASM_COMPILE_OBJECT ${CMAKE_CXX_FLAGS})
185
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100186# Tell linker that reset interrupt handler is our entry point
187add_link_options(--entry Reset_Handler)
alexander3c798932021-03-26 21:42:19 +0000188
189set(PLAT_BSP_INCLUDES
190 ${PLAT_HAL}/bsp/cmsis-device/include
191 ${PLAT_HAL}/bsp/include/
192 ${PLAT_HAL}/bsp/bsp-core/include
193 ${BSP_PACKAGE_DIR}/include
194)
195
196# Include directories:
197set(PLAT_INCLUDE_DIRS
198 ${PLAT_BSP_INCLUDES}
199 ${PLAT_HAL}/utils/include
200 ${PLAT_HAL}/images/include
201 ${PLAT_HAL}/data_presentation/lcd/include
202 ${PLAT_HAL}/timer/include
203 ${SOURCE_GEN_DIR}
204 )
205
206# Source files
207file(GLOB_RECURSE SRC_PLAT_HAL
208
209 # Higher level HAL sources - software logic implementations
210 "${PLAT_HAL}/data_*/*.c"
211 "${PLAT_HAL}/images/*.c"
212 "${PLAT_HAL}/timer/*.c"
213 "${PLAT_HAL}/utils/*.c"
214
215 # Low level HAL sources - these enable interaction with
216 # the actual hardware
217 "${PLAT_HAL}/bsp/cmsis-device/*.c"
218 "${PLAT_HAL}/bsp/bsp-core/*.c"
219 "${BSP_PACKAGE_DIR}/*.c"
220 )
Kshitij Sisodiaf9c19ea2021-05-07 16:08:14 +0100221
222# Special retarget source to direct stdin, stdout and stderr streams to the
223# UART block.
224set(PLAT_RETARGET_SOURCE "${PLAT_HAL}/bsp/bsp-core/retarget.c")