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

More granular circular DMA #242

Open
rudihorn opened this issue Jun 30, 2020 · 3 comments
Open

More granular circular DMA #242

rudihorn opened this issue Jun 30, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@rudihorn
Copy link
Contributor

Currently circular DMA is implemented in a way where the circular buffer has two buffer halves, and then once one buffer half has been filled the buffer half can be read while the next one is filled. If one would like to use a larger buffer e.g. 256 bytes, this means that to use it "properly" one would need to wait until 128 bytes have been filled, making this approach only useful for bulk transfers.

There is another approach, which is to use the DMA_CNDTRx register (STM32 reference manual 13.4.4) to determine the number of bytes the DMA still has to write until the end of the buffer and use it to calculate the number of bytes already transferred into the buffer. Specifically something along the lines of cndtr_last - cndtr (and add the buffer length if negative) should return the number of bytes in the buffer.

I would suggest renaming the current CircBuffer to CircBufferHalves and then implementing new CircBuffer behaviour which provides functions has_data length dequeue or similar.

If something like this makes sense I can try putting together a pull request.

@TheZoq2
Copy link
Member

TheZoq2 commented Jul 2, 2020

I haven't worked with circular buffers yet, but it sounds like it would be nice to have :) I'm not sure how easy it would be to make it work with the ownership system

Also, I vaguely recall there being some discussion about adding DMA traits to embedded-hal, but I can't find that at the moment

@TheZoq2 TheZoq2 added the enhancement New feature or request label Jul 2, 2020
@rudihorn
Copy link
Contributor Author

rudihorn commented Jul 2, 2020

would be nice to have

I mainly just wanted to hear that it isn't a bad thing to do. I would be interested in implementing this, so I will try hacking something together this weekend probably. I'll see if embedded-hal mentions anything, though regardless I'm sure it would be roughly the same.

@TheZoq2
Copy link
Member

TheZoq2 commented Jul 3, 2020

I would be interested in implementing this, so I will try hacking something together this weekend probably.

Sounds great, let me know if you run into any issues :)

I'll see if embedded-hal mentions anything, though regardless I'm sure it would be roughly the same.

The main concern is if embedded-hal is close to finishing their API, in which case we'd have to rewrite parts of it once that gets released.

Also, you'll probably want to have a look at #239 in which I'm changing part of the DMA API. I'll try to finish that conversion today in case you want to base your impl on that

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants