Skip to content

[WIP] Track WCH CH5xx and CH32V4x7 support - #1

Draft
andelf wants to merge 344 commits into
ch32from
add-new-ch32-chips
Draft

andelf wants to merge 344 commits into
ch32from
add-new-ch32-chips

Conversation

@andelf

@andelf andelf commented Oct 31, 2026

Copy link
Copy Markdown

Purpose

Track ongoing WCH-Link, CH5xx and CH32V4x7 development on add-new-ch32-chips, targeting this fork's ch32 branch. Keep this PR as a draft while hardware validation and follow-up fixes continue.

The branch also includes upstream synchronization through f4d190285 (2026-10-22). The current comparison with ch32 contains 344 commits, so this is a development tracking PR covering both that synchronization and the WCH-specific work.

Currently implemented series

These targets have debugging support and flash algorithms in the branch. Target availability does not imply that every part or operation has been tested on hardware.

Series Available targets Current implementation / validation
CH56x CH565, CH569 Debugging and CodeFlash programming support; post-attach flash-window setup command added. Hardware validation remains to be recorded here.
CH57x CH570, CH571, CH572, CH573 Unified target definitions; CH570/CH572 retain their dedicated flash algorithm. Hardware validation remains to be recorded here.
CH58x CH581, CH582, CH583, CH584, CH585 Debugging and CodeFlash support using the shared CH5xx algorithm. Select CH584/CH585 explicitly with --chip; automatic detection is not configured for these two targets. Hardware validation remains to be recorded here.
CH59x CH591, CH592 Debugging and CodeFlash support using the shared CH5xx algorithm. Hardware validation remains to be recorded here.
CH32V4x7 CH32V407RET6/VET6/WEU6; CH32V467RET6/VET6/WEU6 Family 0xA6, package/revision-aware detection, 200 KiB and 136 KiB RAM configurations, and generated usr/usr-legacy/sys/opt flash algorithms. CH32V467WEU6 detection and chip-ID reads are verified on hardware; flash programming and live RTT are pending.

For CH56x/CH57x/CH58x/CH59x, automatic detection depends on the WCH-Link firmware returning a usable chip ID. Use --chip when it returns zero.

Development progress

  • Add and consolidate the CH5xx targets and CodeFlash algorithms.
  • Update the shared CH5xx flash algorithm for 64 KiB erase.
  • Add CH565/CH569 post-attach flash setup.
  • Detect RISC-V autoexec from the data-register bits used by the memory paths, allowing QingKe implementations without program-buffer autoexec to use the supported path.
  • Add CH32V407/CH32V467 targets, detection and option-byte RAM-split selection.
  • Fix WCH-Link attachment timeouts, including reconnecting after automatic target detection.
  • Validate CH32V467WEU6 identification and chip-ID reads on hardware.
  • Validate flash erase/program/verify on the listed families and record the exact chips and probe firmware tested.
  • Validate CH32V4x7 flash algorithms and both RAM layouts on hardware.
  • Validate live RTT and application startup, including the CH32V467 blinky/RTT/CPU-ID examples in ch32-hal.
  • Expand regression coverage and complete broader checks before marking ready for review.

Latest hardware validation — 2026-10-31

Test setup: WCH-LinkE-CH32V305, firmware 2.22 (v42), connected to CH32V467WEU6 with chip ID 0x46740011.

The previous driver used a fixed 100 ms USB timeout. Direct protocol measurements put reconnection at approximately 115–123 ms; even the initial attachment occasionally exceeded 100 ms. This caused probe-rs info --protocol jtag to fail during the second attachment after automatic detection. AttachChip now allows one second; other commands retain their 100 ms timeout.

After installing the fix:

  • probe-rs info --protocol jtag succeeded in 10 consecutive runs and detected CH32V467WEU6.
  • Chip-ID reads at 0x1ffff704 returned 0x46740011, both with automatic detection and with --chip CH32V467WEU6.
  • probe-rs info --verbose --protocol jtag reported family 0xA6 and the matching chip ID.

These checks did not erase or program flash. V4x7 attachment does not opt into the automatic flash-unprotect path.

Checks

  • Release build and local installation of probe-rs succeeded.
  • cargo fmt --all -- --check passed.
  • cargo test -p probe-rs --lib probe::wlink --locked --release passed: 4 tests.
  • Changelog fragments are included for the target additions and fixes.
  • Full test suite and broader regression/hardware validation completed.

