rust-embedded / rust-embedded/svd2rust

The ability to obtain offset values for the modifiable bit fields of registers

Open
#582 4 comments 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

To be able to manipulation of peripheral registers through bit-banding, the values of the offset of the modifiable bit fields in the registers are required.

For example, there are functions for bit-banding here: https://docs.rs/stm32f1xx-hal/0.9.0/stm32f1xx_hal/bb/index.html

Implementation variant:

pub mod perih_name {
   ...
   pub mod reg_name {
      ...
      pub const field_name_OFFSET: u8 = ...;
      ...
   }
   ...
}

Example of an implementation variant (stm32f1):

pub mod rcc {
   ...
   pub mod apb2enr {
      ...
      pub const USART1EN_OFFSET: u8 = 14;
      ...
      impl<'a> USART1EN_W<'a> {
         ...
         pub fn bit(self, value: bool) -> &'a mut W {
            self.w.bits = (self.w.bits & !(0x01 << USART1EN_OFFSET)) | ((value as u32 & 0x01) << USART1EN_OFFSET);
            self.w
         }
      }
      ...
      impl R {
         ...
         pub fn usart1en(&self) -> USART1EN_R {
            USART1EN_R::new(((self.bits >> USART1EN_OFFSET) & 0x01) != 0)
         }
         ...
      }
      ...
   }
   ...
}

Usage example:

unsafe {
   use stm32f1xx_hal::{self as hal, pac};
   hal::bb::set(&(*pac::RCC::PTR).apb2enr, pac::rcc::apb2enr::USART1EN_OFFSET);
}

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 by comparing the requested generated register modules with the stm32f1 example and the bit-banding functions documented in stm32f1xx-hal. Determine how the generated field offset values should be exposed and verify that the usage pattern shown in the issue is supported.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
embedded-iot, tooling
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.