Skip to content

refactor(firmware/c_board): Split app/bsp layout and align firmware packaging#27

Merged
qzhhhi merged 3 commits intomainfrom
dev/bootloader
Mar 2, 2026
Merged

refactor(firmware/c_board): Split app/bsp layout and align firmware packaging#27
qzhhhi merged 3 commits intomainfrom
dev/bootloader

Conversation

@qzhhhi
Copy link
Member

@qzhhhi qzhhhi commented Mar 2, 2026

  • Move app code to app/src/ and app/include/ to make room for future bootloaders.
  • Isolate CubeMX files in bsp/cubemx/, rename linker script to STM32F407XX_APP.ld, and enable NoMain=true.
  • Move main() to the app layer to control startup flow, relocate startup interrupt-disable logic from startup_stm32f407xx.s to main(), and keep TinyUSB IRQ dispatch in CubeMX ISR.
  • Refactor CMake with top-level shared options and app/CMakeLists.txt; update toolchain path, presets, and lint targets.
  • Adapt .scripts/patch_cubemx for the new CubeMX root and patch strategy.
  • Update Dockerfile.build_firmware to package only release ELFs (excluding debug artifacts) from specific board outputs (rmcs_board, c_board_app).

No runtime feature changes are introduced to the c_board application logic; startup and packaging flows are strictly reorganized.

c_board 固件重构:应用层与 BSP 分离(更新摘要)

概述

本 PR 将 c_board 固件重构为明确的 app / bsp 分层,主要目标为支持未来 bootloader、清晰化启动组织及改进固件打包流程。声称无运行时功能性变化;改动集中在源码/头文件重组、启动入口迁移、中断初始化语义、CMake 架构重构以及构建/打包脚本更新。

主要改动点

  • 目录与文件重组

    • 应用层迁移:应用源码与头文件从 firmware/c_board/src/ → firmware/c_board/app/src/ 与 firmware/c_board/app/include/(相关 include 引用已更新)。
    • BSP(CubeMX)隔离:CubeMX 生成文件移至 firmware/c_board/bsp/cubemx/。
    • 链接脚本:新增并区分应用链接脚本 STM32F407XX_APP.ld。
    • 新增工具链文件:新增 firmware/c_board/cmake/gcc-arm-none-eabi.cmake;同时移除/重构了 cubemx 子目录下的旧工具链配置。
  • 启动流程与中断管理

    • main() 迁移:删除 bsp/cubemx/Core/Src/main.c 中的 main,应用入口迁移到 firmware/c_board/app/src/app.cpp(定义 App 构造与 run 主循环)。
    • CubeMX 配置:rmcs_slave.ioc 将 ProjectManager.NoMain 设为 true,阻止 CubeMX 自动生成 main。
    • 启动汇编调整:startup_stm32f407xx.s 中移除了 Reset_Handler 里显式禁用中断的指令;启动时的中断禁用语义由应用层/初始化逻辑调整。
    • ISR 保留:TinyUSB 的 IRQ 分发保留在 CubeMX 生成的 ISR(stm32f4xx_it.c),新增前向声明 tusb_int_handler(uint8_t, bool) 以配合应用层处理。
    • InterruptMutex 初始值:firmware/c_board/app/src/utility/interrupt_lock.hpp 中 InterruptMutex::lock_count_ 从 1 改为 0(初始化为未锁定)。
  • 应用实现迁移

    • 新增 firmware/c_board/app/src/app.cpp,定义 librmcs::firmware::App 的构造、初始化序列及 [[noreturn]] App::run()(主循环含 tud_task() 与各外设轮询/传输)。
    • 删除旧实现 firmware/c_board/src/app.cpp(移除原 extern "C" AppEntry 与旧 App 定义)。
  • CMake 架构重构

    • 项目与语言声明:firmware/c_board/CMakeLists.txt 改为 project(librmcs-firmware LANGUAGES C CXX ASM),并引入 C++23 设置。
    • 共享配置函数:新增 c_board_apply_target_options(target linker_file) 以集中配置包含路径、编译选项、宏定义与链接选项。
    • app 层 CMake:新增 firmware/c_board/app/CMakeLists.txt,创建可执行目标 c_board_app 及 tinyusb_app(OBJECT 库),配置 TinyUSB 源、编译定义(CFG_TUSB_MCU=OPT_MCU_STM32F4)与依赖。
    • CubeMX 集成:通过 add_subdirectory("${LIBRMCS_STM32_CUBEMX_ROOT}/cmake/stm32cubemx" SYSTEM) 引入 stm32cubemx;cubemx 的内部 CMake 改为使用 add_library(stm32cubemx OBJECT) 聚合驱动与 MX 应用源码(对象库模型)。
    • CMakePresets.json:修正 toolchainFile 路径为 cmake/gcc-arm-none-eabi.cmake。
  • 构建与打包脚本调整

    • Dockerfile.build_firmware:构建流程简化为仅产出 release ELF,分别为 rmcs_board 与 c_board_app 复制统一命名的 ELF 到 /output,构建目录改为 /tmp/build-*/,移除多配置产物与复杂清理逻辑。
    • .scripts/patch_cubemx:重构补丁策略为在 CubeMX CMake 末尾注入 tail(STM32CUBEMX_TAIL / 锚点),改用 LIBRMCS_CMSIS_CORE_ROOT/Core/Include 的 CMSIS 路径替换,强化未找到锚点时的错误检测;更新默认 CubeMX 根为 firmware/c_board/bsp/cubemx,扩展 stale 文件列表。
    • .scripts/lint-targets.yml:将 c_board 的 lint/扫描路径指向 firmware/c_board/app/src 与 firmware/c_board/app/include。
  • 其他小改动

    • bsp/cubemx/.gitignore 新增 STM32F407XX_FLASH.ld 与 cmake/gcc-arm-none-eabi.cmake。
    • 绝大多数头文件引用更新为 app 路径(can、gpio、led、logger、spi、timer、uart、usb、utility 等),逻辑与接口未改动。
    • 删除了 cubemx 子目录下原有的 gcc-arm-none-eabi.cmake(其配置迁移到新位置)。

风险与注意事项

  • 虽然 PR 不声称改变运行时行为,但对启动顺序、中断初始状态(不再在重置处理里自动禁中断)、链接脚本及散段布局做了关键性调整。建议在 CI 与真实硬件上执行完整回归构建与启动测试,重点验证:
    • 中断在早期初始化阶段的可见性与竞态(InterruptMutex 初始值变化的影响)。
    • SystemClock_Config 与各外设初始化的时序(main 从 BSP 移至应用层后的调用时序)。
    • 链接脚本(STM32F407XX_APP.ld)与内存/段布局是否满足运行时需求。
    • TinyUSB 中断分发与前向声明的兼容性。

结论

这是一次以构建、打包与启动组织为中心的重构:将应用从 CubeMX 输出中剥离为独立 app 层、将 CubeMX 保留为 BSP 提供者并改造为对象库集成,调整工具链与 CI 打包以只产出应用 release ELF。需要在硬件/CI 上验证启动与中断相关的细微语义变化。

…ackaging

- Move app code to `app/src/` and `app/include/` to make room for future bootloaders.
- Isolate CubeMX files in `bsp/cubemx/`, rename linker script to `STM32F407XX_APP.ld`, and enable `NoMain=true`.
- Move `main()` to the app layer to control startup flow, relocate startup interrupt-disable logic from `startup_stm32f407xx.s` to `main()`, and keep TinyUSB IRQ dispatch in CubeMX ISR.
- Refactor CMake with top-level shared options and `app/CMakeLists.txt`; update toolchain path, presets, and lint targets.
- Adapt `.scripts/patch_cubemx` for the new CubeMX root and patch strategy.
- Update `Dockerfile.build_firmware` to package only release ELFs (excluding debug artifacts) from specific board outputs (`rmcs_board`, `c_board_app`).

No runtime feature changes are introduced to the c_board application logic; startup and packaging flows are strictly reorganized.
@coderabbitai
Copy link

coderabbitai bot commented Mar 2, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 02faa56 and a8a2f25.

