🛠 Acquérir le micro PDM MP45DT02 : I2S2, filtre PDM-vers-PCM et contraintes de sortie

STM32F4DISCOVERY (STM32F407VGT6 Discovery kit) · avance · Schéma : chaîne d'acquisition micro de la STM32F4DISCOVERY — micro omnidirectionnel MP45DT02 en sortie PDM 1 bit horlogée par I2S2, décimation logicielle vers un PCM 16 bits, puis exfiltration vers un PC via un convertisseur USB-série externe sur UART2 (PA2/PA3) ; encart : UART1 interdit (PB6 = SCL du codec), PA0 occupé par USER.

Objective

Use the MP45DT02, the omnidirectional PDM digital microphone embedded on the STM32F4DISCOVERY. Unlike an analog microphone, it does not output a voltage but a high-frequency 1-bit PDM stream, which the STM32F407 captures via I2S2 (in "receive" mode) and then decimates to 16-bit PCM using a filter provided in STM32CubeF4. The real advanced-level challenge is not the microphone itself: it is where to output the data, as this board accumulates serial pinout pitfalls.

The acquisition chain

  1. I2S2 in reception for the PDM clock: the CubeF4 audio BSP (BSP_AUDIO_IN_*, record demos in Projects/STM32F4-Discovery/) configures the peripheral and the PDM filter (decimation + low-pass filter) that produces 16-bit PCM.
  2. Double-buffered DMA: while the half-buffer is being processed, the next one fills up — the HalfTransfer/TransferComplete callback reloads the analysis window.
  3. Data exfiltration: the board has neither a micro-SD pin nor an Ethernet PHY (the 10/100 MAC is inside the chip, not on the connector). Three options: the OTG FS port in CDC mode (see the USB tutorial), an external USB-serial dongle on UART2 PA2/PA3, or 100% on-board processing (VAD, clap detection) without export.

Pinout pitfalls that turn a lab exercise into a nightmare

Code skeleton

#include "stm32f4_discovery.h"
#include "stm32f4_discovery_audio.h"

static int16_t pcmBuf[2 * AUDIO_IN_BUF_SIZE]; /* double buffer DMA */

int main(void)
{
  HAL_Init;
  SystemClock_Config;                       /* 168 MHz */
  MX_I2S2_Init;                             /* I2S2 RX horloge PDM */
  BSP_AUDIO_IN_Init(AUDIO_IN_FREQUENCY_DEFAULT, 16, 0);
  BSP_AUDIO_IN_Record(pcmBuf, 2 * AUDIO_IN_BUF_SIZE);

  while (1) {
    if (halfReady) { halfReady = 0; Uart2Send(pcmBuf, AUDIO_IN_BUF_SIZE); }
    if (fullReady) { fullReady = 0; Uart2Send(pcmBuf + AUDIO_IN_BUF_SIZE,
                                              AUDIO_IN_BUF_SIZE); }
  }
}
/* Callbacks BSP_AUDIO_IN_HalfTransfer_CallBack / TransferComplete */

Complete procedure

  1. Compile the CubeF4 record demo for STM32F4-Discovery as a reference (I2S2 pinout + PDM filter are already correct).
  2. Replace the write to the codec with your exfiltration method: OTG CDC or UART2 at the maximum speed supported by your cable.
  3. On the PC side, capture the stream (8-bit signed or 16-bit depending on your setup) and plot a spectrogram: voice should appear below 4 kHz.
  4. For a real product, process on-board (energy per frame, lightweight wake-word) and output only events.

Expected verification

When clapping, the spectrogram shows a wide-band burst; when speaking, formants appear below 4 kHz. A regular noise floor without structure indicates a poorly sized PDM filter or incorrect I2S2 clocking.

Common errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials