Skip to content
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

Prevent starting a new I2C transmission before previous stop finishes. #737

Merged
merged 2 commits into from
Feb 4, 2024

Conversation

zyma98
Copy link
Contributor

@zyma98 zyma98 commented Feb 2, 2024

When a stop condition is generated by the I2C DMA (example), the code does not wait for the finish of the stop condition. However, the comments falsely indicate that there will be a spin-wait.

The I2C interface can get stuck if a new I2C transmission attempts to start while the previous stop condition is being generated. The new transaction will be inadvertently terminated by the previous stop condition. Subsequently, the I2C interface gets stuck. The following figure shows that a previous stop condition being generated can immediately terminate a new start condition, and after that the I2C interface is stuck.

image

Since ISRs should finish as quickly as possible, the fix should not let ISRs spin-wait in the interrupt handler until the stop condition finishes. Instead, the spin-wait should be placed before starting a new transmission.

The patch also removes incorrect comments that falsely indicate that the code will spin-wait until the stop condition finishes.

When a stop condition is generated by the I2C DMA callback, the code
does not wait for the finish of the stop condition. If while the stop
condition is being generated and a new I2C transaction attempts to
start, the new transaction will be inadvertently terminated by the
previous stop condition.

Since ISRs should finish as quickly as possible, the ISRs should not
spin-wait until the stop condition finishes. Instead, the spin-wait
should be placed before starting a new transaction.

The patch also removes incorrect comments that falsely indicate that
the code will spin-wait until the stop condition finishes.
@zyma98 zyma98 changed the title Prevent starting a new I2C transaction before previous stop finishes. Prevent starting a new I2C transmission before previous stop finishes. Feb 2, 2024
@burrbull
Copy link
Contributor

burrbull commented Feb 3, 2024

Looks reasonable for me.

cc @therealprof What do you think?

Copy link
Member

@therealprof therealprof left a comment

Choose a reason for hiding this comment

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

LGTM, too.

@burrbull burrbull added this pull request to the merge queue Feb 4, 2024
Merged via the queue into stm32-rs:master with commit 403fddb Feb 4, 2024
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants