nrf-hal icon indicating copy to clipboard operation
nrf-hal copied to clipboard

Implement a polling async SPI interface

Open dflemstr opened this issue 4 years ago • 9 comments

Addresses a part of #128. The existing code was moved around and with an optimizing compiler I expect it to generate the same code as before.

There are also new polling versions of the transfer functions that don't block. The idea is that one could call these from interrupt handlers to get non-blocking/low power SPI transfers. The returned types intentionally don't implement core::future::Future since that would require waker management.

See https://github.com/dflemstr/embedded-platform/tree/master/platforms/nrf52840 for higher-level async code that could be supported by this change.

dflemstr avatar Jan 23 '20 22:01 dflemstr

Thank you for the pull request, @dflemstr! It seems that nobody (including me) has the time to look into it right now. Sorry!

Feel free to ping @nrf-rs/nrf52 and @nrf-rs/nrf91, to remind us, if you feel it's taken too long.

hannobraun avatar Jan 28 '20 06:01 hannobraun

Pinging @nrf-rs/nrf52 and @nrf-rs/nrf91 :)

dflemstr avatar Feb 14 '20 11:02 dflemstr

I couldn't find any place where this code calls set_low on the chip select pin. Is that handled differently or is this missing?

jonas-schievink avatar Feb 14 '20 22:02 jonas-schievink

I think this looks basically fine now. Have you tested this on real hardware?

jonas-schievink avatar Feb 21 '20 20:02 jonas-schievink

I have tested it on a Particle Argon, but the SPI slave device (which is custom made...) has a few power glitches (even when using a different master device) so I would appreciate some secondary testing by someone with a more reliable SPI slave device

dflemstr avatar Feb 22 '20 09:02 dflemstr

Isn't this API susceptible to the mem::forget problem ? See https://docs.rust-embedded.org/embedonomicon/dma.html#memforget

thalesfragoso avatar Mar 21 '20 18:03 thalesfragoso

@thalesfragoso how would you recommend that we fix it in this case?

dflemstr avatar Mar 23 '20 19:03 dflemstr

Right now, I see two solutions:

  • 'static borrows, also explained in the embedonomicon: https://docs.rust-embedded.org/embedonomicon/dma.html#static-bound, you can see an example implementation here: https://github.com/stm32-rs/stm32f1xx-hal/blob/master/src/dma.rs (Pin probably wasn't used because it wasn't stabilized back then).

  • Using owning pointers, like this implementation: https://github.com/nrf-rs/nrf52-hal/pull/102, I also did an adaption of that to get rid of the size features, you can see it here: https://github.com/thalesfragoso/usbd-serial/blob/writer-impl/src/pool_serial.rs

thalesfragoso avatar Mar 23 '20 19:03 thalesfragoso

@thalesfragoso @jonas-schievink as you might see from the PR metadata, I've decided to get some clarity around async HAL in https://github.com/rust-embedded/embedded-hal/pull/206 before I'd feel comfortable with picking a direction for how to continue this PR.

dflemstr avatar May 31 '20 20:05 dflemstr