32F417 DMA double buffer mode
Hi All,
I have a waveform generator which uses TIM4 to trigger the DACs and they trigger DMA to transfer 32-bit words to the DACs (concurrently).
I am using the DMA double buffer mode. So I have two source pointers, which are supposed to get flipped each time the transfer count reaches zero.
// CT is bit 19; 1 = wavebuf1 is being read, so we can update wavebuf0.
// It was found that this check is not needed; there were no artefacts anyway.
if ((DMA1_Stream5->CR & (1<<19)) != 0)
{
wavebuf0[i]=dac1val|(dac2val<<16);
}
else
{
wavebuf1[i]=dac1val|(dac2val<<16);
}I have it more or less running but found a couple of things which I'd like to clarify:
1) The double buffer mode seems pointless because one can write to the buffer(s) anyway at any time, with no artefacts on the output waveform. Am I right that this mode is intended for when you want to always start with a fresh and complete buffer? In lots of cases one could just use a single buffer and write to the top or the bottom half according to the value in the DMA address pointer.
2) AIUI, the DMA flips the CT bit (bit 19 in CR) at the end of each transfer and I think it does it when the transfer count reaches zero. So if one stops the transfer before the count reached zero, am I right that bit will never get flipped? That seems to be what I found, and I am now flipping it manually, and ensuring a) the DMA is disabled and b) it is done via a copy of CR and not by doing RMW on CR.