rust-embedded / rust-embedded/svd2rust

Is generated atomic register access correct?

Open
#793 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
857
Forks
164
PR merge metrics
No merged PRs in 30d

Description

svd2rust can generate atomic register operations by using the --atomics flag
https://docs.rs/svd2rust/latest/svd2rust/#the---atomics-flag
It generates code that looks like this:
https://github.com/ra-rs/ra/blob/main/pac/ra4m1/src/generic/atomic.rs

I'm not certain that these will act as intended, as atomic operations are not required to be volatile.
In particular, it's not clear that doing two of these operations back-to-back will not be optimised by the compiler and reduced to a single operation instead.

The discussions around volatile atomic access have not been resolved yet as far as I know:
https://rust-lang.zulipchat.com/#narrow/stream/136281-t-opsem/topic/volatile.20atomic.20in.20Rust.3F
https://internals.rust-lang.org/t/pre-pre-rfc-exploring-api-design-space-for-volatile-atomics/19989

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the --atomics flag documentation and the generated pac/ra4m1/src/generic/atomic.rs example. Review whether back-to-back atomic operations are volatile and can be optimized together, then consult the linked Rust discussions on volatile atomic access. Done means establishing whether the generated operations are correct and documenting or resolving the required change.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot, tooling
Issue type
Bug
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.