esp32 icon indicating copy to clipboard operation
esp32 copied to clipboard

Bitfield stripping is broken on indexed peripherals

Open MabezDev opened this issue 5 years ago • 4 comments

Seems like https://github.com/esp-rs/esp32/pull/14 has unfortunately & subtley broken the code gen for indexed registers.

MabezDev avatar Jan 30 '20 21:01 MabezDev

Ah that is unfortunate. :/

If you'd like to back out #14, that'd be fine. I'm trying to approach this more generally directly in the idf2svd tool, but don't have that ready to go yet.

On the idf2svd front, I can identify which of the peripherals are indexed by looking for defines which look like REG_(.*)_BASE(i). Meanwhile the DR_REG_(.*)_BASE defines in soc.h seem like the cleanest starting point for which peripherals should exist. Unfortunately this inverts the existing logic a bit so its not an easy change. I'm taking a slight detour to see if it would be useful to use https://docs.rs/nom/5.1.0/nom/ to capture more of the information out of the defines. Perhaps I'll have something soon or someone will have a better approach.

davidkern avatar Jan 30 '20 22:01 davidkern

I will try and figure out why svdtools isn't patching the copied peripherals, but I will resort to reverting #14 if I can't figure it out.

On the idf2svd front, I can identify which of the peripherals are indexed by looking for defines which look like REG_(.)BASE(i). Meanwhile the DR_REG(.)_BASE

I looked into a similar approach but didn't go any further with it because of the inconsistencies in soc.h, for example the timer groups are referred to everywhere as timg but inside soc.h they are referred to as timergroup. I hope you have more luck than I did!

MabezDev avatar Jan 31 '20 13:01 MabezDev

I have an idea as to why this stopped working. Instead of _copying we used to _derive indexed peripherals from the general one i.e I2C0 & I2C1 were derived from I2C, hence applying the fix to just the I2C peripheral worked.

Now that we _copy, we have to change the registers on the copied peripherals too.

Something like changing the following line from: https://github.com/esp-rs/esp32/blob/9a41f6afe809d946ede10b5d11287ab56c881813/svd/patches/_rename_bitfields.yaml#L38

I2C* might do it, as this should capture all the copied peripherals too. If this does work this will have to be repeated for all peripherals where multiple exist.

MabezDev avatar Feb 04 '20 14:02 MabezDev

Re-opening as we had to revert the fix in #19

MabezDev avatar Feb 26 '20 21:02 MabezDev