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

Add initial Drop for numerous drivers #2484

Closed
wants to merge 3 commits into from

Conversation

JurajSadel
Copy link
Contributor

Thank you for your contribution!

We appreciate the time and effort you've put into this pull request.
To help us review it efficiently, please ensure you've gone through the following checklist:

Submission Checklist 📝

  • I have updated existing examples or added new ones (if applicable).
  • I have used cargo xtask fmt-packages command to ensure that all changed code is formatted correctly.
  • My changes were added to the CHANGELOG.md in the proper section.
  • I have added necessary changes to user code to the Migration Guide.
  • My changes are in accordance to the esp-rs API guidelines

Extra:

Pull Request Details 📖

Description

Please provide a clear and concise description of your changes, including the motivation behind these changes. The context is crucial for the reviewers.

Testing

Describe how you tested your changes.

I will add more info about status/issues I've encountered etc later today or tomorrow morning. Opening as a draft until then.

cc #1382

Copy link
Contributor

@bugadani bugadani left a comment

Choose a reason for hiding this comment

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

I'm slightly worried about placing peripherals back into reset. Since we always call reset before/after enable, I think we might do the following changes:

fn reset should just assert reset, and shouldn't release it.
fn enable should just release the reset, and enable clocks
fn disbale should just disable clocks and not assert reset.

esp-hal/src/system.rs Outdated Show resolved Hide resolved
Comment on lines +989 to +990
REF_COUNTER.fetch_sub(1, Relaxed);
if REF_COUNTER.load(Relaxed) == 0 {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
REF_COUNTER.fetch_sub(1, Relaxed);
if REF_COUNTER.load(Relaxed) == 0 {
if REF_COUNTER.fetch_sub(1, Relaxed) == 1 {

There's no reason to read one more time.

Copy link
Contributor

Choose a reason for hiding this comment

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

This Drop also means new_internal should no longer enable clocks. Otherwise it's possible to create Rmt (enables clocks), then drop it (it won't disable clocks because no Channels have been created).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, this is a failed try for peripherals that has Channels/Operators etc. We come up with this idea with @bjoernQ but yeah, it's not quite good yet. I just wanted to keep it here (for now) to show what kind of issues we have to solve (or think of).

@@ -314,7 +314,7 @@ where
fn new_inner(usb_device: impl Peripheral<P = USB_DEVICE> + 'd) -> Self {
// Do NOT reset the peripheral. Doing so will result in a broken USB JTAG
// connection.
PeripheralClockControl::enable(crate::system::Peripheral::UsbDevice);
PeripheralClockControl::enable(crate::system::Peripheral::UsbDevice, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just noting that we'll have to make sure dropping UsbSerialJtag doesn't reset the peripheral. Which is borderline impossible to do now :)

@bjoernQ bjoernQ mentioned this pull request Nov 15, 2024
6 tasks
@bugadani
Copy link
Contributor

Closed via #2544

@bugadani bugadani closed this Nov 21, 2024
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