Skip to content

Allow using #[cfg(...)] attributes on register fields#16

Open
jeandudey wants to merge 1 commit intodrone-os:masterfrom
jeandudey:2021_07_21-allow-cfg-in-reg
Open

Allow using #[cfg(...)] attributes on register fields#16
jeandudey wants to merge 1 commit intodrone-os:masterfrom
jeandudey:2021_07_21-allow-cfg-in-reg

Conversation

@jeandudey
Copy link

@jeandudey jeandudey commented Jul 21, 2021

Small non-breaking change to the reg! macro. It now allows the usage of #[cfg(...)] attributes on register fields. This is particularly useful for drone-os/drone-cortexm#5 as it allows to restrict the STKALIGN field to a read-only field on Cortex-M7 CPUs.

Also, I've got another usage for this, adding the IC and DC fields to SCB_CCR which is present on some Cortex-M7 (optionally).

For example:

reg! {
    /// Configuration and control register.
    pub SCB CCR => {
        address => 0xE000_ED14;
        size => 0x20;
        reset => 0x0000_0200;
        traits => { RReg WReg };
        fields => {
            #[cfg(not(cortexm_core = "cortexm7_r0p1"))]
            /// Force exception stacking start in double word aligned address.
            STKALIGN => { offset => 9; width => 1; traits => { RRRegField WWRegField } }
            #[cfg(cortexm_core = "cortexm7_r0p1")]
            /// Force exception stacking start in double word aligned address.
            STKALIGN => { ... }
            ...
        };
}

Signed-off-by: Jean Pierre Dudey <me@jeandudey.tech>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant