blob: 75e70a2e375a013dafdfa9e07984600b6c3beb2b [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# MPS3 platform support library #
20#########################################################
21
22cmake_minimum_required(VERSION 3.15.6)
23set(PLATFORM_DRIVERS_TARGET platform-drivers)
24project(${PLATFORM_DRIVERS_TARGET}
25 DESCRIPTION "Platform drivers library for MPS3 FPGA/FVP targets"
26 LANGUAGES C CXX ASM)
27
28# 1. We should be cross-compiling (MPS3 taregt only runs Cortex-M targets)
29if (NOT ${CMAKE_CROSSCOMPILING})
30 message(FATAL_ERROR "No ${PLATFORM_DRIVERS_TARGET} support for this target.")
31endif()
32
33# 2. Set the platform cmake descriptor file
34if (NOT DEFINED PLATFORM_CMAKE_DESCRIPTOR_FILE)
35 set(PLATFORM_CMAKE_DESCRIPTOR_FILE
alexandercb8a9872022-02-11 13:23:22 +000036 cmake/subsystem-profiles/${TARGET_SUBSYSTEM}.cmake
alexander31ae9f02022-02-10 16:15:54 +000037 CACHE PATH
38 "Platform's CMake descriptor file path")
39endif()
40
41## Include the platform cmake descriptor file
42include(${PLATFORM_CMAKE_DESCRIPTOR_FILE})
43
44# 3. Generate sources:
45if (NOT DEFINED SOURCE_GEN_DIR)
46 set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp)
47endif()
48
49set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_memmap.h.template)
50set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_irqs.h.template)
51set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/mem_regions.h.template)
52
53configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h")
54configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h")
55configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h")
56
57# If a TA config file is provided, we generate a settings file
58if (DEFINED TA_CONFIG_FILE)
59 include(${TA_CONFIG_FILE})
60 set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/timing_adapter_settings.template)
61 configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h")
62endif()
63
64# 4. Create static library
65add_library(${PLATFORM_DRIVERS_TARGET} STATIC)
66
67## Include directories - public
68target_include_directories(${PLATFORM_DRIVERS_TARGET}
69 PUBLIC
70 include
71 ${SOURCE_GEN_DIR})
72
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000073## Include directories - private
74target_include_directories(${PLATFORM_DRIVERS_TARGET}
75 PRIVATE
76 source/include)
77
alexander31ae9f02022-02-10 16:15:54 +000078## Platform sources
79target_sources(${PLATFORM_DRIVERS_TARGET}
80 PRIVATE
81 source/device_mps3.c
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000082 source/timer_mps3.c
83 source/platform_drivers.c)
84
Isabella Gottardiee4920b2022-02-25 14:29:32 +000085## Directory for additional components required by MPS3:
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000086if (NOT DEFINED COMPONENTS_DIR)
87 set(COMPONENTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../components)
88endif()
alexander31ae9f02022-02-10 16:15:54 +000089
90## Platform component: uart
91target_sources(${PLATFORM_DRIVERS_TARGET}
92 PRIVATE
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000093 ${COMPONENTS_DIR}/uart_cmsdk/uart_cmsdk.c)
alexander31ae9f02022-02-10 16:15:54 +000094target_include_directories(${PLATFORM_DRIVERS_TARGET}
95 PUBLIC
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000096 ${COMPONENTS_DIR}/uart_cmsdk/include)
alexander31ae9f02022-02-10 16:15:54 +000097
98## Platform component: LCD
99target_sources(${PLATFORM_DRIVERS_TARGET}
100 PRIVATE
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000101 ${COMPONENTS_DIR}/lcd_mps3/glcd_mps3.c)
alexander31ae9f02022-02-10 16:15:54 +0000102target_include_directories(${PLATFORM_DRIVERS_TARGET}
103 PUBLIC
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000104 ${COMPONENTS_DIR}/lcd_mps3/include)
alexander31ae9f02022-02-10 16:15:54 +0000105
106## This target provides the following definitions for MPS3 specific behaviour
107## TODO: We should aim to remove this now with platform refactoring..
108target_compile_definitions(${PLATFORM_DRIVERS_TARGET}
109 PUBLIC
110 MPS3_PLATFORM
111 ACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ}
112 $<$<BOOL:TA_CONFIG_FILE>:TIMING_ADAPTER_AVAILABLE>)
113
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000114# Add dependencies:
alexander31ae9f02022-02-10 16:15:54 +0000115target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +0000116 log cmsis_device)
alexander31ae9f02022-02-10 16:15:54 +0000117
Isabella Gottardiee4920b2022-02-25 14:29:32 +0000118# If Ethos-U is enabled, we need the driver library too
119if (ETHOS_U_NPU_ENABLED)
120
121
122 ## Platform component: Ethos-U initialization
123 target_sources(${PLATFORM_DRIVERS_TARGET}
124 PRIVATE
125 ${COMPONENTS_DIR}/ethosu_npu_init/ethosu_npu_init.c)
126 target_include_directories(${PLATFORM_DRIVERS_TARGET}
127 PUBLIC
128 ${COMPONENTS_DIR}/ethosu_npu_init/include)
129
130 ## Platform component: Ethos-U timing apadpter initialization
131 target_sources(${PLATFORM_DRIVERS_TARGET}
132 PRIVATE
133 ${COMPONENTS_DIR}/ethosu_ta_init/ethosu_ta_init.c)
134 target_include_directories(${PLATFORM_DRIVERS_TARGET}
135 PUBLIC
136 ${COMPONENTS_DIR}/ethosu_ta_init/include)
137
138 if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH)
139 message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should"
140 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
141 endif()
142
143 # Timing adapter
144 if (NOT DEFINED ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH)
145 message(FATAL_ERROR "ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH should"
146 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
147 endif()
148
149 target_compile_definitions(${PLATFORM_DRIVERS_TARGET}
150 PUBLIC
151 ARM_NPU)
152
153 # For the driver, we need to provide the CMSIS_PATH variable
154 set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory")
155 add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
156 add_subdirectory(${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH} ${CMAKE_BINARY_DIR}/timing-adapter)
157
158 target_link_libraries(${PLATFORM_DRIVERS_TARGET}
159 PUBLIC
160 ethosu_core_driver
161 timing_adapter)
162
163 if (NOT DEFINED ETHOS_U_NPU_ID)
164 set(ETHOS_U_NPU_ID U55)
165 endif()
166
167 if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
168 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
169 endif()
170
171 if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
172 if (ETHOS_U_NPU_ID STREQUAL U55)
173 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
174 else ()
175 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.")
176 endif ()
177
178 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
179 # Shared Sram can be used for Ethos-U55 and Ethos-U65
180 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
181
182 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
183 # Dedicated Sram is used only for Ethos-U65
184 if (ETHOS_U_NPU_ID STREQUAL U65)
185 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}")
186 else ()
187 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.")
188 endif ()
189 else ()
190 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
191 endif ()
192
193 target_compile_definitions(${PLATFORM_DRIVERS_TARGET}
194 PUBLIC
195 ${ETHOS_U_NPU_MEMORY_MODE_FLAG})
196endif()
197
198# 5. Display status:
alexander31ae9f02022-02-10 16:15:54 +0000199message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
200message(STATUS "*******************************************************")
201message(STATUS "Library : " ${PLATFORM_DRIVERS_TARGET})
202message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR})
203message(STATUS "*******************************************************")