[stm32] i2c hard driver fixup:增加硬件I2C传输超时等待时间

问题:
在使用硬件 I2C 驱动进行音频模块 WM8978 配置时,发现连续 rt_i2c_transfer 进行 I2C 传输时发现,连续多次调用 rt_i2c_transfer 会出现丢包现象;溯源发现是每次使用 rt_i2c_transfer 传输2字节,传输频率过高导致底层 HAL_I2C_Master_Seq_Transmit_DMA 报错 HAL_BUSY;

现象:
rt_completion_wait超时等待完成之后,I2C仍处于HAL_I2C_STATE_BUSY_TX状态,且后续第二次运行至HAL_I2C_Master_Seq_Transmit_DMA时会直接返回HAL_BUSY,从而直接 goto out; 退出而不会再次进行超时等待;

* drv_hard_i2c.c: 修复325行缺失'}'语法错误;更改HAL_I2C_xx_Transimt_xx调用中目标设备地址值;i2c_hard_config.h: 添加STM32F系列芯片xx_DMA_CONFIG宏定义;

* 回溯I2C设备地址传参处(msg->addr<<1)修改;

* fixup: 增加硬件I2C传输延时,解决连续传输导致HAL_BUSY状态;
This commit is contained in:
SCZeiDan 2024-05-05 00:51:27 +08:00 committed by GitHub
parent 39e6b36bb0
commit d78429eb8e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 2 additions and 2 deletions

View File

@ -177,7 +177,7 @@ static rt_ssize_t stm32_i2c_master_xfer(struct rt_i2c_bus_device *bus,
LOG_D("xfer msgs[%d] addr=0x%2x buf=0x%x len= 0x%x flags= 0x%x", i, msg->addr, msg->buf, msg->len, msg->flags);
next_msg = &msgs[i + 1];
next_flag = next_msg->flags;
timeout = msg->len/TRANS_TIMEOUT_PERSEC + 1;
timeout = msg->len/TRANS_TIMEOUT_PERSEC + 5;
if (next_flag & RT_I2C_NO_START)
{
if ((next_flag & RT_I2C_RD) == (msg->flags & RT_I2C_RD))
@ -250,7 +250,7 @@ static rt_ssize_t stm32_i2c_master_xfer(struct rt_i2c_bus_device *bus,
}
/* last msg */
msg = &msgs[i];
timeout = msg->len/TRANS_TIMEOUT_PERSEC+1;
timeout = msg->len/TRANS_TIMEOUT_PERSEC + 5;
if (msg->flags & RT_I2C_NO_STOP)
mode = I2C_LAST_FRAME_NO_STOP;
else