forked from ObKo/stm32-cmake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindFreeRTOS.cmake
259 lines (221 loc) · 11.1 KB
/
FindFreeRTOS.cmake
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
# For information about why and how of this file: https://cmake.org/cmake/help/latest/command/find_package.html
set(FreeRTOS_PORTS ARM_CM0 ARM_CM3 ARM_CM3_MPU ARM_CM4_MPU ARM_CM4F ARM_CM7 ARM_CM7_MPU ARM_CM23 ARM_CM23_NTZ ARM_CM33 ARM_CM33_NTZ)
set(FreeRTOS_armv8_PORTS ARM_CM23_NTZ ARM_CM33_NTZ ARM_CM23 ARM_CM33)
set(FreeRTOS_armv8_trustZone_PORTS ARM_CM23 ARM_CM33)
if(NOT FreeRTOS_FIND_COMPONENTS)
set(FreeRTOS_FIND_COMPONENTS ${FreeRTOS_PORTS})
endif()
list(REMOVE_DUPLICATES FreeRTOS_FIND_COMPONENTS)
if((NOT FREERTOS_PATH) AND (DEFINED ENV{FREERTOS_PATH}))
set(FREERTOS_PATH $ENV{FREERTOS_PATH} CACHE PATH "Path to FreeRTOS")
message(STATUS "ENV FREERTOS_PATH specified, using FREERTOS_PATH: ${FREERTOS_PATH}")
endif()
if(NOT FREERTOS_PATH)
set(DEFAULT_FREERTOS_PATH "/opt/FreeRTOS")
if(EXISTS ${DEFAULT_FREERTOS_PATH})
set(FREERTOS_PATH ${DEFAULT_FREERTOS_PATH} CACHE PATH "Path to FreeRTOS")
message(STATUS "No FREERTOS_PATH specified using default: ${DEFAULT_FREERTOS_PATH}")
else()
message(STATUS
"No FreeRTOS folder found at default location ${DEFAULT_FREERTOS_PATH}. "
"Leaving empty.."
)
endif()
endif()
if(STM32H7 IN_LIST FreeRTOS_FIND_COMPONENTS)
list(REMOVE_ITEM FreeRTOS_FIND_COMPONENTS STM32H7)
list(APPEND FreeRTOS_FIND_COMPONENTS STM32H7_M7 STM32H7_M4)
endif()
if(STM32WB IN_LIST BSP_FIND_COMPONENTS)
list(REMOVE_ITEM FreeRTOS_FIND_COMPONENTS STM32WB)
list(APPEND FreeRTOS_FIND_COMPONENTS STM32WB_M4)
endif()
if(STM32WL IN_LIST BSP_FIND_COMPONENTS)
list(REMOVE_ITEM FreeRTOS_FIND_COMPONENTS STM32WL)
list(APPEND FreeRTOS_FIND_COMPONENTS STM32WL_M4 STM32WL_M0PLUS)
endif()
# This section fills the family and ports components list
foreach(COMP ${FreeRTOS_FIND_COMPONENTS})
string(TOUPPER ${COMP} COMP)
string(REGEX MATCH "^STM32([FGHLMUW]P?[0-9BL])([0-9A-Z][0-9M][A-Z][0-9A-Z])?_?(M0PLUS|M4|M7)?.*$" FAMILY_COMP ${COMP})
# Valid family component, so add it (e.g. STM32H7)
if(CMAKE_MATCH_1)
list(APPEND FreeRTOS_FIND_COMPONENTS_FAMILIES ${FAMILY_COMP})
continue()
endif()
# Was not a family component, so add it to the port list
list(APPEND FreeRTOS_FIND_COMPONENTS_PORTS ${COMP})
endforeach()
if(NOT FreeRTOS_FIND_COMPONENTS_PORTS)
set(FreeRTOS_FIND_COMPONENTS_PORTS ${FreeRTOS_PORTS})
endif()
list(REMOVE_DUPLICATES FreeRTOS_FIND_COMPONENTS)
list(REMOVE_DUPLICATES FreeRTOS_FIND_COMPONENTS_PORTS)
list(REMOVE_DUPLICATES FreeRTOS_FIND_COMPONENTS_FAMILIES)
set(FreeRTOS_HEAPS 1 2 3 4 5)
macro(stm32_find_freertos FreeRTOS_NAMESPACE FREERTOS_PATH)
find_path(FreeRTOS_COMMON_INCLUDE
NAMES FreeRTOS.h
PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS"
PATH_SUFFIXES "Source/include" "include"
NO_DEFAULT_PATH
)
if(NOT FreeRTOS_COMMON_INCLUDE)
message(WARNING "FreeRTOS common include path not found, build might fail")
endif()
list(APPEND FreeRTOS_INCLUDE_DIRS "${FreeRTOS_COMMON_INCLUDE}")
find_path(FreeRTOS_SOURCE_DIR
NAMES tasks.c
PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS"
PATH_SUFFIXES "Source"
NO_DEFAULT_PATH
)
if(NOT (TARGET FreeRTOS))
add_library(FreeRTOS INTERFACE IMPORTED)
target_sources(FreeRTOS INTERFACE
"${FreeRTOS_SOURCE_DIR}/tasks.c"
"${FreeRTOS_SOURCE_DIR}/list.c"
"${FreeRTOS_SOURCE_DIR}/queue.c"
)
target_include_directories(FreeRTOS INTERFACE "${FreeRTOS_COMMON_INCLUDE}")
endif()
if(NOT (TARGET ${FreeRTOS_NAMESPACE}::Coroutine))
add_library(${FreeRTOS_NAMESPACE}::Coroutine INTERFACE IMPORTED)
target_sources(${FreeRTOS_NAMESPACE}::Coroutine INTERFACE "${FreeRTOS_SOURCE_DIR}/croutine.c")
target_link_libraries(${FreeRTOS_NAMESPACE}::Coroutine INTERFACE FreeRTOS)
endif()
if(NOT (TARGET ${FreeRTOS_NAMESPACE}::EventGroups))
add_library(${FreeRTOS_NAMESPACE}::EventGroups INTERFACE IMPORTED)
target_sources(${FreeRTOS_NAMESPACE}::EventGroups INTERFACE "${FreeRTOS_SOURCE_DIR}/event_groups.c")
target_link_libraries(${FreeRTOS_NAMESPACE}::EventGroups INTERFACE FreeRTOS)
endif()
if(NOT (TARGET ${FreeRTOS_NAMESPACE}::StreamBuffer))
add_library(${FreeRTOS_NAMESPACE}::StreamBuffer INTERFACE IMPORTED)
target_sources(${FreeRTOS_NAMESPACE}::StreamBuffer INTERFACE "${FreeRTOS_SOURCE_DIR}/stream_buffer.c")
target_link_libraries(${FreeRTOS_NAMESPACE}::StreamBuffer INTERFACE FreeRTOS)
endif()
if(NOT (TARGET ${FreeRTOS_NAMESPACE}::Timers))
add_library(${FreeRTOS_NAMESPACE}::Timers INTERFACE IMPORTED)
target_sources(${FreeRTOS_NAMESPACE}::Timers INTERFACE "${FreeRTOS_SOURCE_DIR}/timers.c")
target_link_libraries(${FreeRTOS_NAMESPACE}::Timers INTERFACE FreeRTOS)
endif()
foreach(HEAP ${FreeRTOS_HEAPS})
if(NOT (TARGET ${FreeRTOS_NAMESPACE}::Heap::${HEAP}))
add_library(${FreeRTOS_NAMESPACE}::Heap::${HEAP} INTERFACE IMPORTED)
target_sources(${FreeRTOS_NAMESPACE}::Heap::${HEAP} INTERFACE "${FreeRTOS_SOURCE_DIR}/portable/MemMang/heap_${HEAP}.c")
target_link_libraries(${FreeRTOS_NAMESPACE}::Heap::${HEAP} INTERFACE FreeRTOS)
endif()
endforeach()
foreach(PORT ${FreeRTOS_FIND_COMPONENTS_PORTS})
if(${PORT} IN_LIST FreeRTOS_armv8_trustZone_PORTS)
set(ARMv8_NON_SECURE "::NON_SECURE")
endif()
find_path(FreeRTOS_${PORT}_PATH
NAMES portmacro.h
PATHS "${FREERTOS_PATH}" "${FREERTOS_PATH}/FreeRTOS"
PATH_SUFFIXES
"portable/GCC/${PORT}"
"portable/GCC/${PORT}/r0p1"
"portable/GCC/${PORT}/non_secure"
"Source/portable/GCC/${PORT}"
"Source/portable/GCC/${PORT}/r0p1"
"Source/portable/GCC/${PORT}/non_secure"
NO_DEFAULT_PATH
)
if(NOT FreeRTOS_${PORT}_PATH)
message(WARNING "FreeRTOS port path not found, build might fail")
endif()
list(APPEND FreeRTOS_INCLUDE_DIRS "${FreeRTOS_${PORT}_PATH}")
find_file(FreeRTOS_${PORT}_SOURCE
NAMES port.c
PATHS "${FreeRTOS_${PORT}_PATH}"
NO_DEFAULT_PATH
)
if(NOT (TARGET ${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE}))
add_library(${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE} INTERFACE IMPORTED)
target_link_libraries(${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE} INTERFACE FreeRTOS)
target_sources(${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE} INTERFACE "${FreeRTOS_${PORT}_SOURCE}")
target_include_directories(${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE} INTERFACE "${FreeRTOS_${PORT}_PATH}")
message(trace "FindFreeRTOS: creating target ${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE}")
# armv8-m needs additional file even if using "No Trust Zone" port
if(${PORT} IN_LIST FreeRTOS_armv8_PORTS)
target_sources(${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE} INTERFACE "${FreeRTOS_${PORT}_PATH}/portasm.c")
endif()
if(${PORT} IN_LIST FreeRTOS_armv8_trustZone_PORTS)
# create the secure target
add_library(${FreeRTOS_NAMESPACE}::${PORT}::SECURE INTERFACE IMPORTED)
# ::SECURE doesn't link FreeRTOS like ::NON_SECURE does
target_sources(${FreeRTOS_NAMESPACE}::${PORT}::SECURE INTERFACE "${FreeRTOS_${PORT}_PATH}/../secure/secure_context.c"
"${FreeRTOS_${PORT}_PATH}/../secure/secure_context_port.c"
"${FreeRTOS_${PORT}_PATH}/../secure/secure_heap.c"
"${FreeRTOS_${PORT}_PATH}/../secure/secure_init.c")
message(trace "FindFreeRTOS: creating target ${FreeRTOS_NAMESPACE}::${PORT}::SECURE")
# non-secure part needs declaratation from secure includes
target_include_directories(${FreeRTOS_NAMESPACE}::${PORT}${ARMv8_NON_SECURE} INTERFACE "${FreeRTOS_${PORT}_PATH}/../secure")
# secure part needs declaratation from non-secure includes and common freeRTOS includes
target_include_directories(${FreeRTOS_NAMESPACE}::${PORT}::SECURE INTERFACE "${FreeRTOS_${PORT}_PATH}"
"${FreeRTOS_COMMON_INCLUDE}")
endif()
endif()
if(FreeRTOS_${PORT}_PATH AND
FreeRTOS_${PORT}_SOURCE AND
FreeRTOS_COMMON_INCLUDE AND
FreeRTOS_SOURCE_DIR)
set(FreeRTOS_${PORT}_FOUND TRUE)
else()
set(FreeRTOS_${PORT}_FOUND FALSE)
endif()
endforeach()
endmacro()
message(STATUS "Search for FreeRTOS ports: ${FreeRTOS_FIND_COMPONENTS_PORTS}")
if(NOT FreeRTOS_FIND_COMPONENTS_FAMILIES)
stm32_find_freertos(FreeRTOS ${FREERTOS_PATH})
else()
message(STATUS "Search for FreeRTOS families: ${FreeRTOS_FIND_COMPONENTS_FAMILIES}")
foreach(COMP ${FreeRTOS_FIND_COMPONENTS_FAMILIES})
string(TOLOWER ${COMP} COMP_L)
string(TOUPPER ${COMP} COMP)
string(REGEX MATCH "^STM32([FGHLMUW]P?[0-9BL])([0-9A-Z][0-9M][A-Z][0-9A-Z])?_?(M0PLUS|M4|M7)?.*$" COMP ${COMP})
if((NOT CMAKE_MATCH_1) AND (NOT CMAKE_MATCH_2))
message(FATAL_ERROR "Unknown FreeRTOS component: ${COMP}")
endif()
if(CMAKE_MATCH_2)
set(FAMILY ${CMAKE_MATCH_1})
set(STM_DEVICES "${CMAKE_MATCH_1}${CMAKE_MATCH_2}")
else()
set(FAMILY ${CMAKE_MATCH_1})
stm32_get_devices_by_family(STM_DEVICES FAMILY ${FAMILY})
endif()
if(CMAKE_MATCH_3)
set(CORE ${CMAKE_MATCH_3})
set(CORE_C "::${CORE}")
set(CORE_U "_${CORE}")
else()
unset(CORE)
unset(CORE_C)
unset(CORE_U)
endif()
string(TOLOWER ${FAMILY} FAMILY_L)
if(NOT STM32_CUBE_${FAMILY}_PATH)
set(STM32_CUBE_${FAMILY}_PATH /opt/STM32Cube${FAMILY} CACHE PATH "Path to STM32Cube${FAMILY}")
message(STATUS "Did not specify STM32_CMSIS_${FAMILY}_PATH, using default STM32_CUBE_${FAMILY}_PATH: ${STM32_CUBE_${FAMILY}_PATH}")
endif()
stm32_find_freertos(FreeRTOS::STM32::${FAMILY}${CORE_C} ${STM32_CUBE_${FAMILY}_PATH}/Middlewares/Third_Party/FreeRTOS)
foreach(PORT_COMP ${FreeRTOS_FIND_COMPONENTS_PORTS})
if(FreeRTOS_${PORT_COMP}_PATH AND
FreeRTOS_${PORT_COMP}_SOURCE AND
FreeRTOS_COMMON_INCLUDE AND
FreeRTOS_SOURCE_DIR)
set(FreeRTOS_${COMP}_FOUND TRUE)
else()
set(FreeRTOS_${COMP}_FOUND FALSE)
endif()
endforeach()
endforeach()
endif()
include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(FreeRTOS
REQUIRED_VARS FreeRTOS_INCLUDE_DIRS
FOUND_VAR FreeRTOS_FOUND
HANDLE_COMPONENTS
)