forked from wolfSSL/wolfBoot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstm32_hal_download.cmake
More file actions
197 lines (168 loc) · 6.54 KB
/
stm32_hal_download.cmake
File metadata and controls
197 lines (168 loc) · 6.54 KB
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
# wolfboot/cmake/stm32_hal_download.cmake
#
# Copyright (C) 2026 wolfSSL Inc.
#
# This file is part of wolfBoot.
#
# wolfBoot is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# wolfBoot is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1335, USA
#
# If not found:
# 1) The CubeIDE
# 2) VisualGDB/EmbeddedBSPs/arm-eabi/com.sysprogs.arm.stm32
# 3) User-specified
#
# ... then download HAL files as needed:
# Ensure this file is only included and initialized once
if(CMAKE_VERSION VERSION_LESS 3.10)
# Fallback path for older CMake, and anything else that wants to detect is loaded
if(DEFINED STM32_HAL_DOWNLOAD_CMAKE_INCLUDED)
return()
endif()
else()
include_guard(GLOBAL)
endif()
if(ENABLE_HAL_DOWNLOAD) # Entire file wrapper
include(FetchContent)
if(NOT FUNCTIONS_CMAKE_INCLUDED)
include(cmake/functions.cmake)
endif()
# Accumulators for the DSL
set(_DL_NAMES)
set(_DL_URLS)
set(_DL_TAGS)
# Mini DSL
function(add_download)
cmake_parse_arguments(AD "" "" "NAME;URL;TAG" ${ARGN})
if(NOT AD_NAME)
message(FATAL_ERROR "add_download requires NAME")
endif()
if(NOT AD_URL)
message(FATAL_ERROR "add_download requires URL")
endif()
if(NOT AD_TAG)
set(AD_TAG "master")
endif()
list(APPEND _DL_NAMES "${AD_NAME}")
list(APPEND _DL_URLS "${AD_URL}")
list(APPEND _DL_TAGS "${AD_TAG}")
set(_DL_NAMES "${_DL_NAMES}" PARENT_SCOPE)
set(_DL_URLS "${_DL_URLS}" PARENT_SCOPE)
set(_DL_TAGS "${_DL_TAGS}" PARENT_SCOPE)
endfunction()
set(DOWNLOADS_FOUND false)
# If a downloads list is provided, include it
if(DEFINED WOLFBOOT_DOWNLOADS_CMAKE)
if(EXISTS "${WOLFBOOT_DOWNLOADS_CMAKE}")
message(STATUS "Including downloads list: ${WOLFBOOT_DOWNLOADS_CMAKE}")
include("${WOLFBOOT_DOWNLOADS_CMAKE}")
set(DOWNLOADS_FOUND true)
else()
# If there's a defined download, the file specified needs to exist!
message(FATAL_ERROR "WOLFBOOT_DOWNLOADS_CMAKE enabled but file now found: ${WOLFBOOT_DOWNLOADS_CMAKE}")
endif()
else()
message(STATUS "No WOLFBOOT_DOWNLOADS_CMAKE and no builtin defaults for target: ${WOLFBOOT_TARGET}. Skipping auto downloads.")
endif() # WOLFBOOT_DOWNLOADS_CMAKE
# Fallback: The stm32l4 trio is known to be needed, so hard-coded here:
if(WOLFBOOT_TARGET STREQUAL "stm32l4" AND (NOT DOWNLOADS_FOUND))
message(STATUS "WARNING not downloads found for known target needing them: stm32l4" )
add_download(
NAME st_hal
URL https://github.com/STMicroelectronics/stm32l4xx_hal_driver.git
TAG v1.13.5
)
add_download(
NAME cmsis_dev
URL https://github.com/STMicroelectronics/cmsis_device_l4.git
TAG v1.7.4
)
add_download(
NAME cmsis_core
URL https://github.com/ARM-software/CMSIS_5.git
TAG 5.9.0
)
endif()
# Validate lists are aligned
list(LENGTH _DL_NAMES _n1)
list(LENGTH _DL_URLS _n2)
list(LENGTH _DL_TAGS _n3)
if(NOT (_n1 EQUAL _n2 AND _n1 EQUAL _n3))
message(FATAL_ERROR "add_download internal list length mismatch: names=${_n1} urls=${_n2} tags=${_n3}")
endif()
# Nothing to do
if(_n1 EQUAL 0)
set(STM32_HAL_DOWNLOAD_CMAKE_INCLUDED TRUE)
#---------------------------------------------------------------------------------------------
message(STATUS "No files found needing to be downloaded. If needed, configure WOLFBOOT_DOWNLOADS_CMAKE")
return()
#---------------------------------------------------------------------------------------------
endif()
# Fetch loop
set(FETCHCONTENT_QUIET OFF)
set(FETCHCONTENT_BASE_DIR "${CMAKE_BINARY_DIR}/_deps")
set(_ALL_NAMES)
math(EXPR _last "${_n1} - 1")
foreach(i RANGE 0 ${_last})
list(GET _DL_NAMES ${i} _name)
list(GET _DL_URLS ${i} _url)
list(GET _DL_TAGS ${i} _tag)
message(STATUS "Fetching ${_url} (tag ${_tag})")
FetchContent_Declare(${_name}
GIT_REPOSITORY "${_url}"
GIT_TAG "${_tag}"
GIT_SHALLOW TRUE
GIT_PROGRESS FALSE
)
list(APPEND _ALL_NAMES "${_name}")
endforeach()
if(_ALL_NAMES)
FetchContent_MakeAvailable(${_ALL_NAMES})
endif()
# st_hal
FetchContent_GetProperties(st_hal) # ensures *_SOURCE_DIR vars are available
if(DEFINED st_hal_SOURCE_DIR AND EXISTS "${st_hal_SOURCE_DIR}")
set_and_echo_dir(HAL_BASE "${st_hal_SOURCE_DIR}")
set_and_echo_dir(HAL_DRV "${st_hal_SOURCE_DIR}")
else()
message(FATAL_ERROR "st_hal source dir not found; expected after FetchContent.")
endif()
# cmsis_dev
FetchContent_GetProperties(cmsis_dev)
if(DEFINED cmsis_dev_SOURCE_DIR AND EXISTS "${cmsis_dev_SOURCE_DIR}")
set_and_echo_dir(HAL_CMSIS_DEV "${cmsis_dev_SOURCE_DIR}/Include")
else()
message(FATAL_ERROR "cmsis_dev source dir not found.")
endif()
# cmsis_core
FetchContent_GetProperties(cmsis_core)
if(DEFINED cmsis_core_SOURCE_DIR AND EXISTS "${cmsis_core_SOURCE_DIR}")
set_and_echo_dir(HAL_CMSIS_CORE "${cmsis_core_SOURCE_DIR}/CMSIS/Core/Include")
else()
message(FATAL_ERROR "cmsis_core source dir not found.")
endif()
# Map include directories when known names are fetched
# Adjust or extend this block if you add more components
if(TARGET st_hal)
set_and_echo_dir(HAL_BASE "${st_hal_SOURCE_DIR}")
set_and_echo_dir(HAL_DRV "${st_hal_SOURCE_DIR}")
endif()
if(TARGET cmsis_dev)
set_and_echo_dir(HAL_CMSIS_DEV "${cmsis_dev_SOURCE_DIR}/Include")
endif()
if(TARGET cmsis_core)
set_and_echo_dir(HAL_CMSIS_CORE "${cmsis_core_SOURCE_DIR}/CMSIS/Core/Include")
endif()
endif() #ENABLE_HAL_DOWNLOAD
set(STM32_HAL_DOWNLOAD_CMAKE_INCLUDED true)