rp-rs / rp2040-pac

A Rust PAC for the RP2040 Microcontroller
142 stars 28 forks source link

Fix clear-on-write fields that aren't actually clear-on-write #69

Open 9names opened 1 year ago

9names commented 1 year ago

I wrote this out in matrix a week ago. I've updated it to remove some inaccuracy, and am recording it here so we don't forget to fix it.

I've tested out using the Rust svdtools generated PAC - looks like we might need some changes around some registers. Specifically, the SVD describes some fields as modifiedWriteValues: clear from the SVD reference: svd1 an example of one of these fields from the rp2040 reference manual svd2

we were previously using .set_bit() on these fields, but in svd2rust this is removed for modifiedWriteValues: clear (since as far as it's concerned, any operation will clear the bit)

the accessor still has a .bit(value:bool) associated function, so we could change all of our calls on these frields from .set_bit() to .bit(true) and it should work for both old and new versions of the PAC

I feel like the SVD has probably got it wrong - at least in the case above. the write doesn't clear the bitfield. it sets the bit, and then you have to poll it until it's clear before moving on - it's a later hardware event that clears the bitfield.