feat[STM32][I2C]: add timing control support for hard i2c#11322
Conversation
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
📌 Code Review Assignment🏷️ Tag: bsp_stm32Reviewers: Liang1795 hamburger-os wdfk-prog Changed Files (Click to expand)
📊 Current Review Status (Last Updated: 2026-04-13 11:45 CST)
📝 Review Instructions
|
9ecb60a to
3c0749d
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the STM32 hardware I2C driver to clarify and standardize the meaning of the timing configuration field based on the underlying I2C IP generation (legacy vs TIMINGR-based), and adds a runtime timing-control entry for legacy IPs. It also aligns BSP config defaults accordingly and fixes a DMA RX initialization assignment issue.
Changes:
- Split
timingsemantics by I2C IP generation (legacy: Hz; TIMINGR-based: raw TIMINGR value) and apply defaults whentiming == 0. - Add legacy-only bus control command to update timing at runtime, and initialize legacy bus
max_hz/usage_freqfromtiming. - Update F1/F4 timing configs to
100000(Hz) and add a new F7 hard-I2C config using TIMINGR values; fix DMA RX FIFO/Burst init assignments.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| bsp/stm32/libraries/HAL_Drivers/drivers/drv_hard_i2c.h | Introduces IP-generation macros and documents/defines timing semantics and control command. |
| bsp/stm32/libraries/HAL_Drivers/drivers/drv_hard_i2c.c | Applies default timing, adjusts init paths per IP generation, updates timeout/error handling behavior, adds legacy timing control, and fixes DMA RX init fields. |
| bsp/stm32/libraries/HAL_Drivers/drivers/config/f7/i2c_hard_config.h | Adds F7 hard-I2C configuration using TIMINGR timing values. |
| bsp/stm32/libraries/HAL_Drivers/drivers/config/f4/i2c_hard_config.h | Updates legacy timing values to be bus frequency in Hz. |
| bsp/stm32/libraries/HAL_Drivers/drivers/config/f1/i2c_hard_config.h | Adds legacy timing values (Hz) for F1 configs. |
bsp/stm32/libraries/HAL_Drivers/drivers/config/f7/i2c_hard_config.h
Outdated
Show resolved
Hide resolved
bsp/stm32/libraries/HAL_Drivers/drivers/config/f7/i2c_hard_config.h
Outdated
Show resolved
Hide resolved
3c0749d to
061cbbf
Compare
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
当前 STM32 硬件 I2C 驱动对不同代际 I2C IP 的 timing 语义处理不一致:
ClockSpeed/DutyCycle进行配置,但部分配置项中使用了原始寄存器风格的 timing 值;TIMINGR值;因此,这个 PR 主要用于统一 STM32 硬件 I2C 的 timing 语义处理方式,按 I2C IP 代际区分配置逻辑,并补充 legacy IP 的 timing control 支持。
你的解决方案是什么 (what is your solution)
本次改动主要包括:
在
drv_hard_i2c.h中增加STM32_I2C_LEGACY_IP和STM32_I2C_TIMINGR_IP分类宏,明确timing字段语义:timing表示总线频率(Hz)timing表示原始TIMINGR寄存器值在
drv_hard_i2c.c中新增默认 timing 处理逻辑:100000TIMINGR常量timing == 0时行为不确定调整 I2C 初始化逻辑:
cfg->timing配置ClockSpeedcfg->timing配置Init.Timing为 legacy IP 增加
BSP_I2C_CTRL_SET_TIMING控制命令:usage_freq/max_hz更新系列配置头文件:
timing配置改为100000i2c_hard_config.h,继续使用 TIMINGR 配置方式调整超时和错误处理逻辑:
usage_freq估算传输超时顺带修正 DMA RX 初始化中 FIFO/Burst 参数误写到 TX handle 的问题
请提供验证的bsp和config (provide the config and bsp)
BSP:
bsp/stm32/...].config:
BSP_USING_HARD_I2C1、BSP_I2C1_RX_USING_DMA等]action:
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up