Skip to main content
RPuch.2
Associate II
February 25, 2023
Question

Data acquisition from PDM microphones via SAI using DMA - problem with writing to PDM_buffer

  • February 25, 2023
  • 7 replies
  • 6326 views

I have configured the readout of 4 PDM microphones through the SAI interface. I am using 1 slot of 32 bits per frame.

0693W00000aHesQQAS.png 

I have enabled DMA.

0693W00000aHesVQAS.pngUnfortunately, when reading PDM data, the first 6 and last 2 values of the array are filled with zeros. This happens regardless of the size of the PDM_buffer.

0693W00000aHesaQAC.png 

Do I have something misconfigured? What could be the cause?

Edit: If the PDM_buffer array is of type uint16_t, there are 2x more zeros (12+4 ), and in the case of uint8_t 4x more zeros (24+8).

This topic has been closed for replies.

7 replies

waclawek.jan
Super User
February 25, 2023

Which STM32?

Read out and check/post content of DMA and SAI registers, perhaps at the point just before SAI gets enabled.

If DMA is circular, I see no reason why DMA buffer won't get filled entirely.

JW

[EDIT] Although you did not tell us the STM32 model you are using, you enable caches in code, so mind cache coherency and DMA - read the related note here.

RPuch.2
RPuch.2Author
Associate II
February 25, 2023

I use STM32H743ZIT6 (Nucleo).

How can I read out content of DMA and SAI registers?

I work in CubeIDE and HAL library.

Edit: I have tried the first solution from the link and it doesn't work. Tomorrow I'll check the second one.

AScha.3
Super User
February 26, 2023

>How can I read out content of DMA and SAI registers?

in debug (when paused) -> SFRs

can see all peri. registers

0693W00000aHfeAQAS.png

"If you feel a post has answered your question, please click ""Accept as Solution""."
RPuch.2
RPuch.2Author
Associate II
February 26, 2023

SAI and DMA registers:0693W00000aHfnbQAC.png0693W00000aHfnWQAS.png

RPuch.2
RPuch.2Author
Associate II
February 26, 2023

To see proper register values, I had to pause and resume debug process.

S0NDTR and SAI_ADR change after every pause.

Edit:

None of the 3 solutions from the link worked.

After commenting out the SCB_EnableDCache() line, it populates the array correctly for me.

But can I just disable DCache like this with impunity? Will, for example, pdm2pcm work properly for me without it?

Piranha
Principal III
March 6, 2023

Disabling the D-cache will at least halve the performance. Such a desire rises a question of why do you chose one of the most complex MCUs out there, if you are not willing to learn how it works and actually use it's features.

RPuch.2
RPuch.2Author
Associate II
March 6, 2023

Sound acquisition is just one of the components of my project. I chose H7 for several reasons: I need high performance (DSP, ANN), I couldn't handle DMA support in F7, I use interfaces that I didn't have in F4 and F7. The fact is that I am a layman in the subject of microcontrollers. So far, I've treated them as a tool that I don't have to delve into too much. This worked with F1, F4 and F7. Problems started with DMA in F7, so I changed to H7. Here I ran into more problems.

waclawek.jan
Super User
February 26, 2023

You need to understand, what caching means and why is it a problem using it with DMA. Read https://community.st.com/s/question/0D53W00001Z9K9TSAV/maintaining-cpu-data-cache-coherence-for-dma-buffers and links from there.

JW

RPuch.1
Associate II
October 9, 2023

OK, I tried different things, I read many articles about similar problems, but I can't deal with it. Is there any relatively simple way to deal with DCache support? Can you show me step by step what I should change and in which files, or what I should add in my program to make DCache work properly?