Showing results for 
Search instead for 
Did you mean: 

Some questions about SAI configuration for PDM audio acquisition

Associate III

I'm using SAI PDM interface to record pdm audio coming from 4 microphones. I'm using a stm32wb55rg and the memsmic1's example.

There are some parts I don't understand with the SAI configuration in the example. Here is a part of the code provided in the example :


As I'm using 4 microphones with a wanted PCM audio sampling of 48 kHz + 64 decimation, PDM_Clock_Freq is set to 3072 and frame length is set to 16 (I didn't change these values there are the original ones), thus AudioFrequency is equal to 768 000.

But when I try to get the same configuration using the ioc interface, the max frequency I can use is 192 kHz :

0693W00000Lyi1HQAR.pngWhy can't I put 768 KHz ? It's a bit annoying if you can't configure all the settings directly in the ioc interface :\

Also, I see "SAI_PDM_CLOCK2_ENABLE". Why is it Clock2 and not Clock 1 ? What are the differences between these two clocks ?

Another question I have is about clock configuration. Looking at the code provided in the example, I got this clock configuration for SAI :


(Here is the part of the code I followed to get the clock configuration):


I am wondering why SAI clock is set to 49.14 MHz. As the microphone clock input need to be set to 3.071 MHz for 48Khz PCM audio with 64 decimation, I would expect something like number of mic * 3.072 MHz but It seems like I didn't understand this part.

There is this table in the reference manual of stm32wb55. Shouldn't I use the 12.288 MHz bit clock frequency instead ?


Sorry for all these questions. I'd greatly appreciate any help !

ST Employee


For each microphone, the PDMIF stores up to 8 bits before sending them to CPU via the SAIA.

As you want to support 4 microphones at 48 kHz (after decimation), you will need SAI frames of 4x8 bits = 32 bits.

The bitstream clock frequency for the microphone is 3.072 MHz as you intend to perform a decimation by 64. The bitclock of the SAIA must go 4 times faster than the microphone bitstream clock: 3.072 x 4 = 12.288 MHz.

If the SAI is receiving a 49.152 MHz kernel clock, it shall work, but you can reduce the frequency to 24.576 or 12.288 MHz it shall work as well.

Concerning the frame structure of the SAIA, the user spec proposes 3 options:

  1. Having 4 slots of 8 bytes. 
  2. Having 2 slots of 16 bits
  3. Having 1 slot of 32 bits

The RXFOFO delivers a data to the CPU every time a slot is received.

  • In the first configuration you will receive 4 bytes per frame and each byte contains the data of a same microphone
  • In the second configuration you will receive 2 half-words of 16 bits per frame and each half-word contains the data of 2 microphones
  • In the second configuration you will receive 1 word of 32 bits per frame and each word contains the data of 4 microphones

I suggest selecting the format the best suited to the function doing the pdm2pcm conversion.

In all cases the audio frequency (i.e. frame sync rate is 12.288MHz/32 = 384 kHz).

I suspect that the limitation of 192 kHz applies for normal audio use-cases because of max bitclock frequency, however PDMIF is a particular case and higher frequency rates must be allowed…

There is maybe a work around, but I am not 100% sure it works because I did not try on my own.

Instead of having a frame of 32 bits, you can try to use a frame of 64 bits.

We keep the bitclock at 12.288 MHz (mandatory). By doing so you will have either 8 slots of 8 bits, 4 slots of half words, or 2 slots of 32 bits. In this case the audio frame frequency will be 192 kHz instead of 384 kHz. I hope CubeMX will be happy.

If I remember fine, only the first frame sync of the SAI is used by the PDMIF, so by doing in this way you can still use CubeMX to program the interface and work-around the limitation of 192kHz max.

Best Regards