Repository navigation
Conversation
When command_find_block() rejects a block that begins with MESSAGE_STX1, the resync search starts at buf[0], finds that same byte and pops nothing. Every later call fails on the same bytes, so the receive buffer never drains. Once it is more than half full, usb_cdc stops reading the bulk out endpoint and the bootloader NAKs all further data until it is reset. This happens on Creality K1 series printers, whose udev rules probe every new ttyACM device for an AI lidar by writing "af ff 02 00 01 55 fa fd". Katapult discards the first four bytes, then livelocks on "01 55", so flashtool's CONNECT always times out. Start the resync search after the first byte of the rejected block. Fixes Arksine#137 Signed-off-by: Tom Hodgson <tom@justsanity.com>
This was referenced Oct 27, 2026
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.
command_find_block()can livelock when a rejected block begins withMESSAGE_STX1. The resyncmemchr()starts atbuf[0], finds the same byte, and pops nothing. Every later call fails on the same bytes, so the receive buffer never drains. Once it is more than half full,usb_cdcstops reading the bulk OUT endpoint and the device NAKs everything until it is reset. The same function is used byserial_irq.candcanserial.c, so the fix applies to those transports too.On Creality K1 series printers this happens every time. Their udev rules probe new ttyACM devices by writing
af ff 02 00 01 55 fa fd, which is the cause of #137. I'll put the details in that issue.This change starts the resync search one byte past the start of the rejected block. Progress on the error path is then guaranteed. The entry path, with
CF_NEED_SYNCset from an earlier call, still accepts a valid STX1 atbuf[0].Testing
v0.0.1-104-gfcb2f84), CONNECT always timed out after the udev probe. With the probe out of the way, unmodified flashtool.py connected and flashed from the printer.command_find_block()and theusb_cdcbulk out loop:01 88 xx LENheader with a large LEN leaves 65–127 bytes buffered.usb_cdcwon't read another packet until 64 bytes are free, so a block longer than what's buffered can never complete. That needs a header that's well-formed by chance, so I've left it out of this PR. Happy to look at it separately if you'd like.test/configs/stm32g4.configbuilds cleanly: text grows 5240 → 5244 bytes.Fixes #137