cmake stm32 模板

这篇具有很好参考价值的文章主要介绍了cmake stm32 模板。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

软件

mingw
cmake
gcc-arm-none-eabi-gcc
并添加环境变量

文件结构
├─Bsp
│ ├─driver_time
│ └─driver_uart
├─cmake
├─Component
│ └─Fifo
├─Driver
│ ├─Inc
│ └─Src
├─Lib
│ ├─CMSIS
│ │ ├─Core
│ │ │ └─Include
│ │ └─Device
│ │ └─ST
│ │ └─STM32F7xx
│ │ └─Include
│ └─STM32F7xx_HAL_Driver
│ ├─Inc
│ │ └─Legacy
│ └─Src
├─Link
├─Start_up
└─User

执行脚本

build.bat

@echo off

set  dir_path= %cd%
set  cmake_path=\tools\cmake-3.27.0-windows-x86_64\bin
set  gcc_path=\tools\gcc-arm-none-eabi-10.3-2021.10\bin
set  mingw_path=tools\MinGW64\bin

@REM echo  %dir_path%%gcc_path%
@REM echo  %dir_path%%cmake_path%
set path=%dir_path%%gcc_path%;%path%
set path=%dir_path%%cmake_path%;%path%
set path=%dir_path%%mingw_path%;%path%
@REM echo %PATH%
IF /i "%1"=="-C" (
    rd /s /q build
) ELSE IF /i "%1"=="" (
    IF EXIST build (
    cd build
    cmake -G "MinGW Makefiles" ..
    make
    cd ..
    ) ELSE (
    md build
    cd build
    cmake -G "MinGW Makefiles" ..
    make
    cd ..
    )
)

简单的cmake 模板

# No operating system
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.21)

# specify cross compilers and tools
set(CMAKE_C_COMPILER arm-none-eabi-gcc)
set(CMAKE_CXX_COMPILER arm-none-eabi-g++)
set(CMAKE_ASM_COMPILER arm-none-eabi-gcc)
set(CMAKE_AR arm-none-eabi-ar)
set(CMAKE_OBJCOPY arm-none-eabi-objcopy)
set(CMAKE_OBJDUMP arm-none-eabi-objdump)
set(SIZE arm-none-eabi-size)
# skip compiler checks
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

project(MiniBot C CXX ASM)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

add_compile_options(-mcpu=cortex-m3 -mthumb -mthumb-interwork)
add_compile_options(-ffunction-sections -fdata-sections -fno-common -fmessage-length=0)

# uncomment to mitigate c++17 absolute addresses warnings
#set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wno-register")

# Enable assembler files preprocessing
add_compile_options($<$<COMPILE_LANGUAGE:ASM>:-x$<SEMICOLON>assembler-with-cpp>)

if ("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
    message(STATUS "Maximum optimization for speed")
    add_compile_options(-Ofast)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
    message(STATUS "Maximum optimization for speed, debug info included")
    add_compile_options(-Ofast -g)
elseif ("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
    message(STATUS "Maximum optimization for size")
    add_compile_options(-Os)
else ()
    message(STATUS "Minimal optimization, debug info included")
    add_compile_options(-Og -g)
endif ()

include_directories(
    ./
    # ${CMAKE_SOURCE_DIR}/drivers/CMSIS/Include
    # ${CMAKE_SOURCE_DIR}/drivers/CMSIS/Device/ST/STM32F1xx/Include
    # ${CMAKE_SOURCE_DIR}/drivers/STM32F1xx_HAL_Driver/Inc
    # ${CMAKE_SOURCE_DIR}/drivers/STM32F1xx_HAL_Driver/Inc/Legacy
    # ${CMAKE_SOURCE_DIR}/main
)
add_definitions(-DUSE_HAL_DRIVER -D__MICROLIB -DSTM32F1 -DSTM32F1xx -DSTM32F103xB)

# aux_source_directory(${CMAKE_SOURCE_DIR}/drivers/STM32F1xx_HAL_Driver/Src HAL_DRIVER)
# aux_source_directory(${CMAKE_SOURCE_DIR}/drivers/CMSIS/Device/ST/STM32F1xx/Source/Templates SYSTEM)
# aux_source_directory(${CMAKE_SOURCE_DIR}/main MAIN)

aux_source_directory(${CMAKE_SOURCE_DIR}/User USER)

set(STARTUP       ${CMAKE_SOURCE_DIR}/startup/startup_stm32f103xb.s)
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/Link/STM32F103C8Tx_FLASH.ld)

add_link_options(-Wl,-gc-sections,--print-memory-usage,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map)
add_link_options(-mcpu=cortex-m3 -mthumb -mthumb-interwork)
add_link_options(-T ${LINKER_SCRIPT})

add_executable(${PROJECT_NAME}.elf  ${USER} ${STARTUP} ${LINKER_SCRIPT})

set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${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}
Building ${BIN_FILE}")

多个文件模板

cmake/arm-none-eabi.cmake

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)

set(CMAKE_C_COMPILER ${CROSS_COMPILE_PREFIX}gcc)
set(CMAKE_CXX_COMPILER ${CROSS_COMPILE_PREFIX}g++)
set(CMAKE_ASM_COMPILER ${CROSS_COMPILE_PREFIX}gcc)
set(CMAKE_AR ${CROSS_COMPILE_PREFIX}ar)
set(CMAKE_OBJCOPY ${CROSS_COMPILE_PREFIX}objcopy)
set(CMAKE_OBJDUMP ${CROSS_COMPILE_PREFIX}objdump)
set(SIZE ${CROSS_COMPILE_PREFIX}size)

# 设置c++ c 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_C_STANDARD 11)

cmake/cortex_m0.cmake

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR cortex-m0)

SET(MCPU_FLAGS "-mcpu=cortex-m0 -mthumb")
SET(VFP_FLAGS "")

ADD_DEFINITIONS(
    -DARM_MATH_CM0
    )

cmake/cortex_m3.cmake

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR cortex-m3)
#添加 编译标志
SET(MCPU_FLAGS "-mthumb -mthumb-interwork -mcpu=cortex-m3")
#添加浮点运算标准
SET(VFP_FLAGS "-mfloat-abi=soft")


add_definitions(
  -DUSE_HAL_DRIVER 
  -DSTM32F1
  )

cmake/cortex_m4.cmake

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR cortex-m4)

SET(MCPU_FLAGS "-mthumb -mcpu=cortex-m4")
SET(VFP_FLAGS "-mfloat-abi=soft")

ADD_DEFINITIONS(
    -DARM_MATH_CM4 
    -DARM_MATH_MATRIX_CHECK 
    -DARM_MATH_ROUNDING 
    -D__FPU_PRESENT=1
    )

cmake/cortex_m7.cmake

SET(CMAKE_SYSTEM_NAME Generic)
SET(CMAKE_SYSTEM_PROCESSOR cortex-m4)

SET(FPU "-mfpu=fpv5-d16")
SET(MCPU_FLAGS "-mthumb -mcpu=cortex-m7 ${FPU}")
SET(VFP_FLAGS "-mfloat-abi=hard")

ADD_DEFINITIONS(
    -DUSE_HAL_DRIVER
    )

cmake/gcc-flags.cmake

#判断包含架构文件
if(CMAKE_ARCH_TYPE MATCHES CM0)
include(${CMAKE_SOURCE_DIR}/cmake/cortex_m0.cmake)
elseif(CMAKE_ARCH_TYPE MATCHES CM3)
include(${CMAKE_SOURCE_DIR}/cmake/cortex_m3.cmake)
elseif(CMAKE_ARCH_TYPE MATCHES CM4)
include(${CMAKE_SOURCE_DIR}/cmake/cortex_m4.cmake)
elseif(CMAKE_ARCH_TYPE MATCHES CM7)
    include(${CMAKE_SOURCE_DIR}/cmake/cortex_m7.cmake)
endif()

# 设置编译选项
# 定义通用编译器参数; ${MCPU_FLAGS}   处理器内核信息 ${VFP_FLAGS}    浮点运算单元类型 
SET(CFCOMMON
    "${MCPU_FLAGS} ${VFP_FLAGS}  --specs=nano.specs -specs=rdimon.specs --specs=nosys.specs -Wall -fmessage-length=0 -ffunction-sections -fdata-sections"
)

# 定义最快运行速度发行模式的编译参数;
SET(CMAKE_C_FLAGS_RELEASE "-Os  ${CFCOMMON}")
SET(CMAKE_CXX_FLAGS_RELEASE "-Os  ${CFCOMMON} -fno-exceptions")
SET(CMAKE_ASM_FLAGS_RELEASE "${MCPU_FLAGS} ${VFP_FLAGS} -x assembler-with-cpp")

# 定义最小尺寸且包含调试信息的编译参数;
SET(CMAKE_C_FLAGS_RELWITHDEBINFO "-Os -g  ${CFCOMMON}")
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-Os -g  ${CFCOMMON} -fno-exceptions")
SET(CMAKE_ASM_FLAGS_RELWITHDEBINFO "${MCPU_FLAGS} ${VFP_FLAGS} -x assembler-with-cpp")

# 定义最小尺寸的编译参数;
SET(CMAKE_C_FLAGS_MINSIZEREL "-Os  ${CFCOMMON}")
SET(CMAKE_CXX_FLAGS_MINSIZEREL "-Os  ${CFCOMMON} -fno-exceptions")
SET(CMAKE_ASM_FLAGS_MINSIZEREL "${MCPU_FLAGS} ${VFP_FLAGS} -x assembler-with-cpp")

# 定义调试模式编译参数;
SET(CMAKE_C_FLAGS_DEBUG "-O0 -g  ${CFCOMMON}")
SET(CMAKE_CXX_FLAGS_DEBUG "-O0 -g  ${CFCOMMON} -fno-exceptions")
SET(CMAKE_ASM_FLAGS_DEBUG "${MCPU_FLAGS} ${VFP_FLAGS} -x assembler-with-cpp")


SET(CMAKE_EXE_LINKER_FLAGS   "  -T ${LINKER_SCRIPT} -lnosys -Wl,-Map=${PROJECT_BINARY_DIR}/${PROJECT_NAME}.map -Wl,--gc-sections,--print-memory-usage")

cmake/postbuild.cmake

set(HEX_FILE ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex)
set(BIN_FILE ${PROJECT_BINARY_DIR}/${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}
Building ${BIN_FILE}")

根目录

CMakeLists.txt

├─Bsp
├─cmake
├─Component
├─Driver
├─Lib
├─Link
├─Start_up
└─User


set(CROSS_COMPILE_PREFIX arm-none-eabi-)
include(${CMAKE_SOURCE_DIR}/cmake/arm-none-eabi.cmake)

cmake_minimum_required(VERSION 3.21)

SET(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)

#显示编译过程
set ( CMAKE_VERBOSE_MAKEFILE off  )
# 项目名称
project(stm32f767_project)

# 开启汇编
ENABLE_LANGUAGE( ASM)
# 项目构建类型
set(CMAKE_BUILD_TYPE  "Debug")
#set(CMAKE_BUILD_TYPE  "Release")
#set(CMAKE_BUILD_TYPE  "RelWithDebInfo")
#set(CMAKE_BUILD_TYPE  "MinSizeRel")
# 设置内核架构
set(CMAKE_ARCH_TYPE  "CM7")

# 添加头文件路径
include_directories(
    ./
    ./User 
)
#添加源码路径
aux_source_directory(${CMAKE_SOURCE_DIR}/User         USER)


#添加启动代码路径
set(STARTUP       ${CMAKE_SOURCE_DIR}/Start_up/startup_stm32f767xx.s)
#添加链接脚本路径
set(LINKER_SCRIPT ${CMAKE_SOURCE_DIR}/Link/STM32F767IGTx_FLASH.ld)

# 宏定义
add_definitions(
  -DSTM32F767xx
  )


# 保护 架构 flag cmake文件
include(${CMAKE_SOURCE_DIR}/cmake/gcc-flags.cmake)

# 打印 构建信息
MESSAGE(STATUS "-----------------------------------------------")

IF("${CMAKE_BUILD_TYPE}" STREQUAL "Release")
  MESSAGE(STATUS "**** Maximum optimization for speed ****")
ELSEIF("${CMAKE_BUILD_TYPE}" STREQUAL "RelWithDebInfo")
  MESSAGE(STATUS "**** Maximum optimization for size, debug info included ****")
ELSEIF("${CMAKE_BUILD_TYPE}" STREQUAL "MinSizeRel")
  MESSAGE(STATUS "**** Maximum optimization for size ****")
ELSE() # "Debug"
  MESSAGE(STATUS "**** No optimization, debug info included ****")
ENDIF()

MESSAGE(STATUS "CMAKE_C_FLAGS:     ${CMAKE_C_FLAGS} ")
MESSAGE(STATUS "CMAKE_CXX_FLAGS:     ${CMAKE_CXX_FLAGS} ")
MESSAGE(STATUS "CMAKE_ASM_FLAGS:    ${CMAKE_ASM_FLAGS} ")
MESSAGE(STATUS "CMAKE_EXE_LINKER_FLAGS:    ${CMAKE_EXE_LINKER_FLAGS} ")
MESSAGE(STATUS "-----------------------------------------------")

#生成目标文件
add_executable(${PROJECT_NAME}.elf 
               ${STARTUP} 
               ${LINKER_SCRIPT}
               ${USER}
               )
# 添加子文件
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Driver)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Bsp)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Lib)
ADD_SUBDIRECTORY(${CMAKE_SOURCE_DIR}/Component)

include(${CMAKE_SOURCE_DIR}/cmake/postbuild.cmake)

bsp
CMakeLists.txt

├─Bsp
│  ├─driver_time
│  └─driver_uart



TARGET_SOURCES(
  ${PROJECT_NAME}.elf
  PRIVATE # {{BEGIN_TARGET_SOURCES}}
          ${CMAKE_CURRENT_LIST_DIR}/driver_time/driver_time.c
          ${CMAKE_CURRENT_LIST_DIR}/driver_time/driver_time_cfg.c
          # {{END_TARGET_SOURCES}}
          # {{BEGIN_TARGET_SOURCES}}
          ${CMAKE_CURRENT_LIST_DIR}/driver_uart/driver_uart.c
          ${CMAKE_CURRENT_LIST_DIR}/driver_uart/driver_uart_callout.c
          ${CMAKE_CURRENT_LIST_DIR}/driver_uart/driver_uart_cfg.c
          # {{END_TARGET_SOURCES}}
)

# Add the Common/inc directory to the project include list
TARGET_INCLUDE_DIRECTORIES( ${PROJECT_NAME}.elf PUBLIC 
${CMAKE_CURRENT_LIST_DIR}/driver_time   
${CMAKE_CURRENT_LIST_DIR}/driver_uart
)

Component
CMakeLists.txt

├─Component
│  └─Fifo

TARGET_SOURCES(
  ${PROJECT_NAME}.elf
  PRIVATE # {{BEGIN_TARGET_SOURCES}}
          ${CMAKE_CURRENT_LIST_DIR}/Fifo/Fifo.c
          # {{END_TARGET_SOURCES}}
)

# Add the Common/inc directory to the project include list
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME}.elf PUBLIC 
            ${CMAKE_CURRENT_LIST_DIR}/Fifo)

Lib
CMakeLists.txt

├─Lib
│  ├─CMSIS
│  │  ├─Core
│  │  │  └─Include
│  │  └─Device
│  │      └─ST
│  │          └─STM32F7xx
│  │              └─Include
│  └─STM32F7xx_HAL_Driver
│      ├─Inc
│      │  └─Legacy
│      └─Src


