-
Notifications
You must be signed in to change notification settings - Fork 182
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
adc-dma timer #99
adc-dma timer #99
Conversation
Looks like the build failed for |
Example: reading multiple ADC channels using DMA. Note: this example uses PR that has not yet been merged: see stm32-rs/stm32f1xx-hal#99 Signed-off-by: Sergey Matyukevich <geomatsi@gmail.com>
Hi @burrbull , Thanks for working on extremely useful DMA bits ! I have been testing suggested functionality using the following simple setup:
It looks like suggested use of Here is a patch on top of your PR that made things work properly for me:
Thoughts ? Comments ? Regards, |
Thank you for testing. I could not do it last month. And you are right:
|
I tried to do changes compatible with existent code base and forgot about mode. What about make generic |
src/adc.rs
Outdated
14 => self.rb.smpr1.modify(|_, w| w.smp14().bits(sample_time)), | ||
15 => self.rb.smpr1.modify(|_, w| w.smp15().bits(sample_time)), | ||
16 => self.rb.smpr1.modify(|_, w| w.smp16().bits(sample_time)), | ||
17 => self.rb.smpr1.modify(|_, w| w.smp17().bits(sample_time)), | ||
_ => unreachable!(), | ||
} | ||
|
||
return; |
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.
clippy
suggests to remove this return
src/adc.rs
Outdated
fn set_sequence(&mut self); | ||
} | ||
|
||
impl<PIN> SetChannels<PIN> for Adc<ADC1> |
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.
In basic OneShot
implementation single channel sequence is configured in convert
function. In the case of multiple channels, we have to implement SetChannel
anyway to specify particular list of channels. So could you please clarify why do we need this implementation of SetChannels for single channel ? Does it help to maintain backward compatibility for with_dma
?
3080353
to
679a898
Compare
impl Adc<ADC1> { | ||
pub fn with_dma<PINS>(mut self, pins: PINS, dma_ch: C1) -> AdcDma<PINS> | ||
pub fn with_dma<PIN>(mut self, pins: PIN, dma_ch: C1) -> AdcDma<PIN, Continuous> |
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.
Just a nitpick: pin
instead of pins
?
Looks good and works fine. Thanks ! Do you have any specific plans about stm32f100 build failure ? |
Waiting for stm32-rs release. |
Hi @burrbull and all, I did more experiments with ADC/DMA trying to re-configure ADC channels to read for each new transfer. The sequence of operations is as follows:
Full example is available here It turned out, that this approach provided incorrect results. In particular, readings were shifted as if DMA was started from the last ADC channel of the previous configuration. To be more specific, suppose that I have the following levels on ADC inputs:
If I don't switch between these two channel configurations, then I get proper readings:
However if I switch between those configurations after each reading, then I get the following readings:
It looks like DMA somehow does not reset its starting position after
Though I am not really sure if this is the right thing to do... Thoughts ? Comments ? Regards, |
Is the build error here related to stm32-rs/stm32-rs#270? |
As far as I can see, required ADC changes have been merged to stm32-rs, so we are waiting for release v0.9.0. Meanwhile I failed to build the following setup:
The build failed for all the 3 targets stm32f10[013]. The root cause was in some name changes for
Regards, |
Does it work as expected with disabling ADC? |
Not sure what you mean. Could you please clarify your question ? I did not test with up-to-date stm32-rs. I am testing with stm32f101 where your current version is working fine. But in my tests I still use additional patch #99 (comment) on top of your PR to make sure that DMA is properly reset on split. |
Rebased. |
@burrbull Would you mind rebasing this again? :) |
Rebased |
Looks like some great changes, thanks! |
cc @TheZoq2
cc @therealprof