Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@bradjc
Copy link
Contributor

@bradjc bradjc commented Oct 9, 2025

Pull Request Overview

This pull request converts the nrf5x crate to be forbid unsafe. This is in some ways an example of what it might look like to try to split our chip crates into safe and unsafe, with all of the drivers moved to safe, and the instantiations in unsafe.

There are hidden static mut in the nrf5x crate which I removed. The AES change was bigger than anticipated and needs testing.

I removed the pinmux check. Having a global variable for that runtime check does not seem worth it.

Testing Strategy

todo

TODO or Help Wanted

n/a

Documentation Updated

  • Updated the relevant files in /docs, or no updates are required.

Formatting

  • Ran make prepush.

Copy link
Member

@alevy alevy left a comment

Choose a reason for hiding this comment

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

This is doing a lot much which seems pretty undesirable to me, particularly moving a lot of functionality that should be the responsibility of a chip into the board.

I'd advocate for this being converted to a draft PR, as potentially a basis for discussion of whether/which features should move where to enable no-unsafe or minimize unsafe in certain chip crates.

Moreover, merging a design pattern change like this whole cloth for just one chip, rather than more targeted parts of the design pattern across all chips, seems worse to me. It means chip-developers are going to end up with conflicting sources for what responsibilities each component should have.

@bradjc
Copy link
Contributor Author

bradjc commented Oct 9, 2025

a basis for discussion of whether/which features should move where to enable no-unsafe or minimize unsafe in certain chip crates.

This would be very helpful. This PR only changes boards in two ways:

  1. Provide a second static buffer to create the default chip peripherals. Boards were already providing one. So adding two follows an existing pattern.
  2. Requires that creating pins needs passing in the registers. This avoids the pin constructor using unsafe to define its own registers. It's entirely possible this could be refactored somehow.

Questions for designs:

  1. Where should StaticRef::new() be called?
  2. Should we remove static mut buffers from chips? If so, where does the buffer come from?
  3. Should chips define components that boards can use to create the default peripherals?
  4. How badly do we actually want to remove unsafe from chips? The way the nrf5x gpio implementation hacks the MMIO address based on the pin number is pretty cute.

@bradjc
Copy link
Contributor Author

bradjc commented Oct 9, 2025

Moreover, merging a design pattern change like this whole cloth for just one chip, rather than more targeted parts of the design pattern across all chips, seems worse to me. It means chip-developers are going to end up with conflicting sources for what responsibilities each component should have.

Changing all chips is hard. And harder to test. I would advocate for converting the nrf5 stack into the beacon example, writing docs around that example, and then telling people that is the example.

@tyler-potyondy
Copy link
Contributor

As a sidenote, I'm glad to see the Nrf5x aes implementation updated to use a TakeCell. The existing implementation is unsound with regards to DMA.

@bradjc
Copy link
Contributor Author

bradjc commented Oct 10, 2025

As a sidenote, I'm glad to see the Nrf5x aes implementation updated to use a TakeCell. The existing implementation is unsound with regards to DMA.

Unfortunately I'm pretty sure it still is, but hopefully this is easier to fix whenever DmaCell is created.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants