Skip to content

Updated to fix a issue where CCLoader hangs with no response after a cold USB reconnect - #4

Open
randy197 wants to merge 3 commits into
Jason2866:masterfrom
randy197:master
Open

Updated to fix a issue where CCLoader hangs with no response after a cold USB reconnect#4
randy197 wants to merge 3 commits into
Jason2866:masterfrom
randy197:master

Conversation

@randy197

@randy197 randy197 commented Jul 26, 2026

Copy link
Copy Markdown

This took me a few hours an many AI token to work out what was happening, but I finally got it flashing. I've added a note in the readme to explain what users will need to do if they have issues programming.
Not sure how this would effect windows or MacOS as I have only tested on Linux.

Basically without doing a esptool reset after a cold plug in of the 8266 it wouldn't communicate with CCLoader. I (ie. Claude) have added a few changes to the firmware to solve a couple of bugs and along with the esptool reset I was able to get this to work.

Summary by CodeRabbit

  • Bug Fixes

    • Improved serial handshake reliability by clearing stale data and retrying when no response is received.
    • Added clearer failure handling for invalid chip detection, transfer checksum errors, and verification failures.
    • Improved programming flow stability and reset behavior after interrupted operations.
  • Documentation

    • Added guidance for recovering from hangs after cold USB reconnects on ESP8266/NodeMCU-style boards.

randy197 added 3 commits July 26, 2026 19:03
Added timestamp functions and improved error handling for RS232 communication.
Added a known issue regarding CCLoader hanging after USB reconnect and provided a workaround using esptool for ESP8266/NodeMCU boards.
@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The Arduino loader now clears stale serial input, validates chip identification, handles block checksum and verification failures, and resumes programming requests after successful blocks. The Linux loader adds reset settling, serial flushing, timed SBEGIN retries, and retry exhaustion handling. The README documents a cold-reconnect workaround.

Changes

Serial programming flow

Layer / File(s) Summary
Firmware handshake and block programming
CCLoader/src/CCLoader.ino
The loader accepts buffered handshakes, reports invalid chip IDs, validates and optionally verifies received blocks, erases on failure, and continues or completes programming through the updated state flow.
Linux reset and handshake retry
SourceCode/Linux/main.c
The Linux client flushes startup input, tracks monotonic receive timing, retries SBEGIN during stalled handshakes, and stops after the retry limit.
Cold reconnect workaround
README.md
The README documents running esptool ... chip_id after a cold USB reconnect before using CCLoader.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant LinuxLoader
  participant CCLoader
  participant Flash
  LinuxLoader->>CCLoader: Send SBEGIN
  CCLoader->>CCLoader: Drain stale input and validate handshake
  CCLoader->>Flash: Read chip ID and erase
  LinuxLoader->>CCLoader: Send data block
  CCLoader->>Flash: Write and optionally verify block
  CCLoader-->>LinuxLoader: Send ERRO or request next block
Loading

Poem

A rabbit hops where serial bytes flow,
Stale noise out, clean handshakes glow.
Blocks are checked with careful cheer,
Retries return when none appear.
Flash lights blink—success is near!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main fix: CCLoader hanging after a cold USB reconnect.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@CCLoader/src/CCLoader.ino`:
- Around line 546-550: Update the Serial handshake parsing around the
available-byte check so rejecting an unexpected command consumes only the single
unexpected byte, preserving subsequent bytes such as SBEGIN and verify for the
next iteration. Ensure the receive buffer remains intact after noise and the
valid handshake can still be parsed without waiting indefinitely.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 52381901-258a-480e-bef6-06bd0517e606

📥 Commits

Reviewing files that changed from the base of the PR and between 774b995 and 67b5db9.

📒 Files selected for processing (3)
  • CCLoader/src/CCLoader.ino
  • README.md
  • SourceCode/Linux/main.c

Comment thread CCLoader/src/CCLoader.ino
Comment on lines +546 to +550
if(Serial.available()>=2) // was strictly ==2: a single stray byte
// ahead of the real handshake could make
// this condition never trigger, hanging
// forever.
{

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Do not discard the byte following an unexpected command.

With RX data [noise, SBEGIN, verify], Line 558 consumes SBEGIN after rejecting noise, leaving only verify; the next iteration waits forever for two bytes. Discard only the unexpected byte so the next iteration can parse the intact handshake.

Proposed fix
       if(Serial.read() == SBEGIN)
       {
         Verify = Serial.read();
         Continue = 1;
       }
-      else
-      {
-        Serial.read(); // Clear RX buffer
-      }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if(Serial.available()>=2) // was strictly ==2: a single stray byte
// ahead of the real handshake could make
// this condition never trigger, hanging
// forever.
{
if(Serial.available()>=2) // was strictly ==2: a single stray byte
// ahead of the real handshake could make
// this condition never trigger, hanging
// forever.
{
if(Serial.read() == SBEGIN)
{
Verify = Serial.read();
Continue = 1;
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@CCLoader/src/CCLoader.ino` around lines 546 - 550, Update the Serial
handshake parsing around the available-byte check so rejecting an unexpected
command consumes only the single unexpected byte, preserving subsequent bytes
such as SBEGIN and verify for the next iteration. Ensure the receive buffer
remains intact after noise and the valid handshake can still be parsed without
waiting indefinitely.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant