Repository navigation
i2c: share bus recovery across software and hardware backends - #12120
Draft
silencebadwolf wants to merge 2 commits into
Draft
silencebadwolf wants to merge 2 commits into
silencebadwolf wants to merge 2 commits into
Conversation
|
|
Contributor
|
支持软、硬 I²C 共用 Bus Clear 算法,但建议这版先只做公共 helper + 显式恢复,把传输失败后的自动恢复拆到后续 PR。
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
拉取/合并请求描述:(PR description)
[
为什么提交这份 PR / Why
A controller can time out while the target is still holding SDA low. Returning the error lets the caller continue, but the next transfer can fail until the wires are released. The bus-clear sequence is common to GPIO bit-banging and hardware controllers that can temporarily hand their pins over to GPIO.
We saw this on a GD32H759IMT6 board running a downstream RT-Thread v5.3.0 firmware with two independent single-controller I2C buses and 4.7 kΩ board-side pull-ups.
0x60. A write reported NACK and BUSY (0x8010). SCL was high and SDA stayed low after shutdown. One recovery clock and STOP released the bus in the natural incident. A later transaction succeeded without resetting or cycling power. A separate interrupted-read experiment needed three clocks.0x5d. The driver recorded LOSTARB and BUSY (0x8201). SCL was high and SDA stayed low with the controller stopped. The driver latched the fault, so later touches failed until reboot. The downstream touch recovery change is build-verified only.These are observations from downstream DMA/IRQ-based drivers. The first electrical trigger remains unknown. The upstream GD32 example in this PR uses its polling backend.
解决方案 / Approach
rt_i2c_bus_clear()helper using the existingrt_i2c_bit_opsline callbacks. With exclusive physical ownership and open-drain pins, sample SCL, try at most nine clocks when SDA is held low, and attempt STOP on each high phase. Finish when the lines release. Report failure if the bus stays low.RT_I2C_DEV_CTRL_UNLOCKviart_i2c_control(bus, RT_I2C_DEV_CTRL_UNLOCK, RT_NULL). The bus mutex serializes the command with transfers. Software I2C also uses the helper for its startup check before publishing the bus.CONFIG_RT_I2C_BITOPS_BUS_RECOVERY=y. This option is off by default and is for single-controller buses. After a failed transfer that releases the bus, it attempts recovery only when SCL is high and SDA is still low. The failed transfer keeps its error result. The explicit unlock command remains available for maintenance.Bus clear follows NXP UM10204 section 3.1.16.
验证 / Validation
bsp/gd32/arm/gd32h759i-eval, ARM GCC 13.2.1, SCons.CONFIG_BSP_USING_I2C=y,CONFIG_BSP_USING_HARD_I2C=y,CONFIG_BSP_USING_HARD_I2C0=y,CONFIG_BSP_GD32H7_I2C_BUS_RECOVERY=y,CONFIG_RT_USING_SOFT_I2C=y,CONFIG_RT_USING_SOFT_I2C0=y, andCONFIG_RT_I2C_BITOPS_BUS_RECOVERY=y. Both backends linked the same helper.RT_I2C_BITOPS_BUS_RECOVERYdisabled and software I2C still enabled. ARM object inspection confirmed that the transfer path calls the common helper only in the opt-in build.RT_USING_SOFT_I2CandRT_USING_I2C_BITOPSdisabled. The hardware driver still linked the common helper.]
当前拉取/合并请求的状态 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