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 #3805 #3806

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

Fix #3805 #3806

wants to merge 6 commits into from

Conversation

Tnze
Copy link

@Tnze Tnze commented Jan 25, 2025

We must register the waker before enabling the EOC interrupt and starting convert

@Tnze
Copy link
Author

Tnze commented Jan 25, 2025

TODO:

  • Call unsafe { NVIC::unmask(pac::interrupt::ADC1_2) }; somehow. I don't know
  • Apply this to other chips Doesn't need

});
T::regs().cr1().modify(|w| w.set_eocie(true));

let mut started = false;
Copy link
Member

Choose a reason for hiding this comment

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

I think this shouldn't be needed, it should be OK to start the conversion before registering the waker. Even if the conversion finishes "too soon" the task will see EOC is set and return Ready.

Are you sure these changes are needed to make it work? The "enable interrupt" you added in new is not enough?

Copy link
Author

@Tnze Tnze Jan 27, 2025

Choose a reason for hiding this comment

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

The calling convention is that the operation should be apply when the first time poll is called.

Copy link
Author

Choose a reason for hiding this comment

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

According to https://doc.rust-lang.org/std/future/trait.Future.html#tymethod.poll

Futures alone are inert; they must be actively polled to make progress, meaning that each time the current task is woken up, it should actively re-poll pending futures that it still has an interest in.

We should do nothing before the Future is polled. (even though the outer asynchronous function will generate such Future, let the internal poll_fn follow this is definitely better)

Copy link
Author

Choose a reason for hiding this comment

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

Also noticed that

Note that on multiple calls to poll, only the Waker from the Context passed to the most recent call should be scheduled to receive a wakeup.

I will fix it.

Copy link
Member

Choose a reason for hiding this comment

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

The calling convention is that the operation should be apply when the first time poll is called.

convert is already an async fn. All the code in an async fn is already executed only after polling the future for the first time (the future autogenerated by the compiler for async fn convert()) The poll_fn future is just an "inner" future that the user never sees.

Copy link
Author

Choose a reason for hiding this comment

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

You are right. But it's nice to make internal Future follow the convention. And I can't see disadvantage there.

Copy link
Member

@Dirbaio Dirbaio Jan 27, 2025

Choose a reason for hiding this comment

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

You are right. But it's nice to make internal Future follow the convention. And I can't see disadvantage there.

It makes the code use a bit more flash, it makes it slightly slower, and it is inconsistent with the rest of embassy-stm32.

And I think the change also prevents duplicated trigger the conversion.

it doesn't. code inside an async fn runs only once, the compiler tracks the state of it.

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