Skip to content

all: update to the latest version of stm32-svd files/patches#13

Closed
deadprogram wants to merge 1 commit intomainfrom
update-feb-2026
Closed

all: update to the latest version of stm32-svd files/patches#13
deadprogram wants to merge 1 commit intomainfrom
update-feb-2026

Conversation

@deadprogram
Copy link
Copy Markdown
Member

This PR is to update the SVD files to the latest version, along with the needed patches by using some of @knieriem wotk from their fork.

It does appear to include the enumeratedValues I mentioned in #12

Note that the make mods task did not work for me, I patched the files manually before regenerating the SVD files using make

Signed-off-by: deadprogram <ron@hybridgroup.com>
@deadprogram
Copy link
Copy Markdown
Member Author

/home/ron/.gvm/pkgsets/go1.25.5/global/bin/tinygo build -size short -o test.hex -target=bluepill            examples/blinky1
# machine
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_adc_f1.go:39:61: undefined: stm32.ADC_SMPR1_SMP11_Pos
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_adc_f1.go:41:55: undefined: stm32.ADC_SMPR2_SMP1_Pos
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_adc_f1.go:52:13: stm32.ADC1.SetSQR3_SQ1 undefined (type *stm32.ADC_Type has no field or method SetSQR3_SQ1)
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:102:30: undefined: stm32.TIM_SR_CC1IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:109:30: undefined: stm32.TIM_DIER_CC1IE
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:153:20: cannot use uint32(psc - 1) (value of type uint32) as uint16 value in argument to t.Device.PSC.Set
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:163:19: cannot use arrtype(top - 1) (value of type uint32) as uint16 value in argument to t.Device.ARR.Set
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:213:32: undefined: stm32.TIM_CCMR1_Output_OC1M_Pos
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:220:34: undefined: stm32.TIM_CCER_CC1E
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:223:29: undefined: stm32.TIM_EGR_CC1G
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:226:30: undefined: stm32.TIM_SR_CC1IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:245:32: undefined: stm32.TIM_DIER_CC1IE
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:248:30: undefined: stm32.TIM_SR_CC1IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:264:16: undefined: stm32.TIM_CCER_CC1P
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:267:28: cannot use val (variable of type uint32) as uint16 value in argument to t.Device.CCER.ReplaceBits
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:267:39: undefined: stm32.TIM_CCER_CC1P_Msk
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:282:31: undefined: stm32.TIM_SR_CC1IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:287:31: undefined: stm32.TIM_SR_CC2IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:292:31: undefined: stm32.TIM_SR_CC3IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:297:31: undefined: stm32.TIM_SR_CC4IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:304:30: undefined: stm32.TIM_SR_CC1IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:304:51: undefined: stm32.TIM_SR_CC2IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:304:72: undefined: stm32.TIM_SR_CC3IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:304:93: undefined: stm32.TIM_SR_CC4IF
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:310:10: cannot use &t.Device.CCR1 (value of type *volatile.Register16) as *volatile.Register32 value in return statement
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:312:10: cannot use &t.Device.CCR2 (value of type *volatile.Register16) as *volatile.Register32 value in return statement
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:314:10: cannot use &t.Device.CCR3 (value of type *volatile.Register16) as *volatile.Register32 value in return statement
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:316:10: cannot use &t.Device.CCR4 (value of type *volatile.Register16) as *volatile.Register32 value in return statement
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:325:10: cannot use &t.Device.CCMR1_Output (value of type *volatile.Register16) as *volatile.Register32 value in return statement
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:327:10: cannot use &t.Device.CCMR1_Output (value of type *volatile.Register16) as *volatile.Register32 value in return statement
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:329:10: cannot use &t.Device.CCMR2_Output (value of type *volatile.Register16) as *volatile.Register32 value in return statement
/home/ron/Development/tinygo/tinygo-122/src/machine/machine_stm32_tim.go:331:10: cannot use &t.Device.CCMR2_Output (value of type *volatile.Register16) as *volatile.Register32 value in return statement

Not quite working yet...

@deadprogram deadprogram marked this pull request as draft February 19, 2026 22:56
@knieriem
Copy link
Copy Markdown
Contributor

