Improve flash reliability at high baud rates; update stubs to v1.1.0 - #58
Merged
Conversation
Signed-off-by: deadprogram <ron@hybridgroup.com>
Signed-off-by: deadprogram <ron@hybridgroup.com>
The esp-flasher-stub v1.1.0 uses double-buffering: it ACKs each flash data block immediately, then writes to flash as a post-process. During flash writes the ESP32 ROM disables interrupts (SPI bus shared with cache), causing the 128-byte UART FIFO to overflow if the next block arrives too soon. Additionally, USB-UART bridges occasionally lose bytes at 460800 baud, producing truncated SLIP frames. Fix with three complementary changes: - Add port.Drain() to sendCommand to ensure each frame is physically committed to the USB-UART bridge before proceeding. - Add a post-process delay (waitForStubFlashWrite) after each flash block ACK proportional to the estimated page count, giving the stub time to finish its flash write before new data arrives. - Retry flash block writes on both TimeoutError and retryable CommandErrors (bad data length / bad checksum), with RX buffer flushes between attempts to clear stale partial-frame responses. Also update CommandError to decode the v1.1.0 stub's 16-bit big-endian response codes (0xC000=bad data length, 0xC100=bad checksum, etc.) and add IsRetryable() to distinguish transient serial errors from device-side failures. Signed-off-by: deadprogram <ron@hybridgroup.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.
This PR fixes intermittent flash failures (timeouts and data corruption) when flashing ESP32 at 460800 baud.