blob: 57eef61742a8d63438eb3f4b4075fa5597426774 [file] [log] [blame]
Kshitij Sisodiad5679cc2022-03-03 16:30:07 +00001#----------------------------------------------------------------------------
2# Copyright (c) 2022 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#----------------------------------------------------------------------------
17
18#########################################################
19# Ethos-U NPU initialization library #
20#########################################################
21
22cmake_minimum_required(VERSION 3.15.6)
23set(ETHOS_U_NPU_INIT_COMPONENT ethosu_npu_init_component)
24project(${ETHOS_U_NPU_INIT_COMPONENT}
25 DESCRIPTION "Ethos-U NPU initialization library"
26 LANGUAGES C CXX ASM)
27
28if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH)
29 message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should"
30 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
31endif()
32
33# For the driver, we need to provide the CMSIS_PATH variable
34set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory")
35add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
36
37# Create static library
38add_library(${ETHOS_U_NPU_INIT_COMPONENT} STATIC)
39
40## Include directories - public
41target_include_directories(${ETHOS_U_NPU_INIT_COMPONENT}
42 PUBLIC
43 include
44 ${SOURCE_GEN_DIR})
45
46## Component sources
47target_sources(${ETHOS_U_NPU_INIT_COMPONENT}
48 PRIVATE
49 ethosu_npu_init.c)
50
51## Add dependencies:
52target_link_libraries(${ETHOS_U_NPU_INIT_COMPONENT} PUBLIC
53 cmsis_device
54 ethosu_core_driver
55 log)
56
57## Memory mode target definition
58if (NOT DEFINED ETHOS_U_NPU_ID)
59 set(ETHOS_U_NPU_ID U55)
60endif()
61
62if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
63 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
64endif()
65
66if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
67 if (ETHOS_U_NPU_ID STREQUAL U55)
68 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
69 else ()
70 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.")
71 endif ()
72
73elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
74 # Shared Sram can be used for Ethos-U55 and Ethos-U65
75 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
76
77elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
78 # Dedicated Sram is used only for Ethos-U65
79 if (ETHOS_U_NPU_ID STREQUAL U65)
80 list(APPEND ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM" "-DETHOS_U_NPU_CACHE_SIZE=${ETHOS_U_NPU_CACHE_SIZE}")
81 else ()
82 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.")
83 endif ()
84
85else ()
86 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
87
88endif ()
89
90target_compile_definitions(${ETHOS_U_NPU_INIT_COMPONENT}
91 PUBLIC
92 ${ETHOS_U_NPU_MEMORY_MODE_FLAG})
93
94# Display status
95message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
96message(STATUS "*******************************************************")
97message(STATUS "Library : " ${ETHOS_U_NPU_INIT_COMPONENT})
98message(STATUS "*******************************************************")