rust-embedded / rust-embedded/svd2rust

Small atomic writes

Open
#220 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

As far as I can tell, all registers are modelled as 32-bit VolatileCells, and ptr::read_volatile and ptr::write_volatile will cause full-word load and store operations. That's ok in a read-modify-write sequence, the bitwise operators won't mind if they work on u32, u16 or u8.

But what if I didn't need to set bits in multiple locations, and just want to access properly-aligned half-words or bytes? I doubt the compiler will be clever enough to convert a load-word operation followed by some bit masking into a load-byte operation. Would it be possible to detect whether a register contains aligned 16-bit or 8-bit fields, and create methods to access them directly? This would gain us atomic access, compared to a read-modifyNthBte-write sequence. (Also it might make the API more fluent, see #205).

Taking this into extreme, many cores do support bit banding. From what I gather, this is still translates into a read and write operation on the bus so it's not exactly faster, but again it would be atomic. Creating methods that support bit-banded reading and writing of single-bit register fields would be quite nice.

What do you think? Are there any concerns regarding API design?

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

No files, tests, or entry points are named. Start by tracing how svd2rust models generated 32-bit VolatileCell registers and their accessors; done would require an agreed API and design for aligned half-word, byte, and bit-banded access, followed by implementation and validation.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.