Skip to content

Commit 8959d92

Browse files
authored
Initial support for STM32L4xx (#1720)
- Added compiler options file - Added the sources logic - Changed so CHIBIOS supports the STM32L4xx - Added the STM32L4xx cube package find logic Signed-off-by: piwi1263 <[email protected]>
1 parent a9c118d commit 8959d92

File tree

4 files changed

+245
-1
lines changed

4 files changed

+245
-1
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#
2+
# Copyright (c) .NET Foundation and Contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
#################################################################
7+
# WHEN ADDING A NEW SERIES add the appropriate GCC options below
8+
#################################################################
9+
10+
# need to specify this for assembler
11+
set(CMAKE_ASM_FLAGS " -mthumb -mcpu=cortex-m4 -x assembler-with-cpp" CACHE INTERNAL "asm compiler flags")
12+
13+
# need to specify linker flags here
14+
set(CMAKE_EXE_LINKER_FLAGS " -Wl,--gc-sections -Wl,--no-wchar-size-warning -Wl,--print-memory-usage -mthumb -mcpu=cortex-m4 -mfpu=fpv5-sp-d16 -mfloat-abi=hard -mabi=aapcs -nostartfiles " CACHE INTERNAL "executable linker flags")
15+
16+
17+
function(NF_SET_COMPILER_OPTIONS TARGET)
18+
19+
# include any extra options coming from any extra args?
20+
target_compile_options(${TARGET} PUBLIC ${ARGN} -mthumb -mcpu=cortex-m4 -mfpu=fpv4-sp-d16 -mfloat-abi=hard -mabi=aapcs -nostdlib -Wall -Wextra -Werror -ffunction-sections -fshort-wchar -falign-functions=16 -fdata-sections -fno-builtin -fno-common -fomit-frame-pointer -mlong-calls -fdollars-in-identifiers -fno-exceptions -fno-unroll-loops -frounding-math -fsignaling-nans -ffloat-store -fno-math-errno -ftree-vectorize -fcheck-new )
21+
22+
# this series has FPU
23+
target_compile_definitions(${TARGET} PUBLIC -DCORTEX_USE_FPU=TRUE)
24+
25+
endfunction()
26+
27+
28+
function(NF_SET_LINKER_OPTIONS TARGET)
29+
30+
# request specs from newlib nano
31+
set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " --specs=nano.specs ")
32+
33+
# set extra linker flags
34+
set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " ${ARGN}")
35+
36+
# set optimization linker flags for RELEASE and MinSizeRel
37+
if(CMAKE_BUILD_TYPE STREQUAL "Release" OR CMAKE_BUILD_TYPE STREQUAL "MinSizeRel")
38+
set_property(TARGET ${TARGET} APPEND_STRING PROPERTY LINK_FLAGS " -flto -fuse-linker-plugin -Os")
39+
endif()
40+
41+
# set optimization flags
42+
nf_set_optimization_options(${TARGET})
43+
44+
# set link map
45+
nf_set_link_map(${TARGET})
46+
47+
endfunction()
Lines changed: 166 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
#
2+
# Copyright (c) .NET Foundation and Contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
# from startup_stm32L4xx.mk
7+
# List of the ChibiOS generic STM32L4xx startup and CMSIS files.
8+
9+
################################################################################################
10+
# WHEN ADDING A NEW BOARD add the source code file for the hal/ports/STM32/STM32L4xx/platform.mk
11+
################################################################################################
12+
13+
set(CHIBIOS_PORT_SRCS
14+
# startup code
15+
crt1.c
16+
vectors.S
17+
crt0_v7m.S
18+
19+
nvic.c
20+
stm32_isr.c
21+
hal_lld.c
22+
23+
hal_adc_lld.c
24+
hal_can_lld.c
25+
hal_crypto_lld.c
26+
hal_dac_lld.c
27+
stm32_dma.c
28+
stm32_exti.c
29+
hal_pal_lld.c
30+
hal_i2c_lld.c
31+
#hal_mac_lld.c
32+
hal_usb_lld.c
33+
hal_wspi_lld.c
34+
hal_trng_lld.c
35+
hal_rtc_lld.c
36+
hal_sdc_lld.c
37+
38+
hal_i2s_lld.c
39+
hal_spi_lld.c
40+
41+
hal_st_lld.c
42+
hal_gpt_lld.c
43+
hal_icu_lld.c
44+
hal_pwm_lld.c
45+
46+
hal_serial_lld.c
47+
hal_uart_lld.c
48+
49+
hal_wdg_lld.c
50+
51+
# RT
52+
chcore.c
53+
chcore_v7m.c
54+
chcoreasm_v7m.S
55+
)
56+
57+
foreach(SRC_FILE ${CHIBIOS_PORT_SRCS})
58+
set(CHIBIOS_L4_SRC_FILE SRC_FILE-NOTFOUND)
59+
find_file(CHIBIOS_L4_SRC_FILE ${SRC_FILE}
60+
PATHS
61+
62+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ports/ARMCMx/compilers/GCC
63+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/startup/ARMCMx/compilers/GCC
64+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ports/ARMCMx
65+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/common/ARMCMx
66+
67+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/STM32F4xx
68+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/ADCv3
69+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CANv1
70+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CRYPv1
71+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DACv1
72+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DMAv1
73+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/EXTIv1
74+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/GPIOv3
75+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/I2Cv2
76+
#${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/MACv1
77+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/OTGv1
78+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/QUADSPIv1
79+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RNGv1
80+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RTCv2
81+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1
82+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SPIv2
83+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/TIMv1
84+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/USARTv2
85+
${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/xWDGv1
86+
87+
CMAKE_FIND_ROOT_PATH_BOTH
88+
)
89+
# message("${SRC_FILE} >> ${CHIBIOS_L4_SRC_FILE}") # debug helper
90+
list(APPEND CHIBIOS_SOURCES ${CHIBIOS_L4_SRC_FILE})
91+
endforeach()
92+
93+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/portability/GCC)
94+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/startup/ARMCMx/compilers/GCC)
95+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/startup/ARMCMx/devices/STM32L4xx)
96+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ext/ARM/CMSIS/Core/Include)
97+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/common/ext/ST/STM32L4xx)
98+
99+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/ADCv3)
100+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CANv1)
101+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/CRYPv1)
102+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DACv1)
103+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/DMAv1)
104+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/EXTIv1)
105+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/GPIOv3)
106+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/I2Cv2)
107+
#list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/MACv1)
108+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/OTGv1)
109+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/QUADSPIv1)
110+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RNGv1)
111+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/RTCv2)
112+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SDMMCv1)
113+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/SPIv2)
114+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/TIMv1)
115+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/USARTv2)
116+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_BINARY_DIR}/ChibiOS_Source/os/hal/ports/STM32/LLD/xWDGv1)
117+
118+
119+
####################################################################################
120+
# WHEN ADDING A NEW CHIBIOS OVERLAY component add the include directory(ies) below
121+
####################################################################################
122+
# component STM32_FLASH
123+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2)
124+
# component STM32_CRC
125+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1)
126+
# component STM32_RNG
127+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1)
128+
# component STM32_FSMC (Flexible Memory Controller)
129+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1)
130+
# component STM32_ONEWIRE (One Wire driver)
131+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1)
132+
# component STM32_QSPI (Quad-SPI)
133+
list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1)
134+
135+
###############################################################################################################################
136+
# Add above the required include directory(ies) for a new nanoFramework overlay component that you are adding
137+
# following the template below.
138+
#
139+
# list(APPEND CHIBIOS_INCLUDE_DIRS ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/<path-here>)
140+
###############################################################################################################################
141+
142+
143+
####################################################################################################
144+
# WHEN ADDING A NEW CHIBIOS OVERLAY component add the source file(s) specific to this series below
145+
####################################################################################################
146+
# component STM32_FLASH
147+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FLASHv2/flash_lld.c)
148+
# component STM32_CRC
149+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/CRCv1/crc_lld.c)
150+
# component STM32_RNG
151+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/RNGv1/rng_lld.c)
152+
# component STM32_FSMC (Flexible Memory Controller)
153+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_nand_lld.c)
154+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sdram_lld.c)
155+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/FSMCv1/fsmc_sram_lld.c)
156+
# component STM32_ONEWIRE
157+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/ONEWIREv1/onewire_lld.c)
158+
# component STM32_QSPI (Quad-SPI)
159+
list(APPEND ChibiOSnfOverlay_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/ports/STM32/LLD/QSPIv1/qspi_lld.c)
160+
161+
##########################################################################################################################
162+
# Add above ALL the source code file(s) low level driver specif for a series required for a new nanoFramework
163+
# overlay component that you are adding following the template below.
164+
#
165+
# list(APPEND CHIBIOS_SOURCES ${PROJECT_SOURCE_DIR}/targets/CMSIS-OS/ChibiOS/nf-overlay/os/hal/src/<path-here>)
166+
##########################################################################################################################

