Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

improve SX12xx/SPI read performance #29

Closed
wants to merge 3 commits into from
Closed

Conversation

oll3
Copy link
Contributor

@oll3 oll3 commented Sep 23, 2023

Main point of PR is to read all bytes from SX12xx chip with a single SPI transfer. This instead of reading one byte at a time.
This since reading all bytes with one operation is much more performant, especially when reading longer packets and when DMA is used.

While at this some other small things caught my eye. Like repeating some register operations a lot, so did some cleaning there too.

Instead of reading a single byte at a time - read all bytes with a single SPI transfer.
This is much more performant, especially when reading longer packets and when DMA is used.

Also remove the special case of read() (read_with_status()) since it's the same operation as a regular read, just with the first byte read being status.
@ceekdee ceekdee self-requested a review September 23, 2023 22:25
@ceekdee ceekdee added the ?.x.? release Non-breaking enhancement release label Sep 23, 2023
@ceekdee
Copy link
Collaborator

ceekdee commented Sep 23, 2023

First off, thank you for the effort to improve the performance of this crate. It's great to see that level of work here.

I would like to understand your test environment (embedded framework, MCU, LoRa board), if you can share that information. Also, it would be good to know if you are using lora-phy for P2P or LoRaWAN. If you are using Embassy, you would have needed to take some steps to get that working with lora-phy version 2 (the GitHub main branch), since Embassy itself still uses version 1.

The reason I ask is I was unable to run a simple P2P receive example with this update, and had read issues when executing a more complicated LoRaWAN case on which I am working. Both of these tests use a recent version of Embassy. We'll work that out as we move forward.

For reference, this is what I used for a patch to test with Embassy, which hopefully pulls in your update in its entirety:

[patch.crates-io]
lora-phy = { git = "https://github.com/embassy-rs/lora-phy", rev = "143229c4bcebe546d691d69054eb0e1675b156fe"}

@oll3
Copy link
Contributor Author

oll3 commented Sep 24, 2023

Atm I run a fork of lora-phy on my board, but with embassy. Only p2p.
These are some of the modifications I've done on the fork which I thought could benefit the upstream project. But I was a bit optimistic to not test them in isolation. Will do and come back.

@ceekdee
Copy link
Collaborator

ceekdee commented Sep 24, 2023

For your planning purposes, I will be unavailable from September 27 through October 23. Given the significance of this update, I doubt I will be able to adequately review and test it before I leave. I apologize.

@oll3
Copy link
Contributor Author

oll3 commented Sep 27, 2023

Did some quick testing and I could send P2P, but on the receiving side it seems to get stuck in the irq processing loop once it actually receives something. Same behavior with just the single read operation fix. Will investigate further at a later time.

@plaes
Copy link
Contributor

plaes commented Sep 28, 2023

Nice work! I'm currently attempting to adapt the existing sx1276_7_8_9 driver to work with sx1272 and can at least send out the packets with this patchset.

Also, would it make sense to include simpler single-buffer write/read methods in the SpiInterface impl? It seems that multi-buffer write is only used for sx1261 in a single location (add_register_to_retention_list).

@lucasgranberg
Copy link
Collaborator

Did some quick testing and I could send P2P, but on the receiving side it seems to get stuck in the irq processing loop once it actually receives something. Same behavior with just the single read operation fix. Will investigate further at a later time.

Did you find the time to investigate?

@oll3
Copy link
Contributor Author

oll3 commented Oct 16, 2023

Also, would it make sense to include simpler single-buffer write/read methods in the SpiInterface impl? It seems that multi-buffer write is only used for sx1261 in a single location (add_register_to_retention_list).

I did notice this too, that some functions are written to handle these edge cases which might make normal use of them a bit convoluted. So personally I think it could make sense and might make some parts easier to follow.

Did you find the time to investigate?

Not yet unfortunately, a bit busy elsewhere atm. But it's on my to-do list!

@CBJamo CBJamo mentioned this pull request Oct 16, 2023
@oll3
Copy link
Contributor Author

oll3 commented Oct 26, 2023

Closing since #35 fixed main point of this PR.

@oll3 oll3 closed this Oct 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
?.x.? release Non-breaking enhancement release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants