Skip to content

Conversation

@amken3d
Copy link

@amken3d amken3d commented Jan 9, 2026

Background

The lib/stm32-svd submodule was updated from e6db8e3 to 5b13c6d during tinygo-org/stm32-svd#11. This update includes new device families and updated register definitions.

Issue 1: orderPeripherals tracking by wrong key

Problem: The orderPeripherals function in gen-device-svd.go is designed to reorder peripherals so that base peripherals are processed before peripherals that derive from them (via SVD's derivedFrom attribute). However, it was tracking known peripherals by their groupName, not their actual name.

Example from stm32u595.svd:

I2C1
I2C
...


I2C5
...


SEC_I2C5
...

The old code would:

  1. Process I2C1, add "I2C" (groupName) to known peripherals
  2. Process I2C5, check if "I2C1" exists in known peripherals → not found (only "I2C" exists)
  3. Defer I2C5 to missingBasePeripherals
  4. Process SEC_I2C5, check if "I2C5" exists → not found
  5. Eventually process deferred peripherals, but I2C5 still can't find I2C1 → nil pointer panic

Fix: Track peripherals by their name field since that's what derivedFrom references.

Issue 2: Whitespace in interrupt names

Problem: Some SVD files in the updated stm32-svd contain interrupt names with leading whitespace (e.g., FLASH in stm32l0x1.svd). The generator was using these names directly without sanitization, producing invalid Go code:

func interrupt FLASH() { // Invalid: space in function name
callHandlers(IRQ_ FLASH) // Invalid: space in identifier
}

Fix: Apply strings.TrimSpace and cleanName to interrupt names before use.


These issues only surfaced with the newer SVD files because:

  1. The new files have more complex derivedFrom chains (peripheral → derived → derived again)
  2. The upstream stm32-rs project introduced whitespace in some interrupt names

Ensure proper resolution of `DerivedFrom` peripherals with error checks for missing references. Clean up interrupt names to remove extra spaces and ensure consistency. This improves the reliability of the SVD parsing tool.
@dgryski
Copy link
Member

dgryski commented Jan 9, 2026

What other platforms are affected by this? (It seems like this a breaking change, even if it's a fix.)

@amken3d
Copy link
Author

amken3d commented Jan 9, 2026

The tool ran cleanly on all chip familiies. The nil check on derivedFrom catches SVD bugs rather than introducing new failures. Tracking by peripheral name (not group name) is correct per SVD spec since derivedFrom references peripheral names. The generated output matches existing files semantically (same number of definitions), with only minor whitespace formatting differences. I checked this by diffing the outputs for rp2040,rp2350 and stm32g0b1.

@dgryski
Copy link
Member

dgryski commented Jan 10, 2026

Sorry, I thought this was a fix for #5154 which would have different generated code.

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