2022-04-22 01:05 AM
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 :
Why 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 !
2022-04-28 01:17 AM
Hello,
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:
The RXFOFO delivers a data to the CPU every time a slot is received.
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