Skip to content

I2C Fix #748

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Nov 5, 2019
Merged

I2C Fix #748

merged 4 commits into from
Nov 5, 2019

Conversation

fpistm
Copy link
Member

@fpistm fpistm commented Oct 31, 2019

jmchiappa and others added 4 commits October 30, 2019 16:00
When NACK is received by master, instead of immediate re-transmission
by twi driver, error is reported. Up to application to manage
re-transmission.

This fix regression found on STM32F2 and STM32F4 when using I2C_OTHER_FRAME.
See PR stm32duino#663
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
@fpistm fpistm added this to the 1.8.0 milestone Oct 31, 2019
@ABOSTM ABOSTM self-requested a review November 5, 2019 13:21
Copy link
Contributor

@ABOSTM ABOSTM left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me.

@fpistm fpistm merged commit eb85955 into stm32duino:master Nov 5, 2019
@fpistm fpistm deleted the I2C_fix branch November 5, 2019 14:33
Copy link
Contributor

@matthijskooijman matthijskooijman left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We found a small error handling problem introduced by this PR, see inline comment.

&& (delta < I2C_TIMEOUT_TICK));

err = HAL_I2C_GetError(&(obj->handle));
if ((delta > I2C_TIMEOUT_TICK)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This introduces a new problem: When this timeout is triggered, I2C_OK is triggered. This happens because in the loop above, it checks for (delta < I2C_TIMEOUT_TICK), so it breaks out of the loop as soon as delta == I2C_TIMEOUT_TICK. Then, this if checks for (delta > I2C_TIMEOUT_TICK), which is not yet false. Since the hardware reports no errors either, I2C_OK is returned.

We noticed this when something confused the I2C hardware and prevented it from continuing somehow. We haven't figured out what the underlying cause is, but we did notice that we did not get an I2C error (just invalid data), which I think can be traced back to this problem.

The same applies to i2c_write_master above, I think.

Fixing this is, I think, a matter of replacing > with >= here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more thing: This > and < combination was already present in the old code, but due to the old structure there it would, I think, only be problematic when an ACK failure occured exactly a the timeout, which is of course extremely likely. These refactorings have caused this to happen on every timeout instead.

Fixing this is, I think, a matter of replacing > with >= here.

We just tried this, and it seems to work. @HendryKaak is considering to prepare a PR for this.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

STM32 I2C driver "repeated start" issue
4 participants