-
Notifications
You must be signed in to change notification settings - Fork 158
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
Add cfg to Peripheral fields #181
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @korken89 (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. |
I tested by compiling the crate for all |
The commented line (28) in //println!("cargo:rustc-cfg=armv7em"); It was added by @adamgreig here. Should we remove the comment, merge the two blocks, ignore the clippy lint? |
I'd remove the commented out code, replacing with a note as to why armv7em isn't there (if appropriate). Edit: We should merge the two identical if statement arms as well. |
Done! The "e" in |
Looking good. Just a couple of questions about v6m vs v8m.base. I'm sure what you've done is right, but I felt it was worth double checking. |
Thanks! I can not see the questions that you have 👀 |
They're inline comments that should appear in the source code diff view. |
Hah. And I need to click 'Submit'... |
Adding conditional compilation to the fields of this structure is a breaking change. For the same reason as https://github.com/rust-embedded/cortex-m/pull/180/files#r360940824 The reason these fields are not conditionally compiled is because destructuring this structure or referencing its fields would otherwise become inconvenient (e.g. see cortex-m-rtfm where the fields are referenced but never used). As |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The references are taken from the Armv8-M ARM.
Here is an image from the reference manual presenting the availability of the debug features in Mainline or Baseline:
You are right and I did not think about mentioning the fact that this is indeed a breaking change! Does it have any consequences on the changes themselves? I guess because of that it will have to be tagged as a new major version?
Makes sense! Would you say it is better to leave it as it was before then? I think that having But as it was said in the other PR, it also makes more sense to have |
I'm starting to wonder if inferring the Processor model (e.g. Cortex-M4), and its associated peripherals, from the architecture/instruction-set (e.g. ARMv7E-M), which is given by the target (e g. thumbv7em-none-eabi) is actually a good idea. As the instruction sets are backwards compatible, what if I wanted to write a portable binary that ran on a Cortex-M3, M4 and M33, and used runtime feature detection to determine what peripherals were available? I would want ARMv7-M instructions, but acess to the M33's peripherals. Or what if some future peripheral is added to some mythical Cortex-M5, but which otherwise implements ARMv7E-M? Or, what if some CPU doesn't have the features outlined in the relevant ARM as Optional? The LLVM backend generally has a distinction between TARGET and CPU. I wonder if we can make use of that, and if we can, whether we should. |
Is the main goal of those It is true that some Arm C compilers (the ones that I know) give you the option of choosing either the architecture or the CPU but in Rust there is only the target switch. Having the possibility to choose a specific CPU could help having more precise The way I think about those |
I guess I need to rebase because of 6ac19a5. |
So #193 is in now, so we're fine with |
I would say so! It would also mean that if a consumer of this crate wants to target multiple architectures, he would have to somehow use the same build configs: if target.starts_with("thumbv6m-") {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv6m");
} else if target.starts_with("thumbv7m-") {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv7m");
} else if target.starts_with("thumbv7em-") {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv7m");
println!("cargo:rustc-cfg=armv7em"); // (not currently used)
} else if target.starts_with("thumbv8m.base") {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv8m");
println!("cargo:rustc-cfg=armv8m_base");
} else if target.starts_with("thumbv8m.main") {
println!("cargo:rustc-cfg=cortex_m");
println!("cargo:rustc-cfg=armv8m");
println!("cargo:rustc-cfg=armv8m_main");
} Those would become more "standard". |
bors r+ |
👎 Rejected by label |
I think needs the clippy allow from #189 to land first, then it will build. |
bors r+ |
👎 Rejected by label |
@jonas-schievink - you added the |
Yeah, #181 (comment) has not been addressed yet. |
But didn't #193 fix that? |
No, that future-proofed cortex-m for when new fields get added, but libraries can still move all current fields out of That doesn't mean we shouldn't do this, since IMO it does make things more clear, but this is a pretty big drawback. Maybe we can find a better solution that directly addresses what RTFM wants to do (which is use certain core peripherals for itself and only hand the remaining ones to the user), but I don't know how that would look. Sounds like a good thing to bring up at the next meeting though. |
Ok, the outcome of the meeting was:
So, I think we agreed we'd close this. |
On the whole I agree with #181 (comment) but one alternative idea: we could instead add some cortex-m features such as That way, most users can have a smaller Peripheral struct that relates to just their CPU without the overhead of loads of unused/inaccessible fields, we can simplify cortex-m's build.rs as well as having it make more sense than the current not-quite-right "thumbv6m == cortex-m0" logic, and crates wanting to destructure |
Update cfg attributes and code documentation to take into consideration the new Armv8-M architecture profiles. Signed-off-by: Hugues de Valon <hugues.devalon@arm.com>
Thanks for the update! The main reason for this PR was to address one comment of my other PR adding the SAU peripheral that is still pending. I think the idea around adding cortex-m features per CPU should probably be discussed in another issue. I have updated this one, removing the |
bors r+ |
👎 Rejected by label |
@jonas-schievink I modified this PR to only be an update of code documentation and add |
bors r=thejpster |
Build succeeded: |
The cfg conditional compilation attribute was only set on impl blocks of peripherals. This commit also sets it on the fields themselves to be more consistent.
Also adds Armv8-M Baseline to the blacklist of the ITM peripheral (cf rule
FMQF
of the Armv8-M ARM).