Skip to content

Commit 2a96ef2

Browse files
committed
add cmake for f0, f1
1 parent 946d3fd commit 2a96ef2

File tree

9 files changed

+342
-2
lines changed

9 files changed

+342
-2
lines changed

.github/workflows/build_iar.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ jobs:
3232
# Alphabetical order
3333
# Note: bundle multiple families into a matrix since there is only one self-hosted instance can
3434
# run IAR build. Too many matrix can hurt due to setup/teardown overhead.
35-
- 'stm32f0 stm32f1 stm32f7 stm32l4'
35+
- 'stm32f7 stm32l4'
3636
steps:
3737
- name: Clean workspace
3838
run: |
@@ -58,7 +58,7 @@ jobs:
5858
# Alphabetical order
5959
# Note: bundle multiple families into a matrix since there is only one self-hosted instance can
6060
# run IAR build. Too many matrix can hurt due to setup/teardown overhead.
61-
- 'stm32g0 stm32g4 stm32h7'
61+
- 'stm32f0 stm32f1 stm32g0 stm32g4 stm32h7'
6262
steps:
6363
- name: Clean workspace
6464
run: |
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(MCU_VARIANT stm32f070xb)
2+
set(JLINK_DEVICE stm32f070rb)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/stm32F070rbtx_flash.ld)
5+
6+
function(update_board TARGET)
7+
target_compile_definitions(${TARGET} PUBLIC
8+
STM32F070xB
9+
CFG_EXAMPLE_VIDEO_READONLY
10+
)
11+
endfunction()
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
set(MCU_VARIANT stm32f072xb)
2+
set(JLINK_DEVICE stm32f072rb)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F072RBTx_FLASH.ld)
5+
6+
function(update_board TARGET)
7+
target_compile_definitions(${TARGET} PUBLIC
8+
STM32F072xB
9+
CFG_EXAMPLE_VIDEO_READONLY
10+
)
11+
endfunction()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(MCU_VARIANT stm32f072xb)
2+
set(JLINK_DEVICE stm32f072vb)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F072VBTx_FLASH.ld)
5+
6+
function(update_board TARGET)
7+
target_compile_definitions(${TARGET} PUBLIC
8+
STM32F072xB
9+
LSI_VALUE=40000
10+
CFG_EXAMPLE_VIDEO_READONLY
11+
)
12+
endfunction()

hw/bsp/stm32f0/family.cmake

Lines changed: 134 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,134 @@
1+
include_guard()
2+
3+
if (NOT BOARD)
4+
message(FATAL_ERROR "BOARD not specified")
5+
endif ()
6+
7+
set(ST_FAMILY f0)
8+
set(ST_PREFIX stm32${ST_FAMILY}xx)
9+
10+
set(ST_HAL_DRIVER ${TOP}/hw/mcu/st/stm32${ST_FAMILY}xx_hal_driver)
11+
set(ST_CMSIS ${TOP}/hw/mcu/st/cmsis_device_${ST_FAMILY})
12+
set(CMSIS_5 ${TOP}/lib/CMSIS_5)
13+
14+
# include board specific
15+
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
16+
17+
# toolchain set up
18+
set(CMAKE_SYSTEM_PROCESSOR cortex-m0 CACHE INTERNAL "System Processor")
19+
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
20+
21+
set(FAMILY_MCUS STM32F0 CACHE INTERNAL "")
22+
23+
# enable LTO if supported
24+
include(CheckIPOSupported)
25+
check_ipo_supported(RESULT IPO_SUPPORTED)
26+
if (IPO_SUPPORTED)
27+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
28+
endif ()
29+
30+
31+
#------------------------------------
32+
# BOARD_TARGET
33+
#------------------------------------
34+
# only need to be built ONCE for all examples
35+
function(add_board_target BOARD_TARGET)
36+
if (NOT TARGET ${BOARD_TARGET})
37+
add_library(${BOARD_TARGET} STATIC
38+
${ST_CMSIS}/Source/Templates/system_${ST_PREFIX}.c
39+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal.c
40+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_cortex.c
41+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc.c
42+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc_ex.c
43+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_gpio.c
44+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
45+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart_ex.c
46+
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
47+
)
48+
target_include_directories(${BOARD_TARGET} PUBLIC
49+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
50+
${CMSIS_5}/CMSIS/Core/Include
51+
${ST_CMSIS}/Include
52+
${ST_HAL_DRIVER}/Inc
53+
)
54+
target_compile_options(${BOARD_TARGET} PUBLIC
55+
)
56+
target_compile_definitions(${BOARD_TARGET} PUBLIC
57+
)
58+
59+
update_board(${BOARD_TARGET})
60+
61+
# Startup
62+
set(STARTUP_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s)
63+
set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)
64+
65+
# Linker
66+
set(LD_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/linker/${MCU_VARIANT}_flash.icf)
67+
68+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
69+
target_link_options(${BOARD_TARGET} PUBLIC
70+
"LINKER:--script=${LD_FILE_GNU}"
71+
-nostartfiles
72+
# nanolib
73+
--specs=nosys.specs
74+
--specs=nano.specs
75+
)
76+
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
77+
target_link_options(${BOARD_TARGET} PUBLIC
78+
"LINKER:--config=${LD_FILE_IAR}"
79+
)
80+
endif ()
81+
endif ()
82+
endfunction()
83+
84+
85+
#------------------------------------
86+
# Functions
87+
#------------------------------------
88+
function(family_configure_example TARGET)
89+
family_configure_common(${TARGET})
90+
91+
# Board target
92+
add_board_target(board_${BOARD})
93+
94+
#---------- Port Specific ----------
95+
# These files are built for each example since it depends on example's tusb_config.h
96+
target_sources(${TARGET} PUBLIC
97+
# BSP
98+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
99+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
100+
)
101+
target_include_directories(${TARGET} PUBLIC
102+
# family, hw, board
103+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
104+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
105+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
106+
)
107+
108+
# Add TinyUSB target and port source
109+
family_add_tinyusb(${TARGET} OPT_MCU_STM32F0)
110+
target_sources(${TARGET}-tinyusb PUBLIC
111+
${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
112+
)
113+
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
114+
115+
# Link dependencies
116+
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
117+
118+
# Flashing
119+
family_flash_stlink(${TARGET})
120+
#family_flash_jlink(${TARGET})
121+
endfunction()
122+
123+
124+
function(family_configure_device_example TARGET)
125+
family_configure_example(${TARGET})
126+
endfunction()
127+
128+
function(family_configure_host_example TARGET)
129+
family_configure_example(${TARGET})
130+
endfunction()
131+
132+
function(family_configure_dual_usb_example TARGET)
133+
family_configure_example(${TARGET})
134+
endfunction()
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
set(MCU_VARIANT stm32f103xb)
2+
set(JLINK_DEVICE stm32f103c8)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F103X8_FLASH.ld)
5+
set(LD_FILE_IAR ${CMAKE_CURRENT_LIST_DIR}/stm32f103x8_flash.icf)
6+
7+
function(update_board TARGET)
8+
target_compile_definitions(${TARGET} PUBLIC
9+
STM32F103xB
10+
HSE_VALUE=8000000U
11+
CFG_EXAMPLE_VIDEO_READONLY
12+
)
13+
endfunction()
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
set(MCU_VARIANT stm32f103xb)
2+
set(JLINK_DEVICE stm32f103rc)
3+
4+
set(LD_FILE_GNU ${CMAKE_CURRENT_LIST_DIR}/STM32F103XC_FLASH.ld)
5+
set(LD_FILE_IAR ${CMAKE_CURRENT_LIST_DIR}/stm32f103xc_flash.icf)
6+
7+
function(update_board TARGET)
8+
target_compile_definitions(${TARGET} PUBLIC
9+
STM32F103xB
10+
HSE_VALUE=8000000U
11+
)
12+
endfunction()

hw/bsp/stm32f1/family.cmake

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
include_guard()
2+
3+
if (NOT BOARD)
4+
message(FATAL_ERROR "BOARD not specified")
5+
endif ()
6+
7+
set(ST_FAMILY f1)
8+
set(ST_PREFIX stm32${ST_FAMILY}xx)
9+
10+
set(ST_HAL_DRIVER ${TOP}/hw/mcu/st/stm32${ST_FAMILY}xx_hal_driver)
11+
set(ST_CMSIS ${TOP}/hw/mcu/st/cmsis_device_${ST_FAMILY})
12+
set(CMSIS_5 ${TOP}/lib/CMSIS_5)
13+
14+
# include board specific
15+
include(${CMAKE_CURRENT_LIST_DIR}/boards/${BOARD}/board.cmake)
16+
17+
# toolchain set up
18+
set(CMAKE_SYSTEM_PROCESSOR cortex-m3 CACHE INTERNAL "System Processor")
19+
set(CMAKE_TOOLCHAIN_FILE ${TOP}/tools/cmake/toolchain/arm_${TOOLCHAIN}.cmake)
20+
21+
set(FAMILY_MCUS STM32F1 CACHE INTERNAL "")
22+
23+
# enable LTO if supported
24+
include(CheckIPOSupported)
25+
check_ipo_supported(RESULT IPO_SUPPORTED)
26+
if (IPO_SUPPORTED)
27+
set(CMAKE_INTERPROCEDURAL_OPTIMIZATION TRUE)
28+
endif ()
29+
30+
31+
#------------------------------------
32+
# BOARD_TARGET
33+
#------------------------------------
34+
# only need to be built ONCE for all examples
35+
function(add_board_target BOARD_TARGET)
36+
if (NOT TARGET ${BOARD_TARGET})
37+
add_library(${BOARD_TARGET} STATIC
38+
${ST_CMSIS}/Source/Templates/system_${ST_PREFIX}.c
39+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal.c
40+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_cortex.c
41+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc.c
42+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_rcc_ex.c
43+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_gpio.c
44+
${ST_HAL_DRIVER}/Src/${ST_PREFIX}_hal_uart.c
45+
${STARTUP_FILE_${CMAKE_C_COMPILER_ID}}
46+
)
47+
target_include_directories(${BOARD_TARGET} PUBLIC
48+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
49+
${CMSIS_5}/CMSIS/Core/Include
50+
${ST_CMSIS}/Include
51+
${ST_HAL_DRIVER}/Inc
52+
)
53+
target_compile_options(${BOARD_TARGET} PUBLIC
54+
)
55+
target_compile_definitions(${BOARD_TARGET} PUBLIC
56+
)
57+
58+
update_board(${BOARD_TARGET})
59+
60+
# Startup
61+
set(STARTUP_FILE_GNU ${ST_CMSIS}/Source/Templates/gcc/startup_${MCU_VARIANT}.s)
62+
set(STARTUP_FILE_IAR ${ST_CMSIS}/Source/Templates/iar/startup_${MCU_VARIANT}.s)
63+
64+
if (CMAKE_C_COMPILER_ID STREQUAL "GNU")
65+
target_link_options(${BOARD_TARGET} PUBLIC
66+
"LINKER:--script=${LD_FILE_GNU}"
67+
-nostartfiles
68+
# nanolib
69+
--specs=nosys.specs
70+
--specs=nano.specs
71+
)
72+
elseif (CMAKE_C_COMPILER_ID STREQUAL "IAR")
73+
target_link_options(${BOARD_TARGET} PUBLIC
74+
"LINKER:--config=${LD_FILE_IAR}"
75+
)
76+
endif ()
77+
endif ()
78+
endfunction()
79+
80+
81+
#------------------------------------
82+
# Functions
83+
#------------------------------------
84+
function(family_configure_example TARGET)
85+
family_configure_common(${TARGET})
86+
87+
# Board target
88+
add_board_target(board_${BOARD})
89+
90+
#---------- Port Specific ----------
91+
# These files are built for each example since it depends on example's tusb_config.h
92+
target_sources(${TARGET} PUBLIC
93+
# BSP
94+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/family.c
95+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../board.c
96+
)
97+
target_include_directories(${TARGET} PUBLIC
98+
# family, hw, board
99+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}
100+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/../../
101+
${CMAKE_CURRENT_FUNCTION_LIST_DIR}/boards/${BOARD}
102+
)
103+
104+
# Add TinyUSB target and port source
105+
family_add_tinyusb(${TARGET} OPT_MCU_STM32F1)
106+
target_sources(${TARGET}-tinyusb PUBLIC
107+
${TOP}/src/portable/st/stm32_fsdev/dcd_stm32_fsdev.c
108+
)
109+
target_link_libraries(${TARGET}-tinyusb PUBLIC board_${BOARD})
110+
111+
# Link dependencies
112+
target_link_libraries(${TARGET} PUBLIC board_${BOARD} ${TARGET}-tinyusb)
113+
114+
# Flashing
115+
family_flash_stlink(${TARGET})
116+
#family_flash_jlink(${TARGET})
117+
endfunction()
118+
119+
120+
function(family_configure_device_example TARGET)
121+
family_configure_example(${TARGET})
122+
endfunction()
123+
124+
function(family_configure_host_example TARGET)
125+
family_configure_example(${TARGET})
126+
endfunction()
127+
128+
function(family_configure_dual_usb_example TARGET)
129+
family_configure_example(${TARGET})
130+
endfunction()

tools/cmake/cpu/cortex-m0.cmake

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
if (TOOLCHAIN STREQUAL "gcc")
2+
set(TOOLCHAIN_COMMON_FLAGS
3+
-mthumb
4+
-mcpu=cortex-m0plus
5+
-mfloat-abi=soft
6+
)
7+
8+
set(FREERTOS_PORT GCC_ARM_CM0 CACHE INTERNAL "")
9+
10+
elseif (TOOLCHAIN STREQUAL "iar")
11+
set(TOOLCHAIN_COMMON_FLAGS
12+
--cpu cortex-m0
13+
)
14+
15+
set(FREERTOS_PORT IAR_ARM_CM0 CACHE INTERNAL "")
16+
17+
endif ()

0 commit comments

Comments
 (0)