bugadani and others added 30 commits July 31, 2026 20:23
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
…tion (probe-rs#4211)

Co-authored-by: Cursor <cursoragent@cursor.com>
… `--chip-erase` always clears UICR (probe-rs#4226)

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
SeanLyonsTI and others added 29 commits October 20, 2026 05:52
Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Dániel Buga <bugadani@gmail.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…e-rs#4478)

Co-authored-by: Paulius Zaleckas <paulius.zaleckas@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
…cted (probe-rs#4513)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: OnlyoutzZ <17393117531@163.com>
Co-authored-by: nsingcommunity <nsingcommunity@nsingtech.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Dániel Buga <bugadani@gmail.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Add the CH585 chip family code (0x4B) to the WCH-Link `RiscvChip` table,
so `AttachChip` no longer fails with `Unknown chip 0x4b` on these parts.

Add a target description for CH585 and CH584. Both expose 448 KiB of code
flash at 0x0; the 32 KiB data flash at 0x70000 is deliberately left out of
the memory map because it is reached through the ISP library rather than the
code address space. SRAM is 128 KiB on the CH585 and 96 KiB on the CH584.

No flash algorithm is included, so these targets support debugging and
memory access but not flashing yet.

Verified on a CH585 with a WCH-LinkE: `info --verbose` reports family 0x4b,
and `read`/`reset` work with `--chip CH585`.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Replace `CH585_Series.yaml` with `CH57X_Series.yaml`, `CH58X_Series.yaml`,
and `CH59X_Series.yaml` covering WCH's QingKe V4A/V4C BLE MCU families:
- `CH57X_Series.yaml`: CH571 (192 KiB Flash / 18 KiB RAM), CH573 (448 KiB Flash / 18 KiB RAM)
- `CH58X_Series.yaml`: CH581, CH582, CH583, CH584, CH585 (448 KiB Flash / 32..128 KiB RAM)
- `CH59X_Series.yaml`: CH591 (192 KiB Flash / 26 KiB RAM), CH592 (448 KiB Flash / 26 KiB RAM)

All three families share a single 1024-byte position-independent CodeFlash
algorithm (`ch32-rs/flash-algorithms` `ch5xx`) that dynamically enforces
the per-chip CodeFlash ceiling via `R8_CHIP_ID` (`0x40001041`) and runs at
each target's default RAM start (`0x20003800` on CH571/573, `0x20000000`
on CH58x/CH59x).

Co-Authored-By: Claude Code <noreply@anthropic.com>
…CH592_Series.yaml

Avoid colliding with Cortex-M0 CH577/CH578/CH579 (`CH57X`) and CH595
(`CH59X`, which uses a different hardware pre-program/page-latch Flash
controller at `0x40001800..0x40001820`), matching the existing
`CH570_CH572_Series.yaml` naming convention.

Co-Authored-By: Claude Code <noreply@anthropic.com>
List CH581, CH582, CH583, CH584, and CH585 explicitly instead of using a
`CH58X` wildcard, since CH586/CH587 have different memory sizes (up to
960 KiB CodeFlash / 256 KiB SRAM) and a separate WCH-Link chip code
(`0xAB`).

Co-Authored-By: Claude Code <noreply@anthropic.com>
….yaml

Use `CH58X_Series.yaml` (`CH58X Series`) to cover CH581, CH582, CH583, CH584,
and CH585.

Co-Authored-By: Claude Code <noreply@anthropic.com>
…H591/592

Each variant's `CodeFlash` `!Nvm` region already bounds its flash size (and the
algorithm checks `R8_CHIP_ID` at runtime), so `ch5xx-code-flash-192k` and
`ch5xx-code-flash-448k` can be collapsed into a single `ch5xx-code-flash`
entry matching `target-gen`'s `compact_flash_algos` behavior.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Fold `CH570_CH572_Series.yaml` into `CH57X_CH58X_CH59X_Series.yaml` and drop
the per-family files. CH570/CH572 switch from `ch570-code-flash` to the
shared position-independent `ch5xx-code-flash`, which already caps those
chip ids (`0x70`/`0x72`) at 240 KiB via `R8_CHIP_ID`.

Co-Authored-By: Claude Code <noreply@anthropic.com>
CH570 and CH572 go back to `ch570-code-flash` unchanged, instead of the
shared `ch5xx-code-flash`. Drop the `0x93000000` detection entry: the
probe firmware reports chip id 0 for that part, so it never matches.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Add a target description for the WCH CH565/CH569 series (QingKe V3A,
448 KiB CodeFlash at 0x0) with the `ch569-code-flash` algorithm from
`algos-ch5xx/ch569` in ch32-rs/flash-algorithms. The algorithm erases in
4 KiB sectors and implements `ReadFlash`, because a halted debug read of
CodeFlash returns a placeholder instead of the stored bytes.

The WCH-Link needs the `0x0d/0x04` post-attach setup that wlink sends for
the CH56X family; without it, flash accesses fail with an abstract
command exception.

Verified on a CH569 with a WCH-LinkE: `download --verify` of a 256-byte
image completes in under two seconds.

Co-Authored-By: Claude Code <noreply@anthropic.com>
Keep the changelog entries to user-visible support, and drop the
implementation notes above the CH565/CH569 algorithm's load address.

Co-Authored-By: Claude Code <noreply@anthropic.com>
erase_all now erases aligned 64 KiB blocks with 0xD8 and the tail with
0x20, matching the vendor loader. The blob is rebuilt from
ch32-rs/flash-algorithms algos-ch5xx/ch5xx.
Only autoexecdata is used by the program-buffer memory paths. Some
debug modules, such as WCH QingKe, implement data-register autoexec but
ignore the progbuf bits, so the previous equality check disabled
autoexec and fell back to one abstract command per word.
Recognise WCH-Link family 0xA6 as the QingKe-V4F CH32V4X7 series and add
the CH32V4X7 Series target with six parts. The RAM split is driven by
USER.RAM_CODE_MOD (bit 6), giving either 200 KiB or 136 KiB, and each
variant carries usr/usr-legacy/sys/opt flash algorithms.

Flash protection is deliberately not enabled for V4x7, so attaching does
not trigger the automatic unprotect path.

Flashing, RTT and the flash algorithms have not been validated on
hardware yet.
@github-actions

Copy link
Copy Markdown

Please do not edit CHANGELOG.md directly. Take a look at CONTRIBUTING.md for information on changelog fragments instead.

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.