Skip to content
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

Fixed couple of packed unaligned issues #11

Closed
wants to merge 1 commit into from
Closed

Fixed couple of packed unaligned issues #11

wants to merge 1 commit into from

Conversation

blietaer
Copy link

Hey !
Tried and fixed couple of packed unaligned issues.
New to Rust, so these are maybe not 'by the book', but since std:: is not available in such a bare metal approach, I worked around it...
...what do you think ? :)

Cheers,
Ben

@dwbrite
Copy link

dwbrite commented Oct 18, 2022

Just a rando with no horse in this race - I don't see what you're solving here (except the new __nop). Maybe you forgot to commit some changes?

That said, pulling things out into shorter vars can be useful sometimes, but

  • adding another variable into the mix is creating more information to keep in your head while reading,
  • "brw" has no semantic meaning so I have to backtrack to figure out what it actually is anyway, and
  • all of that compounds with the shadowing of brw in watchdog.rs, which will make future refactors much more difficult

and, if you do feel the need to pull things out into vars like this, please don't leave the old code in a comment. We have git for version control so we can see what it was before. The comments just add noise.

Hope I don't come off too harsh - keep at it :)

@blietaer
Copy link
Author

blietaer commented Oct 18, 2022 via email

Comment on lines +50 to +52
let brw = self.pcr[p];
// let mut pcr = core::ptr::read_volatile(&self.pcr[p]);
let mut pcr = core::ptr::read_volatile(&brw);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
let brw = self.pcr[p];
// let mut pcr = core::ptr::read_volatile(&self.pcr[p]);
let mut pcr = core::ptr::read_volatile(&brw);
let mut pcr = core:ptr::read_volatile(&{brw});

We're using brw to Copy values before creating the reference, and the goal is just to align the value before use. Instead of creating a new variable for that copy, we can do this by placing the value in a block {...} which seems a little cleaner imo.

Copy link

@dwbrite dwbrite Oct 20, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if/when we should be using raw pointers instead of copying

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! Maybe cleaner than heavy copy indeed... :)

@dwbrite
Copy link

dwbrite commented Oct 20, 2022

Now I see what you're doing - this is all in response to unaligned references becoming an error: rust-lang/rust#82523

@branan thoughts?

@blietaer
Copy link
Author

Hehe yup, that's the point and I followed the very same link for the work around, although - as they suggested a std:: based solution (and we want/need to avoid std:: here in ARM bare metal) - I went for the ugly copy approach.
Let me check a core:: based approach here maybe.

@dwbrite
Copy link

dwbrite commented Oct 22, 2022

The solution in that post is actually applicable to nostd environments using core, which is a (fairly large) subset of std.

core is the freestanding portion of std (all the parts that don't rely on anything provided by the operating system - e.g. memory allocation and file IO)

@blietaer
Copy link
Author

Ah! OK, then let's revert my change to that approach, I can then probably cancel this P.R. and initiate another (in case we'd like to keep this nice tutorial up-to-date and/or compiling-friendly out-of-the-box (but not any horse in this race either...) ).

@blietaer blietaer closed this by deleting the head repository Dec 19, 2023
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.

2 participants