diff --git a/.gitignore b/.gitignore
index 61d4cfa..fc60861 100644
--- a/.gitignore
+++ b/.gitignore
@@ -12,4 +12,6 @@ cmake-build-debug-stm32cube
/STM32H723VGTx_FLASH.ld
-/compile_commands.json
\ No newline at end of file
+/compile_commands.json
+
+.idea
\ No newline at end of file
diff --git a/.idea/.gitignore b/.idea/.gitignore
deleted file mode 100644
index 35410ca..0000000
--- a/.idea/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-# 默认忽略的文件
-/shelf/
-/workspace.xml
-# 基于编辑器的 HTTP 客户端请求
-/httpRequests/
-# Datasource local storage ignored files
-/dataSources/
-/dataSources.local.xml
diff --git a/.idea/.name b/.idea/.name
deleted file mode 100644
index 13bf869..0000000
--- a/.idea/.name
+++ /dev/null
@@ -1 +0,0 @@
-TronOneH7_Scaffold
\ No newline at end of file
diff --git a/.idea/TronOneH7_Scaffold.iml b/.idea/TronOneH7_Scaffold.iml
deleted file mode 100644
index f08604b..0000000
--- a/.idea/TronOneH7_Scaffold.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/copilot.data.migration.agent.xml b/.idea/copilot.data.migration.agent.xml
deleted file mode 100644
index 4ea72a9..0000000
--- a/.idea/copilot.data.migration.agent.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/copilot.data.migration.ask.xml b/.idea/copilot.data.migration.ask.xml
deleted file mode 100644
index 7ef04e2..0000000
--- a/.idea/copilot.data.migration.ask.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/copilot.data.migration.ask2agent.xml b/.idea/copilot.data.migration.ask2agent.xml
deleted file mode 100644
index 1f2ea11..0000000
--- a/.idea/copilot.data.migration.ask2agent.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/copilot.data.migration.edit.xml b/.idea/copilot.data.migration.edit.xml
deleted file mode 100644
index 8648f94..0000000
--- a/.idea/copilot.data.migration.edit.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/editor.xml b/.idea/editor.xml
deleted file mode 100644
index 17f50d3..0000000
--- a/.idea/editor.xml
+++ /dev/null
@@ -1,349 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
deleted file mode 100644
index bce41e5..0000000
--- a/.idea/misc.xml
+++ /dev/null
@@ -1,25 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
\ No newline at end of file
diff --git a/.idea/vcs.xml b/.idea/vcs.xml
deleted file mode 100644
index 94a25f7..0000000
--- a/.idea/vcs.xml
+++ /dev/null
@@ -1,6 +0,0 @@
-
-
-
-
-
-
\ No newline at end of file
diff --git a/CMakeLists.txt b/CMakeLists.txt
index de7b4d1..9b17923 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,15 +1,7 @@
cmake_minimum_required(VERSION 3.22)
-include("cmake/gcc-arm-none-eabi.cmake")
project(TronOneH7_Scaffold)
-# option(BALANCE "Enable balance" ON)
-# option(STEER "Enable steer" ON)
-#option(OMNI "Enable omni" ON)
-# option(INFANTRY_OMNI "Enable infantry moni" ON)
-# option(HERO "Enable hero" ON)
-# option(HERO_STEER "Enable hero_steer" ON)
-# option(DART_STAND "Enable dart stand" ON)
-# option(ENGINEER "Enable engineer" ON)
+list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
# 启用编译命令以便于使用例如 clangd 进行索引
set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)
@@ -47,50 +39,11 @@ if (NOT CMAKE_BUILD_TYPE)
endif ()
message("Build type: ${CMAKE_BUILD_TYPE}")
-# 创建可执行对象类型
+# 创建可执行对象
add_executable(${CMAKE_PROJECT_NAME})
-# 添加子目录
-#add_subdirectory(cmake/stm32cubemx)
-#add_subdirectory(User_Code/bsp)
-#add_subdirectory(User_Code/module)
-#if (STEER)
-# add_subdirectory(User_Code/user/steer)
-# message("You set STEER")
-#
-#elseif (BALANCE)
-# add_subdirectory(User_Code/user/balance)
-# message("You set BALANCE")
-#
-#elseif (OMNI)
-# add_subdirectory(User_Code/user/omni)
-# message("You set OMNI")
-#
-#elseif (INFANTRY_OMNI)
-# add_subdirectory(User_Code/user/infantry_omni)
-# message("You set INFANTRY_OMNI")
-#
-#elseif (DART_STAND)
-# add_subdirectory(User_Code/user/dart_stand)
-# message("You set DART_STAND")
-#
-#elseif (ENGINEER)
-# add_subdirectory(User_Code/user/engineer)
-# message("You set ENGINEER")
-#
-#elseif (HERO)
-# add_subdirectory(User_Code/user/hero)
-# message("You set HERO")
-#
-#elseif (HERO_STEER)
-# add_subdirectory(User_Code/user/hero_steer)
-# message("You set HERO_STEER")
-#endif ()
-
-# # 强制包含头文件
-# target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
-# # -include "${CMAKE_SOURCE_DIR}/User_Code/bsp/safe_check/packed_struct.hpp"
-# )
+include(CompileOptions)
+include(FindModules)
# Add STM32CubeMX generated sources
add_subdirectory(cmake/stm32cubemx)
@@ -98,115 +51,30 @@ add_subdirectory(cmake/stm32cubemx)
# 添加链接库
target_link_libraries(${CMAKE_PROJECT_NAME}
stm32cubemx
- # ${CMAKE_SOURCE_DIR}/Drivers/CMSIS/DSP/Lib/GCC/libarm_cortexM7lfdp_math.a
-)
-#link_libraries("Drivers/CMSIS/DSP/Lib/GCC/libarm_cortexM7lfdp_math.a")
-# 添加包含路径
-include_directories(
- ./Drivers/CMSIS/Include
- ./Drivers/CMSIS/DSP/Include/
-)
-# 添加链接目录
-link_directories(
- ./Drivers/CMSIS/DSP/Lib/GCC
-)
-# 添加编译选项
-add_compile_options(-pipe -Wall -fmessage-length=0 # basic options
- -ffunction-sections -fdata-sections -fno-common # optimize options
-)
-add_link_options(-pipe -Wl,--no-warn-rwx-segments # close RWX warning
- -lc -lstdc++ -lm -lnosys # lib options
- -Wl,--gc-sections -flto -specs=nano.specs -specs=nosys.specs # optimize options
-)
-# 添加全局宏定义
-add_definitions(
- -DUSE_HAL_DRIVER
- -DARM_MATH_CM7
- -DARM_MATH_MATRIX_CHECK
- -DARM_MATH_ROUNDING
- -DARM_MATH_LOOPUNROLL
- -DDISABLEFLOAT16
-)
-# 添加目标编译选项
-target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
- -mthumb
- # -mthumb-interwork
- -mfpu=fpv5-d16
- -mfloat-abi=hard
+ rpl::rpl
)
-
-# 忽略 usbd_desc.c 文件中由于缺少字段初始化引起的警告
-#set_source_files_properties(
-# ${CMAKE_CURRENT_SOURCE_DIR}/USB_DEVICE/App/usbd_desc.c
-# PROPERTIES COMPILE_FLAGS -Wno-missing-field-initializers
-#)
-# 忽略特定文件中的未使用参数警告
-#set_source_files_properties(
-# ${CMAKE_CURRENT_SOURCE_DIR}/Core/Src/freertos.c
-# ${CMAKE_CURRENT_SOURCE_DIR}/USB_DEVICE/App/usbd_cdc_if.c
-# PROPERTIES COMPILE_FLAGS -Wno-unused-parameter
-#)
+file(GLOB_RECURSE USER_SOURCES "${PROJECT_SOURCE_DIR}/User_Code/*.c" "${PROJECT_SOURCE_DIR}/User_Code/*.cpp")
# Add sources to executable
target_sources(${CMAKE_PROJECT_NAME} PRIVATE
- User_Code/bsp/fdcan/bsp_fdcan.c
- User_Code/bsp/spi/bsp_spi.c
- User_Code/bsp/delayticks/delayticks.c
- User_Code/module/periph/ws2812/ws2812.c
- User_Code/application/indicator_app/ws2812status.c
+ ${USER_SOURCES}
# Add user sources here
)
+file(GLOB_RECURSE USER_HEADERS "${CMAKE_SOURCE_DIR}/User_Code/*.h" "${CMAKE_SOURCE_DIR}/User_Code/*.hpp")
+
+foreach (header ${USER_HEADERS})
+ get_filename_component(dir ${header} DIRECTORY)
+ target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${dir})
+endforeach ()
+
# Add include paths
target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE
- User_Code/bsp/fdcan
- User_Code/bsp/spi
- User_Code/bsp/delayticks
- User_Code/module/periph/ws2812
- User_Code/module/paramdef
- User_Code/application/indicator_app
- # Add user defined include paths
+
)
# 添加全局宏定义
target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
# RM_REFEREE
-)
-
-# 添加全局宏定义
-#if (OMNI)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# SENTRY
-# OMNI
-# )
-#elseif (INFANTRY_OMNI)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# # SENTRY
-# INFANTRY_OMNI
-# )
-#elseif (STEER)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# STEER
-# )
-#elseif (BALANCE)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# BALANCE
-# )
-#elseif (HERO)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# HERO
-# )
-#elseif (HERO_STEER)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# HERO_STEER
-# )
-#elseif (DART_STAND)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# DART_STAND
-# )
-#elseif (ENGINEER)
-# target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
-# ENGINEER
-# )
-#endif ()
+)
\ No newline at end of file
diff --git a/cmake/CompileOptions.cmake b/cmake/CompileOptions.cmake
new file mode 100644
index 0000000..bb836bd
--- /dev/null
+++ b/cmake/CompileOptions.cmake
@@ -0,0 +1,26 @@
+add_compile_options(
+ -pipe -Wall -fmessage-length=0 # basic options
+ -ffunction-sections -fdata-sections -fno-common # optimize options
+)
+add_link_options(
+ -pipe -Wl,--no-warn-rwx-segments # close RWX warning
+ -lc -lstdc++ -lm -lnosys # lib options
+ -Wl,--gc-sections -flto -specs=nano.specs -specs=nosys.specs # optimize options
+)
+
+# 添加宏定义
+target_compile_definitions(${CMAKE_PROJECT_NAME} PRIVATE
+ -DUSE_HAL_DRIVER
+ -DARM_MATH_CM7
+ -DARM_MATH_MATRIX_CHECK
+ -DARM_MATH_ROUNDING
+ -DARM_MATH_LOOPUNROLL
+ -DDISABLEFLOAT16
+)
+# 添加目标编译选项
+target_compile_options(${CMAKE_PROJECT_NAME} PRIVATE
+ -mthumb
+ # -mthumb-interwork
+ -mfpu=fpv5-d16
+ -mfloat-abi=hard
+)
\ No newline at end of file
diff --git a/cmake/FindModules.cmake b/cmake/FindModules.cmake
new file mode 100644
index 0000000..7543dd5
--- /dev/null
+++ b/cmake/FindModules.cmake
@@ -0,0 +1,2 @@
+include(FetchContent)
+include(Modules/FindRPL)
\ No newline at end of file
diff --git a/cmake/Modules/.gitkeep b/cmake/Modules/.gitkeep
new file mode 100644
index 0000000..e69de29
diff --git a/cmake/Modules/FindRPL.cmake b/cmake/Modules/FindRPL.cmake
new file mode 100644
index 0000000..58ae31c
--- /dev/null
+++ b/cmake/Modules/FindRPL.cmake
@@ -0,0 +1,10 @@
+find_package(rpl QUIET)
+
+if (NOT rpl_FOUND)
+ FetchContent_Declare(
+ rpl
+ GIT_REPOSITORY https://gitee.com/dlmu-cone/rpl
+ GIT_TAG main
+ )
+ FetchContent_MakeAvailable(rpl)
+endif ()
\ No newline at end of file
diff --git a/cmake/gcc-arm-none-eabi.cmake b/cmake/gcc-arm-none-eabi.cmake
deleted file mode 100644
index fb42d44..0000000
--- a/cmake/gcc-arm-none-eabi.cmake
+++ /dev/null
@@ -1,60 +0,0 @@
-set(CMAKE_SYSTEM_NAME Generic)
-set(CMAKE_SYSTEM_PROCESSOR arm)
-
-set(CMAKE_C_COMPILER_FORCED TRUE)
-set(CMAKE_CXX_COMPILER_FORCED TRUE)
-set(CMAKE_C_COMPILER_ID GNU)
-set(CMAKE_CXX_COMPILER_ID GNU)
-
-# Some default GCC settings
-# arm-none-eabi- must be part of path environment
-set(TOOLCHAIN_PREFIX arm-none-eabi-)
-
-set(CMAKE_C_COMPILER ${TOOLCHAIN_PREFIX}gcc)
-set(CMAKE_ASM_COMPILER ${CMAKE_C_COMPILER})
-set(CMAKE_CXX_COMPILER ${TOOLCHAIN_PREFIX}g++)
-set(CMAKE_LINKER ${TOOLCHAIN_PREFIX}g++)
-set(CMAKE_OBJCOPY ${TOOLCHAIN_PREFIX}objcopy)
-set(CMAKE_SIZE ${TOOLCHAIN_PREFIX}size)
-
-set(CMAKE_EXECUTABLE_SUFFIX_ASM ".elf")
-set(CMAKE_EXECUTABLE_SUFFIX_C ".elf")
-set(CMAKE_EXECUTABLE_SUFFIX_CXX ".elf")
-
-set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
-
-# MCU specific flags
-set(TARGET_FLAGS "-mcpu=cortex-m7 -mfpu=fpv5-d16 -mfloat-abi=hard ")
-
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${TARGET_FLAGS}")
-set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -Wextra -Wpedantic -fdata-sections -ffunction-sections")
-if (CMAKE_BUILD_TYPE MATCHES "Debug")
- set(CMAKE_C_FLAGS_DEBUG "-O0 -g")
- set(CMAKE_CXX_FLAGS_DEBUG "-O0 -g")
-elseif (CMAKE_BUILD_TYPE MATCHES "Release")
- set(CMAKE_C_FLAGS_RELEASE "-O3")
- set(CMAKE_CXX_FLAGS_RELEASE "-O3")
-elseif (CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
- set(CMAKE_C_FLAGS_RELWITHDEBINFO "-O2 -g")
- set(CMAKE_CXX_FLAGS_RELWITHDEBINFO "-O2 -g")
-elseif (CMAKE_BUILD_TYPE MATCHES "MinSizeRel")
- set(CMAKE_C_FLAGS_MINSIZEREL "-Os")
- set(CMAKE_CXX_FLAGS_MINSIZEREL "-Os")
-endif ()
-
-set(CMAKE_ASM_FLAGS "${CMAKE_C_FLAGS} -x assembler-with-cpp -MMD -MP")
-set(CMAKE_CXX_FLAGS "${CMAKE_C_FLAGS} -fno-rtti -fno-exceptions -fno-threadsafe-statics")
-
-set(CMAKE_C_LINK_FLAGS "${TARGET_FLAGS}")
-#set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -T \"${CMAKE_SOURCE_DIR}/MY_FLASH.ld\"")
-
-
-set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} --specs=nano.specs")
-
-set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -T \"${CMAKE_SOURCE_DIR}/STM32H723XG_FLASH.ld\"")
-
-set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,-Map=${CMAKE_PROJECT_NAME}.map -Wl,--gc-sections")
-set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lc -lm -Wl,--end-group")
-set(CMAKE_C_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--print-memory-usage")
-
-set(CMAKE_CXX_LINK_FLAGS "${CMAKE_C_LINK_FLAGS} -Wl,--start-group -lstdc++ -lsupc++ -Wl,--end-group")
\ No newline at end of file
diff --git a/doc/CMake.md b/doc/CMake.md
new file mode 100644
index 0000000..1c406df
--- /dev/null
+++ b/doc/CMake.md
@@ -0,0 +1,99 @@
+项目构建说明(CMake)
+=====================
+
+本文档概述本仓库使用的 CMake 构建系统、主要配置项,以及对用户最相关的自动包含规则(特别是 `User_Code`
+目录中的源文件与头文件)。目标读者是开发者或维护者,希望快速了解如何配置、构建以及把新代码加入工程。
+
+快速概览
+--------
+
+- 构建系统:CMake >= 3.22,生成器默认使用 Ninja(参见 `CMakePresets.json`)。
+- 预设(presets):仓库提供 `Debug` 和 `Release` 两个 configure/build preset(见 `CMakePresets.json`)。
+- 目标可执行文件名:由顶层 CMake 项目名(`TronOneH7_Scaffold`)创建一个可执行目标。
+- 工具链:默认通过 `cmake/starm-clang.cmake` 指定交叉/宿主工具链(在 presets 中通过 `toolchainFile` 引用)。
+- 自动包含:`User_Code` 目录下的所有 `.c`、`.cpp` 源文件会被递归搜集并添加到目标;同目录下的 `.h`、`.hpp` 头文件所在目录也会被自动加入目标的
+ include 路径。
+
+文件和关键配置点
+----------------
+
+- 顶层配置:`CMakeLists.txt`
+ - 设置了 C/C++ 标准(C23, C++23)并启用 ASM 支持。
+ - 导出 `compile_commands.json` 以便 clangd / IDE 索引(`set(CMAKE_EXPORT_COMPILE_COMMANDS TRUE)`)。
+ - 根据 `CMAKE_BUILD_TYPE` 设置编译器的优化/调试选项(Debug/Release/RelWithDebInfo/MinSizeRel)。
+ - 通过 `add_subdirectory(cmake/stm32cubemx)` 引入由 STM32CubeMX 生成的构建片段(包括启动文件、链接脚本、HAL 库设置等)。
+ - 将 `stm32cubemx` 静态/目标库和 `rpl::rpl`(项目中的第三方或子模块库)链接到可执行目标。
+
+- 预设:`CMakePresets.json`
+ - `default` preset 指明生成器(Ninja)、二进制输出目录(`build/${presetName}`)与工具链文件。
+ - `Debug`/`Release` preset 分别继承 `default` 并设置 `CMAKE_BUILD_TYPE`。
+ - 构建命令示例(在仓库根目录运行):
+
+```sh
+cmake --preset Debug
+cmake --build --preset Debug
+```
+
+(Windows 下的 shell 为 cmd.exe,上面命令同样适用;若使用 VS Developer Prompt 或 PowerShell,可在相应环境中运行)
+
+User_Code 的自动包含行为
+----------------------
+顶层 `CMakeLists.txt` 中有两段与 `User_Code` 有关的逻辑:
+
+1. 自动收集源文件:
+
+```cmake
+file(GLOB_RECURSE USER_SOURCES "${PROJECT_SOURCE_DIR}/User_Code/*.c" "${PROJECT_SOURCE_DIR}/User_Code/*.cpp")
+
+target_sources(${CMAKE_PROJECT_NAME} PRIVATE
+ ${USER_SOURCES}
+)
+```
+
+该逻辑会递归查找 `User_Code` 下所有 `.c` 和 `.cpp` 文件,并把它们加入到可执行目标中。开发者只要把源文件放在 `User_Code`
+子目录(或其子目录)下,CMake 在下一次 configure 时会将其纳入构建。
+
+2. 自动加入头文件目录:
+
+```cmake
+file(GLOB_RECURSE USER_HEADERS "${CMAKE_SOURCE_DIR}/User_Code/*.h" "${CMAKE_SOURCE_DIR}/User_Code/*.hpp")
+
+foreach (header ${USER_HEADERS})
+ get_filename_component(dir ${header} DIRECTORY)
+ target_include_directories(${CMAKE_PROJECT_NAME} PRIVATE ${dir})
+endforeach ()
+```
+
+这个片段会递归查找 `User_Code` 下的 `.h`/`.hpp` 文件,并将每个头文件所在的目录添加为目标的私有 include 目录。换句话说:
+
+- 如果你的头文件位于 `User_Code/my_module/include/mymod.h`,该 `include` 目录会被自动添加到编译器的 include 路径中。
+- 如果多个源/头文件位于同一目录,该目录只会被多次添加(可接受,但可通过改进避免重复,如需要我可以帮忙优化)。
+
+如何添加/组织代码(建议)
+------------------------
+
+- 源文件:把 `.c`/`.cpp` 放在 `User_Code//` 下。CMake 会自动发现并编译。
+- 头文件:把 `.h`/`.hpp` 放在与源文件同目录或子目录的 `include/` 目录中,CMake 会将头文件所在目录纳入 include 路径。
+- 如果你想限制某些文件不被自动编译,可以:
+ - 改名(例如添加后缀 `.inert`)或者
+ - 将需要排除的文件放到项目外,或修改 `CMakeLists.txt` 来有选择性地添加源文件(我可以帮助你实现更精细的控制)。
+
+拓展说明(链接库、工具链、CubeMX)
+-----------------------------
+
+- STM32CubeMX:`add_subdirectory(cmake/stm32cubemx)` 会把生成的 HAL/启动/链接脚本等加入工程,相关源通常在
+ `cmake/stm32cubemx` 子项目中管理。
+- 工具链:`CMakePresets.json` 中 `default` preset 指向 `cmake/starm-clang.cmake`。如果你使用不同编译器或调试器,请修改对应
+ preset 的 `toolchainFile` 或在命令行提供 `-DCMAKE_TOOLCHAIN_FILE=...`。
+- 第三方库:示例中 `rpl::rpl` 被链接到目标上;如果需要新增库,请在 `FindModules.cmake` 或 `cmake/Modules` 中添加查找逻辑,或直接使用
+ `add_subdirectory` 引入并 `target_link_libraries`。
+
+诊断与调试
+---------
+
+- 若 clangd / IDE 没有正确索引,请确认 `build/Debug/compile_commands.json`(或对应 preset 的 build 目录)存在。若不存在,请使用
+ `cmake --preset Debug` 重新 configure。
+- 若新加入的源文件未被编译:
+ - 确认文件扩展名是 `.c` / `.cpp` 并放在 `User_Code` 子目录下;
+ - 重新运行 `cmake --preset ` 以刷新 CMake cache(Ninja incremental build 不会改变 configure 阶段的 glob 结果);
+ - 如果希望不依赖 glob,可以手动在 `CMakeLists.txt` 里使用 `target_sources` 显式列出文件列表。