Skip to content

feat: implement config set for CH5xx/CH32 config registers - #124

Open
emolitor wants to merge 2 commits into
ch32-rs:mainfrom
emolitor:feat/config-set
Open

emolitor wants to merge 2 commits into
ch32-rs:mainfrom
emolitor:feat/config-set

Conversation

@emolitor

@emolitor emolitor commented Nov 14, 2026 •

Copy link
Copy Markdown
Contributor

wchisp config set <HEX> is currently a stub: it logs the value and then hits unimplemented!(). This implements it as a verbatim write of the RDPR/USER/DATA/WPR config block.

  • Reads the current block to learn its length and log the before value.
  • Takes the new block as hex (optionally 0x-prefixed) and requires it to match the length the chip reports. Anything else is rejected before writing.
  • Writes it with WriteConfig, then reads back and logs the result.

This is the whole-block counterpart to config reset / enable-debug / disable-debug, which only write the per-device preset values. The idea is to read the block with config info, edit the bytes, and write it back with config set.

config info reads with CFG_MASK_ALL so the string it prints is the config block followed by the bootloader version and chip UID. config set takes only the leading config block (12 bytes) and the help text says so.

`wchisp config set <HEX>` was a stub that logged the value and then hit
`unimplemented!()`, so it could not be used at all. Implement it as a
verbatim write of the RDPR/USER/DATA/WPR config block:

- read the current block (to learn its length and log the before value);
- accept the new block as hex, optionally `0x`-prefixed, and require it to
  match the chip's reported block length;
- write it with WriteConfig and read back.

This is the generic, whole-block counterpart to the existing field-specific
`reset_config` / `enable_debug` / `disable_debug`. The intended workflow is
`config info` to read the block, edit the bytes, then `config set` to write
it back. Help text updated to describe the hex-block format.
`config info` reads with CFG_MASK_ALL and prints the config block followed
by the bootloader version and chip UID, while `config set` requires exactly
the RDPR/USER/DATA/WPR block. The help text told users to pass the string
`config info` prints, which is rejected by the length check. Say which part
of that string to use.
Copilot AI balanced review requested due to automatic review settings November 14, 2026 10:52

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Note

Copilot was unable to complete this review at the selected tier due to model policy or plan restrictions.

🟡 Changes recommended

A critical active finding remains because src/main.rs:366 passes a String to Flashing::set_config which expects &str, causing a compilation error unless the value is borrowed (e.g., via &value or value.as_str()).

1 open issue
What changed in this PR

Implements the previously-stubbed wchisp config set <HEX> command to perform a verbatim write of the device’s RDPR/USER/DATA/WPR configuration block, supporting the intended workflow of reading config, editing bytes, and writing the block back.

Changes:

  • Updated config set CLI help text to clarify expected hex input (config block only).
  • Wired the CLI subcommand to a new flashing-layer implementation.
  • Implemented config-block read/length validation, write via WriteConfig, and read-back logging.
File Description
src/​main.rs Updates the config set CLI documentation and routes the subcommand to the flashing implementation.
src/​flashing.rs Adds set_config to parse/validate a hex config block, write it verbatim to the device, and read it back for logging.

Review effort: Balanced

Comment thread src/main.rs Resolved

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.

2 participants