fix: prevent UART FIFO overflow during I2C bulk write#207
Open
rahul31124 wants to merge 1 commit into
Open
Conversation
Contributor
Reviewer's guide (collapsed on small PRs)Reviewer's GuideBuffers UART payload into RAM before starting the I2C bulk write and adds watchdog servicing to prevent UART FIFO overflow and timeouts during large transfers. Sequence diagram for buffered UART to I2C bulk writesequenceDiagram
actor Host
participant UART1
participant I2C_CommandWriteBulk
participant I2C_bus
participant Watchdog
Host ->> UART1: send device, count, payload bytes
UART1 ->> I2C_CommandWriteBulk: UART1_Read (device)
UART1 ->> I2C_CommandWriteBulk: UART1_Read (count)
loop count bytes
UART1 ->> I2C_CommandWriteBulk: UART1_Read (payload byte)
I2C_CommandWriteBulk ->> I2C_CommandWriteBulk: store in usb_buffer
I2C_CommandWriteBulk ->> Watchdog: WATCHDOG_TimerClear
end
I2C_CommandWriteBulk ->> I2C_bus: I2C_StartSignal
I2C_CommandWriteBulk ->> I2C_bus: I2C_Transmit (device << 1)
loop count bytes
I2C_CommandWriteBulk ->> I2C_bus: I2C_Transmit (usb_buffer[i])
I2C_CommandWriteBulk ->> Watchdog: WATCHDOG_TimerClear
end
I2C_CommandWriteBulk ->> I2C_bus: I2C_StopSignal
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
CloudyPadmal
reviewed
Jul 6, 2026
| uint8_t device = UART1_Read(); | ||
| uint8_t count = UART1_Read(); | ||
|
|
||
| static uint8_t usb_buffer[255]; |
CloudyPadmal
reviewed
Jul 6, 2026
|
|
||
| for (uint8_t i = 0; i < count; i++) { | ||
| usb_buffer[i] = UART1_Read(); | ||
| WATCHDOG_TimerClear(); |
Collaborator
There was a problem hiding this comment.
Do we need to clear the WDT regularly?
CloudyPadmal
reviewed
Jul 6, 2026
| I2C_Transmit(UART1_Read()); | ||
| for (uint8_t i = 0; i < count; i++) { | ||
| I2C_Transmit(usb_buffer[i]); | ||
| WATCHDOG_TimerClear(); |
CloudyPadmal
reviewed
Jul 6, 2026
CloudyPadmal
left a comment
Collaborator
There was a problem hiding this comment.
Looks good with minor comments.
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.
Fixes #206
Large UART transfers could overflow the 4-byte UART FIFO because the host sends data faster than the I2C bus can transmit it, causing dropped bytes and client timeouts.
Changes
I2C_CommandWriteBulk.Summary by Sourcery
Improve I2C bulk write handling by buffering incoming UART data and integrating watchdog servicing to ensure reliable large-transfer operation.
New Features:
Bug Fixes:
Enhancements: