Rich Memory Layout - #36
Merged
Merged
Conversation
aq1018
marked this pull request as draft
May 12, 2026 06:16
Contributor
Author
|
You might want to take a closer look and see if I'm on the right path. This is a big change. If you are OK with the direction this PR is going. I will port all the chips over and deprecate the |
andelf
reviewed
May 12, 2026
generation. Added dump-memory-x tool here so we can spot check memory.x files here.
Contributor
Author
|
Inviting @ExplodingWaffle for feedback as well. |
CH32V203 sub-family yamls.
CLI friendly Option Bytes & ESIG Descriptors
Contributor
Author
CH32F1 support
Merged
5 tasks
aq1018
force-pushed
the
feat/rich-memory-layout
branch
from
June 13, 2026 06:53
cc963d5 to
969752f
Compare
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.
Replaces the flat per-chip
memory:block (only main flash + SRAM) with a family-shared description of the full on-chip flash address space — user flash (split into zero-waitUSR_1and non-zero-waitUSR_2where the silicon has both), system bootloader, option bytes, vendor block, RAM — including per-region programming modes and access permissions. Generated metapac exposes the full shape for HALs and flash algorithms viaMETADATA.memory, and renders per-optionmemory.xlinker scripts at the consumer's build time, with layout variants selectable via Cargo features.Partially addresses #26.
Motivation
Several downstream projects need richer flash-region metadata than the old flat
BANK_1 + SRAMblock provided:ch32-rs/flash-algorithmsis being rewritten on top of metapac so probe-rs can flash every supported chip from a single shared implementation. That requires correct per-region page/erase/write sizes for both fast and standard modes — not just the main bank.ch32-hal's flash driver can use the same region+mode metadata to support option-byte updates and bootloader-area writes through one generic API instead of per-chip constants.OpenServoCore/tinybootwrites to flash at runtime during firmware-update flows and benefits directly from the same metadata.The old schema couldn't express any of this — it modelled only the main user bank, mixed
page_sizeintowrite_sizeon most chips, and had no notion of system/option/vendor regions.Highlights
_common.yamlparent via recursiveinclude_memory(cycle-detected, append-only at every layer).Fast/Standardprogramming modes pulled straight from the RMs.Access { read, write, execute }.memory_sizes:— flat per-region size overrides for fixed-layout parts.memory_ram_code_config:— declares an OB-selectable code/RAM split (SRAM_CODE_MODE); the resolver auto-createsUSR_2atUSR_1.address + codewith sizetotal_flash - code.USR_1(silicon zero-wait region) +USR_2(non-zero-wait); the linker-script renderer auto-merges them into a singleUSRregion when contiguous, or keeps them split when an OB-driven SRAM-backed swap region falls between them.erase_size1024 → 4096,write_sizepage-sized → 2-byte half-word)../d dump-memory-x <chip>dumps every (config × split-combo) to disk for spot-checking.ARM target support: CH32F103
Bundled into this PR is initial support for CH32F1 (C6T6 / C8T6 / R8T6) — WCH's ARM Cortex-M3 line, and the first non-RISC-V family in metapac. A new
archfield on chip YAMLs, an arch-awarepostprocess_pac_rs, and athumbv7m-none-eabibuild in CI mean metapac is no longer RISC-V-only.Chip family coverage
Family files
Memory layouts live under
data/memory/:Common file (
data/memory/CH32V2_V3.yaml):Sub-family (
data/memory/CH32V3_XB.yaml):Chip file — fixed layout (
CH32V305FBP6.yaml)Chip file — OB-selectable split (
CH32V203RBT6.yaml)The resolver auto-creates
USR_2(addressUSR_1 + code, sizetotal_flash - code) for the OB-selectable case; chip YAMLs no longer declareUSR_2themselves.Generated metadata
Selecting a layout
Three Cargo-feature namespaces are emitted.
memory-config-*andmemory-xare orthogonal — config selection affectsMETADATA.memory,memory-xcontrols whether a linker script is rendered.memory-config-<name>— selects which OB code/RAM split populatesMETADATA.memory(USR_1 / USR_2 / RAM sizes). Affects metadata regardless of whethermemory-xis enabled. Enabling more than one is a build-time error.memory-x— enablesmemory.xlinker-script rendering at the consumer's build time, using the chip's default layout or thememory-config-<name>selection if one was made.memory-split-<region>— exposes individual banks (e.g.USR_1+USR_2) instead of the auto-merged region in the rendered linker script. One feature is emitted per multi-bank prefix; today onlymemory-split-usrexists. Only meaningful withmemory-x, so it impliesmemory-x.Rendered
memory.xfor["ch32v203rbt6", "memory-x", "memory-config-c144_r48"]:Pipeline cleanup
The legacy serialization shape is gone from the generator and runtime types:
chip::memory::Settings(parse-side) andFlashSettings(codegen/runtime) structs are removed entirely.MemoryRegionno longer carries asettings:field; per-region erase/write/page sizes are read frommodesonly.primary_flash_regionsnow filters onUSR_*exclusively; theBANK_*name fallback is dropped.settings:blocks remaining in the unmigrated CH5xx / CH645 YAMLs are silently ignored by serde at parse time — they don't compile in CI either way.Deprecated pac-root constants
FLASH_BASE,FLASH_SIZE, andWRITE_SIZE(emitted at the pac root by the codegen) are now#[deprecated(...)]pointing atch32_metapac::MEMORY_LAYOUT— an always-available const (no feature gate) exposing the chip's full memory geometry with const-fn accessors for page/erase/write sizes, role lookup, address-range checks, and access flags. Values are preserved — this is an advisory-only deprecation, no API breakage. Consumers should useMEMORY_LAYOUTto interpret region addresses, sizes, modes, roles, and access permissions in whatever way fits their use case; the same regions remain reachable asMETADATA.memoryunder themetadatafeature.