fix(arm): do not clear STOPF on the I2C NACK path - #40
Merged
Conversation
WaitForFlag cleared NACKCF and STOPCF together when it saw a NACK. But autoend generates the STOP itself in response to that NACK, and FinishTransfer is what waits for the resulting STOPF -- so clearing it there left that wait with nothing to observe, burning the full 25 ms transfer timeout on every failed transfer. Not a hang: the timeout bounds it, and the error the caller sees is the NACK's kOperationFailed rather than the discarded kTimeout. But it made a missing device cost 25 ms per attempt instead of the ~90 us an address phase takes at 100 kHz. Clear only NACKCF and let FinishTransfer see the STOP it was waiting for. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
WaitForFlagclearedNACKCFandSTOPCFtogether when it saw a NACK. Butautoend generates the STOP itself in response to that NACK, and
FinishTransferis what waits for the resultingSTOPF— so clearing it thereleft that wait with nothing to observe, burning the full 25 ms transfer timeout
on every failed transfer.
Not a hang: the timeout bounds it, and the error the caller sees is the NACK's
kOperationFailedrather than the discardedkTimeout. But it made a missingdevice cost 25 ms per attempt instead of the ~90 µs an address phase takes at
100 kHz.
Verified on hardware, not just reasoned about
Flashed
i2c_demoto the F767ZI with nothing on the bus and broke on bothfailure branches of
WaitForFlagto see which one the driver actually takes:ISR = 0x31is the whole argument for this change: TXE (bit 0), NACKF(bit 4) and STOPF (bit 5) are set at the same instant. The STOP has already
happened by the time the NACK is detected — so the old code was clearing a flag
FinishTransferwas about to wait for, guaranteeing the timeout every time.Incidentally this also confirms the I2C driver end to end on real silicon: the
address goes out at 0x50, nothing answers, the peripheral raises NACKF, and
SendDatareturnskOperationFailedwithout hanging.Checks
tools/verify-firmware.shtools/format.sh --checkclean🤖 Generated with Claude Code