Skip to content

Docs: clarify how PAC usage is "unsafe" #4226

Open
@natevw

Description

@natevw

In the Embassy book here

The PAC is the lowest API for accessing peripherals and registers, if you don't count reading/writing directly to memory addresses. It provides distinct types to make accessing peripheral registers easier, but it does not prevent you from writing unsafe code.
the claim is made that a PAC:

does not prevent you from writing unsafe code.

It goes on to give an example blinky app using PAC, which at no point uses any actual unsafe blocks. So I do not understand what this introduction is trying to demonstrate. As a beginner I am wondering/guessing that it may be one of these:

  • that perhaps in Rust embedded cultural practice, the entire PAC crate as a whole is simply considered unsafe and just does not mark its functions as such
  • that perhaps the example is really more pseudo-code and in practice would need to be wrapped in various unsafe caveats
    • I didn't try compile/run it but the code otherwise looks like it's supposed to work as-is so I'd be a little surprised if it were broken?
    • especially since in the context I would expect the example to deliberately emphasize just how unsafe using a PAC is given the intro…
  • or perhaps the introductory paragraph is using "unsafe" not in a technical Safe Rust vs. Unsafe Rust way, but more of just a colloquial e.g. "you might configure a register wrong and then your code/board won't work right"?
    • but you could still make those sorts of logic/hardware mistakes with a HAL crate to some extent too
    • and honestly it seems unlikely given the marketing around Rust that such a core term as "unsafe code" would get used generically/casually when talking about low-level API options here

So none of these guesses seems quite right. Could the wording of this section be updated to clarify what it's trying to say?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions