refactor(firmware/c_board): Externalize STM32 HAL/CMSIS via submodules#26
refactor(firmware/c_board): Externalize STM32 HAL/CMSIS via submodules#26
Conversation
- Move CubeMX-generated project files from `bsp/HAL` to `cubemx` - Replace vendored STM32 HAL/CMSIS sources with git submodules (`cmsis-core`, `cmsis-device-f4`, `stm32f4xx-hal-driver`) - Update firmware CMake and presets to use new paths - Patch CubeMX CMake integration to use repository variables and PRIVATE link scope for project libraries - Add `.scripts/patch_cubemx` to remove redundant generated files and rewrite absolute include/source paths - Update related path references (e.g. startup file comment) No functional behavior change intended.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: Organization UI Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
Walkthrough将 CMSIS 与 STM32F4 HAL 从仓库内移除并改为子模块管理;新增 .scripts/patch_cubemx 脚本以修补 CubeMX 生成的 CMake 配置;更新 c_board 的 CMake 配置与 CMakePresets 指向新的 cubemx 路径;删除原 HAL/CMSIS 目录下大量头文件与构建元数据。 变更
估算代码审查工作量🎯 4 (Complex) | ⏱️ ~45 分钟 可能相关的 PRs
概述(保留)此 PR 重组了固件构建系统,通过在 .gitmodules 中添加三个新的 Git 子模块(STM32F4xx CMSIS 设备、HAL 驱动和 CMSIS 核心),引入了新的 CubeMX 路径补丁脚本,更新了 CMake 配置以指向新的 CubeMX 集成路径,并删除了现已作为子模块管理的冗余 HAL 和 CMSIS 头文件。 诗
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
.scripts/patch_cubemx (1)
76-79: 建议校验target_link_libraries替换命中次数,避免静默失效。Line [76]-[79] 建议改用
subn并断言至少命中 1 次,这样当 CubeMX 输出格式变化时能立刻失败并暴露问题。建议修复
- patched = PROJECT_LINK_LIBRARIES_PATTERN.sub( + patched, replaced = PROJECT_LINK_LIBRARIES_PATTERN.subn( "target_link_libraries(${CMAKE_PROJECT_NAME} PRIVATE ${MX_LINK_LIBS})", patched, ) + if replaced == 0: + raise ValueError( + "Failed to patch target_link_libraries(${CMAKE_PROJECT_NAME} ...)." + )🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In @.scripts/patch_cubemx around lines 76 - 79, The replacement of PROJECT_LINK_LIBRARIES_PATTERN currently uses re.sub via PROJECT_LINK_LIBRARIES_PATTERN.sub on the variable patched; change this to use PROJECT_LINK_LIBRARIES_PATTERN.subn so you receive (new_string, count), assign back to patched and check the count (assert or raise) is >= 1 to fail fast if no replacements occurred; reference the symbols patched, PROJECT_LINK_LIBRARIES_PATTERN, target_link_libraries and use subn to get the hit count and assert it to surface format changes in CubeMX output.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In @.scripts/patch_cubemx:
- Line 35: The ABSOLUTE_PATH_PATTERN currently only matches POSIX-style absolute
paths and omits Windows drive-letter paths; update ABSOLUTE_PATH_PATTERN so it
also recognizes Windows absolute paths by adding an alternative that matches a
drive letter followed by a colon and a forward slash (letter + ":" + "/") while
preserving the existing boundary lookbehind logic, and then apply the same
updated pattern to the subsequent input validation logic that uses
ABSOLUTE_PATH_PATTERN (the block that checks for absolute paths later in the
script) so Windows-generated inputs are correctly detected.
- Around line 97-101: Validate the CubeMX directory structure (e.g., ensure
(cubemx_root / "cmake/stm32cubemx/CMakeLists.txt").is_file()) before calling
remove_stale_files; if the expected file(s) are missing, raise FileNotFoundError
with a clear message referencing cubemx_root, and only then call
remove_stale_files and patch_stm32cubemx_cmake so you never delete files when
the provided --cubemx-root is incorrect.
---
Nitpick comments:
In @.scripts/patch_cubemx:
- Around line 76-79: The replacement of PROJECT_LINK_LIBRARIES_PATTERN currently
uses re.sub via PROJECT_LINK_LIBRARIES_PATTERN.sub on the variable patched;
change this to use PROJECT_LINK_LIBRARIES_PATTERN.subn so you receive
(new_string, count), assign back to patched and check the count (assert or
raise) is >= 1 to fail fast if no replacements occurred; reference the symbols
patched, PROJECT_LINK_LIBRARIES_PATTERN, target_link_libraries and use subn to
get the hit count and assert it to surface format changes in CubeMX output.
ℹ️ Review info
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (134)
.gitmodules.scripts/patch_cubemxfirmware/c_board/CMakeLists.txtfirmware/c_board/CMakePresets.jsonfirmware/c_board/bsp/HAL/.mxprojectfirmware/c_board/bsp/HAL/CMakeLists.txtfirmware/c_board/bsp/HAL/CMakePresets.jsonfirmware/c_board/bsp/HAL/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f407xx.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Device/ST/STM32F4xx/LICENSE.txtfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cachel1_armv7.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_armcc.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_armclang.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_armclang_ltm.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_compiler.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_gcc.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_iccarm.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_version.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_armv81mml.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_armv8mbl.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_armv8mml.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm0.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm0plus.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm1.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm23.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm3.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm33.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm35p.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm4.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm55.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm7.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm85.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_sc000.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_sc300.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_starmc1.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/mpu_armv7.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/mpu_armv8.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/pac_armv81.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/pmu_armv8.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/Include/tz_context.hfirmware/c_board/bsp/HAL/Drivers/CMSIS/LICENSE.txtfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/Legacy/stm32_hal_legacy.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_can.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio_ex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pcd_ex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_pwr_ex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_rcc_ex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_spi.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_tim_ex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_uart.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_bus.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_cortex.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_dma.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_exti.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_gpio.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_pwr.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_rcc.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_spi.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_system.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_tim.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usart.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_usb.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_ll_utils.hfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/LICENSE.txtfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_can.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_cortex.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_dma_ex.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_exti.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ex.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_flash_ramfunc.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_gpio.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pcd_ex.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_pwr_ex.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_rcc_ex.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_spi.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_tim_ex.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal_uart.cfirmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_ll_usb.cfirmware/c_board/bsp/HAL/cmake/starm-clang.cmakefirmware/c_board/bsp/cmsis-corefirmware/c_board/bsp/cmsis-device-f4firmware/c_board/bsp/stm32f4xx-hal-driverfirmware/c_board/cubemx/.gitignorefirmware/c_board/cubemx/Core/Inc/can.hfirmware/c_board/cubemx/Core/Inc/dma.hfirmware/c_board/cubemx/Core/Inc/gpio.hfirmware/c_board/cubemx/Core/Inc/main.hfirmware/c_board/cubemx/Core/Inc/spi.hfirmware/c_board/cubemx/Core/Inc/stm32f4xx_hal_conf.hfirmware/c_board/cubemx/Core/Inc/stm32f4xx_it.hfirmware/c_board/cubemx/Core/Inc/tim.hfirmware/c_board/cubemx/Core/Inc/usart.hfirmware/c_board/cubemx/Core/Inc/usb_otg.hfirmware/c_board/cubemx/Core/Src/can.cfirmware/c_board/cubemx/Core/Src/dma.cfirmware/c_board/cubemx/Core/Src/gpio.cfirmware/c_board/cubemx/Core/Src/main.cfirmware/c_board/cubemx/Core/Src/spi.cfirmware/c_board/cubemx/Core/Src/stm32f4xx_hal_msp.cfirmware/c_board/cubemx/Core/Src/stm32f4xx_it.cfirmware/c_board/cubemx/Core/Src/syscalls.cfirmware/c_board/cubemx/Core/Src/sysmem.cfirmware/c_board/cubemx/Core/Src/system_stm32f4xx.cfirmware/c_board/cubemx/Core/Src/tim.cfirmware/c_board/cubemx/Core/Src/usart.cfirmware/c_board/cubemx/Core/Src/usb_otg.cfirmware/c_board/cubemx/STM32F407XX_FLASH.ldfirmware/c_board/cubemx/cmake/gcc-arm-none-eabi.cmakefirmware/c_board/cubemx/cmake/stm32cubemx/CMakeLists.txtfirmware/c_board/cubemx/rmcs_slave.iocfirmware/c_board/cubemx/startup_stm32f407xx.sfirmware/c_board/src/utility/interrupt_lock.hpp
💤 Files with no reviewable changes (35)
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ramfunc.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma_ex.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_compiler.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_iccarm.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm1.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_version.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/LICENSE.txt
- firmware/c_board/bsp/HAL/.mxproject
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cachel1_armv7.h
- firmware/c_board/bsp/HAL/CMakePresets.json
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_gcc.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_cortex.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_armclang.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm0.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/pac_armv81.h
- firmware/c_board/bsp/HAL/CMakeLists.txt
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Device/ST/STM32F4xx/Include/system_stm32f4xx.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Device/ST/STM32F4xx/LICENSE.txt
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_armcc.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/mpu_armv7.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/cmsis_armclang_ltm.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/tz_context.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Device/ST/STM32F4xx/Include/stm32f4xx.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_sc000.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/core_cm0plus.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_exti.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/mpu_armv8.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_flash_ex.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h
- firmware/c_board/bsp/HAL/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_can.h
- firmware/c_board/bsp/HAL/Drivers/CMSIS/Include/pmu_armv8.h
bsp/HALtocubemxcmsis-core,cmsis-device-f4,stm32f4xx-hal-driver).scripts/patch_cubemxto remove redundant generated files and rewrite absolute include/source pathsNo functional behavior change intended.
PR #26 - 通过子模块外部化 STM32 HAL/CMSIS(更新)
概述
将 firmware/c_board 项目中的 CubeMX/STM32 HAL/CMSIS 相关源从仓库内的直写副本迁移为外部 git 子模块管理;同时调整 CubeMX 生成的 CMake 集成、更新 CMake 配置/预设并添加自动化补丁脚本以修正生成文件的绝对路径与冗余产物。目标为重构与路径、依赖管理清理;不引入功能行为变更。
主要变更
兼容性与注意事项
益处