TARGET_SOURCES(
  ${PROJECT_NAME}.elf
  PRIVATE # {{BEGIN_TARGET_SOURCES}}
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_adc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_adc_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_can.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cec.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cortex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_crc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_crc_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cryp.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_cryp_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dac.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dac_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dcmi.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dcmi_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dfsdm.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dma.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dma2d.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dma_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_dsi.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_eth.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_exti.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_flash.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_flash_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_gpio.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_hash.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_hash_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_hcd.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_i2c.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_i2c_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_i2s.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_irda.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_iwdg.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_jpeg.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_lptim.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_ltdc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_ltdc_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_mdios.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_mmc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_nand.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_nor.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_pcd.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_pcd_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_pwr.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_pwr_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_qspi.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rcc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rcc_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rng.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rtc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_rtc_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sai.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sai_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sd.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sdram.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_smartcard.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_smartcard_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_smbus.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_spdifrx.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_spi.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_spi_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_sram.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_tim_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_uart.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_uart_ex.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_usart.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_hal_wwdg.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_adc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_crc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_dac.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_dma.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_dma2d.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_exti.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_fmc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_gpio.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_i2c.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_lptim.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_pwr.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_rcc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_rng.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_rtc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_sdmmc.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_spi.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_tim.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usart.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_usb.c
          ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Src/stm32f7xx_ll_utils.c
          # {{END_TARGET_SOURCES}}
)

# Add the Common/inc directory to the project include list
TARGET_INCLUDE_DIRECTORIES(${PROJECT_NAME}.elf PUBLIC 
              ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Inc
              ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Inc 
              ${CMAKE_CURRENT_LIST_DIR}/STM32F7xx_HAL_Driver/Inc/Legacy
              ${CMAKE_CURRENT_LIST_DIR}/CMSIS/Include 
              ${CMAKE_CURRENT_LIST_DIR}/CMSIS/Core/Include
              ${CMAKE_CURRENT_LIST_DIR}/CMSIS/Device/ST/STM32F7xx/Include
)

Driver
CMakeLists.txt文章来源地址https://www.toymoban.com/news/detail-676384.html

├─Driver
│  ├─Inc
│  └─Src

TARGET_SOURCES(
  ${PROJECT_NAME}.elf
  PRIVATE # {{BEGIN_TARGET_SOURCES}}
          ${CMAKE_CURRENT_LIST_DIR}/Src/gpio.c
          ${CMAKE_CURRENT_LIST_DIR}/Src/stm32f7xx_hal_msp.c
          ${CMAKE_CURRENT_LIST_DIR}/Src/stm32f7xx_it.c
          ${CMAKE_CURRENT_LIST_DIR}/Src/system_stm32f7xx.c
          ${CMAKE_CURRENT_LIST_DIR}/Src/tim.c
          ${CMAKE_CURRENT_LIST_DIR}/Src/usart.c
          # {{END_TARGET_SOURCES}}
)

# Add the Common/inc directory to the project include list
TARGET_INCLUDE_DIRECTORIES(  ${PROJECT_NAME}.elf PUBLIC  
${CMAKE_CURRENT_LIST_DIR}/Inc
)

