cancel
Showing results for 
Search instead for 
Did you mean: 

How to use PDM MEMS microphone on PB8 (MCLK) with STM32WBxx

FFlet
Associate II

I am using the MEMSMIC1 Microphones_Streaming example (https://www.st.com/en/embedded-software/x-cube-memsmic1.html) with the STM32WBxx chip.

I am trying to change the clocking pin from PB13 to PB8 to use the example with custom hardware.

I am trying to do this by modifying the pin definitions in the ccm02m1_audio.h file:

#ifdef USE_STM32WBXX_NUCLEO /* defines valid only for STM32WB */

 /* I2S Configuration defines */

#define AUDIO_IN_SAI_INSTANCE                  SAI1_Block_A

#define AUDIO_IN_SAI_CLK_ENABLE()                __SAI1_CLK_ENABLE()

#define AUDIO_IN_SAI_SCK_PIN                   GPIO_PIN_8

#define AUDIO_IN_SAI_SCK_GPIO_PORT                GPIOB

#define AUDIO_IN_SAI_SCK_GPIO_CLK_ENABLE()            __GPIOB_CLK_ENABLE()

#define AUDIO_IN_SAI_SCK_AF                   GPIO_AF13_SAI1

#define AUDIO_IN_SAI_SD_PIN                  GPIO_PIN_15

#define AUDIO_IN_SAI_SD_GPIO_PORT               GPIOB

#define AUDIO_IN_SAI_SD_GPIO_CLK_ENABLE()           __GPIOB_CLK_ENABLE();

#define AUDIO_IN_SAI_SD_AF                   GPIO_AF13_SAI1

I am able to change change to PA8 but not PB8.

PB8 uses MCLK rather than SCK and so I believe this might be the issue.

Does anyone know how I might get around this problem?

Finlay

1 REPLY 1
Eleon BORLINI
ST Employee

​Hi @FFlet​ , consider that the SAI samples on the bit clock, and not on the master clock, and on PB8 the MCLK is running. However, you could set the SAI interface in a proper way, making the bit clock same as master clock, e.g. in these two ways:

  1. Set the frequency to 8kHz to get a 2.048MHz bit clock, or
  2. Set 8 slots of 32 bits at 8kHz to get a 2.048MHz bit clock

Regards