-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[WIP] use modular_bitfield crate #282
[WIP] use modular_bitfield crate #282
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @jonas-schievink (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
CI for Rust 1.38 seems to fail because |
I'm fine with this in principle, but we might want to remove the bitfields-generated API entirely (otherwise we export an API generated by a crate that might change incompatibly) |
@jonas-schievink thanks for the update and info. I am going to update the
Can you elaborate on that point? So are you thinking about removing the
|
Yeah exactly. We could still use this crate internally, but would write our own API to wrap it. If (and this is a somewhat long-term plan for cortex-m 1.0, which isn't very close yet) |
Okay cool, I will keep you updated on the |
Hey! Definitely agree to use something more up-to-date and currently maintained! Maybe the author of
Those fields are currently unused but they do representation something in the payload. Maybe they will be for some use in the future! One generic question about your crate: how do your represent unused/reserved fields in a payload? With |
Some really good questions, @hug-dev !
I like your vision about the bigger picture for the Rust ecosystem. Both crates are vastly different though. Whereas Performance wise both crates are more or less the same from what I can tell.
Yes I already noticed that this feature is needed so I already created some issues for that:
You are right that both crates work differently in that regard. It might be nice to be able to specify Note that the |
Ah yes, I can understand that both crates are very different in how they are used. I guess I was hoping that the two implementations could co-exist in some way in the same crate but maybe it's not possible that easily and would not make sense. In the defense of Thanks for linking with the corresponding issues, nice that you thought about those. In summary, I am happy to switch |
Do we still need the |
Cool! I will work on those open issues and keep you updated in this PR once I am done and fine with it. :) Will then also update the PR to cover the other usage sites. |
Can you point me to the specific location of code in question? |
I guess you mean the #[inline]
pub fn mpu_region(self) -> Option<u8> {
if self.tt_resp.srvalid() {
// Cast is safe as SREGION field is defined on 8 bits.
Some(self.tt_resp.sregion() as u8)
} else {
None
}
} For which I can say: Yes it looks like with Also this gives me the ideas about implementing |
I am not yet done with the updates on the design of ShowcasePlease tell me what you like and especially what you dislike about this current direction. The cryptic looking For bitfields such as #[bitfield(bits = 32, filled = false)]
#[derive(Copy, Clone)]
#[repr(u32)]
/// Control Register description.
pub struct Ctrl {
enable: bool,
allns: bool,
}
#[bitfield(bits = 32, filled = false)]
#[derive(Copy, Clone)]
#[repr(C, u32)]
/// Type Register description.
pub struct Type {
sregion: u8,
}
#[bitfield(bits = 32, filled = false)]
#[derive(Copy, Clone)]
#[repr(C, u32)]
/// Region Number Register description.
pub struct Rnr {
region: u8,
}
#[bitfield]
#[derive(Copy, Clone)]
#[repr(C, u32)]
/// Region Base Address Register description.
pub struct Rbar {
#[skip] __: B5,
baddr: B27,
}
#[bitfield]
#[derive(Copy, Clone)]
#[repr(C, u32)]
/// Region Limit Address Register description.
pub struct Rlar {
enable: bool,
nsc: bool,
#[skip] __: B3,
laddr: B27,
}
#[bitfield]
#[derive(Copy, Clone)]
#[repr(C, u32)]
/// Secure Fault Status Register description.
pub struct Sfsr {
invep: bool,
invis: bool,
inver: bool,
auviol: bool,
invtran: bool,
lsperr: bool,
sfarvalid: bool,
lserr: bool,
}
#[bitfield]
#[derive(Copy, Clone)]
#[repr(C, u32)]
/// Secure Fault Address Register description.
pub struct Sfar {
address: u32, // Why is this a bitfield? Could be a simple `u32`.
} |
I just finalized version 0.11 of the |
I am done with replacing the old This was the warnings I have also fixed in this PR:
|
FYI: I do not proposed, yet, to merge this PR before I am sure that the |
The compiler warnings are incorrect. The code in cortex-m should be correct. I've filed rust-lang/rust#78819 for this. |
Thanks for the info. However, I think using |
@jonas-schievink I can of course remove the warning fixes if they are unwanted. |
Btw.: I have only used features of the |
rust-lang/rust#78819 has been fixed, please undo the |
This reverts commit dcfb7f3. # Conflicts: # src/peripheral/mod.rs
Is there still interest in this? I'd be willing to update to recent |
335: Prepare for v0.7.2 release of cortex-m r=thalesfragoso a=adamgreig We've had #328 merged for a while and it fixes a pretty annoying bug which is still in the wild. Can anything think of anything else to get in before a release? If there's nothing coming up (I think #282 needs some more discussion and #331 won't affect the published crate itself) we could get this released. Co-authored-by: Adam Greig <[email protected]>
We just discussed this in our meeting and we're inclined to go for it. We'll need to figure out whether this is a breaking change, i.e. which target release to bring it in. @Robbepop Would you mind cleaning it up and update the title? |
I will next weekend. Looking forward. :) |
…-use-modular-bitfield
Being based on Rust version 1.38 this might be problematic, I will have to check. What is the reason for this specific version for |
Right now, cortex-m's minimum supported Rust version (MSRV) is 1.38, hence the CI check. It's possible to bump it if necessary though, do you know what the MSRV modular_bitfield would require is / what features it needs? |
I will check which version is needed at minimum. However, looking at the CI output it could very well be that Rust 1.38 also works if I change code a little bit. |
Closing this due to my own inactivity. If the maintainers still want this we can try to tackle this again. |
282: Doc adding memory sections in memory.x r=therealprof a=tstellanova As noted in #281 it is possible to define additional memory sections in `memory.x`. Added some documentation on how to do this. Co-authored-by: Todd Stellanova <[email protected]>
This experimental PR simply replaced the
bitfield!
macro from thebitfield
crate with the#[bitfield]
attribute macro of themodular_bitfield
crate. I am the author of the latter crate and wanted to know if you are interested in using it. Some benchmarks I have conducted earlier shows that both crates perform pretty much equally. There was just one benchmark where apparentlymodular_bitfield
performed roughly 25% better for a setter case.Generally the
modular_bitfield
crate is actively maintained and just received lots of new features. Also it is probably a bit more convenient to use as you might notice from the diff. Finally, by introducing themodular_bitfield
to thecmse.rs
file I noticed that themregion
andmvalid
fields are unused. Is this intentional?If you like the changes done in this PR I can also convert the other usage sites of
bitfield!
to use themodular_bitfield
crate instead. So far I just replaced one usage site so that the diff is clearer to you.