rust-embedded / svd2rust

Generate Rust register maps (`struct`s) from SVD files
Apache License 2.0
687 stars 149 forks source link

Add support for atomic xor/clear/set register operations for Raspberry Pi RP2040 microcontroller #535

Open richardanaya opened 3 years ago

richardanaya commented 3 years ago

As per https://datasheets.raspberrypi.org/rp2040/rp2040-datasheet.pdf "2.1.2. Atomic Register Access"

Screen Shot 2021-08-01 at 10 27 20 PM

This looks vaguely similar to something that was done for the msp430. Unsure how common this is for cortex M registers across the board. Would this be some type of very specific target?

henkkuli commented 2 years ago

I have described one possible implementation for this in a comment elsewhere, but I don't know how to gate that for specific registers or peripherals only. I tried to look at the corresponding SVD file but haven't found any indication there that some registers should be atomic*. I also couldn't find a way to encode this info in a SVD file, at least based on a surface look at svd_parser. Does anyone here have an idea how to mark only some peripherals/registers as atomic? Maybe have another file listing all atomic peripherals/registers? Or list each atomic peripheral as a flag?

*All registers except those belonging to SIO peripheral should be atomic.

burrbull commented 2 years ago

As SVD doesn't have such info, the only way I see is to implement atomic operation for all registers, but make them unsafe as it done for write_with_zero.

henkkuli commented 2 years ago

That would be unfortunate, but at least it would work.

By the way, I have a POC available in my fork if someone wants to take a look. Would something like that fly? I can try to finish a PR, but for that I need some help with how to gate the feature for RP2040 target only.