Skip to content

feat[bsp][stm32]: add Input Capture support for STM32F1 and STM32H7 - #11975

Open
wdfk-prog wants to merge 1 commit into
RT-Thread:masterfrom
wdfk-prog:stm32/input_capture
Open

wdfk-prog wants to merge 1 commit into
RT-Thread:masterfrom
wdfk-prog:stm32/input_capture

Conversation

@wdfk-prog

Copy link
Copy Markdown
Contributor

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

为 STM32 HAL BSP 增加 RT-Thread Input Capture 设备驱动支持,使应用能够通过统一的 Input Capture 设备接口获取定时器捕获的脉冲宽度。

本次优先适配 STM32F1 和 STM32H7 系列,支持通过 Kconfig 选择定时器、捕获通道及相关参数,减少不同 BSP 重复实现 Input Capture 驱动的工作。

你的解决方案是什么 (what is your solution)

  1. 新增 drv_inputcapture.c 和 drv_inputcapture.h,基于 STM32 HAL TIM Input Capture 实现 RT-Thread 设备操作及捕获中断回调。
  2. 为 STM32F1 和 STM32H7 增加 Input Capture 配置头文件,支持按需启用 TIM1~TIM4,并配置设备名称、捕获通道、数字滤波及初始捕获边沿。
  3. 更新 Kconfig、SConscript 和 drv_config.h,接入驱动编译与系列配置。
  4. 根据 APB 时钟分频和 HAL/CMSIS 能力宏计算定时器时钟,兼容可用的 TIMPRE 配置,并在硬件支持时使用 32 位计数器范围。
  5. 支持软件切换捕获极性,通过捕获计数差计算脉冲宽度;为支持相应 HAL 极性定义的硬件保留双边沿捕获适配能力。
  6. 重新打开捕获设备时,在启动通道中断前清除对应通道的捕获标志和过捕获标志,避免上次运行遗留的中断事件影响新的捕获过程。

使用约束:

  • GPIO、定时器时钟和 NVIC 初始化依赖目标 BSP 的 HAL MSP 配置。
  • 同一物理 TIM 及其 IRQ 需由一个驱动独占,避免与 PWM、HWTIMER 等驱动冲突。
  • 使用 HAL 回调注册机制的工程,需要完成相应回调注册。
  • 用户需至少启用一个 TIM;捕获间隔超过计数器回绕周期的情况不提供多次溢出恢复。

当前验证情况:

已完成三轮本地全范围静态代码审查,未发现尚未解决的必修问题。尚未执行 STM32F1/H7 BSP 编译、目标板实测或 CI 构建,因此不将静态审查结果视为硬件验证通过。

请提供验证的bsp和config (provide the config and bsp)

  • BSP: 尚未进行具体 BSP 的编译和板级验证;目标适配系列为 STM32F1、STM32H7。
  • .config: 尚无已验证的目标板 .config。建议启用 RT_USING_INPUT_CAPTURE、BSP_USING_INPUT_CAPTURE,并至少选择一个 BSP_USING_INPUT_CAPTURE_TIM1~BSP_USING_INPUT_CAPTURE_TIM4;可按需设置 BSP_INPUT_CAPTURE_COUNTER_HZ。
  • action: 尚未执行 GitHub Actions,无构建成功链接。

]

当前拉取/合并请求的状态 Intent for your PR

必须选择一项 Choose one (Mandatory):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

- Implement RT-Thread Input Capture devices using STM32 HAL TIM1-TIM4, with configurable channels, filters and initial capture polarity.

- Add STM32F1 and STM32H7 configuration headers and integrate the driver into Kconfig and SConscript.

- Handle APB timer clock multipliers, TIMPRE and 32-bit counter capabilities using HAL feature macros.

- Clear pending capture and overcapture flags before restarting a capture channel.
@wdfk-prog

Copy link
Copy Markdown
Contributor Author

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • Use workflow from 保持默认分支(通常为 master)
    Keep the default branch (usually master) in Use workflow from
  • 在 branch 输入框填写 PR 分支 stm32/input_capture
    Enter PR branch stm32/input_capture in the branch field
  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将作为独立提交推送至你的分支。
    The formatting changes will be pushed to your branch as a separate commit.

完成后,提交将自动更新至 stm32/input_capture 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the stm32/input_capture branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions Bot added BSP: STM32 BSP related with ST/STM32 BSP labels Nov 2, 2026
@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

📌 Code Review Assignment

🏷️ Tag: bsp_stm32

Reviewers: @Liang1795 @hamburger-os @wdfk-prog

Changed Files (Click to expand)
  • bsp/stm32/libraries/HAL_Drivers/drivers/Kconfig
  • bsp/stm32/libraries/HAL_Drivers/drivers/SConscript
  • bsp/stm32/libraries/HAL_Drivers/drivers/config/f1/inputcapture_config.h
  • bsp/stm32/libraries/HAL_Drivers/drivers/config/h7/inputcapture_config.h
  • bsp/stm32/libraries/HAL_Drivers/drivers/drv_config.h
  • bsp/stm32/libraries/HAL_Drivers/drivers/drv_inputcapture.c
  • bsp/stm32/libraries/HAL_Drivers/drivers/drv_inputcapture.h

📊 Current Review Status (Last Updated: 2026-11-02 17:40 CST)


📝 Review Instructions

  1. 维护者可以通过单击此处来刷新审查状态: 🔄 刷新状态
    Maintainers can refresh the review status by clicking here: 🔄 Refresh Status

  2. 确认审核通过后评论 LGTM/lgtm
    Comment LGTM/lgtm after confirming approval

  3. PR合并前需至少一位维护者确认
    PR must be confirmed by at least one maintainer before merging

ℹ️ 刷新CI状态操作需要具备仓库写入权限。
ℹ️ Refresh CI status operation requires repository Write permission.

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown

MemBrowse Memory Report · Explore what changed →

No memory changes detected for:


Catch memory regressions in CI with MemBrowse. Free for open source.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BSP: STM32 BSP related with ST/STM32 BSP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant