Audio Buffer Overrun

Hello, I am doing a sound classification on STM32 discovery BL475E IoT board. I have imported the edge Impulse C++ library in my code and executed it. I am currently getting audio buffer overrun message while executing the code. Any help why I am getting this and what should I do. Thanks.

@waqas.isa What is the exact error that you see, and how have you imported the C++ Library into your project? Mbed example or with STM32Cube.IDE?

Hi @janjongboom thanks a lot for your response. I have used STM32Cube.IDE to include the project in my folder as you guided in my previous question. I have used the audio example provided by shawn https://github.com/ShawnHymel/ei-keyword-spotting/tree/master/embedded-demos/stm32cubeide/nucleo-l476-keyword-spotting here. But after studying the STM32 BL475E IOT discovery board. I realize it is using DFSDM interface for recording audio from microphone. But unfortunately I am unable to find any example or code help to how to get data from STM32 BL475E MP34DT01 MEM microphone. Kindly please if you can guide me to any example for getting data from microphone on STM32 BL475E.

@waqas.isa Ah! I did not know you were using a PDM microphone. STM32CubeMX has built-in examples for I2S, but I don’t think they have anything for PDM (I could be wrong). With a brief search, it looks like they have a PDM library (https://www.st.com/en/licensed-software/audiopdm-mw.html) and some documentation on how to use it (https://www.st.com/resource/en/application_note/dm00380469-interfacing-pdm-digital-microphones-using-stm32-mcus-and-mpus-stmicroelectronics.pdf).

I’m not very familiar with PDM, so I don’t think I’ll be able to help much here. The general idea is you need to either use an RTOS or interrupt-based scheme to sample from the PDM mic at set intervals (your sampling frequency, e.g. 16 kHz) or use built-in hardware (if available) to perform continuous DMA transfer from the mic to a buffer. Both will take some work, and you’ll need to make sure that you’re not using too much processing time to do this (or you’ll overflow the buffer, as you’ve seen).

I used I2S in my example, so you can see where the DMA is set up and how callbacks are constructed to fill up the buffer.

thanks a lot @ShawnHymel for a detailed response. yes from what I read STM32 BL475E has a PDM MEM on board and uses DFSDM interface for audio as given in user manual. It would be great if I can find a working example of data recording. Otherwise the document you provided is a good start and covers DFSDM interface configuration, I will study it and try to make it work. and buffer overrun is a concern. Lets see maybe @janjongboom might have come across an example as BL475E is supported.

FYI https://github.com/edgeimpulse/firmware-st-b-l475e-iot01a <-- this has audio examples and a driver for the MP34 that I stole from an Application Note pack from ST, plus continuous inferencing already implemented. Just remove the tflite-model, model-parameters and edge-impulse-sdk folders and drop your files in. Then at the bottom of main (right before the REPL starting) invoke run_nn_continuous_normal() to invoke the network.

https://github.com/janjongboom/b-l475e-iot01a-audio-mbed <-- standalone example on driving the microphone on this board (but on Mbed, I think it basically runs as-is to port in CubeIDE because that’s where the driver came from).

hello @janjongboom thanks a lot for your response. I have compiled the code you provided at https://github.com/edgeimpulse/firmware-st-b-l475e-iot01a by replacing the folders as you kindly told. I have tried to use both run_nn_normal() and run_nn_continuous_normal() but I am getting these errors can you kindly suggest what I am doing wrong here. Thanks a lot!
Error when run_nn_normal is used


Error when run_nn_continuous_normal is used

@waqas.isa As it states in the top one, there’s not enough memory to extract the features. What’s the DSP block that you’ve used? I reckon you have ~35K RAM free on this device, so keep an eye on the ‘On-device performance’ widget on the DSP screen to make sure you stay under.

oh Ok thanks @janjongboom I used the MFE block. I will try again with spectrogram and see if its within 35K thanks for your response.