blob: 0d844b2765e8b624ebcccc9160c1e99a498c21f5 [file] [log] [blame]
alexander31ae9f02022-02-10 16:15:54 +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# HAL library #
20#########################################################
21
22cmake_minimum_required(VERSION 3.15.6)
23
24set(HAL_TARGET hal)
25
26project(${HAL_TARGET}
27 DESCRIPTION "HAL library"
28 LANGUAGES C CXX)
29
30# Create static library
31add_library(${HAL_TARGET} STATIC)
32
33# Select which profile needs to be used:
34if (${CMAKE_CROSSCOMPILING})
35 set(PLATFORM_PROFILE bare-metal)
36else()
37 set(PLATFORM_PROFILE native)
38endif()
39
40set(PLATFORM_PROFILE_DIR profiles/${PLATFORM_PROFILE})
41
42## Common include directories - public
43target_include_directories(${HAL_TARGET}
44 PUBLIC
45 include
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000046 ${PLATFORM_PROFILE_DIR}/timer/include)
alexander31ae9f02022-02-10 16:15:54 +000047
48## Common sources for all profiles
49target_sources(${HAL_TARGET}
50 PRIVATE
51 hal.c
52 ${PLATFORM_PROFILE_DIR}/data_presentation/data_psn.c
53 ${PLATFORM_PROFILE_DIR}/data_acquisition/data_acq.c
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000054 ${PLATFORM_PROFILE_DIR}/timer/platform_timer.c)
alexander31ae9f02022-02-10 16:15:54 +000055
56if (DEFINED VERIFY_TEST_OUTPUT)
57 message(STATUS "Test output verification flag is: ${VERIFY_TEST_OUTPUT}")
58 target_compile_definitions(${HAL_TARGET} PUBLIC
59 VERIFY_TEST_OUTPUT=${VERIFY_TEST_OUTPUT})
60endif ()
61
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000062if (NOT DEFINED PLATFORM_DRIVERS_DIR)
63 message(FATAL_ERROR "PLATFORM_DRIVERS_DIR need to be defined for this target")
64endif()
65
66
alexander31ae9f02022-02-10 16:15:54 +000067############################ bare-metal profile #############################
68if (PLATFORM_PROFILE STREQUAL bare-metal)
69
alexander31ae9f02022-02-10 16:15:54 +000070 ## Additional include directories - public
71 target_include_directories(${HAL_TARGET}
72 PUBLIC
73 ${PLATFORM_PROFILE_DIR}/bsp/include)
74
75 ## Additional include directories - private
76 target_include_directories(${HAL_TARGET}
77 PRIVATE
78 ${PLATFORM_PROFILE_DIR}/data_presentation/lcd/include)
79
80 ## Additional sources - public
81 target_sources(${HAL_TARGET}
82 PUBLIC
83 ${PLATFORM_PROFILE_DIR}/bsp/retarget.c)
84
85 ## Additional sources - private
86 target_sources(${HAL_TARGET}
87 PRIVATE
88 ${PLATFORM_PROFILE_DIR}/data_presentation/lcd/lcd_img.c)
89
90 ## Compile definition:
91 target_compile_definitions(${HAL_TARGET}
92 PUBLIC
93 PLATFORM_HAL=PLATFORM_CORTEX_M_BAREMETAL)
94
95 # Add dependencies for platform_driver first, in case they are needed by it.
96 add_subdirectory(cmsis_device ${CMAKE_BINARY_DIR}/cmsis_device)
97
alexander31ae9f02022-02-10 16:15:54 +000098 # If Ethos-U is enabled, we need the driver library too
99 if (ETHOS_U_NPU_ENABLED)
100
101 if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH)
102 message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should"
103 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
104 endif()
105
106 # Timing adapter, should, in theory be part of platform-drivers. For now
107 # limiting the scope of refactoring - but in future, TA should not be
108 # needed if not available on the target platform.
109 if (NOT DEFINED ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH)
110 message(FATAL_ERROR "ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH should"
111 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
112 endif()
113
114 target_compile_definitions(${HAL_TARGET}
115 PUBLIC
116 ARM_NPU)
117
118 # For the driver, we need to provide the CMSIS_PATH variable
119 set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory")
120 add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
121 add_subdirectory(${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH} ${CMAKE_BINARY_DIR}/timing-adapter)
122
123 target_link_libraries(${HAL_TARGET}
124 PUBLIC
125 ethosu_core_driver
126 timing_adapter)
127
128 if (NOT DEFINED ETHOS_U_NPU_ID)
129 set(ETHOS_U_NPU_ID U55)
130 endif()
131
132 if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
133 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
134 endif()
135
136 if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
137 if (ETHOS_U_NPU_ID STREQUAL U55)
138 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
139 else ()
140 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.")
141 endif ()
142
143 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
144 # Shared Sram can be used for Ethos-U55 and Ethos-U65
145 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
146
147 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
148 # Dedicated Sram is used only for Ethos-U65
149 if (ETHOS_U_NPU_ID STREQUAL U65)
150 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_DEDICATED_SRAM")
151 else ()
152 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.")
153 endif ()
154 else ()
155 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
156 endif ()
157
158 target_compile_definitions(${HAL_TARGET}
159 PUBLIC
160 ${ETHOS_U_NPU_MEMORY_MODE_FLAG})
161 endif()
162
163############################ native profile #############################
164elseif (PLATFORM_PROFILE STREQUAL native)
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000165
alexander31ae9f02022-02-10 16:15:54 +0000166 ## Additional include directories - private
167 target_include_directories(${HAL_TARGET}
168 PRIVATE
169 ${PLATFORM_PROFILE_DIR}/data_presentation/log/include)
170
171 ## Additional sources - private
172 target_sources(${HAL_TARGET}
173 PRIVATE
174 ${PLATFORM_PROFILE_DIR}/data_presentation/log/log.c)
175
176 ## Compile definition:
177 target_compile_definitions(${HAL_TARGET}
178 PUBLIC
179 PLATFORM_HAL=PLATFORM_UNKNOWN_LINUX_OS
180 ACTIVATION_BUF_SRAM_SZ=0)
alexander31ae9f02022-02-10 16:15:54 +0000181endif()
182
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000183# Add platform-drivers target
184add_subdirectory(${PLATFORM_DRIVERS_DIR} ${CMAKE_BINARY_DIR}/platform_driver)
185
186# Link time library targets:
187target_link_libraries(${HAL_TARGET}
188 PUBLIC
189 log
190 platform-drivers)
191
alexander31ae9f02022-02-10 16:15:54 +0000192# Display status:
193message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
194message(STATUS "*******************************************************")
195message(STATUS "Library : " ${HAL_TARGET})
196message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR})
197message(STATUS "*******************************************************")