TC275 操作I2C读操作时陷入while循环无法退出 TC275 I2C read operation is stuck in a while loop and cannot exit

公告

大中华汽车电子生态圈社区并入开发者社区- 更多资讯点击此

Tip / 登入 to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
DLinH
Level 1
Level 1
First like given First like received 10 sign-ins

TC275作为主芯片,通过I2C读取EEPROM芯片数据,在调用iLLD库的IfxI2c_I2c_read函数时,偶发程序卡在以下while循环中无法退出。

DLinH_0-1673508187046.png

发现是PIRQSS寄存器的RX位一直保持为1,无法退出循环。然后修改了此段代码,增加了超时退出while循环的操作,修改后发现退出while循环后,进入了下面的ERRIRQSS分支,RXF_OFL位被置为1。并且在下一次操作I2C,把数据写入TXD寄存器时,触发了SPB总线故障。

触发SPB总线故障的原因应该是手册里写的,FIFO还处于接收状态时写入TXD寄存器。

DLinH_1-1673508548560.jpeg

最终排查发现,由于在操作I2C时已经使能了CPU中断,当I2C以下红框内的操作被中断函数打断超过一个字节数据时间时,就会引起while循环无法退出、触发RXF_OFL置位、FIFO处于接收状态无法退出等问题。

DLinH_2-1673508721903.jpeg

很显然这应该是iLLD的代码问题。目前我能做的临时解决方案就是在进行这段操作前临时关闭中断,完成操作后再恢复中断,以保证底层操作的时序正确。

DLinH_3-1673509142653.png

 

希望能对以上方案进行评估,或者提出一个理想的解决方案,能够在以上I2C操作被打断一段时间后,避免发生一系列的异常问题。谢谢!

 

1 解答
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

From above description, when you call  IfxI2c_I2c_read(), if there is any interrupt to occupy too much time, the function will be stuck. So you add disable interrupt and enable interrupt again in the function. I think it's fine but you should test if the function will be stuck if read nothing from I2C. The ILLD is an evaluation free software which can be modified or enhanced by the user.

在原帖中查看解决方案

0 点赞
5 回复数
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

DlinH,

Thank you for your kind advice, this will be reported internally.

dw

0 点赞
DLinH
Level 1
Level 1
First like given First like received 10 sign-ins

thanks for your reply! I want to know that whether my solution is feasible? Or there is a better solution to the problem?

0 点赞
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

From above description, when you call  IfxI2c_I2c_read(), if there is any interrupt to occupy too much time, the function will be stuck. So you add disable interrupt and enable interrupt again in the function. I think it's fine but you should test if the function will be stuck if read nothing from I2C. The ILLD is an evaluation free software which can be modified or enhanced by the user.

0 点赞
DLinH
Level 1
Level 1
First like given First like received 10 sign-ins

thanks for your reply! And from the perspective of underlying logic, I want to know why in this code, if there is any interrupt to occupy too much time, the following while loop cannot be skipped, ERRIRQSS.RXF_OFL will  be set, and the I2C FIFO state can not go out of RX state?

DLinH_0-1675219283876.png

 

0 点赞
Di_W
Moderator
Moderator
Moderator
1000 replies posted 250 solutions authored 100 likes received

From above code, if any AL_OFF/ NACK_OFF/ RX_OFF/ERRIRQSS is set, the while loop will stuck. For the reason, you can debug your code, try to make an interrupt in below the loop, and check which bit is set.

0 点赞