到了这里,关于cmake stm32 模板的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

  • STM32开发环境搭建&工程创建(嵌入式学习)

    简介 STM32CubeMX是STMicroelectronics公司提供的一款集成开发环境(IDE)工具,用于快速配置和初始化STM32微控制器系列的软件工程。它提供了图形化界面和交互式工具,使开发者能够轻松地生成STM32微控制器的初始化代码和配置文件。 STM32CubeMX具有以下主要功能和特点: 微控制器

    2024年02月11日
    浏览(66)
  • 蓝桥杯嵌入式STM32G431RBT6竞赛指南与模板——最后的绝唱

    谨以此文和我去年前的一篇蓝桥杯单片机的教程构成电子类的 青铜双壁. 国信长天单片机竞赛训练之原理图讲解及常用外设原理(遗失的章节-零)_昊月光华的博客-CSDN博客     目录 时钟树 串口重定向:printf输出 动态点灯(点灯大师) 按键(常用状态机) 同一时刻对多个按键按

    2024年02月07日
    浏览(47)
  • 嵌入式物联网STM32实战开发代码例程库

    几百个例程清单,CSDN下载地址: https://download.csdn.net/download/weixin_39804904/88671879 开发例程清单(持续新增中,欢迎点赞关注): 0001基于STM32F103单片机GPIO实现控制LED灯闪烁的程序代码0001.rar 0002基于STM32F103单片机GPIO实现按键KEY的检测程序代码0002.rar 0003基于STM32F103单片机GPIO实现

    2024年02月02日
    浏览(46)
  • 嵌入式系统开发13——STM32输出PWM实现呼吸灯

    本文主要介绍在STM32F103C8T6上,利用定时器输出PWM波形,进而驱动LED实现呼吸灯。 使用TIM3和TIM4,分别输出一个PWM波形,PWM的占空比随时间变化,去驱动你外接的一个LED以及最小开发板上已焊接的LED(固定接在 PC13 GPIO端口),实现2个 LED呼吸灯的效果。 脉冲宽度调制(PWM) ,是

    2023年04月08日
    浏览(84)
  • 【STM32嵌入式系统设计与开发】——7有源蜂鸣器应用

    STM32资料包: 百度网盘下载链接:链接:https://pan.baidu.com/s/1mWx9Asaipk-2z9HY17wYXQ?pwd=8888 提取码:8888 观察电路图,核心板PD14连接底板中的P2外接排针,将正负极接上直流电压即可持续发声,频率固定。LED的PA0连接底板的D1灯。 步骤1:复制工程模板“1_Template”重命名为“4_Active

    2024年03月21日
    浏览(69)
  • 嵌入式系统开发笔记104:在STM32CubeIDE中导入工程

      本文讲述如何在STM32CubeIDE中导入现有工程。

    2024年02月16日
    浏览(52)
  • STM32F4+FreeRTOS+LVGL实现嵌入式快速开发(缝合怪)

    极速进行项目开发,只需要懂一款芯片架构+一个操作系统+一个GUI。各种部件程序全靠抄 ,成为究极缝合怪。本文用stm32f407+FreeRTOS+lvgl演示一些demo。 原文链接:STM32F4+FreeRTOS+LVGL实现快速开发(缝合怪) lvgl官方的音乐播放器demo: 百问网的2048小游戏: STM32F407这款芯片就不多介绍

    2024年02月08日
    浏览(60)
  • 嵌入式开发--STM32G4系列片上FLASH的读写

    这个玩意吧,说起来很简单,就是几行代码的事,但楞是折腾了我大半天时间才搞定。原因后面说,先看代码吧: 读操作很简单,以32位方式读取的时候是这样的: 需要注意的是,当以32位方式读取时,地址需要是4的整数倍,即32位。 8位或16位方式类似操作即可 需要注意的

    2024年01月18日
    浏览(68)
  • 【嵌入式开发工具】STM32+Keil实现软件工程搭建与开发调试

    本篇文章介绍了使用Keil来对STM32F103C8芯片进行初始工程搭建,以及开发与工程调试的完整过程,帮助读者能够在实战中体会到Keil这个开发环境的使用方法,了解一个嵌入式工程从无到有的过程,并且具备快速搭建一个全新芯片对应最小软件工程的基本能力思路。文章首先介绍

    2024年02月05日
    浏览(59)
  • 嵌入式开发的学习与未来展望:借助STM32 HAL库开创创新之路

      引言: 嵌入式开发作为计算机科学领域的重要分支,为我们的日常生活和产业发展提供了无限的可能。STMicroelectronics的STM32系列芯片以其出色的性能和广泛的应用领域而备受关注。而STM32 HAL库作为嵌入式开发的高级库,为学习者提供了更高效、更简单的开发方式。本文将结

    2024年02月12日
    浏览(46)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包