-
Notifications
You must be signed in to change notification settings - Fork 0
/
FindSTM32L5xx.cmake
157 lines (125 loc) · 6.66 KB
/
FindSTM32L5xx.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
#[=======================================================================[.rst:
FindSTM32L5xx
----------------
Provides a module find backend for the STM32L5xx board support package.
This should not be imported. It should be used with find_package:
``find_package(STM32L5xx COMPONENTS BSP FreeRTOS USB )``
When called with find package, it will add a static library target of the same
name, with appropriate definitions, suitable for use in target_link_library.
There are several available subcomponents that callers may want to pick and
choose from; some of them require different supporting setup in the calling
project. Each component is namespaced under STM32L5xx.
Provides the variables ``STM32L5xx_BSP_FOUND`` as a bool and ``STM32L5xx_BSP_DIR``
as the path to the source.
Each component has its own ``STM32L5xx_${COMPONENT}_FOUND`` and so on set
of exported variables.
The ``Drivers`` subcomponent is always selected no matter whether it is present
in the components list, since it is the fundamental part of the BSP.
Drivers
+++++++
The Drivers component (``STM32L5xx_Drivers``) contains the drivers and device
header files. ``find_package`` exported variables are
``STM32L5xx_Drivers_FOUND``, etc. This is the contents of the ``Drivers/``
subdirectory of the BSP.
You can select the Drivers component by adding ``Drivers`` to the ``COMPONENTS``
argument of ``find_package``: ``find_package(STM32L5xx COMPONENTS Drivers)``.
This can then be added to calling projects by calling
``target_link_libraries(mytarget STM32L5xx_Drivers)``.
Some options need to be set by the calling project on the imported
``STM32L5xx_Drivers`` target before it can be used. Specifically,
- ``target_compile_definitions`` should be used on the library target to set
the appropriate board definition for the boardfile for the specific processor
being used (i.e.
``target_compile_definitions(STM32L5xx_Drivers PUBLIC STM32L5xx)``)
- ``target_include_directories`` should be used to add an include directory that
contains the STM32 hal conf file ``stm32L5xx_hal_conf.h``, which is included by
the library to provide the individual HAL module enable/disable flags
FreeRTOS
++++++++
The FreeRTOS component (``STM32L5xx_FreeRTOS``) contains a port of FreeRTOS to
the STM32. This is the ``Middlewares/Third_Party/FreeRTOS`` subdirectory, or at
least most of it (this isn't compiler-sensitive, it always selects the GCC version
of compiler-dependent options).
You can select the FreeRTOS component by adding ``FreeRTOS`` to the ``COMPONENTS``
argument of ``find_package``: ``find_package(STM32L5xx COMPONENTS FreeRTOS)``.
This can then be added to calling projects by calling
``target_link_libraries(mytarget STM32L5xx_FreeRTOS)``.
Some options need to be set by the calling project on the imported
``STM32L5xx_FreeRTOS`` target before it can be used. Specifically,
- ``target_compile_definitions`` should be used on the library target to set
the appropriate board definition for the boardfile for the specific processor
being used (i.e.
``target_compile_definitions(STM32L5xx_FreeRTOS PUBLIC STM32L5xx)``)
- ``target_include_directories`` should be used to add an include directory that
contains a ``FreeRTOSConfig.h`` file that sets FreeRTOS configuration options.
- The caller can also set a CMake property on the imported
``STM32L5xx_FreeRTOS`` component called ``FREERTOS_HEAP_IMPLEMENTATION`` to
select the heap implementation from the ones provided by freertos. These should
be the names of the one of the heap implementation c files without the extension,
e.g.
``set_target_properties(STM32L5xx_FreeRTOS PROPERTIES FREERTOS_HEAP_IMPLEMENTATION "heap_5")``
#]=======================================================================]
include(FetchContent)
FetchContent_Declare(
STM32_L5_BSP_SOURCE
GIT_REPOSITORY "https://github.com/STMicroelectronics/STM32CubeL5"
GIT_TAG "v1.4.0"
GIT_SHALLOW
PREFIX ${CMAKE_SOURCE_DIR}/stm32-tools/
SOURCE_DIR ${CMAKE_SOURCE_DIR}/stm32-tools/stm32L5xx-bsp
)
FetchContent_MakeAvailable(STM32_L5_BSP_SOURCE)
FetchContent_GetProperties(STM32_L5_BSP_SOURCE
SOURCE_DIR bsp_source
POPULATED bsp_populated
)
set(STM32L5xx_BSP_FOUND ${bsp_populated} PARENT_SCOPE)
set(STM32L5xx_BSP_DIRECTORY ${bsp_source} PARENT_SCOPE)
set(STM32L5xx_BSP_VERSION "1.4.0" PARENT_SCOPE)
set(STM32L5xx_BSP_VERSION_STRING "1.4.0" PARENT_SCOPE)
file(GLOB_RECURSE hal_driver_sources ${bsp_source}/Drivers/STM32L5xx_HAL_Driver/Src/*.c)
# GLOB_RECURSE lists files in alphabetical order. That means that the hal, which is
# structured so that each subsystem has stm32L5xx_hal_subsystem.c and
# stm32L5xx_hal_subsystem_ex.c, will have subsystem.c packed into the archive
# before hal_subsystem_ex.c. That breaks some of the hal code, which has weak definitions
# of some functions in subsystem.c that should be overridden in subsystem_ex.c, but
# if subsystem.c comes before subsystem_ex.c in the archive, the linker will pick
# the weak one. By reversing the order, we make subsystem_ex come befeore subsystem,
# and the correct function gets picked.
list(REVERSE hal_driver_sources)
macro(add_STM32L5_driver suffix)
add_library(
STM32L5xx_Drivers_${suffix} STATIC
${hal_driver_sources})
target_include_directories(
STM32L5xx_Drivers_${suffix}
PUBLIC ${bsp_source}/Drivers/STM32L5xx_HAL_Driver/Inc
${bsp_source}/Drivers/STM32L5xx_HAL_Driver/Inc/Legacy
${bsp_source}/Drivers/CMSIS/Device/ST/STM32L5xx/Include
${bsp_source}/Drivers/CMSIS/Core/Include)
set_target_properties(
STM32L5xx_Drivers_${suffix}
PROPERTIES C_STANDARD 11
C_STANDARD_REQUIRED TRUE)
endmacro()
set(STM32L5xx_Drivers_FOUND ${bsp_populated} PARENT_SCOPE)
set(freertos_source ${bsp_source}/Middlewares/Third_Party/FreeRTOS/Source)
set(freertos_port_source ${freertos_source}/portable/GCC/ARM_CM33_NTZ/non_secure)
file(GLOB freertos_common_sources ${freertos_source}/*.c)
macro(add_STM32L5_freertos suffix)
add_library(
STM32L5xx_FreeRTOS_${suffix} STATIC
${freertos_common_sources}
${freertos_port_source}/port.c
${freertos_port_source}/portasm.c
$<IF:$<BOOL:$<TARGET_PROPERTY:FREERTOS_HEAP_IMPLEMENTATION>>,${freertos_source}/portable/MemMang/$<TARGET_PROPERTY:FREERTOS_HEAP_IMPLEMENTATION>.c,"">)
target_include_directories(
STM32L5xx_FreeRTOS_${suffix}
PUBLIC ${freertos_source}/include
${freertos_port_source})
set_target_properties(
STM32L5xx_FreeRTOS_${suffix}
PROPERTIES C_STANDARD 11
C_STANDARD_REQUIRED TRUE)
endmacro()
set(STM32L5xx_FreeRTOS_FOUND ${bsp_populated} PARENT_SCOPE)