-
Notifications
You must be signed in to change notification settings - Fork 1.2k
stm32/adc/v3: added support for DMA based adc sampling #4583
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
Conversation
|
@Dirbaio Okay to merge? |
|
hey @lulf , any reason not to merge this? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @maor1993,
To add compatibility in a STM32G0, some minor changes should be done. I tested those modifications in a STM32G071CBUx, and seems to work fine.
* spelling mistakes fixed * added required changes to ringbufferedadc to support G0
|
@jduranf can you merge? |
Sorry, no. I'm like you, just wanting this PR to be merged |
|
@Dirbaio , this PR is open for over a month, passes all checks and required by other users, is there a reason not merge this? |
| #[cfg(not(any(adc_g0, adc_u0)))] | ||
| T::regs().cfgr().modify(|reg| { | ||
| reg.set_discen(false); | ||
| reg.set_cont(true); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using continuous and circular mode means you sample as fast as possible for the ADC. This means that the DMA buffer fills up really quickly and care must be taken when setting up the task that reads from the buffer.
As an alternative approach I think you should consider using triggered measurements to control the rate at which new samples are taken. I have started working on this for the g4 series #4786 but it would be good to develop similar APIs for all versions in the long run.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, getting a fast as possible buffer was the point.
this is intended for audio applications where you want a constant stream of samples
in my case I needed to sample 4 analog inputs as fast as possible and only pass to a different task samples that pass some threshold.
as such, by setting the sequence to the highest sample time I was able to get super fast samples without needing to retrigger the ADC, essentially acting as a clock source for the audio pipeline
while the device I used, stm32l412kb does not support changing the clock to the ADC, other devices do.
alternatively you can also drive the conversion starts from a timer, as such this will ensure the ADC is always ready to provide samples and the relevant task will be awaken every time the DMA buffer is half full.
|
I've not been around for a while, but barring objections from @lulf and @Dirbaio I'm going to try to get these ADC pull requests merged. For me, ideally I would like to see a consistent interface across all versions. So let's see what we have here: This version of adc ringbuffer:
Existing version of adc ringbuffer:
Just from a glance, I prefer what you've done, allowing the sequence to be passed to the constructor, rather than set as a method. To be honest, the existing ringbuffer seems like an attempt to work around the under-developed v2 mod. The largest objection that I have is the public new constructor for the ringbuffer. There should be one way to obtain a ringbuffer, If you remove the |
Thanks for the effort, will |
yes, that's fine. |
👍🏾 done |
|
@xoviat Thanks for reviewing and merging, feel free to pick up the stm32 PRs that have been around for a while, I don't have much bandwidth or technical insight into stm32 to follow up on the more complex ones. |
A lot of the code is based / copied from
ringbuffered_v2.rsI did make several changes I hope are accepted
1. V3 adc dma is not seperated to its own file to lower the amount of code duplication2. ADC dma will not halt/kill DMA on overrun, allowing the user the freedom to handle the error as they wish
3. User has access to
disable_adc, which allows to pause ADC and DMAtested on stm32l412kb6u and stm32l432kc