CMake/Modules/FindCHIBIOS.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
# check if the series name is supported
1111

12-
set(CHIBIOS_STM_SUPPORTED_SERIES "STM32F0xx" "STM32F4xx" "STM32F7xx" "STM32H7xx" "TICC3200" CACHE INTERNAL "supported STM series names for ChibiOS")
12+
set(CHIBIOS_STM_SUPPORTED_SERIES "STM32F0xx" "STM32F4xx" "STM32F7xx" "STM32H7xx" "TICC3200" "STM32L4xx" CACHE INTERNAL "supported STM series names for ChibiOS")
1313
set(CHIBIOS_TI_SUPPORTED_SERIES "TICC3200" CACHE INTERNAL "supported TI series names for ChibiOS")
1414

1515
list(FIND CHIBIOS_STM_SUPPORTED_SERIES ${TARGET_SERIES} TARGET_SERIES_NAME_INDEX)
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#
2+
# Copyright (c) 2019 The nanoFramework project contributors
3+
# See LICENSE file in the project root for full license information.
4+
#
5+
6+
# set include directories
7+
list(APPEND STM32L4_CubePackage_INCLUDE_DIRS "${PROJECT_BINARY_DIR}/STM32L4_CubePackage_Source/Drivers/STM32L4xx_HAL_Driver/Inc")
8+
9+
# source files
10+
set(STM32_CubePackage_SRCS
11+
12+
# add HAL files here as required
13+
)
14+
15+
foreach(SRC_FILE ${STM32L4_CubePackage_SRCS})
16+
set(STM32L4_CubePackage_SRC_FILE SRC_FILE-NOTFOUND)
17+
find_file(STM32L4_CubePackage_SRC_FILE ${SRC_FILE}
18+
PATHS
19+
20+
"${PROJECT_BINARY_DIR}/STM32L4_CubePackage_Source/Drivers/STM32L4xx_HAL_Driver/Src"
21+
22+
CMAKE_FIND_ROOT_PATH_BOTH
23+
)
24+
# message("${SRC_FILE} >> ${STM32L4_CubePackage_SRC_FILE}") # debug helper
25+
list(APPEND STM32L4_CubePackage_SOURCES ${STM32L4_CubePackage_SRC_FILE})
26+
endforeach()
27+
28+
29+
include(FindPackageHandleStandardArgs)
30+
31+
FIND_PACKAGE_HANDLE_STANDARD_ARGS(STM32L4_CubePackage DEFAULT_MSG STM32L4_CubePackage_INCLUDE_DIRS STM32L4_CubePackage_SOURCES)

0 commit comments

Comments
 (0)