Add per-byte timeout budget for rp2 I2C #5189
Open
+8
−2
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.
I was hitting an issue with using an SSD1306 display and the tinygo.org/x/drivers/ssd1306 i2c driver. The display worked, but then after about ~20 minutes of running, I would get i2c write timeout errors, even though the screen was still updating. This was due to eventually needing GC to run and that made gosched() take long enough that we hit the i2c timeout.
I see this is actually fixed in the dev branch: gosched() time is compensated for. But I also see that the total, fixed timeout was lowered from 40ms to 4ms.
For the SSD1306 driver which sends the full frame buffer, about 1025 bytes, when it does an update, 4ms is not enough time.
I2C consumes 9 clock pulses per byte (8 bits + ACK). So the wire time for N bytes is: t≈9N/f.
Any single I2C write of ~180+ bytes @ 400kHz is guaranteed to exceed 4 ms wire time.
Any single write of ~45+ bytes @ 100kHz is guaranteed to exceed 4 ms.
My proposed fix is adding a 100us budget per byte to be transfered, with a cap of 500ms.