Skip to content

Merge bit fields that only moved inside their own register - #18

Merged
salkinium merged 1 commit into
mainfrom
fix/relocated-bit-fields
Sep 17, 2026
Merged

salkinium merged 1 commit into
mainfrom
fix/relocated-bit-fields

Conversation

@salkinium

Copy link
Copy Markdown
Member

Follow-up to #17, which left source compatibility half-applied.

The inconsistency

source mode located a register by its name, because a CMSIS header
abstracts the offset away into a structure member. But it still located a bit
field by its position, even though the same header abstracts the position
just as much into its _Pos and _Msk macros.

So a bit field that keeps both its name and its register is now a relocation
instead of a conflict.

Why IWDG had two variants

This was the only difference between the two IWDG implementations:

SR.EWIF: moved SR[15] != SR[14]

The early wake-up flag is bit 15 on the STM32WBA2 and bit 14 on the STM32WBA5.
Everything else — KR, PR, RLR, the rest of SR, WINR, EWCR — lines
up exactly, so one flag split every STM32 into two watchdogs.

It is not a data bug. All three sources agree with each other on both sides:

Source STM32WBA2 STM32WBA5
CMSIS header IWDG_SR_EWIF_Pos (15UL) (14UL)
ST SVD <bitOffset>15</bitOffset> 14
Reference manual RM0521: "Bit 15 EWIF" RM0493: "Bits 31:15 Reserved … Bit 14 EWIF"

IWDG is now one variant across all 287 devices.

Permutations are not relocations

A bit field permuted inside its register keeps its conflict, since its position
is what it means. Bit 9 of GTZC_TZSC_SECCFGR1 is USART2 on one device and
WWDG on another, and merging those would give a map where 116 peripherals each
claim two bits.

The two are separable: a permutation renames every position it touches, while a
relocation moves into bits that nobody else claims. Without that guard, source
variants collapse to 280 and GTZC_TZSC wrongly merges to 1.

Results

Mode Before After
binary 387 387
source 319 300
similar 282 268

Twelve groups collapse: DBGMCU 8→5, RCC 29→25, EXTI 8→6, SDMMC 4→2,
PWR 15→14, TAMP 3→2, and IWDG, WWDG, VREFBUF, DCACHE, HASH,
GFXMMU 2→1.

Explorer

Relocated fields are drawn at each of their positions with a dashed outline,
tagged · relocated in the inspector, and listed per variant under "Moved, but
the same bit field". The gist is already updated.

The regrouping created 214 new feature keys, which Gemma named, so the published
table went 2623 → 2837 and every one of the 6184 feature slots is named.

Note

The rule also merges EXTI's EMR1.EM mask variants (EMR1[30:19] vs
EMR1[31:30]) in source mode. documentation_only() already tolerated those in
similar mode, so it is consistent, but it is a looser case than the clean
EWIF relocation.

…ster

Source compatibility located a register by its name, since a CMSIS header
abstracts the offset away into a structure member, but still located a bit
field by its position. A header abstracts the position just as much into its
_Pos and _Msk macros, so a bit field that keeps both its name and its register
is now relocated instead of a conflict.

This is the only difference between the two IWDG implementations: the early
wake-up flag IWDG_SR_EWIF is bit 15 on the STM32WBA2 and bit 14 on the
STM32WBA5, which the headers, the ST SVD files and RM0521 and RM0493 all
agree on, so the flag alone split every STM32 into two watchdogs.

A bit field that is permuted inside its register is not relocated, since its
position is what it means: bit 9 of GTZC_TZSC_SECCFGR1 is USART2 on one device
and WWDG on another. A permutation therefore renames every position it touches,
while a relocation moves into bits that nobody else claims.

Source variants go from 319 to 300 and similar from 282 to 268, binary is
unchanged. The relocated bit fields are drawn at each of their positions and
listed per variant in the explorer.
@salkinium
salkinium merged commit 6690112 into main Sep 17, 2026
10 checks passed
@salkinium
salkinium deleted the fix/relocated-bit-fields branch September 17, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant