blob: 105fc9b766eaf2ac4319553274b0bd174bc230c1 [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# A generic (simple) 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 a generic target"
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
36 ${CMAKE_CURRENT_SOURCE_DIR}/cmake/subsystem-profiles/simple_platform.cmake)
37endif()
38
39## Include the platform cmake descriptor file
40include(${PLATFORM_CMAKE_DESCRIPTOR_FILE})
41
42# 3. Generate sources:
43if (NOT DEFINED SOURCE_GEN_DIR)
44 set(SOURCE_GEN_DIR ${CMAKE_BINARY_DIR}/generated/bsp)
45endif()
46
47set(MEM_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_memmap.h.template)
48set(IRQ_PROFILE_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/peripheral_irqs.h.template)
49set(MEM_REGIONS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/mem_regions.h.template)
50
51configure_file("${MEM_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_memmap.h")
52configure_file("${IRQ_PROFILE_TEMPLATE}" "${SOURCE_GEN_DIR}/peripheral_irqs.h")
53configure_file("${MEM_REGIONS_TEMPLATE}" "${SOURCE_GEN_DIR}/mem_regions.h")
54
Isabella Gottardiee4920b2022-02-25 14:29:32 +000055## If a TA config file is provided, we generate a settings file
alexander31ae9f02022-02-10 16:15:54 +000056if (DEFINED TA_CONFIG_FILE)
57 include(${TA_CONFIG_FILE})
58 set(TA_SETTINGS_TEMPLATE ${CMAKE_CURRENT_SOURCE_DIR}/cmake/templates/timing_adapter_settings.template)
59 configure_file("${TA_SETTINGS_TEMPLATE}" "${SOURCE_GEN_DIR}/timing_adapter_settings.h")
60endif()
61
62# 4. Create static library
63add_library(${PLATFORM_DRIVERS_TARGET} STATIC)
64
65## Include directories - public
66target_include_directories(${PLATFORM_DRIVERS_TARGET}
67 PUBLIC
68 include
69 ${SOURCE_GEN_DIR})
70
71## Platform sources
72target_sources(${PLATFORM_DRIVERS_TARGET}
73 PRIVATE
74 source/stubs_glcd.c
Kshitij Sisodiaa1256e32022-02-23 14:40:45 +000075 source/timer_simple_platform.c
76 source/platform_drivers.c)
alexander31ae9f02022-02-10 16:15:54 +000077
Isabella Gottardiee4920b2022-02-25 14:29:32 +000078## Directory for additional components required by generic platform:
79if (NOT DEFINED COMPONENTS_DIR)
80 set(COMPONENTS_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../components)
81endif()
82
alexander31ae9f02022-02-10 16:15:54 +000083## Platform component: uart
84target_sources(${PLATFORM_DRIVERS_TARGET}
85 PRIVATE
Isabella Gottardiee4920b2022-02-25 14:29:32 +000086 ${COMPONENTS_DIR}/uart_pl011/uart_pl011.c)
alexander31ae9f02022-02-10 16:15:54 +000087target_include_directories(${PLATFORM_DRIVERS_TARGET}
88 PUBLIC
Isabella Gottardiee4920b2022-02-25 14:29:32 +000089 ${COMPONENTS_DIR}/uart_pl011/include)
alexander31ae9f02022-02-10 16:15:54 +000090
91## Compile defs
92target_compile_definitions(${PLATFORM_DRIVERS_TARGET}
93 PUBLIC
94 ACTIVATION_BUF_SRAM_SZ=${ACTIVATION_BUF_SRAM_SZ}
95 $<$<BOOL:TA_CONFIG_FILE>:TIMING_ADAPTER_AVAILABLE>)
96
Isabella Gottardiee4920b2022-02-25 14:29:32 +000097# Add dependencies:
alexander31ae9f02022-02-10 16:15:54 +000098target_link_libraries(${PLATFORM_DRIVERS_TARGET} PUBLIC
99 cmsis_device
100 log)
101
Isabella Gottardiee4920b2022-02-25 14:29:32 +0000102# If Ethos-U is enabled, we need the driver library too
103if (ETHOS_U_NPU_ENABLED)
104
105 ## Platform component: Ethos-U initialization
106 target_sources(${PLATFORM_DRIVERS_TARGET}
107 PRIVATE
108 ${COMPONENTS_DIR}/ethosu_npu_init/ethosu_npu_init.c)
109 target_include_directories(${PLATFORM_DRIVERS_TARGET}
110 PUBLIC
111 ${COMPONENTS_DIR}/ethosu_npu_init/include)
112
113 ## Platform component: Ethos-U timing apadpter initialization
114 target_sources(${PLATFORM_DRIVERS_TARGET}
115 PRIVATE
116 ${COMPONENTS_DIR}/ethosu_ta_init/ethosu_ta_init.c)
117 target_include_directories(${PLATFORM_DRIVERS_TARGET}
118 PUBLIC
119 ${COMPONENTS_DIR}/ethosu_ta_init/include)
120
121 if (NOT DEFINED ETHOS_U_NPU_DRIVER_SRC_PATH)
122 message(FATAL_ERROR "ETHOS_U_NPU_DRIVER_SRC_PATH should"
123 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
124 endif()
125
126 # Timing adapter
127 if (NOT DEFINED ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH)
128 message(FATAL_ERROR "ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH should"
129 " be defined when ETHOS_U_NPU_ENABLED=${ETHOS_U_NPU_ENABLED}")
130 endif()
131
132 target_compile_definitions(${PLATFORM_DRIVERS_TARGET}
133 PUBLIC
134 ARM_NPU)
135
136 # For the driver, we need to provide the CMSIS_PATH variable
137 set(CMSIS_PATH ${CMSIS_SRC_PATH} CACHE PATH "Path to CMSIS directory")
138 add_subdirectory(${ETHOS_U_NPU_DRIVER_SRC_PATH} ${CMAKE_BINARY_DIR}/ethos-u-driver)
139 add_subdirectory(${ETHOS_U_NPU_TIMING_ADAPTER_SRC_PATH} ${CMAKE_BINARY_DIR}/timing-adapter)
140
141 target_link_libraries(${PLATFORM_DRIVERS_TARGET}
142 PUBLIC
143 ethosu_core_driver
144 timing_adapter)
145
146 if (NOT DEFINED ETHOS_U_NPU_ID)
147 set(ETHOS_U_NPU_ID U55)
148 endif()
149
150 if (NOT DEFINED ETHOS_U_NPU_MEMORY_MODE)
151 set(ETHOS_U_NPU_MEMORY_MODE Shared_Sram)
152 endif()
153
154 if (ETHOS_U_NPU_MEMORY_MODE STREQUAL Sram_Only)
155 if (ETHOS_U_NPU_ID STREQUAL U55)
156 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEM_MODE_SRAM_ONLY")
157 else ()
158 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.")
159 endif ()
160
161 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Shared_Sram)
162 # Shared Sram can be used for Ethos-U55 and Ethos-U65
163 set(ETHOS_U_NPU_MEMORY_MODE_FLAG "-DETHOS_U_NPU_MEMORY_MODE=ETHOS_U_NPU_MEMORY_MODE_SHARED_SRAM")
164
165 elseif (ETHOS_U_NPU_MEMORY_MODE STREQUAL Dedicated_Sram)
166 # Dedicated Sram is used only for Ethos-U65
167 if (ETHOS_U_NPU_ID STREQUAL U65)
168 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}")
169 else ()
170 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.")
171 endif ()
172 else ()
173 message(FATAL_ERROR "Non compatible Ethos-U NPU memory mode ${ETHOS_U_NPU_MEMORY_MODE}")
174 endif ()
175
176 target_compile_definitions(${PLATFORM_DRIVERS_TARGET}
177 PUBLIC
178 ${ETHOS_U_NPU_MEMORY_MODE_FLAG})
179endif()
180
181# 5. Display status:
alexander31ae9f02022-02-10 16:15:54 +0000182message(STATUS "CMAKE_CURRENT_SOURCE_DIR: " ${CMAKE_CURRENT_SOURCE_DIR})
183message(STATUS "*******************************************************")
184message(STATUS "Library : " ${PLATFORM_DRIVERS_TARGET})
185message(STATUS "CMAKE_SYSTEM_PROCESSOR : " ${CMAKE_SYSTEM_PROCESSOR})
186message(STATUS "*******************************************************")