Skip to content

fix: support reliable CH585 ISP flashing - #113

Open
hitsmaxft wants to merge 1 commit into
ch32-rs:mainfrom
hitsmaxft:ch585-support
Open

hitsmaxft wants to merge 1 commit into
ch32-rs:mainfrom
hitsmaxft:ch585-support

Conversation

@hitsmaxft

@hitsmaxft hitsmaxft commented Aug 28, 2026

Copy link
Copy Markdown

Summary

Adds a CH585-specific ISP flow for the programming constraints observed on real CH585 hardware. The implementation temporarily clears CFG_DEBUG_EN and CFG_ROM_READ, keeps the required key/session across erase and PROGRAM, starts a new key phase for VERIFY, restores the exact entry configuration only after full verification, and then resets.

Changes

  • isolate CH585 policy in src/ch585.rs
  • preserve the established non-CH585 flash, packet, and reset paths
  • enforce CH585 two-byte BootROM operation status
  • retain one CH585 key session from configuration through erase and PROGRAM
  • use a fresh key phase for VERIFY
  • restore the exact pre-flash configuration only after successful full verification
  • make CH585 Debug enable change only bit 4 and verify complete readback
  • avoid reapplying USB configuration 1 when it is already active

Validation

  • host unit tests: 13/13 pass on macOS arm64 through the repository Nix environment
  • release build: pass
  • exact fork hardware run on CH585M UID 98-5B-29-5A-04-DC-C5-91: pass
    • input image: 596 bytes, padded to 600 bytes with FF
    • full erase: pass
    • program: pass
    • full verify: pass
    • configuration restored byte-for-byte: ffffffffffffffffd73f0f45
    • BootROM reset: pass
    • post-reset WCH-Link attach identified CH585 and an authenticated Debug Module v2
  • CH582 regression tests: pass; physical CH582 testing was intentionally not run

Scope

Generic response-status changes already covered by PR #110 are intentionally not duplicated here.

@hitsmaxft
hitsmaxft marked this pull request as draft August 28, 2026 02:25
@hitsmaxft
hitsmaxft marked this pull request as ready for review August 29, 2026 07:59
@hitsmaxft

hitsmaxft commented Sep 9, 2026

Copy link
Copy Markdown
Author

this PR is tested well. It is ready to be merged.

This branch has not been deployed

No deployments
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