Using DMA in Circular mode does not update the data array
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-07-25 7:41 AM
Hi guys,
I'm working on STM32F746-Discovery and I'm trying to read through DMA the digital microphone. I would like to save in a circular buffer the readed data, so that I can process it using DSP. The code is pretty simple and I started from the Audio Record and Playback application provided by ST. Firstly I define the buffer array of size 4096uint16_t audioBuffer[AUDIO_BUFFER_SIZE];
Then inside the ''main function'' I start the recording process
BSP_AUDIO_IN_Init(INPUT_DEVICE_DIGITAL_MICROPHONE_2, 100, DEFAULT_AUDIO_IN_FREQ);
BSP_AUDIO_IN_Record(&audioBuffer[0], AUDIO_BUFFER_SIZE);
Then I'm just checking the array everytime the DMA transfer finish callback is called
void
BSP_AUDIO_IN_TransferComplete_CallBack(
void
)
{
uint32_t index;
for
(index=1000;index<1020;index++)
printf
(
''%d ''
, audioBuffer[index]);
printf
(
''\r\n''
);
}
I obtain the same sequence outputted every half second more or less (maybe a quarter of second). Why the array is not updated? The rest of the code is exactly the same from the demo application.
Thanks in advance
#cache-coherence #adc #dma #discovery #stm32f7 #board #cache
- Labels:
-
ADC
-
DMA
-
STM32F7 Series
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-07-25 8:22 AM
Make sure you use uncached memory, there is not coherency management here.
Up vote any posts that you find helpful, it shows what's working..
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-07-25 8:59 AM
Thanks clive1, I solved removing the caching. In the case that I want to leave the cache enabled, how can I do it without messing with the buffer?
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2016-07-26 12:25 AM
As clive said, there is no cache coherence between the peripherals (DMA in your case) and CPU. You'll have to manually program coherence.
Example: before DMAing from memory, call SCB_CleanDCache_by_Addr() to flush the buffer to RAM. Likewise, after DMAing to memory (i.e. in BSP_AUDIO_IN_TransferComplete_CallBack()), call SCB_InvalidateDCache_by_Addr().See AN4839: Level 1 cache on STM32F7 SeriesUnless you're a hardcore optimizer, I doubt you want to do this. I'm an optimization freak, but I'd rather use the dTCM if I want high bandwidth (64bit vs 32bit for regular SRAM), low latency memory.I did some rough latency benchmarks by timing 16 back to back loads using the DWT cycle counter:SRAM: 8.6 cycles/loaddTCM: 2.3 cycles/loaddCache: 1.5 cycles/loadFeel a little misled because the documentation says the dTCM has 0 cycle latency.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-10-17 12:58 PM
Thank you very much!!!! I've spent 5 days resolving the same problem.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2017-10-17 1:21 PM
I haven't dug too deeply into the architecture used here, but with other cached ARM platforms there are usually two views of the same memory, you should access things touched via DMA via the uncached view.
Up vote any posts that you find helpful, it shows what's working..
