使用 Clion IDE 开发 stm32 使用标准库 可以使用 qemu 代替开发版
使用 CMakeLists.txt 编译项目
set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
cmake_minimum_required(VERSION 3.26)
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)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
project(clion_stm32_cmakelist_project 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)
message(STATUS "Minimal optimization, debug info included")
add_compile_options(-Og -g)
add_definitions(
-DUSE_HAL_DRIVER
-DSTM32F103xB
-DUSE_STDPERIPH_DRIVER
-DSTM32F10X_HD
)
include_directories(
./stm_lib/inc
./stm_lib/src
./cmsis_boot
./cmsis
)
file(GLOB_RECURSE SOURCES
"cmsis_boot/startup/*.*"
"cmsis_boot/*.c"
"cmsis_boot/*.h"
"cmsis/*.h"
"stm_lib/inc/*.h"
"stm_lib/src/*.c"
"main.c"
)
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 ${CMAKE_SOURCE_DIR}/STM32F103C8Tx_FLASH.ld)
add_executable(${PROJECT_NAME}.elf ${SOURCES} ${CMAKE_SOURCE_DIR}/STM32F103C8Tx_FLASH.ld)
add_custom_command(TARGET ${PROJECT_NAME}.elf POST_BUILD
COMMAND ${CMAKE_OBJCOPY} -Oihex $<TARGET_FILE:${PROJECT_NAME}.elf> ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.hex
COMMAND ${CMAKE_OBJCOPY} -Obinary $<TARGET_FILE:${PROJECT_NAME}.elf> ${PROJECT_BINARY_DIR}/${PROJECT_NAME}.bin
COMMENT "Building ${HEX_FILE}
Building ${BIN_FILE}")
使用 docker qemu 模拟器
qemu-system-arm -M stm32-f103c8 -kernel clion_stm32_cmakelist_project.bin
标签:PROJECT,CMakeLists,set,CMAKE,stm32,add,eabi,标砖库,arm
From: https://www.cnblogs.com/guanchaoguo/p/17617045.html