🛠 Acquérir le micro PDM MP45DT02 : I2S2, filtre PDM-vers-PCM et contraintes de sortie
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
- I2S2 in reception for the PDM clock: the CubeF4 audio BSP (
BSP_AUDIO_IN_*, record demos inProjects/STM32F4-Discovery/) configures the peripheral and the PDM filter (decimation + low-pass filter) that produces 16-bit PCM. - Double-buffered DMA: while the half-buffer is being processed, the next one fills up — the
HalfTransfer/TransferCompletecallback reloads the analysis window. - 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
- UART1 is unusable without board modifications: its alternate pins are PB6/PB7, but PB6 is the I2C SCL for the CS43L22 codec (explicit comment in the MicroPython port: "Without board modifications, this makes UART1 unusable on this board").
- PA0 (UART4 TX/CTS) is occupied by the USER button and WKUP; the MicroPython port documents removing SB20 to free the pin.
- PC7 is the codec's MCLK: avoid using it for serial if the codec is active.
- The ST-LINK VCP is not wired on stock boards: an external serial cable on PA2/PA3 remains the safe route.
- Bandwidth budget: at 115200 baud, 16-bit stereo PCM at 16 kHz requires 512 kbit/s — impossible over a single serial link. Reduce parameters (mono, 8 kHz, 8 bits, or compression) or switch to USB CDC.
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
- Compile the CubeF4 record demo for STM32F4-Discovery as a reference (I2S2 pinout + PDM filter are already correct).
- Replace the write to the codec with your exfiltration method: OTG CDC or UART2 at the maximum speed supported by your cable.
- 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.
- 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
- Wiring an analog microphone output to an ADC pin: the MP45DT02 is a digital PDM peripheral on I2S2, not an analog microphone.
- Choosing UART1 "because it's the first one": PB6/PB7 conflict with the codec, and the board is documented as incompatible with UART1 without modification.
- Aiming for 44.1 kHz stereo 16-bit over a 115200 baud serial link: the data rate is physically exceeded by a factor of ten.
- Neglecting codec/microphone interaction: both audio peripherals share the control I2C and interrupts — the BSP warns that the CS43L22's I2C can be corrupted by user ISRs.
Other tutorials for this board
- Premier téléversement sur la STM32F4DISCOVERY avec l'Arduino STM32duino
- Zephyr RTOS sur la STM32F4DISCOVERY : west build et west flash
- MicroPython sur la STM32F4DISCOVERY : REPL interactif et pilotage des LED
- STM32Cube HAL et BSP officiel : LED, bouton et accéléromètre avec détection automatique
- Lecture audio sur le codec CS43L22 : I2S, classe D et les limitations du BSP
- USB OTG FS sur le port micro-AB : se faire passer pour un périphérique classe CDC