Skip to content

Use safe-mmio crate in PL011 UART driver example and RTC exercise solution #2752

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

qwandor
Copy link
Collaborator

@qwandor qwandor commented May 16, 2025

No description provided.

@qwandor qwandor force-pushed the aarch64 branch 3 times, most recently from d150008 to b583093 Compare May 16, 2025 14:19
@qwandor qwandor requested a review from djmitche May 16, 2025 14:20
@qwandor qwandor force-pushed the aarch64 branch 3 times, most recently from 861086f to dfc78c0 Compare May 16, 2025 19:55
@qwandor qwandor requested a review from mgeisler May 23, 2025 19:04
@mgeisler
Copy link
Collaborator

Use safe-mmio crate in PL011 UART driver example and RTC exercise solution

A question that comes to mind is why?

I see that you're replacing some raw pointers and hand-written structs with something from a new crate. What is the benefit?

Put differently, before, I could reason about the code directly. Now, I need to know something about the two crates that are in use. So it almost seems like a step back from a pedagogical point of view?

@mgeisler
Copy link
Collaborator

Ah, I read a bit more and it seems that this allows one to avoid calling unsafe methods? That's of course nice.

Would it be useful to show students both the hand-written version we have used up until now, and also the nice abstracted version you have in this PR?

Copy link
Collaborator

@mgeisler mgeisler left a comment

Choose a reason for hiding this comment

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

Feel free to merge since I understand that you would like to show people how safe and nice the API can be. But consider the learning opportunity of hand-writing the more low-level approach as well.

@qwandor
Copy link
Collaborator Author

qwandor commented May 28, 2025

Feel free to merge since I understand that you would like to show people how safe and nice the API can be. But consider the learning opportunity of hand-writing the more low-level approach as well.

True, using safe-mmio obscures a bit what is actually going on, which makes it more difficult to explain. It's also an opinionated choice. On the other hand, I want to make the final driver we end up with an example of good practice, because I've seen that people tend to copy and paste the examples from this course as a starting point for writing their own code.

I think this is a tricky balance we have in a lot of the course, between teaching the fundamentals of how the Rust language works, and showing the practical side of how to write good idiomatic Rust code. I'm inclined to have more of the latter, as people are going to go away from this course to work on new projects in Rust, sometimes without an experienced Rust developer on their team, and so I think it's important to set them up to write good Rust code right away.

One option I considered was to keep the old version as a step along the way, and then have another slide where we go through and refactor it to an improved version using safe-mmio. I'm worried that makes for too many steps though, as we already have the first version in pl011_minimal.rs using a single raw pointer.

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