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

Fix interrupt::free. #433

Closed
wants to merge 9 commits into from

Conversation

reitermarkus
Copy link
Member

@reitermarkus reitermarkus commented Apr 22, 2022

Don't pass CricialSection to closure passed to interrupt::free.

Depends on rust-embedded/critical-section#13.

@reitermarkus reitermarkus requested a review from a team as a code owner April 22, 2022 12:27
@rust-highfive
Copy link

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @adamgreig (or someone else) soon.

Please see the contribution instructions for more information.

@rust-highfive rust-highfive added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m labels Apr 22, 2022
@adamgreig
Copy link
Member

Thanks for the PR! We discussed this a bit in last week's meeting here; the trouble is basically that interrupt::free() doesn't meet the guarantees required by CriticalSection on multi-core systems or systems executing in unprivileged mode. Ultimately the solution is probably to move towards something like the critical-section crate (possibly integrating that into bare-metal). In the meantime for cortex-m 0.8, it might be best to actually have interrupt::free() not give the closure a CriticalSection token at all, and just execute the closure in the context of disabled interrupts. That's still useful, but it wouldn't permit safe access to a Mutex any longer, so we'd want something else in place before releasing 0.8.

@reitermarkus
Copy link
Member Author

I guess in this case we need three things:

  • interrupt::free which does not pass a bare_metal::CriticalSection section.
  • Implementation of critical_section::CriticalSection for single and multi-core.
  • Some function which does pass a bare_metal::CriticalSection to a closure so we can actually lock a bare_metal::Mutex.

@thejpster
Copy link
Contributor

As far as I am aware, you can’t implement it for multi-core devices using only the standard Cortex-M peripherals. For example, on the Raspberry Silicon RP2040 you need to use the Spinlock registers in the SIO peripheral.

I also don’t think you could even know you were on a multi-core system using only the standard Cortex-M peripherals.

@reitermarkus
Copy link
Member Author

The critical_section::CriticalSection implementation would have to be an opt-in feature anyways.

I think it makes sense to then have a HAL either provide this implementation or opt into the single-core version in this crate.

@thejpster
Copy link
Contributor

I think the HALs should provide an implementation. I’m unsure whether it’s ok for them to re-export one from here. Perhaps if it’s behind a feature flag, or in a macro, it’s OK.

@reitermarkus
Copy link
Member Author

I’m unsure whether it’s ok for them to re-export one from here.

Not sure what you mean by re-export here. The HAL (for a single-core chip) will then simply activate the cortex-m/singlecore feature.

@reitermarkus
Copy link
Member Author

Some function which does pass a bare_metal::CriticalSection to a closure so we can actually lock a bare_metal::Mutex.

Ah, critical_section::CriticalSection is a re-export of bare_metal::CriticalSection, I though it would have to be the other way around. So critical_section::with already allows this.

@reitermarkus reitermarkus force-pushed the fix-interrupt branch 6 times, most recently from 4a9b53d to a3c5b41 Compare May 5, 2022 20:40
@reitermarkus reitermarkus force-pushed the fix-interrupt branch 5 times, most recently from eb2dc48 to d055118 Compare May 8, 2022 11:24
bors bot added a commit to rust-embedded/wg that referenced this pull request Jul 27, 2022
627: I would like to join the HAL team. r=adamgreig a=Dirbaio

I would like to

- Help with `embedded-hal` development. Getting the `1.0` release done, helping with async, reviewing...
- Adopt [`critical-section`](https://github.com/embassy-rs/critical-section) into the WG as the official cross-arch critical section abstraction. See rust-embedded/cortex-m#433, also discussed in some WG meetings previously. (I guess HAL is the most fitting team for it?)

Thank you!

~ Dario Nieuwenhuis

Co-authored-by: Dario Nieuwenhuis <[email protected]>
@Dirbaio
Copy link
Member

Dirbaio commented Jul 28, 2022

I've released critical-section 1.0.0-alpha.1. Unless concerns are found, I think it's likely this'll be the final 1.0 design.

bors bot added a commit that referenced this pull request Aug 11, 2022
447: Add implementation for critical-section 1.0 r=adamgreig a=Dirbaio

Picking up #433 since it seems stalled. Changes from #433 are:
- Update to `critical-section 1.0.0-alpha.2`
- Use `bool` restore token
- Name Cargo feature `critical-section-single-core`.

TODO before merging:

- [x] Wait for `critical-section 1.0` release rust-embedded/critical-section#19

Co-Authored-By: Markus Reiter `@reitermarkus` 

Co-authored-by: Dario Nieuwenhuis <[email protected]>
bors bot added a commit that referenced this pull request Aug 12, 2022
447: Add implementation for critical-section 1.0 r=adamgreig a=Dirbaio

Picking up #433 since it seems stalled. Changes from #433 are:
- Update to `critical-section 1.0.0-alpha.2`
- Use `bool` restore token
- Name Cargo feature `critical-section-single-core`.

TODO before merging:

- [x] Wait for `critical-section 1.0` release rust-embedded/critical-section#19

Co-Authored-By: Markus Reiter `@reitermarkus` 

Co-authored-by: Dario Nieuwenhuis <[email protected]>
@reitermarkus
Copy link
Member Author

Fixed in #447.

@reitermarkus reitermarkus deleted the fix-interrupt branch December 4, 2023 20:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-cortex-m
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants