Missing `pub` in register bitfields

未关闭
#478 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
45/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
停滞
技术栈
rust
领域
embedded-iot

调研方向

首先定位 issue 中引用的 SAU Sfsr 和 Sfar 位域声明,然后检查 SCB、SAU 及相关外设中的其他寄存器位域,确认是否存在相同的可见性模式。验证 crate 外部的调用方可以访问指定的状态位方法,并确认仍可通过现有的 read API 使用寄存器定义。

由索引模型根据 Issue 内容生成。

描述

enhancement

In general, the definitions for a lot of the registers defined in SCB, SAU, etc., are rather deficient, but my current complaint is the Fault Status registers.

The ones defined in SCB are just defined as RW<u32>, so if you want to check individual bits, you have to define your own bitfield (or do the bit twiddling manually). Disappointing, but usable.

In SAU, the situation seems a little better: there are bitfield macros for Sfsr and Sfar! That sounds great, until you try to use them:

#[exception]
unsafe fn SecureFault() {
    let peripherals = cortex_m::Peripherals::steal();
    let sfsr = peripherals.SAU.sfsr.read();
    if sfsr.invep() {
        log::error!("INVEP");
    }
}

which gets you

error[E0624]: method `invep` is private
   --> <snip>/src/main.rs:122:13
    |
122 |       if sfsr.invep() {
    |               ^^^^^ private method
    |
   ::: <snip>/.cargo/registry/src/github.com-1ecc6299db9ec823/cortex-m-0.7.7/src/peripheral/sau.rs:81:1
    |
81  | / bitfield! {
82  | |     /// Secure Fault Status Register description
83  | |     #[repr(C)]
84  | |     #[derive(Copy, Clone)]
...   |
93  | |     lserr, _: 7;
94  | | }
    | |_- private method defined here

so you end up having to do the same thing (define your own bitfield or do the bit twiddling manually), only now you have to pull the value out of the existing bitfield with sfsr.0.

The sau crate doesn't do anything with this register, yet this bitfield definition makes it useless outside of the crate.

Fix

The register definitions could use a lot of love 🙁, but the obvious fix here is to make the fields in the bitfield pub, e.g.:

bitfield! {
    /// Secure Fault Status Register description
    #[repr(C)]
    #[derive(Copy, Clone)]
    pub struct Sfsr(u32);
    pub invep, _: 0;
    pub invis, _: 1;
    pub inver, _: 2;
    pub auviol, _: 3;
    pub invtran, _: 4;
    pub lsperr, _: 5;
    pub sfarvalid, _: 6;
    pub lserr, _: 7;
}

// Ditto for all other `bitfield`s
主要语言
Rust
星标
1k
派生
202
平均合并
1 天 4 小时
30 天内合并 PR
2

环境准备

这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

rust-embedded/cortex-m 的其他 Issue

查看 rust-embedded/cortex-m 的全部 Issue

相似的 Issue

更多 Rust Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。