Hi, I will have a look into why "make mods" did not work (anymore?). The mechanism just applies some ed files (in good old Plan 9 tradition ;-) to deal with the 32 bit ->16 bit narrowing issue. I know that the README suggests not to patch files here, but rather upstream, but I feel these changes won't be accepted upstream. They added a lot of patches themselves that narrow registers from 32 bit to 16 bit. This is a problem for TinyGo, since we rely on the 32-bit nature of registers. I looked up quite some register manuals an it appears to me that registers in these cases may be accessed using 32-bit access. Perhaps they decided it with some optimization in mind.
#10
So in the .ed file I try to collect all the cases necessary to compile all TinyGo examples for all stm32 targets.
So this would explain the errors refering to 16 / 32 bits mismatches.

The other errors - undefined ... - likely have to do with gen-device-svd not generating these things. Please see my branch https://github.com/knieriem/tinygo/tree/update-gen-device-svd that should contain fixes for these cases.
The generation has shown to be a bit tricky: There are basic and advanced timers, for instance, with more or less registers available. They all are represented by a TIM_Type. I realized the problem that if the first instance of a timer defined in a .svd file is a basic timer, then only the basic register set would be recognized and generated, then TIM peripherals would be regarded as handled. I changed this so that the advanced timers would be sorted first.

For a broader picture behind my patches regarding TinyGo on stm32 please also see knieriem/tinygo#1 . It would be cool to resolve some of these issues, but I realize regarding the large number of STM32 families and variants that it requires some kind of structured approach.

Just to be sure we are looking at the same problem: Are you using the new Rust based svdtools or the older python based tools?

@deadprogram
Copy link
Copy Markdown
Member Author

Are you using the new Rust based svdtools or the older python based tools?

I am using the rust crate as directed by the README in the https://github.com/stm32-rs/stm32-rs repo:

cargo install svdtools --version 0.5.0

@amken3d
Copy link
Copy Markdown
Contributor

amken3d commented Feb 20, 2026

There is also this related PR tinygo-org/tinygo#5168

@knieriem
Copy link
Copy Markdown
Contributor

@amken3d I am not sure if tinygo-org/tinygo#5168 does handle all the changes current stm32 svds (Rust svdtools) bring with them (?). Please compare e.g. with the existing changes in the patch set tinygo-org/tinygo@release...knieriem:tinygo:update-gen-device-svd, there appears some more things that are important for proper generation, like peripheral reordering, or dim array support (see also #10).

@deadprogram
Copy link
Copy Markdown
Member Author

@knieriem maybe you could please make a PR against the dev branch with your changes to gen-device-svd?

@knieriem
Copy link
Copy Markdown
Contributor

I have found the reason why make mods likely didn't work for you: In the mods.ed file I was using plan9port ed's syntax instead of Linux ed's, which mainly differ regarding the meaning of ? and \?.

Since there have been some more 16-bit register adjustments upstream very recently (regarding TIM v1 and v2), I decided to skip mods.ed and implement a small, perhaps better maintainable patch program in Go instead: patch.go.gz

It disables most of the size: 16 modifications and can be started from the Makefile like this:

# Apply changes to .yaml files.
mods:
	go run patch.go

With patch.go and the updated gen-device-svd tool, the bluepill example from above should compile again.

As noted in tinygo-org/tinygo#5212 and #10, a few changes to some TinyGo files may be necessary, like done in tinygo-org/tinygo@1c75aff and tinygo-org/tinygo@683ebf2. Also, the stm32g0b1 target needs some small adjustments, since a few names change in stm32g0b1.go.

@deadprogram
Copy link
Copy Markdown
Member Author

deadprogram commented Feb 20, 2026

implement a small, perhaps better maintainable patch program in Go instead

thank you for that!

@deadprogram
Copy link
Copy Markdown
Member Author

@knieriem will you submit PR against this repo with the patch.go etc?

@knieriem
Copy link
Copy Markdown
Contributor

Yes, I will do that. Shall we keep the name patch.go, or adjust it to the Make target mods => mods.go? Or better use "make patch"?

@deadprogram
Copy link
Copy Markdown
Member Author

Yes, I will do that. Shall we keep the name patch.go, or adjust it to the Make target mods => mods.go? Or better use "make patch"?

make patch sounds reasonable to me.

@deadprogram
Copy link
Copy Markdown
Member Author

Gentle ping about the patch, @knieriem I am so eager to test 😸 thank you!

@deadprogram
Copy link
Copy Markdown
Member Author

Closing in favor of #14

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.

3 participants