Skip to content

embassy-nrf/twim: prevent extra STOPs on ERROR - #6726

Open
Wassasin wants to merge 1 commit into
embassy-rs:mainfrom
Wassasin:fix/embassy-nrf/twim-anack-stop
Open

embassy-nrf/twim: prevent extra STOPs on ERROR#6726
Wassasin wants to merge 1 commit into
embassy-rs:mainfrom
Wassasin:fix/embassy-nrf/twim-anack-stop

Conversation

@Wassasin

@Wassasin Wassasin commented Aug 6, 2026

Copy link
Copy Markdown
Contributor

Solves #6722. Tested on NRF52840-DK and custom NRF9160 board.

The NRF TWIM can issue an ERROR event without a STOP event also being issued. This happens for example with an ANACK (address nack). The manual states:

The TWI master does not stop by itself when the RAM buffer is full, or when an error occurs. The STOP task must be issued, using a local or PPI shortcut, or in software as part of the error handler.

What the manual does not say, that if you issue STOP when no transfer is happening, that the peripheral goes into a broken state.
Thus we should prevent STOP from being issued by the driver, unless it is necessary.

This PR moves only for the async driver the issuance of STOP in the event of an ERROR to the interrupt handler. STOP is still being issued in the blocking API, as well as in the transaction loop when there are no more pending transactions.

This PR loses the ability to emit Error::Timeout, but it is not clear to me how this was ever going to be triggered. The ERROR event should never be pending without errorsrc also containing something.

Further work

This PR does not fix the rule:

The TWI master cannot be stopped while suspended, so the STOP task must be issued after the TWI master has been resumed.

We were already not following that rule currently, but peeking into the nrfx implementation got me thinking whether we maybe should.

Please discuss if we should tackle that, and if so in this PR or in another PR.

@leftger leftger added the e-nrf Issues for the nRF family of chips label Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e-nrf Issues for the nRF family of chips

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants