Last active
July 1, 2023 18:01
-
-
Save eugene-babichenko/3118042a23d2082bfba624f3f2039843 to your computer and use it in GitHub Desktop.
CMakeLists.txt and toolchain file for building STM32 HAL-based projects generated with STM32CubeMX with arm-none-eabi-gcc. STM32CubeMX settings. Toolchain: SW4STM32. ☑ Generate under root.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
set(PRJ_NAME CLion_STM_LED) | |
set(MCU_FAMILY STM32F1xx) | |
set(MCU_LINE STM32F103xB) | |
set(MCU_LINKER_SCRIPT STM32F103RBTx_FLASH.ld) | |
cmake_minimum_required(VERSION 3.6) | |
project(${PRJ_NAME} C ASM) | |
add_definitions(-D${MCU_LINE}) | |
add_definitions(-DUSE_HAL_LIBRARY) | |
file(GLOB_RECURSE USER_SOURCES Src/*.c) | |
file(GLOB_RECURSE HAL_SOURCES Drivers/${MCU_FAMILY}_HAL_DRIVER/Src/*.c) | |
file(GLOB_RECURSE CMSIS_SYSTEM Drivers/CMSIS/Device/ST/${MCU_FAMILY}/Source/Templates/system_${MCU_FAMILY}.c) | |
file(GLOB_RECURSE CMSIS_STARTUP Drivers/CMSIS/Device/ST/${MCU_FAMILY}/Source/Templates/gcc/startup_${MCU_LINE}.s) | |
set(SOURCE_FILES ${USER_SOURCES} ${HAL_SOURCES} ${CMSIS_SYSTEM} ${CMSIS_STARTUP} ${MCU_LINKER_SCRIPT}) | |
include_directories(Drivers/CMSIS/Device/ST/STM32F1xx/Include) | |
include_directories(Drivers/CMSIS/Include) | |
include_directories(Drivers/STM32F1xx_HAL_Driver/Inc) | |
include_directories(Inc) | |
add_executable(${PROJECT_NAME}.elf ${SOURCE_FILES}) | |
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-Map=${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.map") | |
set(HEX_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.hex) | |
set(BIN_FILE ${PROJECT_SOURCE_DIR}/build/${PROJECT_NAME}.bin) | |
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD | |
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${HEX_FILE} | |
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${BIN_FILE} | |
COMMENT "Building ${HEX_FILE} \nBuilding ${BIN_FILE}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
include(CMakeForceCompiler) | |
set(MCU_LINKER_SCRIPT STM32F103RBTx_FLASH.ld) | |
set(MCU_ARCH cortex-m3) | |
set(MCU_FLOAT_ABI soft) | |
set(MCU_FPU fpv4-sp-d16) | |
set(CMAKE_SYSTEM_NAME Generic) | |
set(CMAKE_SYSTEM_VERSION 1) | |
CMAKE_FORCE_C_COMPILER(arm-none-eabi-gcc GCC) | |
CMAKE_FORCE_CXX_COMPILER(arm-none-eabi-g++ GCC) | |
set(COMMON_FLAGS "-mcpu=${MCU_ARCH} -mthumb -mthumb-interwork -mfloat-abi=${MCU_FLOAT_ABI} -ffunction-sections -fdata-sections -g -fno-common -fmessage-length=0") | |
if (MCU_FLOAT_ABI STREQUAL hard) | |
set(COMMON_FLAGS "${COMMON_FLAGS} -mfpu=${MCU_FPU}") | |
endif () | |
set(CMAKE_CXX_FLAGS "${COMMON_FLAGS} -std=c++11") | |
set(CMAKE_C_FLAGS "${COMMON_FLAGS} -std=gnu99") | |
set(CMAKE_EXE_LINKER_FLAGS "-Wl,-gc-sections -T ${CMAKE_SOURCE_DIR}/${MCU_LINKER_SCRIPT}") |
Well, I created this gist 3 years ago and many things may have changed since that time. Haven't used it in a while. I suggest that you may be using an incorrect MCU_FAMILY
value (are you really running STM32F1XX?) or STMicroelectronics have changed the structure of their generated projects and replaced Templates/system_${MCU_FAMILY}.c
with something else.
Hi,
Which file path should we put these two files (CMakeList.txt and STM32Toolchain.cmake) in the file structure of the project?
Secondly,
For cmake, What parameters should we run in terminal?
@karginbilgehan please take a look at README https://github.com/eugene-babichenko/cubemx2cmake
Thank you so much. If I have a question, Can I send e-mail?
Yevhenii Babichenko <[email protected]> şunları yazdı (29 Eyl 2019 18:30):
… @karginbilgehan please take at README https://github.com/eugene-babichenko/cubemx2cmake
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
I added all header and source files but I get some linking errors. Do you
have any idea about this topic?
Note: Error attached.
[image: Screenshot from 2019-09-29 23-56-52.png]
Yevhenii Babichenko <[email protected]>, 29 Eyl 2019 Paz, 18:30
tarihinde şunu yazdı:
… @karginbilgehan <https://github.com/karginbilgehan> please take at README
https://github.com/eugene-babichenko/cubemx2cmake
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<https://gist.github.com/3118042a23d2082bfba624f3f2039843?email_source=notifications&email_token=AFQT4X3CUWPV6G2TUNUMPYLQMDC2TA5CNFSM4HWSJU5KYY3PNVWWK3TUL52HS4DFVNDWS43UINXW23LFNZ2KUY3PNVWWK3TUL5UWJTQAFZSQA#gistcomment-3040512>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AFQT4X777IH76SH3S3DXTRTQMDC2TANCNFSM4HWSJU5A>
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no folder like gcc/.... in Templates & not present system_STM32F1XX.c file means in -> Templates/system_${MCU_FAMILY}.c)