2020-06-19 08:46 AM
Hello everyone,
My goal is to record audio from one MP34DT05-A microphone via SAI PROTOCOL in an STM32F446 Nucleo Board. In resume, I receive data from microphone via DMA, then I make the transformation via PDM2PCM Library and write the buffer into an SD CARD via SDIO.
I'm using STM32Cube IDE and I can see that the two buffers (input SAI data and output PDM2PCM data) are always being updated with values. Also, I confirmed that all the values are written into the SD with no missing values.
I tried to replicate the code from "Microphone_Streaming" Stm32 examples (also made in this video: https://www.youtube.com/watch?v=BjTj1XXpjBU. But the result is always looking like this graph below. It seems like the microphone never respond to any higher sound...
My feeling is that the parameters are not correctly adjusted and I'm missing something. Unfortunately, I think all the documentation available is very weak and I'm not reaching all the knowledge and attention necessary to be sure about what I'm doing. Can anyone help me?
(I set the SAI clock to 3.07MHz so with a 64 decimation parameter I should be able to acquire data at 48kHz).
SAI and DMA configurations:
SAI_HandleTypeDef hAudioInSai;
uint32_t PDM_Clock_Freq = 3072
hAudioInSai.Instance = SAI1_Block_A;
hAudioInSai.Init.Protocol = SAI_FREE_PROTOCOL;
hAudioInSai.Init.AudioMode = SAI_MODEMASTER_RX;
hAudioInSai.Init.DataSize = SAI_DATASIZE_16;
hAudioInSai.Init.FirstBit = SAI_FIRSTBIT_MSB;
hAudioInSai.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
hAudioInSai.Init.Synchro = SAI_ASYNCHRONOUS;
hAudioInSai.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
hAudioInSai.Init.NoDivider = SAI_MASTERDIVIDER_DISABLE;
hAudioInSai.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
hAudioInSai.Init.ClockSource = SAI_CLKSOURCE_NA;
hAudioInSai.Init.AudioFrequency = ((PDM_Clock_Freq * 1000U) / 16 ) * 2U;
hAudioInSai.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
hAudioInSai.Init.MonoStereoMode = SAI_STEREOMODE;
hAudioInSai.Init.CompandingMode = SAI_NOCOMPANDING;
hAudioInSai.FrameInit.FrameLength = 16;
hAudioInSai.FrameInit.ActiveFrameLength = 1;
hAudioInSai.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
hAudioInSai.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
hAudioInSai.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
hAudioInSai.SlotInit.FirstBitOffset = 0;
hAudioInSai.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
hAudioInSai.SlotInit.SlotNumber = 1;
hAudioInSai.SlotInit.SlotActive = 0x00000003;
DMA_HandleTypeDef hdma_sai1_a;
hdma_sai1_a.Instance = DMA2_Stream1;
hdma_sai1_a.Init.Channel = DMA_CHANNEL_0;
hdma_sai1_a.Init.Direction = DMA_PERIPH_TO_MEMORY;
hdma_sai1_a.Init.PeriphInc = DMA_PINC_DISABLE;
hdma_sai1_a.Init.MemInc = DMA_MINC_ENABLE;
hdma_sai1_a.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
hdma_sai1_a.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
hdma_sai1_a.Init.Mode = DMA_CIRCULAR;
hdma_sai1_a.Init.Priority = DMA_PRIORITY_HIGH;
hdma_sai1_a.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
Filter from PDM2PCM configuration:
PDM_FilterHandler[index].bit_order = PDM_FILTER_BIT_ORDER_MSB;
PDM_FilterHandler[index].endianness = PDM_FILTER_ENDIANNESS_LE;
PDM_FilterHandler[index].high_pass_tap = 2122358088;
PDM_FilterHandler[index].out_ptr_channels = (uint16_t)ChnlNbrOut;
PDM_FilterHandler[index].in_ptr_channels = (uint16_t)ChnlNbrIn;
PDM_FilterConfig[index].output_samples_number = (uint16_t) ((AudioFreq/1000U) * N_MS_PER_INTERRUPT);
PDM_FilterConfig[index].mic_gain = 5;
PDM_FilterConfig[index].decimation_factor = PDM_FILTER_DEC_FACTOR_64;
note: N_MS_PER_INTERRUPT= 1U is number of millisecond of audio at each DMA interrupt.
2020-06-25 05:06 AM
Hi @ALope.1 , our experts suggest to check the MEMSMIC1 functional pack, driver BSP for the X-NUCLEO-CCA02M1 digital microphone expansion board: in this case, the ’STM32WB microcontroller is used. You should find some hints in the .c file STM32CubeExpansion_MEMSMIC1_V5.3.0\Drivers\BSP\CCA02M1\ cca02m1_audio.c, line 290. It is not F446 product, but should be the same configuration, almost every time the SAI configuration is called.
I add STM32F4 topic for more help. Regards
2020-06-25 08:31 AM
Hello @Eleon BORLINI the code is an adaptation from driver BSP that you referred. But even replicating the code a lot of times, I'm couldn't get any good result. Any suggestion?