embassy-rs / chiptool

Apache License 2.0
37 stars 21 forks source link

Fieldset default value is always 0 #14

Closed yodaldevoid closed 7 months ago

yodaldevoid commented 8 months ago

I noticed after a long session of debugging that the default value of every fieldset is set to 0. My assumption and expectation was that a fieldset's default value would be the reset value defined in the SVD.

Was this a conscious decision or simply something not implemented? I wanted to check before putting in work to implement it.

Dirbaio commented 7 months ago

This is intentional, reset values cause a variety of issues that were contrary to the goals of chiptool. For example, in STM32, different GPIO pins might have different reset values (for example the pins used for SWD). We want the pin registers to be an array, so HALs can index them instead of having to use macros to duplicate the code for each pin (causing unreadable code and slow compile times). However, the reset values of all the registers in an array must be the same. This means we're either forced to lie (have wrong reset values) or have ugly macros (not create the array), or simply not play the game at all (ignore reset values, default to 0). Chiptool chooses the latter.

My assumption and expectation was that a fieldset's default value would be the reset value defined in the SVD.

This is because you're used to svd2rust, I'll point out that this is not the case if you use e.g. C-style bit manipulation :)