2017-05-24 09:59 AM
Hi,
I'm using an STM32F446.
I use the circular DMA feature with a DAC output to generate a sinus waveform.
My sinus buffer has 32 values.
What I would like to do is :
- run the DMA for a 'large' amount of time
- be able to stop the DMA when I want, but only at end of buffer (so that the latest data sent to the DAC output is known and fixed).
I tried to change the 'circular mode' to 'normal mode' while the DMA is running (supposing the DMA would continue until end of buffer), but it doesn't work.
I know one of the way is to run in 'normal mode' and use the 'HALF-DMA' interrupt, but I would like to avoid this because it increases CPU load due to the interrupt.
Any idea ?
Thanks for help.#dac-dma-circular-buffer2017-05-24 04:44 PM
Don't know of any trivial way, except simply giving the transfer-complete interrupt a high enough priority and stop it at that moment.
Other way may be to stop the source of DMA trigger, again precisely enough in time.
JW
2017-05-25 01:32 AM
Hey, VDM, I am free this afternoon!
Just using Cube MX to generate a little project to test your requirement.
You can download the attached project to see if it's really whatyou need !
(using STM32F446 Nucleo board)
The dma setting is still in circular mode. Using TIM2's update event to trigger dac.
As to stop the dac only in the end of buffering,
I implemented aDAC_OFFRequest flag and a dac dma call backHAL_DAC_ConvCpltCallbackCh1.
Every time the 32 data are transferred , this callback is called. And IFthe turn off flag is set, the callback function will stop the dac.
I also use LD2(PA5) pin to trigger the oscilloscope. Toggle high as a DAC_OffRequest is set.
________________ Attachments : DAC_DMA_SINE.rar : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006Hyao&d=%2Fa%2F0X0000000bAS%2FYCgk_N4FuAiFwD1jV98z71M0UQyeWmTz73VpTElrDME&asPdf=false2017-05-25 05:18 AM
Thanks
Liu.Zhitai
I'm not used to Cube MX, I'm that kind of guy that mostly works 'from scratch', but it seems your answer is the same as
Waclawek.Jan
: just set a high priority IT at end of DMA transfer and stop it ASAP.I'll try that, thank you for your answers.