Skip to content

Commit fef6a6a

Browse files
authored
Merge pull request #14199 from rwalton-arm/dev/rwalton-arm/refactor-st-mbed-targets
Refactor ST Mbed targets to be CMake buildsystem targets
2 parents 7135c65 + d9e184b commit fef6a6a

File tree

173 files changed

+1432
-880
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

173 files changed

+1432
-880
lines changed

CMakeLists.txt

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
cmake_minimum_required(VERSION 3.19.0 FATAL_ERROR)
77

88
include(${MBED_CONFIG_PATH}/mbed_config.cmake)
9+
include(tools/cmake/set_linker_script.cmake)
910

1011
add_library(mbed-core INTERFACE)
1112

@@ -23,7 +24,6 @@ target_link_libraries(mbed-baremetal
2324
INTERFACE
2425
mbed-core
2526
)
26-
2727
# Validate selected C library type
2828
# The C library type selected has to match the library that the target can support
2929
if(${MBED_C_LIB} STREQUAL "small")
@@ -35,7 +35,7 @@ if(${MBED_C_LIB} STREQUAL "small")
3535
" we are using the standard C library instead."
3636
)
3737
set(MBED_C_LIB "std" CACHE STRING "")
38-
endif()
38+
endif()
3939
endif()
4040
elseif(NOT ${MBED_C_LIB} IN_LIST MBED_TARGET_SUPPORTED_C_LIBS)
4141
message(FATAL_ERROR
@@ -67,7 +67,7 @@ target_compile_definitions(mbed-core
6767

6868
# Add compile definitions for backward compatibility with the toolchain
6969
# supported. New source files should instead check for __GNUC__ and __clang__
70-
# for the GCC_ARM and ARM toolchains respectively.
70+
# for the GCC_ARM and ARM toolchains respectively.
7171
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
7272
target_compile_definitions(mbed-core
7373
INTERFACE
@@ -87,6 +87,15 @@ target_include_directories(mbed-core
8787
${CMAKE_CURRENT_SOURCE_DIR}
8888
)
8989

90+
# We need to generate a "response file" to pass to the C preprocessor because of path length
91+
# limitations on Windows. We set the response file and bind the path to a global property here.
92+
# We query this global property when we set the linker script for the MBED_TARGET being built.
93+
#
94+
# TODO: Remove this and find a more idiomatic way of passing compile definitions to CPP without
95+
# using global properties.
96+
mbed_generate_options_for_linker(${APP_TARGET} LINKER_PREPROCESS_DEFINITIONS)
97+
set_property(GLOBAL PROPERTY COMPILE_DEFS_RESPONSE_FILE ${LINKER_PREPROCESS_DEFINITIONS})
98+
9099
# These targets are made visible here so their source files which
91100
# are spread in different directories can be referenced and can be linked against
92101
# by libraries that depend on them.
@@ -111,6 +120,22 @@ add_subdirectory(features EXCLUDE_FROM_ALL)
111120
add_subdirectory(cmsis/CMSIS_5/CMSIS/RTOS2 EXCLUDE_FROM_ALL)
112121
add_subdirectory(cmsis/device/rtos EXCLUDE_FROM_ALL)
113122

123+
# This is a temporary workaround to prevent the build from failing for MBED_TARGETS that
124+
# haven't been converted to build system targets yet.
125+
# The refactored MBED_TARGETS set the linker script and forward it to the build system as a
126+
# usage requirement. The 'old' mechanism was to set the linker script on the top level mbed-core
127+
# target. This was needed because MBED_TARGETS were not registered as buildsystem targets,
128+
# preventing CMake from working its usage requirements magic and forcing us to set the linker
129+
# script globally.
130+
#
131+
# TODO: Remove when all MBED_TARGETS have been converted to build system targets.
132+
if(TARGET ${MBED_TARGET})
133+
target_link_libraries(mbed-core INTERFACE ${MBED_TARGET})
134+
else()
135+
get_property(LINKER_SCRIPT GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
136+
mbed_set_linker_script(mbed-core ${LINKER_SCRIPT})
137+
endif()
138+
114139
#
115140
# Configures the application
116141
#
@@ -123,45 +148,6 @@ function(mbed_configure_app_target target)
123148
)
124149
endfunction()
125150

126-
#
127-
# Specifies linker script used for linking `target`.
128-
#
129-
function(mbed_set_mbed_target_linker_script target)
130-
get_property(mbed_target_linker_script GLOBAL PROPERTY MBED_TARGET_LINKER_FILE)
131-
mbed_generate_options_for_linker(${target} _linker_preprocess_definitions)
132-
if(MBED_TOOLCHAIN STREQUAL "GCC_ARM")
133-
set(CMAKE_PRE_BUILD_COMMAND
134-
COMMAND "arm-none-eabi-cpp" ${_linker_preprocess_definitions} -x assembler-with-cpp -E -Wp,-P
135-
${mbed_target_linker_script} -o ${CMAKE_BINARY_DIR}/${target}.link_script.ld
136-
137-
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
138-
BYPRODUCTS "${CMAKE_BINARY_DIR}/${target}.link_script.ld"
139-
)
140-
target_link_options(mbed-core
141-
INTERFACE
142-
"-T" "${CMAKE_BINARY_DIR}/${target}.link_script.ld"
143-
"-Wl,-Map=${CMAKE_BINARY_DIR}/${target}${CMAKE_EXECUTABLE_SUFFIX}.map"
144-
)
145-
elseif(MBED_TOOLCHAIN STREQUAL "ARM")
146-
set(CMAKE_PRE_BUILD_COMMAND COMMAND "")
147-
target_link_options(mbed-core
148-
INTERFACE
149-
"--scatter=${mbed_target_linker_script}"
150-
"--predefine=${_linker_preprocess_definitions}"
151-
"--map"
152-
)
153-
endif()
154-
add_custom_command(
155-
TARGET
156-
${target}
157-
PRE_LINK
158-
${CMAKE_PRE_BUILD_COMMAND}
159-
COMMENT
160-
"Link line:"
161-
VERBATIM
162-
)
163-
endfunction()
164-
165151
#
166152
# Converts output file of `target` to binary file and to Intel HEX file.
167153
#

targets/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
3+
include(../tools/cmake/set_linker_script.cmake)
34

45
if("Ambiq_Micro" IN_LIST MBED_TARGET_LABELS)
56
add_subdirectory(TARGET_Ambiq_Micro)

targets/TARGET_STM/CMakeLists.txt

Lines changed: 18 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,29 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("STM32F0" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_STM32F0)
6-
elseif("STM32F1" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_STM32F1)
8-
elseif("STM32F2" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_STM32F2)
10-
elseif("STM32F3" IN_LIST MBED_TARGET_LABELS)
11-
add_subdirectory(TARGET_STM32F3)
12-
elseif("STM32F4" IN_LIST MBED_TARGET_LABELS)
13-
add_subdirectory(TARGET_STM32F4)
14-
elseif("STM32F7" IN_LIST MBED_TARGET_LABELS)
15-
add_subdirectory(TARGET_STM32F7)
16-
elseif("STM32G0" IN_LIST MBED_TARGET_LABELS)
17-
add_subdirectory(TARGET_STM32G0)
18-
elseif("STM32G4" IN_LIST MBED_TARGET_LABELS)
19-
add_subdirectory(TARGET_STM32G4)
20-
elseif("STM32H7" IN_LIST MBED_TARGET_LABELS)
21-
add_subdirectory(TARGET_STM32H7)
22-
elseif("STM32L0" IN_LIST MBED_TARGET_LABELS)
23-
add_subdirectory(TARGET_STM32L0)
24-
elseif("STM32L1" IN_LIST MBED_TARGET_LABELS)
25-
add_subdirectory(TARGET_STM32L1)
26-
elseif("STM32L4" IN_LIST MBED_TARGET_LABELS)
27-
add_subdirectory(TARGET_STM32L4)
28-
elseif("STM32L5" IN_LIST MBED_TARGET_LABELS)
29-
add_subdirectory(TARGET_STM32L5)
30-
elseif("STM32WB" IN_LIST MBED_TARGET_LABELS)
31-
add_subdirectory(TARGET_STM32WB)
32-
endif()
4+
add_subdirectory(TARGET_STM32F0 EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_STM32F1 EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_STM32F2 EXCLUDE_FROM_ALL)
7+
add_subdirectory(TARGET_STM32F3 EXCLUDE_FROM_ALL)
8+
add_subdirectory(TARGET_STM32F4 EXCLUDE_FROM_ALL)
9+
add_subdirectory(TARGET_STM32F7 EXCLUDE_FROM_ALL)
10+
add_subdirectory(TARGET_STM32G0 EXCLUDE_FROM_ALL)
11+
add_subdirectory(TARGET_STM32G4 EXCLUDE_FROM_ALL)
12+
add_subdirectory(TARGET_STM32H7 EXCLUDE_FROM_ALL)
13+
add_subdirectory(TARGET_STM32L0 EXCLUDE_FROM_ALL)
14+
add_subdirectory(TARGET_STM32L1 EXCLUDE_FROM_ALL)
15+
add_subdirectory(TARGET_STM32L4 EXCLUDE_FROM_ALL)
16+
add_subdirectory(TARGET_STM32L5 EXCLUDE_FROM_ALL)
17+
add_subdirectory(TARGET_STM32WB EXCLUDE_FROM_ALL)
3318

34-
target_include_directories(mbed-core
19+
add_library(STM INTERFACE)
20+
21+
target_include_directories(STM
3522
INTERFACE
3623
.
3724
)
3825

39-
target_sources(mbed-core
26+
target_sources(STM
4027
INTERFACE
4128
USBPhy_STM32.cpp
4229
analogin_api.c
Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,20 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("STM32F091xC" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_STM32F091xC)
6-
elseif("STM32F072xB" IN_LIST MBED_TARGET_LABELS)
7-
add_subdirectory(TARGET_STM32F072xB)
8-
elseif("STM32F070xB" IN_LIST MBED_TARGET_LABELS)
9-
add_subdirectory(TARGET_STM32F070xB)
10-
elseif("STM32F030x8" IN_LIST MBED_TARGET_LABELS)
11-
add_subdirectory(TARGET_STM32F030x8)
12-
endif()
4+
add_subdirectory(TARGET_STM32F091xC EXCLUDE_FROM_ALL)
5+
add_subdirectory(TARGET_STM32F072xB EXCLUDE_FROM_ALL)
6+
add_subdirectory(TARGET_STM32F070xB EXCLUDE_FROM_ALL)
7+
add_subdirectory(TARGET_STM32F030x8 EXCLUDE_FROM_ALL)
8+
add_subdirectory(STM32Cube_FW EXCLUDE_FROM_ALL)
139

14-
add_subdirectory(STM32Cube_FW)
10+
add_library(STM32F0 INTERFACE)
1511

16-
target_include_directories(mbed-core
12+
target_include_directories(STM32F0
1713
INTERFACE
1814
.
1915
)
2016

21-
target_sources(mbed-core
17+
target_sources(STM32F0
2218
INTERFACE
2319
analogin_device.c
2420
analogout_device.c
@@ -29,3 +25,5 @@ target_sources(mbed-core
2925
serial_device.c
3026
spi_api.c
3127
)
28+
29+
target_link_libraries(STM32F0 INTERFACE STM STM32F0Cube_FW)

targets/TARGET_STM/TARGET_STM32F0/STM32Cube_FW/CMakeLists.txt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(STM32F0Cube_FW INTERFACE)
5+
6+
target_sources(STM32F0Cube_FW
57
INTERFACE
68
STM32F0xx_HAL_Driver/Legacy/stm32f0xx_hal_can_legacy.c
79
STM32F0xx_HAL_Driver/stm32f0xx_hal.c
@@ -66,7 +68,7 @@ target_sources(mbed-core
6668
system_stm32f0xx.c
6769
)
6870

69-
target_include_directories(mbed-core
71+
target_include_directories(STM32F0Cube_FW
7072
INTERFACE
7173
.
7274
CMSIS

targets/TARGET_STM/TARGET_STM32F0/TARGET_STM32F030x8/CMakeLists.txt

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
99
set(LINKER_FILE TOOLCHAIN_ARM/stm32f030x8.sct)
1010
endif()
1111

12-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
12+
add_library(STM32F030x8 INTERFACE)
1313

14-
target_sources(mbed-core
14+
target_sources(STM32F030x8
1515
INTERFACE
1616
${STARTUP_FILE}
1717
)
1818

19-
target_include_directories(mbed-core
19+
target_include_directories(STM32F030x8
2020
INTERFACE
2121
.
2222
)
23+
24+
mbed_set_linker_script(STM32F030x8 ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
25+
26+
target_link_libraries(STM32F030x8 INTERFACE STM32F0)
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("NUCLEO_F070RB" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NUCLEO_F070RB)
6-
endif()
4+
add_subdirectory(TARGET_NUCLEO_F070RB EXCLUDE_FROM_ALL)
75

86
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
97
set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32f070xb.S)
@@ -13,15 +11,19 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
1311
set(LINKER_FILE TOOLCHAIN_ARM/stm32f070xb.sct)
1412
endif()
1513

16-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(STM32F070xB INTERFACE)
1715

18-
target_sources(mbed-core
16+
target_sources(STM32F070xB
1917
INTERFACE
2018
system_clock.c
2119
${STARTUP_FILE}
2220
)
2321

24-
target_include_directories(mbed-core
22+
target_include_directories(STM32F070xB
2523
INTERFACE
2624
.
2725
)
26+
27+
mbed_set_linker_script(STM32F070xB ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
28+
29+
target_link_libraries(STM32F070xB INTERFACE STM32F0)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(NUCLEO_F070RB INTERFACE)
5+
6+
target_sources(NUCLEO_F070RB
57
INTERFACE
68
PeripheralPins.c
79
)
810

9-
target_include_directories(mbed-core
11+
target_include_directories(NUCLEO_F070RB
1012
INTERFACE
1113
.
1214
)
15+
16+
target_link_libraries(NUCLEO_F070RB INTERFACE STM32F070xB)
Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
if("NUCLEO_F072RB" IN_LIST MBED_TARGET_LABELS)
5-
add_subdirectory(TARGET_NUCLEO_F072RB)
6-
endif()
4+
add_subdirectory(TARGET_NUCLEO_F072RB EXCLUDE_FROM_ALL)
75

86
if(${MBED_TOOLCHAIN} STREQUAL "GCC_ARM")
97
set(STARTUP_FILE TOOLCHAIN_GCC_ARM/startup_stm32f072xb.S)
@@ -13,15 +11,19 @@ elseif(${MBED_TOOLCHAIN} STREQUAL "ARM")
1311
set(LINKER_FILE TOOLCHAIN_ARM/stm32f072xb.sct)
1412
endif()
1513

16-
set_property(GLOBAL PROPERTY MBED_TARGET_LINKER_FILE ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
14+
add_library(STM32F072xB INTERFACE)
1715

18-
target_sources(mbed-core
16+
target_sources(STM32F072xB
1917
INTERFACE
2018
system_clock.c
2119
${STARTUP_FILE}
2220
)
2321

24-
target_include_directories(mbed-core
22+
target_include_directories(STM32F072xB
2523
INTERFACE
2624
.
2725
)
26+
27+
mbed_set_linker_script(STM32F072xB ${CMAKE_CURRENT_SOURCE_DIR}/${LINKER_FILE})
28+
29+
target_link_libraries(STM32F072xB INTERFACE STM32F0)
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
# Copyright (c) 2020 ARM Limited. All rights reserved.
22
# SPDX-License-Identifier: Apache-2.0
33

4-
target_sources(mbed-core
4+
add_library(NUCLEO_F072RB INTERFACE)
5+
6+
target_sources(NUCLEO_F072RB
57
INTERFACE
68
PeripheralPins.c
79
)
810

9-
target_include_directories(mbed-core
11+
target_include_directories(NUCLEO_F072RB
1012
INTERFACE
1113
.
1214
)
15+
16+
target_link_libraries(NUCLEO_F072RB INTERFACE STM32F072xB)

0 commit comments

Comments
 (0)