📒 Files selected for processing (2)
  • .scripts/patch_cubemx
  • firmware/c_board/bsp/cubemx/cmake/stm32cubemx/CMakeLists.txt
🚧 Files skipped from review as they are similar to previous changes (1)
  • firmware/c_board/bsp/cubemx/cmake/stm32cubemx/CMakeLists.txt

Walkthrough

将 firmware/c_board 源重构至 app 子目录,新增 TinyUSB 应用目标并引入 c_board_app,可执行入口与 CubeMX 生成入口被替换;重构 CMake/工具链与 patch_cubemx 行为;调整构建脚本(Dockerfile.build_firmware)与若干启动/中断初始化语义。

Changes

Cohort / File(s) Summary
脚本与补丁
\.scripts/lint-targets.yml, \.scripts/patch_cubemx
lint 目标改为扫描 app/src/app/include;patch_cubemx 改为尾部(EOF)注入,新增尾标识与 EOF 模式、CMSIS include 路径替换和 stale 文件条目。
Docker 构建
Dockerfile.build_firmware
简化构建循环为按板卡单配置构建,提前创建 /output、使用 /tmp/build-* 临时目录,分别复制 rmcs_board 与 c_board ELF 到 /output
顶层 CMake 与预设
firmware/c_board/CMakeLists.txt, firmware/c_board/CMakePresets.json
显式 project 名称并启用 C++23,新增函数 c_board_apply_target_options() 封装目标配置,新增 LIBRMCS_* 路径变量,修正 toolchainFile 路径。
应用层 CMake 与目标
firmware/c_board/app/CMakeLists.txt, firmware/c_board/app/src/*
新增 c_board_app 可执行与 tinyusb_app OBJECT 库,集成 TinyUSB 源与定义;将大量源文件 include 路径迁移到 app/src,新增 App 类实现(初始化与主循环)。
头文件路径迁移
firmware/c_board/app/src/... 多个子目录(can/*,gpio/*,led/*,logger/*,spi/*,timer/*,uart/*,usb/*,utility/*
将包含路径从 firmware/c_board/src/... 改为 firmware/c_board/app/src/...,多数改动仅为 include 路径调整。
中断/启动语义变更
firmware/c_board/app/src/utility/interrupt_lock.hpp, firmware/c_board/bsp/cubemx/startup_stm32f407xx.s
InterruptMutex::lock_count_ 初始值由 1 改为 0;移除 Reset_Handler 中的显式禁用中断指令(启动时不再强制禁中断)。
CubeMX / stm32cubemx 构建整合
firmware/c_board/bsp/cubemx/cmake/stm32cubemx/CMakeLists.txt, firmware/c_board/cmake/gcc-arm-none-eabi.cmake, firmware/c_board/cubemx/cmake/gcc-arm-none-eabi.cmake
新增顶层 toolchain 文件并删除旧 cubemx 下的同名文件;stm32cubemx 从 INTERFACE 改为 OBJECT 库,合并驱动与应用源,公开 include 与 compile definitions。
CubeMX 生成代码与入口调整
firmware/c_board/bsp/cubemx/Core/Inc/main.h, .../Core/Src/main.c, .../Core/Src/stm32f4xx_it.c, .../rmcs_slave.ioc
移除/替换生成的 main/AppEntry(main.c 的 main 实现被删除);IOC 设置 ProjectManager.NoMain=true;在中断文件中添加 tusb_int_handler 原型并替换 tusb.h 包含。
移除的旧源/文件
firmware/c_board/src/app.cpp, firmware/c_board/cubemx/cmake/gcc-arm-none-eabi.cmake
删除旧的 App 实现与旧 cubemx 下的工具链 CMake 文件。
.gitignore 更新
firmware/c_board/bsp/cubemx/.gitignore
新增忽略条目:STM32F407XX_FLASH.ldcmake/gcc-arm-none-eabi.cmake

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 分钟

Possibly related PRs

  • #26 — 与 patch_cubemx 的尾部注入、STALE 文件与 CMSIS 路径替换改动高度重叠。
  • #20 — TinyUSB 集成、usb_descriptors/vendor 与 tud_task/中断处理的迁移与重构直接相关。
  • #19 — c_board 源迁移(src → app)、CMakeLists 与 interrupt_lock/启动语义变更在代码层面有直接重合。

诗歌

🐰 我把代码搬进了 app 的洞,
CMake 按排把依赖整成丛,
TinyUSB 在夜里轻声哼,
中断从一归零心不慌,
构建输出整齐跑向阳。

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: refactoring the firmware layout by splitting app and bsp directories and aligning packaging.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch dev/bootloader

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (4)
firmware/c_board/cmake/gcc-arm-none-eabi.cmake (1)

5-6: 移除手动设置的 CMAKE_C_COMPILER_IDCMAKE_CXX_COMPILER_ID

这两个变量是 CMake 的输出变量,应由 CMake 在项目配置时(通过 project()enable_language())自动检测,而非手动赋值。由于你已在第 10、12 行正确设置了实际的编译器可执行文件路径(arm-none-eabi-gccarm-none-eabi-g++),CMake 将自动识别编译器 ID 为 GNU,无需显式手动设置。手动赋值是非规范做法,违反了现代 CMake 工具链最佳实践。

♻️ 建议修改
-set(CMAKE_C_COMPILER_ID GNU)
-set(CMAKE_CXX_COMPILER_ID GNU)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@firmware/c_board/cmake/gcc-arm-none-eabi.cmake` around lines 5 - 6, Remove
the manual assignments to CMAKE_C_COMPILER_ID and CMAKE_CXX_COMPILER_ID: delete
the set(CMAKE_C_COMPILER_ID GNU) and set(CMAKE_CXX_COMPILER_ID GNU) lines so
CMake can auto-detect the compiler ID; rely on the existing settings of
CMAKE_C_COMPILER and CMAKE_CXX_COMPILER (the arm-none-eabi-gcc/arm-none-eabi-g++
assignments) and ensure project() or enable_language() is used to trigger
detection rather than forcing the *_COMPILER_ID variables.
firmware/c_board/bsp/cubemx/Core/Src/stm32f4xx_it.c (1)

28-28: 考虑通过包含官方头文件而非手写前置声明来保证 TinyUSB 接口的一致性。

第 28 行的手写前置声明 tusb_int_handler 虽然在此处有效,但长期维护中可能面临与上游签名漂移的风险。建议改为直接包含 TinyUSB 头文件(如 #include <tusb.h>),或在统一的适配头中集中管理此声明,以便编译器能自动验证 API 签名。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@firmware/c_board/bsp/cubemx/Core/Src/stm32f4xx_it.c` at line 28, Replace the
handwritten forward declaration of tusb_int_handler with the official TinyUSB
header or a centralized adapter header so the compiler verifies the API
signature: remove the line declaring void tusb_int_handler(uint8_t rhport, bool
in_isr); and instead include the TinyUSB public header (e.g., `#include` <tusb.h>)
or a project adapter header that exposes tusb_int_handler, ensuring the symbol
and signature come from the upstream header rather than a local manual
declaration.
.scripts/patch_cubemx (1)

42-48: 注释与实际代码不符:OBJECT 库不是静态库。

add_library(stm32cubemx OBJECT) 创建的是对象库而非静态库。建议将注释改为更准确的描述。

📝 建议修复注释
-STM32CUBEMX_TAIL = """# Create stm32cubemx static library
+STM32CUBEMX_TAIL = """# Create stm32cubemx object library
 add_library(stm32cubemx OBJECT)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.scripts/patch_cubemx around lines 42 - 48, 注释与实际代码不符:在 STM32CUBEMX_TAIL
字符串中当前说明“Create stm32cubemx static library”误导为静态库,而 add_library(stm32cubemx
OBJECT) 实际创建的是对象库;请更新该注释文本以准确描述为“Create stm32cubemx object library”或类似表述,确保唯一标识符
STM32CUBEMX_TAIL 和 add_library(stm32cubemx OBJECT) 保持不变。
firmware/c_board/app/CMakeLists.txt (1)

32-39: 关于 GLOB_RECURSE 的使用说明。

GLOB_RECURSE 配合 CONFIGURE_DEPENDS 在实践中是可接受的,但需注意:

  1. CMake 官方文档建议显式列出源文件以确保可靠的增量构建
  2. CONFIGURE_DEPENDS 在某些生成器上可能有性能开销

对于当前固件项目规模,这种方式是合理的权衡。如果将来构建时间成为问题,可以考虑显式列出源文件。

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@firmware/c_board/app/CMakeLists.txt` around lines 32 - 39, The CMakeLists
uses GLOB_RECURSE with CONFIGURE_DEPENDS to populate C_BOARD_APP_SOURCES which
can hurt incremental build reliability and performance; either replace the
GLOB_RECURSE usage by explicitly listing source files (move individual
.c/.cpp/.S paths into C_BOARD_APP_SOURCES) so builds are stable, or if you keep
globbing, add a clear comment near the GLOB_RECURSE block documenting the
tradeoff and remove CONFIGURE_DEPENDS to avoid generator-specific overhead until
you need auto-refresh; refer to the CMake variable C_BOARD_APP_SOURCES and the
existing GLOB_RECURSE invocation to locate and apply the change.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@firmware/c_board/CMakeLists.txt`:
- Around line 69-75: The CMake generator expression in target_compile_options
for ${target} uses a single expression with multiple space-separated flags
($<$<COMPILE_LANGUAGE:CXX>:-Wall -Wextra -Wpedantic>), which will be split
before evaluation and break the expression; replace that single multi-flag
generator expression with one generator expression per flag (e.g.
$<$<COMPILE_LANGUAGE:CXX>:-Wall>, $<$<COMPILE_LANGUAGE:CXX>:-Wextra>,
$<$<COMPILE_LANGUAGE:CXX>:-Wpedantic>) so each compiler option is preserved,
keeping the other entries (like $<$<COMPILE_LANGUAGE:CXX>:-fno-unwind-tables>)
unchanged.

---

Nitpick comments:
In @.scripts/patch_cubemx:
- Around line 42-48: 注释与实际代码不符:在 STM32CUBEMX_TAIL 字符串中当前说明“Create stm32cubemx
static library”误导为静态库,而 add_library(stm32cubemx OBJECT)
实际创建的是对象库;请更新该注释文本以准确描述为“Create stm32cubemx object library”或类似表述,确保唯一标识符
STM32CUBEMX_TAIL 和 add_library(stm32cubemx OBJECT) 保持不变。

In `@firmware/c_board/app/CMakeLists.txt`:
- Around line 32-39: The CMakeLists uses GLOB_RECURSE with CONFIGURE_DEPENDS to
populate C_BOARD_APP_SOURCES which can hurt incremental build reliability and
performance; either replace the GLOB_RECURSE usage by explicitly listing source
files (move individual .c/.cpp/.S paths into C_BOARD_APP_SOURCES) so builds are
stable, or if you keep globbing, add a clear comment near the GLOB_RECURSE block
documenting the tradeoff and remove CONFIGURE_DEPENDS to avoid
generator-specific overhead until you need auto-refresh; refer to the CMake
variable C_BOARD_APP_SOURCES and the existing GLOB_RECURSE invocation to locate
and apply the change.

In `@firmware/c_board/bsp/cubemx/Core/Src/stm32f4xx_it.c`:
- Line 28: Replace the handwritten forward declaration of tusb_int_handler with
the official TinyUSB header or a centralized adapter header so the compiler
verifies the API signature: remove the line declaring void
tusb_int_handler(uint8_t rhport, bool in_isr); and instead include the TinyUSB
public header (e.g., `#include` <tusb.h>) or a project adapter header that exposes
tusb_int_handler, ensuring the symbol and signature come from the upstream
header rather than a local manual declaration.

In `@firmware/c_board/cmake/gcc-arm-none-eabi.cmake`:
- Around line 5-6: Remove the manual assignments to CMAKE_C_COMPILER_ID and
CMAKE_CXX_COMPILER_ID: delete the set(CMAKE_C_COMPILER_ID GNU) and
set(CMAKE_CXX_COMPILER_ID GNU) lines so CMake can auto-detect the compiler ID;
rely on the existing settings of CMAKE_C_COMPILER and CMAKE_CXX_COMPILER (the
arm-none-eabi-gcc/arm-none-eabi-g++ assignments) and ensure project() or
enable_language() is used to trigger detection rather than forcing the
*_COMPILER_ID variables.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 34a76fe and ef243e2.

📒 Files selected for processing (64)
  • .scripts/lint-targets.yml
  • .scripts/patch_cubemx
  • Dockerfile.build_firmware
  • firmware/c_board/CMakeLists.txt
  • firmware/c_board/CMakePresets.json
  • firmware/c_board/app/CMakeLists.txt
  • firmware/c_board/app/include/tusb_config.h
  • firmware/c_board/app/src/app.cpp
  • firmware/c_board/app/src/app.hpp
  • firmware/c_board/app/src/can/can.cpp
  • firmware/c_board/app/src/can/can.hpp
  • firmware/c_board/app/src/gpio/gpio.cpp
  • firmware/c_board/app/src/led/led.hpp
  • firmware/c_board/app/src/logger/logger.hpp
  • firmware/c_board/app/src/spi/bmi088/accel.hpp
  • firmware/c_board/app/src/spi/bmi088/base.hpp
  • firmware/c_board/app/src/spi/bmi088/gyro.hpp
  • firmware/c_board/app/src/spi/spi.cpp
  • firmware/c_board/app/src/spi/spi.hpp
  • firmware/c_board/app/src/timer/delay.cpp
  • firmware/c_board/app/src/timer/delay.hpp
  • firmware/c_board/app/src/uart/uart.cpp
  • firmware/c_board/app/src/uart/uart.hpp
  • firmware/c_board/app/src/usb/helper.hpp
  • firmware/c_board/app/src/usb/interrupt_safe_buffer.hpp
  • firmware/c_board/app/src/usb/usb_descriptors.cpp
  • firmware/c_board/app/src/usb/usb_descriptors.hpp
  • firmware/c_board/app/src/usb/vendor.cpp
  • firmware/c_board/app/src/usb/vendor.hpp
  • firmware/c_board/app/src/utility/assert.cpp
  • firmware/c_board/app/src/utility/interrupt_lock.hpp
  • firmware/c_board/app/src/utility/lazy.hpp
  • firmware/c_board/app/src/utility/ring_buffer.hpp
  • firmware/c_board/bsp/cubemx/.gitignore
  • firmware/c_board/bsp/cubemx/Core/Inc/can.h
  • firmware/c_board/bsp/cubemx/Core/Inc/dma.h
  • firmware/c_board/bsp/cubemx/Core/Inc/gpio.h
  • firmware/c_board/bsp/cubemx/Core/Inc/main.h
  • firmware/c_board/bsp/cubemx/Core/Inc/spi.h
  • firmware/c_board/bsp/cubemx/Core/Inc/stm32f4xx_hal_conf.h
  • firmware/c_board/bsp/cubemx/Core/Inc/stm32f4xx_it.h
  • firmware/c_board/bsp/cubemx/Core/Inc/tim.h
  • firmware/c_board/bsp/cubemx/Core/Inc/usart.h
  • firmware/c_board/bsp/cubemx/Core/Inc/usb_otg.h
  • firmware/c_board/bsp/cubemx/Core/Src/can.c
  • firmware/c_board/bsp/cubemx/Core/Src/dma.c
  • firmware/c_board/bsp/cubemx/Core/Src/gpio.c
  • firmware/c_board/bsp/cubemx/Core/Src/main.c
  • firmware/c_board/bsp/cubemx/Core/Src/spi.c
  • firmware/c_board/bsp/cubemx/Core/Src/stm32f4xx_hal_msp.c
  • firmware/c_board/bsp/cubemx/Core/Src/stm32f4xx_it.c
  • firmware/c_board/bsp/cubemx/Core/Src/syscalls.c
  • firmware/c_board/bsp/cubemx/Core/Src/sysmem.c
  • firmware/c_board/bsp/cubemx/Core/Src/system_stm32f4xx.c
  • firmware/c_board/bsp/cubemx/Core/Src/tim.c
  • firmware/c_board/bsp/cubemx/Core/Src/usart.c
  • firmware/c_board/bsp/cubemx/Core/Src/usb_otg.c
  • firmware/c_board/bsp/cubemx/STM32F407XX_APP.ld
  • firmware/c_board/bsp/cubemx/cmake/stm32cubemx/CMakeLists.txt
  • firmware/c_board/bsp/cubemx/rmcs_slave.ioc
  • firmware/c_board/bsp/cubemx/startup_stm32f407xx.s
  • firmware/c_board/cmake/gcc-arm-none-eabi.cmake
  • firmware/c_board/cubemx/cmake/gcc-arm-none-eabi.cmake
  • firmware/c_board/src/app.cpp
💤 Files with no reviewable changes (4)
  • firmware/c_board/cubemx/cmake/gcc-arm-none-eabi.cmake
  • firmware/c_board/bsp/cubemx/Core/Src/main.c
  • firmware/c_board/src/app.cpp
  • firmware/c_board/bsp/cubemx/startup_stm32f407xx.s

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
.scripts/patch_cubemx (1)

38-41: 建议添加注释说明 "Midllewares" 拼写是故意保留的。

正则表达式中的 Midllewares(少了一个 d)是 CubeMX 生成文件中的原始拼写错误。建议添加注释说明这是刻意匹配,避免未来维护者误以为是脚本中的笔误而"修正"它。

💡 建议添加注释
+# Note: "Midllewares" typo is intentional - matches CubeMX's actual output
 DRIVERS_MIDDLEWARES_TO_EOF_PATTERN = re.compile(
     r"^# Drivers Midllewares[\s\S]*\Z",
     re.MULTILINE,
 )
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.scripts/patch_cubemx around lines 38 - 41, The regex constant
DRIVERS_MIDDLEWARES_TO_EOF_PATTERN intentionally contains the misspelling
"Midllewares" to match the exact header produced by CubeMX; add a concise inline
comment above this declaration explaining that the spelling is preserved
intentionally to match CubeMX-generated files (do not correct it), mention
CubeMX as the source of the misspelling, and note that future maintainers should
not "fix" the string because it is deliberately matching external 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:
- Around line 87-91: The script fails on re-run because the replacement block
assumes the anchor exists; modify the logic around
DRIVERS_MIDDLEWARES_TO_EOF_PATTERN.subn and the subsequent check so the code is
idempotent: after computing patched and replacements, if replacements == 0 then
check for presence of STM32CUBEMX_TAIL (or STM32CUBEMX_TAIL_ANCHOR) inside
patched and treat that as "already patched" (no-op) instead of raising
ValueError; otherwise, if neither the anchor nor the tail are present, raise the
error as before. Use the existing symbols (DRIVERS_MIDDLEWARES_TO_EOF_PATTERN,
STM32CUBEMX_TAIL, STM32CUBEMX_TAIL_ANCHOR, patched, replacements) to implement
this detection.

---

Nitpick comments:
In @.scripts/patch_cubemx:
- Around line 38-41: The regex constant DRIVERS_MIDDLEWARES_TO_EOF_PATTERN
intentionally contains the misspelling "Midllewares" to match the exact header
produced by CubeMX; add a concise inline comment above this declaration
explaining that the spelling is preserved intentionally to match
CubeMX-generated files (do not correct it), mention CubeMX as the source of the
misspelling, and note that future maintainers should not "fix" the string
because it is deliberately matching external output.

ℹ️ Review info

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ef243e2 and 02faa56.

📒 Files selected for processing (1)
  • .scripts/patch_cubemx

@qzhhhi qzhhhi merged commit 23d1fb6 into main Mar 2, 2026
5 checks passed
@github-project-automation github-project-automation bot moved this from Todo to Done in RMCS Slave SDK Mar 2, 2026
@qzhhhi qzhhhi deleted the dev/bootloader branch March 2, 2026 18:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

1 participant