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

[BUG] SPI sleep die at async fn with_completion() #463

Closed
xiaguangbo opened this issue Jul 18, 2024 · 1 comment
Closed

[BUG] SPI sleep die at async fn with_completion() #463

xiaguangbo opened this issue Jul 18, 2024 · 1 comment

Comments

@xiaguangbo
Copy link
Contributor

Running 10/s, can cause problem in minutes or seconds. Won't trigger watchdog, but tokio won't run tasks. In async fn with_completion and async fn spi_transmit_async ... fut adding log printing wil greatly reduce the probability of occurrence.
If change the way use SPI, be no occurrence problem.
I'm not sure which sentence has problem for the time being in spi_transmit_async.

No problem:

let mut dbuf = [0u8; 16];

for i in 0..8 {
    self.spi
    .transaction_async(&mut [
        Operation::Write(&[0xc0 + (i * 2) as u8]),
        Operation::Write(&dbuf[i * 2..i * 2 + 2]),
    ])
    .await
    .unwrap();
}

Have problem:

let mut dbuf = [0u8; 16];

self.spi
    .transaction_async(&mut [
        Operation::Write(&[0xc0]),
        Operation::Write(&dbuf[0..16]),
    ])
    .await
    .unwrap();

spi.rs:

async fn with_completion<F, D>(fut: F, dtor: D) -> F::Output
where
    F: Future,
    D: FnMut(bool),
{
    struct Completion<D>
    where
        D: FnMut(bool),
    {
        dtor: D,
        completed: bool,
    }

    impl<D> Drop for Completion<D>
    where
        D: FnMut(bool),
    {
        fn drop(&mut self) {
            (self.dtor)(self.completed);
        }
    }

    let mut completion = Completion {
        dtor,
        completed: false,
    };

    let result = fut.await; // There is acertain chance of stop.

    completion.completed = true;

    result
}
@xiaguangbo
Copy link
Contributor Author

use sync api

@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Aug 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

1 participant