stm32f4_discovery_audio.c
Go to the documentation of this file.
1 
37 /*==============================================================================
38  User NOTES
39 1. How To use this driver:
40 --------------------------
41  - This driver supports STM32F4xx devices on STM32F4-Discovery Kit:
42  a) to play an audio file (all functions names start by BSP_AUDIO_OUT_xxx)
43  b) to record an audio file through MP45DT02, ST MEMS (all functions names start by AUDIO_IN_xxx)
44 
45 a) PLAY A FILE:
46 ==============
47  + Call the function BSP_AUDIO_OUT_Init(
48  OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER,
49  OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or
50  OUTPUT_DEVICE_BOTH)
51  Volume: initial volume to be set (0 is min (mute), 100 is max (100%)
52  AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...)
53  this parameter is relative to the audio file/stream type.
54  )
55  This function configures all the hardware required for the audio application (codec, I2C, I2S,
56  GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
57  If the returned value is different from 0 or the function is stuck then the communication with
58  the codec (try to un-plug the power or reset device in this case).
59  - OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream.
60  - OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream.
61  - OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented
62  into the audio jack on the discovery board). When the Headphone is connected it is used
63  as output. When the headphone is disconnected from the audio jack, the output is
64  automatically switched to Speaker.
65  - OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream
66  at the same time.
67  + Call the function BSP_AUDIO_OUT_Play(
68  pBuffer: pointer to the audio data file address
69  Size: size of the buffer to be sent in Bytes
70  )
71  to start playing (for the first time) from the audio file/stream.
72  + Call the function BSP_AUDIO_OUT_Pause() to pause playing
73  + Call the function BSP_AUDIO_OUT_Resume() to resume playing.
74  Note. After calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() should be called
75  for resume (it is not allowed to call BSP_AUDIO_OUT_Play() in this case).
76  Note. This function should be called only when the audio file is played or paused (not stopped).
77  + For each mode, you may need to implement the relative callback functions into your code.
78  The Callback functions are named BSP_AUDIO_OUT_XXXCallBack() and only their prototypes are declared in
79  the stm32f4_discovery_audio.h file. (refer to the example for more details on the callbacks implementations)
80  + To Stop playing, to modify the volume level, the frequency or to mute, use the functions
81  BSP_AUDIO_OUT_Stop(), BSP_AUDIO_OUT_SetVolume(), AUDIO_OUT_SetFrequency() BSP_AUDIO_OUT_SetOutputMode and BSP_AUDIO_OUT_SetMute().
82  + The driver API and the callback functions are at the end of the stm32f4_discovery_audio.h file.
83 
84 Driver architecture:
85 --------------------
86  + This driver provide the High Audio Layer: consists of the function API exported in the stm32f4_discovery_audio.h file
87  (BSP_AUDIO_OUT_Init(), BSP_AUDIO_OUT_Play() ...)
88  + This driver provide also the Media Access Layer (MAL): which consists of functions allowing to access the media containing/
89  providing the audio file/stream. These functions are also included as local functions into
90  the stm32f4_discovery_audio.c file (I2S3_Init()...)
91 
92 Known Limitations:
93 -------------------
94  1- When using the Speaker, if the audio file quality is not high enough, the speaker output
95  may produce high and uncomfortable noise level. To avoid this issue, to use speaker
96  output properly, try to increase audio file sampling rate (typically higher than 48KHz).
97  This operation will lead to larger file size.
98  2- Communication with the audio codec (through I2C) may be corrupted if it is interrupted by some
99  user interrupt routines (in this case, interrupts could be disabled just before the start of
100  communication then re-enabled when it is over). Note that this communication is only done at
101  the configuration phase (BSP_AUDIO_OUT_Init() or BSP_AUDIO_OUT_Stop()) and when Volume control modification is
102  performed (BSP_AUDIO_OUT_SetVolume() or BSP_AUDIO_OUT_SetMute()or BSP_AUDIO_OUT_SetOutputMode()).
103  When the audio data is played, no communication is required with the audio codec.
104  3- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size,
105  File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file.
106  4- Supports only Stereo audio streaming. To play mono audio streams, each data should be sent twice
107  on the I2S or should be duplicated on the source buffer. Or convert the stream in stereo before playing.
108  5- Supports only 16-bits audio data size.
109 
110 b) RECORD A FILE:
111 ================
112  + Call the function BSP_AUDIO_IN_Init(
113  AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...)
114  )
115  This function configures all the hardware required for the audio application (I2S,
116  GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK.
117 
118  + Call the function BSP_AUDIO_IN_Record(
119  pbuf Main buffer pointer for the recorded data storing
120  size Current size of the recorded buffer
121  )
122  to start recording from the microphone.
123 
124  + User needs to implement user callbacks to retrieve data saved in the record buffer
125  (AUDIO_IN_RxHalfCpltCallback/BSP_AUDIO_IN_ReceiveComplete_CallBack)
126 
127  + Call the function AUDIO_IN_STOP() to stop recording
128 
129 ==============================================================================*/
130 
131 /* Includes ------------------------------------------------------------------*/
132 #include "stm32f4_discovery_audio.h"
133 
158 /* These PLL parameters are valid when the f(VCO clock) = 1Mhz */
159 const uint32_t I2SFreq[8] = {8000, 11025, 16000, 22050, 32000, 44100, 48000, 96000};
160 const uint32_t I2SPLLN[8] = {256, 429, 213, 429, 426, 271, 258, 344};
161 const uint32_t I2SPLLR[8] = {5, 4, 4, 4, 4, 6, 3, 1};
176 /*##### PLAY #####*/
179 
180 /*### RECORDER ###*/
182 
183 /* PDM filters params */
184 PDM_Filter_Handler_t PDM_FilterHandler[2];
185 PDM_Filter_Config_t PDM_FilterConfig[2];
186 
195 static uint8_t I2S3_Init(uint32_t AudioFreq);
196 static uint8_t I2S2_Init(uint32_t AudioFreq);
197 static void PDMDecoder_Init(uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut);
214 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
215 {
216  uint8_t ret = AUDIO_OK;
217 
218  /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
220 
221  /* I2S data transfer preparation:
222  Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
225  {
226  /* Init the I2S MSP: this __weak function can be redefined by the application*/
228  }
229 
230  /* I2S data transfer preparation:
231  Prepare the Media to be used for the audio transfer from memory to I2S peripheral */
232  /* Configure the I2S peripheral */
233  if(I2S3_Init(AudioFreq) != AUDIO_OK)
234  {
235  ret = AUDIO_ERROR;
236  }
237 
238  if(ret == AUDIO_OK)
239  {
240  /* Retieve audio codec identifier */
242  {
243  /* Initialize the audio driver structure */
245  }
246  else
247  {
248  ret = AUDIO_ERROR;
249  }
250  }
251 
252  if(ret == AUDIO_OK)
253  {
254  pAudioDrv->Init(AUDIO_I2C_ADDRESS, OutputDevice, Volume, AudioFreq);
255  }
256 
257  return ret;
258 }
259 
266 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size)
267 {
268  /* Call the audio Codec Play function */
269  if(pAudioDrv->Play(AUDIO_I2C_ADDRESS, pBuffer, Size) != 0)
270  {
271  return AUDIO_ERROR;
272  }
273  else
274  {
275  /* Update the Media layer and enable it for play */
277 
278  /* Return AUDIO_OK when all operations are correctly done */
279  return AUDIO_OK;
280  }
281 }
282 
288 void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
289 {
290  HAL_I2S_Transmit_DMA(&hAudioOutI2s, pData, Size);
291 }
292 
301 uint8_t BSP_AUDIO_OUT_Pause(void)
302 {
303  /* Call the Audio Codec Pause/Resume function */
305  {
306  return AUDIO_ERROR;
307  }
308  else
309  {
310  /* Call the Media layer pause function */
312 
313  /* Return AUDIO_OK when all operations are correctly done */
314  return AUDIO_OK;
315  }
316 }
317 
325 uint8_t BSP_AUDIO_OUT_Resume(void)
326 {
327  /* Call the Audio Codec Pause/Resume function */
329  {
330  return AUDIO_ERROR;
331  }
332  else
333  {
334  /* Call the Media layer resume function */
336 
337  /* Return AUDIO_OK when all operations are correctly done */
338  return AUDIO_OK;
339  }
340 }
341 
349 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
350 {
351  /* Call DMA Stop to disable DMA stream before stopping codec */
353 
354  /* Call Audio Codec Stop function */
355  if(pAudioDrv->Stop(AUDIO_I2C_ADDRESS, Option) != 0)
356  {
357  return AUDIO_ERROR;
358  }
359  else
360  {
361  if(Option == CODEC_PDWN_HW)
362  {
363  /* Wait at least 1ms */
364  HAL_Delay(1);
365 
366  /* Reset the pin */
368  }
369 
370  /* Return AUDIO_OK when all operations are correctly done */
371  return AUDIO_OK;
372  }
373 }
374 
381 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
382 {
383  /* Call the codec volume control function with converted volume value */
384  if(pAudioDrv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0)
385  {
386  return AUDIO_ERROR;
387  }
388  else
389  {
390  /* Return AUDIO_OK when all operations are correctly done */
391  return AUDIO_OK;
392  }
393 }
394 
401 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd)
402 {
403  /* Call the Codec Mute function */
404  if(pAudioDrv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0)
405  {
406  return AUDIO_ERROR;
407  }
408  else
409  {
410  /* Return AUDIO_OK when all operations are correctly done */
411  return AUDIO_OK;
412  }
413 }
414 
423 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output)
424 {
425  /* Call the Codec output Device function */
427  {
428  return AUDIO_ERROR;
429  }
430  else
431  {
432  /* Return AUDIO_OK when all operations are correctly done */
433  return AUDIO_OK;
434  }
435 }
436 
443 void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
444 {
445  /* PLL clock is set depending by the AudioFreq (44.1khz vs 48khz groups) */
447 
448  /* Update the I2S audio frequency configuration */
449  I2S3_Init(AudioFreq);
450 }
451 
457 {
458  if(hi2s->Instance == I2S3)
459  {
460  /* Call the user function which will manage directly transfer complete */
462  }
463 }
464 
470 {
471  if(hi2s->Instance == I2S3)
472  {
473  /* Manage the remaining file size and new address offset: This function should
474  be coded by user (its prototype is already declared in stm32f4_discovery_audio.h) */
476  }
477 }
478 
487 __weak void BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
488 {
489  RCC_PeriphCLKInitTypeDef rccclkinit;
490  uint8_t index = 0, freqindex = 0xFF;
491 
492  for(index = 0; index < 8; index++)
493  {
494  if(I2SFreq[index] == AudioFreq)
495  {
496  freqindex = index;
497  }
498  }
499  /* Enable PLLI2S clock */
500  HAL_RCCEx_GetPeriphCLKConfig(&rccclkinit);
501  /* PLLI2S_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
502  if ((freqindex & 0x7) == 0)
503  {
504  /* I2S clock config
505  PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLM)
506  I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
508  rccclkinit.PLLI2S.PLLI2SN = I2SPLLN[freqindex];
509  rccclkinit.PLLI2S.PLLI2SR = I2SPLLR[freqindex];
510  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
511  }
512  else
513  {
514  /* I2S clock config
515  PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLM)
516  I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
518  rccclkinit.PLLI2S.PLLI2SN = 258;
519  rccclkinit.PLLI2S.PLLI2SR = 3;
520  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
521  }
522 }
523 
529 __weak void BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
530 {
531  static DMA_HandleTypeDef hdma_i2sTx;
532  GPIO_InitTypeDef GPIO_InitStruct;
533 
534  /* Enable I2S3 clock */
535  I2S3_CLK_ENABLE();
536 
537  /*** Configure the GPIOs ***/
538  /* Enable I2S GPIO clocks */
541 
542  /* I2S3 pins configuration: WS, SCK and SD pins ----------------------------*/
543  GPIO_InitStruct.Pin = I2S3_SCK_PIN | I2S3_SD_PIN;
544  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
545  GPIO_InitStruct.Pull = GPIO_NOPULL;
546  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
547  GPIO_InitStruct.Alternate = I2S3_SCK_SD_WS_AF;
548  HAL_GPIO_Init(I2S3_SCK_SD_GPIO_PORT, &GPIO_InitStruct);
549 
550  GPIO_InitStruct.Pin = I2S3_WS_PIN ;
551  HAL_GPIO_Init(I2S3_WS_GPIO_PORT, &GPIO_InitStruct);
552 
553  /* I2S3 pins configuration: MCK pin */
555  GPIO_InitStruct.Pin = I2S3_MCK_PIN;
556  HAL_GPIO_Init(I2S3_MCK_GPIO_PORT, &GPIO_InitStruct);
557 
558  /* Enable the I2S DMA clock */
560 
561  if(hi2s->Instance == I2S3)
562  {
563  /* Configure the hdma_i2sTx handle parameters */
564  hdma_i2sTx.Init.Channel = I2S3_DMAx_CHANNEL;
565  hdma_i2sTx.Init.Direction = DMA_MEMORY_TO_PERIPH;
566  hdma_i2sTx.Init.PeriphInc = DMA_PINC_DISABLE;
567  hdma_i2sTx.Init.MemInc = DMA_MINC_ENABLE;
570  hdma_i2sTx.Init.Mode = DMA_NORMAL;
571  hdma_i2sTx.Init.Priority = DMA_PRIORITY_HIGH;
572  hdma_i2sTx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
574  hdma_i2sTx.Init.MemBurst = DMA_MBURST_SINGLE;
575  hdma_i2sTx.Init.PeriphBurst = DMA_PBURST_SINGLE;
576 
577  hdma_i2sTx.Instance = I2S3_DMAx_STREAM;
578 
579  /* Associate the DMA handle */
580  __HAL_LINKDMA(hi2s, hdmatx, hdma_i2sTx);
581 
582  /* Deinitialize the Stream for new transfer */
583  HAL_DMA_DeInit(&hdma_i2sTx);
584 
585  /* Configure the DMA Stream */
586  HAL_DMA_Init(&hdma_i2sTx);
587  }
588 
589  /* I2S DMA IRQ Channel configuration */
592 }
593 
599 __weak void BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
600 {
601  GPIO_InitTypeDef GPIO_InitStruct;
602 
603  /* I2S DMA IRQ Channel deactivation */
605 
606  if(hi2s->Instance == I2S3)
607  {
608  /* Deinitialize the Stream for new transfer */
609  HAL_DMA_DeInit(hi2s->hdmatx);
610  }
611 
612  /* Disable I2S block */
613  __HAL_I2S_DISABLE(hi2s);
614 
615  /* CODEC_I2S pins configuration: SCK and SD pins */
616  GPIO_InitStruct.Pin = I2S3_SCK_PIN | I2S3_SD_PIN;
617  HAL_GPIO_DeInit(I2S3_SCK_SD_GPIO_PORT, GPIO_InitStruct.Pin);
618 
619  /* CODEC_I2S pins configuration: WS pin */
620  GPIO_InitStruct.Pin = I2S3_WS_PIN;
621  HAL_GPIO_DeInit(I2S3_WS_GPIO_PORT, GPIO_InitStruct.Pin);
622 
623  /* CODEC_I2S pins configuration: MCK pin */
624  GPIO_InitStruct.Pin = I2S3_MCK_PIN;
625  HAL_GPIO_DeInit(I2S3_MCK_GPIO_PORT, GPIO_InitStruct.Pin);
626 
627  /* Disable I2S clock */
629 
630  /* GPIO pins clock and DMA clock can be shut down in the applic
631  by surcgarging this __weak function */
632 }
633 
638 {
639 }
640 
645 {
646 }
647 
652 {
653 }
654 
655 /*******************************************************************************
656  Static Functions
657 *******************************************************************************/
658 
663 static uint8_t I2S3_Init(uint32_t AudioFreq)
664 {
665  /* Initialize the hAudioOutI2s Instance parameter */
667 
668  /* Disable I2S block */
670 
671  /* I2S3 peripheral configuration */
672  hAudioOutI2s.Init.AudioFreq = AudioFreq;
679  /* Initialize the I2S peripheral with the structure above */
681  {
682  return AUDIO_ERROR;
683  }
684  else
685  {
686  return AUDIO_OK;
687  }
688 }
689 
705 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
706 {
707 
708  /* Configure PLL clock */
710 
711  /* Configure the PDM library */
712  /* On STM32F4-Discovery a single microphone is mounted, samples are duplicated
713  to make stereo audio streams */
714  PDMDecoder_Init(AudioFreq, ChnlNbr, 2);
715 
716  /* Configure the I2S peripheral */
719  {
720  /* Initialize the I2S Msp: this __weak function can be rewritten by the application */
722  }
723 
724  /* Configure the I2S2 */
725  I2S2_Init(AudioFreq);
726 
727  /* Return AUDIO_OK when all operations are correctly done */
728  return AUDIO_OK;
729 }
730 
737 uint8_t BSP_AUDIO_IN_Record(uint16_t* pbuf, uint32_t size)
738 {
739  uint32_t ret = AUDIO_ERROR;
740 
741  /* Start the process receive DMA */
742  HAL_I2S_Receive_DMA(&hAudioInI2s, pbuf, size);
743 
744  /* Return AUDIO_OK when all operations are correctly done */
745  ret = AUDIO_OK;
746 
747  return ret;
748 }
749 
754 uint8_t BSP_AUDIO_IN_Stop(void)
755 {
756  uint32_t ret = AUDIO_ERROR;
757 
758  /* Call the Media layer pause function */
760 
761  /* Return AUDIO_OK when all operations are correctly done */
762  ret = AUDIO_OK;
763 
764  return ret;
765 }
766 
771 uint8_t BSP_AUDIO_IN_Pause(void)
772 {
773  /* Call the Media layer pause function */
775 
776  /* Return AUDIO_OK when all operations are correctly done */
777  return AUDIO_OK;
778 }
779 
784 uint8_t BSP_AUDIO_IN_Resume(void)
785 {
786  /* Call the Media layer pause/resume function */
788 
789  /* Return AUDIO_OK when all operations are correctly done */
790  return AUDIO_OK;
791 }
792 
799 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume)
800 {
801  /* Set the Global variable AudioInVolume */
802  AudioInVolume = Volume;
803 
804  /* Return AUDIO_OK when all operations are correctly done */
805  return AUDIO_OK;
806 }
807 
814 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf)
815 {
816  uint16_t AppPDM[INTERNAL_BUFF_SIZE/2];
817  uint32_t index = 0;
818 
819  /* PDM Demux */
820  for(index = 0; index<INTERNAL_BUFF_SIZE/2; index++)
821  {
822  AppPDM[index] = HTONS(PDMBuf[index]);
823  }
824 
825  for(index = 0; index < DEFAULT_AUDIO_IN_CHANNEL_NBR; index++)
826  {
827  /* PDM to PCM filter */
828  PDM_Filter((uint8_t*)&AppPDM[index], (uint16_t*)&(PCMBuf[index]), &PDM_FilterHandler[index]);
829  }
830  /* Duplicate samples since a single microphone in mounted on STM32F4-Discovery */
831  for(index = 0; index < PCM_OUT_SIZE; index++)
832  {
833  PCMBuf[(index<<1)+1] = PCMBuf[index<<1];
834  }
835 
836  /* Return AUDIO_OK when all operations are correctly done */
837  return AUDIO_OK;
838 }
839 
845 {
846  /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
848 }
849 
855 {
856  /* Manage the remaining file size and new address offset: This function
857  should be coded by user (its prototype is already declared in stm32f4_discovery_audio.h) */
859 }
860 
869 __weak void BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
870 {
871  RCC_PeriphCLKInitTypeDef rccclkinit;
872 
873  /*Enable PLLI2S clock*/
874  HAL_RCCEx_GetPeriphCLKConfig(&rccclkinit);
875  /* PLLI2S_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
876  if ((AudioFreq & 0x7) == 0)
877  {
878  /* Audio frequency multiple of 8 (8/16/32/48/96/192)*/
879  /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 192 Mhz */
880  /* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 192/6 = 32 Mhz */
882  rccclkinit.PLLI2S.PLLI2SN = 192;
883  rccclkinit.PLLI2S.PLLI2SR = 6;
884  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
885  }
886  else
887  {
888  /* Other Frequency (11.025/22.500/44.100) */
889  /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 290 Mhz */
890  /* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 290/2 = 145 Mhz */
892  rccclkinit.PLLI2S.PLLI2SN = 290;
893  rccclkinit.PLLI2S.PLLI2SR = 2;
894  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
895  }
896 }
897 
903 __weak void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
904 {
905  static DMA_HandleTypeDef hdma_i2sRx;
906  GPIO_InitTypeDef GPIO_InitStruct;
907 
908  /* Enable the I2S2 peripheral clock */
909  I2S2_CLK_ENABLE();
910 
911  /* Enable I2S GPIO clocks */
914 
915  /* I2S2 pins configuration: SCK and MOSI pins ------------------------------*/
916  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
917  GPIO_InitStruct.Pull = GPIO_NOPULL;
918  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
919 
920  GPIO_InitStruct.Pin = I2S2_SCK_PIN;
921  GPIO_InitStruct.Alternate = I2S2_SCK_AF;
922  HAL_GPIO_Init(I2S2_SCK_GPIO_PORT, &GPIO_InitStruct);
923 
924  GPIO_InitStruct.Pin = I2S2_MOSI_PIN ;
925  GPIO_InitStruct.Alternate = I2S2_MOSI_AF;
926  HAL_GPIO_Init(I2S2_MOSI_GPIO_PORT, &GPIO_InitStruct);
927 
928  /* Enable the DMA clock */
930 
931  if(hi2s->Instance == I2S2)
932  {
933  /* Configure the hdma_i2sRx handle parameters */
934  hdma_i2sRx.Init.Channel = I2S2_DMAx_CHANNEL;
935  hdma_i2sRx.Init.Direction = DMA_PERIPH_TO_MEMORY;
936  hdma_i2sRx.Init.PeriphInc = DMA_PINC_DISABLE;
937  hdma_i2sRx.Init.MemInc = DMA_MINC_ENABLE;
940  hdma_i2sRx.Init.Mode = DMA_CIRCULAR;
941  hdma_i2sRx.Init.Priority = DMA_PRIORITY_HIGH;
942  hdma_i2sRx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
944  hdma_i2sRx.Init.MemBurst = DMA_MBURST_SINGLE;
945  hdma_i2sRx.Init.PeriphBurst = DMA_MBURST_SINGLE;
946 
947  hdma_i2sRx.Instance = I2S2_DMAx_STREAM;
948 
949  /* Associate the DMA handle */
950  __HAL_LINKDMA(hi2s, hdmarx, hdma_i2sRx);
951 
952  /* Deinitialize the Stream for new transfer */
953  HAL_DMA_DeInit(&hdma_i2sRx);
954 
955  /* Configure the DMA Stream */
956  HAL_DMA_Init(&hdma_i2sRx);
957  }
958 
959  /* I2S DMA IRQ Channel configuration */
962 }
963 
969 __weak void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
970 {
971  GPIO_InitTypeDef gpio_init_structure;
972 
973  /* I2S DMA IRQ Channel deactivation */
975 
976  if(hi2s->Instance == I2S2)
977  {
978  /* Deinitialize the Stream for new transfer */
979  HAL_DMA_DeInit(hi2s->hdmarx);
980  }
981 
982  /* Disable I2S block */
983  __HAL_I2S_DISABLE(hi2s);
984 
985  /* Disable pins: SCK and SD pins */
986  gpio_init_structure.Pin = I2S2_SCK_PIN;
987  HAL_GPIO_DeInit(I2S2_SCK_GPIO_PORT, gpio_init_structure.Pin);
988  gpio_init_structure.Pin = I2S2_MOSI_PIN;
989  HAL_GPIO_DeInit(I2S2_MOSI_GPIO_PORT, gpio_init_structure.Pin);
990 
991  /* Disable I2S clock */
993 
994  /* GPIO pins clock and DMA clock can be shut down in the applic
995  by surcgarging this __weak function */
996 }
997 
1002 {
1003  /* This function should be implemented by the user application.
1004  It is called into this driver when the current buffer is filled
1005  to prepare the next buffer pointer and its size. */
1006 }
1007 
1012 {
1013  /* This function should be implemented by the user application.
1014  It is called into this driver when the current buffer is filled
1015  to prepare the next buffer pointer and its size. */
1016 }
1017 
1022 {
1023  /* This function is called when an Interrupt due to transfer error on or peripheral
1024  error occurs. */
1025 }
1026 
1027 /*******************************************************************************
1028  Static Functions
1029 *******************************************************************************/
1030 
1038 static void PDMDecoder_Init(uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut)
1039 {
1040  uint32_t index = 0;
1041 
1042  /* Enable CRC peripheral to unlock the PDM library */
1044 
1045  for(index = 0; index < ChnlNbrIn; index++)
1046  {
1047  /* Init PDM filters */
1048  PDM_FilterHandler[index].bit_order = PDM_FILTER_BIT_ORDER_LSB;
1049  PDM_FilterHandler[index].endianness = PDM_FILTER_ENDIANNESS_LE;
1050  PDM_FilterHandler[index].high_pass_tap = 2122358088;
1051  PDM_FilterHandler[index].out_ptr_channels = ChnlNbrOut;
1052  PDM_FilterHandler[index].in_ptr_channels = ChnlNbrIn;
1053  PDM_Filter_Init((PDM_Filter_Handler_t *)(&PDM_FilterHandler[index]));
1054 
1055  /* PDM lib config phase */
1056  PDM_FilterConfig[index].output_samples_number = AudioFreq/1000;
1057  PDM_FilterConfig[index].mic_gain = 24;
1058  PDM_FilterConfig[index].decimation_factor = PDM_FILTER_DEC_FACTOR_64;
1059  PDM_Filter_setConfig((PDM_Filter_Handler_t *)&PDM_FilterHandler[index], &PDM_FilterConfig[index]);
1060  }
1061 }
1062 
1070 static uint8_t I2S2_Init(uint32_t AudioFreq)
1071 {
1072  /* Initialize the hAudioInI2s Instance parameter */
1074 
1075  /* Disable I2S block */
1077 
1078  /* I2S2 peripheral configuration */
1079  hAudioInI2s.Init.AudioFreq = 2 * AudioFreq;
1086 
1087  /* Initialize the I2S peripheral with the structure above */
1089  {
1090  return AUDIO_ERROR;
1091  }
1092  else
1093  {
1094  return AUDIO_OK;
1095  }
1096 }
1097 
1111 {
1112  /* Manage the error generated on DMA FIFO: This function
1113  should be coded by user (its prototype is already declared in stm32f4_discovery_audio.h) */
1114  if(hi2s->Instance == I2S3)
1115  {
1117  }
1118  if(hi2s->Instance == I2S2)
1119  {
1121  }
1122 }
1123 
1140 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
I2S_STANDARD
#define I2S_STANDARD
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:68
I2S_MODE_MASTER_TX
#define I2S_MODE_MASTER_TX
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:194
BSP_AUDIO_OUT_SetVolume
uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
Controls the current audio volume level.
Definition: stm32f4_discovery_audio.c:381
I2S_STANDARD_LSB
#define I2S_STANDARD_LSB
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:205
DMA_InitTypeDef::Channel
uint32_t Channel
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:51
BSP_AUDIO_IN_SetVolume
uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume)
Controls the audio in volume level.
Definition: stm32f4_discovery_audio.c:799
BSP_AUDIO_IN_MspDeInit
__weak void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
DeInitializes BSP_AUDIO_IN MSP.
Definition: stm32f4_discovery_audio.c:969
HAL_I2S_TxHalfCpltCallback
void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
Tx Half Transfer completed callbacks.
Definition: stm32f4_discovery_audio.c:469
__HAL_LINKDMA
#define __HAL_LINKDMA(__HANDLE__, __PPP_DMA_FIELD__, __DMA_HANDLE__)
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:66
__IO
#define __IO
Definition: imxrt1050/imxrt1050-evkb/CMSIS/core_cm7.h:237
GPIO_MODE_AF_PP
#define GPIO_MODE_AF_PP
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:122
BSP_AUDIO_OUT_MspInit
__weak void BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
AUDIO OUT I2S MSP Init.
Definition: stm32f4_discovery_audio.c:529
I2S3_WS_GPIO_PORT
#define I2S3_WS_GPIO_PORT
Definition: stm32f4_discovery_audio.h:93
BSP_AUDIO_IN_PDMToPCM
uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf)
Converts audio format from PDM to PCM.
Definition: stm32f4_discovery_audio.c:814
DMA_PINC_DISABLE
#define DMA_PINC_DISABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:240
I2S2_SCK_GPIO_CLK_ENABLE
#define I2S2_SCK_GPIO_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:120
HAL_NVIC_EnableIRQ
void HAL_NVIC_EnableIRQ(IRQn_Type IRQn)
BSP_AUDIO_OUT_Pause
uint8_t BSP_AUDIO_OUT_Pause(void)
Pauses the audio file stream. In case of using DMA, the DMA Pause feature is used....
Definition: stm32f4_discovery_audio.c:301
__DMA_HandleTypeDef
DMA handle Structure definition.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:139
NULL
#define NULL
Definition: porcupine/demo/c/dr_libs/tests/external/miniaudio/extras/speex_resampler/thirdparty/resample.c:92
DEFAULT_AUDIO_IN_CHANNEL_NBR
#define DEFAULT_AUDIO_IN_CHANNEL_NBR
Definition: stm32f4_discovery_audio.h:156
BSP_AUDIO_IN_Stop
uint8_t BSP_AUDIO_IN_Stop(void)
Stops audio recording.
Definition: stm32f4_discovery_audio.c:754
AUDIO_DrvTypeDef::Play
uint32_t(* Play)(uint16_t, uint16_t *, uint16_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:86
GPIO_InitTypeDef
GPIO Init structure definition
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:47
CODEC_PDWN_HW
#define CODEC_PDWN_HW
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/cs43l22/cs43l22.h:85
I2S_InitTypeDef::CPOL
uint32_t CPOL
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:64
I2S2_CLK_ENABLE
#define I2S2_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:116
I2S2_CLK_DISABLE
#define I2S2_CLK_DISABLE()
Definition: stm32f4_discovery_audio.h:117
AUDIO_IN_IRQ_PREPRIO
#define AUDIO_IN_IRQ_PREPRIO
Definition: stm32f4_discovery_audio.h:140
hAudioInI2s
I2S_HandleTypeDef hAudioInI2s
Definition: stm32f4_discovery_audio.c:181
I2S2_MOSI_AF
#define I2S2_MOSI_AF
Definition: stm32f4_discovery_audio.h:126
DMA_InitTypeDef::Priority
uint32_t Priority
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:75
DMA_InitTypeDef::PeriphInc
uint32_t PeriphInc
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:58
HAL_I2S_TxCpltCallback
void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s)
Tx Transfer completed callbacks.
Definition: stm32f4_discovery_audio.c:456
I2S_InitTypeDef::MCLKOutput
uint32_t MCLKOutput
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:58
I2S2_SCK_AF
#define I2S2_SCK_AF
Definition: stm32f4_discovery_audio.h:121
AudioInVolume
__IO uint16_t AudioInVolume
Definition: stm32f4_discovery_audio.c:187
GPIO_InitTypeDef::Alternate
uint32_t Alternate
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:61
AUDIO_ERROR
#define AUDIO_ERROR
Definition: stm32f4_discovery_audio.h:150
I2SPLLN
const uint32_t I2SPLLN[8]
Definition: stm32f4_discovery_audio.c:160
HAL_I2S_RxCpltCallback
void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s)
Rx Transfer completed callbacks.
Definition: stm32f4_discovery_audio.c:844
I2S_HandleTypeDef
I2S handle Structure definition.
Definition: stm32f7xx_hal_i2s.h:91
__HAL_RCC_CRC_CLK_ENABLE
#define __HAL_RCC_CRC_CLK_ENABLE()
Definition: stm32f7xx_hal_rcc.h:409
HAL_NVIC_DisableIRQ
void HAL_NVIC_DisableIRQ(IRQn_Type IRQn)
RCC_PeriphCLKInitTypeDef::PeriphClockSelection
uint32_t PeriphClockSelection
Definition: stm32f7xx_hal_rcc_ex.h:128
BSP_AUDIO_IN_Init
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Initializes wave recording.
Definition: stm32f4_discovery_audio.c:705
I2S_InitTypeDef::Standard
uint32_t Standard
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:52
I2S3_WS_CLK_ENABLE
#define I2S3_WS_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:87
I2S3_DMAx_STREAM
#define I2S3_DMAx_STREAM
Definition: stm32f4_discovery_audio.h:99
BSP_AUDIO_OUT_TransferComplete_CallBack
__weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
Manages the DMA full Transfer complete event.
Definition: stm32f4_discovery_audio.c:637
CS43L22_ID_MASK
#define CS43L22_ID_MASK
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/cs43l22/cs43l22.h:150
I2S_HandleTypeDef::hdmatx
DMA_HandleTypeDef * hdmatx
Definition: stm32f7xx_hal_i2s.h:114
AUDIO_I2C_ADDRESS
#define AUDIO_I2C_ADDRESS
AUDIO I2C Interface pins.
Definition: stm32f4_discovery.h:247
I2S3_Init
static uint8_t I2S3_Init(uint32_t AudioFreq)
Initializes the Audio Codec audio interface (I2S).
Definition: stm32f4_discovery_audio.c:663
__DMA_HandleTypeDef::Init
DMA_InitTypeDef Init
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:143
RCC_PERIPHCLK_I2S
#define RCC_PERIPHCLK_I2S
Definition: stm32f7xx_hal_rcc_ex.h:237
DMA_InitTypeDef::FIFOThreshold
uint32_t FIFOThreshold
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:83
DMA_CIRCULAR
#define DMA_CIRCULAR
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:282
I2S3_DMAx_MEM_DATA_SIZE
#define I2S3_DMAx_MEM_DATA_SIZE
Definition: stm32f4_discovery_audio.h:103
BSP_AUDIO_IN_ClockConfig
__weak void BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
Audio In Clock Config.
Definition: stm32f4_discovery_audio.c:869
DMA_InitTypeDef::PeriphDataAlignment
uint32_t PeriphDataAlignment
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:64
pAudioDrv
static AUDIO_DrvTypeDef * pAudioDrv
Definition: stm32f4_discovery_audio.c:177
I2S2_DMAx_IRQ
#define I2S2_DMAx_IRQ
Definition: stm32f4_discovery_audio.h:133
RCC_PeriphCLKInitTypeDef::PLLI2S
RCC_PLLI2SInitTypeDef PLLI2S
Definition: stm32f7xx_hal_rcc_ex.h:131
HAL_I2S_DMAPause
HAL_StatusTypeDef HAL_I2S_DMAPause(I2S_HandleTypeDef *hi2s)
AUDIODATA_SIZE
#define AUDIODATA_SIZE
Definition: stm32f4_discovery_audio.h:146
BSP_AUDIO_OUT_Play
uint8_t BSP_AUDIO_OUT_Play(uint16_t *pBuffer, uint32_t Size)
Starts playing audio stream from a data buffer for a determined size.
Definition: stm32f4_discovery_audio.c:266
INTERNAL_BUFF_SIZE
#define INTERNAL_BUFF_SIZE
Definition: stm32f4_discovery_audio.h:160
I2S2_SCK_GPIO_PORT
#define I2S2_SCK_GPIO_PORT
Definition: stm32f4_discovery_audio.h:119
AUDIO_OUT_IRQ_PREPRIO
#define AUDIO_OUT_IRQ_PREPRIO
Definition: stm32f4_discovery_audio.h:109
HAL_Delay
void HAL_Delay(uint32_t Delay)
This function provides minimum delay (in milliseconds) based on variable incremented.
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Src/stm32f4xx_hal.c:389
I2S2_MOSI_GPIO_PORT
#define I2S2_MOSI_GPIO_PORT
Definition: stm32f4_discovery_audio.h:124
DMA_MBURST_SINGLE
#define DMA_MBURST_SINGLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:326
AUDIO_RESET_PIN
#define AUDIO_RESET_PIN
Definition: stm32f4_discovery.h:251
I2S_CPOL_HIGH
#define I2S_CPOL_HIGH
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:262
I2S2_MOSI_GPIO_CLK_ENABLE
#define I2S2_MOSI_GPIO_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:125
I2SFreq
const uint32_t I2SFreq[8]
Definition: stm32f4_discovery_audio.c:159
hAudioOutI2s
I2S_HandleTypeDef hAudioOutI2s
Definition: stm32f4_discovery_audio.c:178
I2S_HandleTypeDef::Instance
SPI_TypeDef * Instance
Definition: stm32f7xx_hal_i2s.h:94
HAL_OK
@ HAL_OK
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_def.h:42
DMA_PERIPH_TO_MEMORY
#define DMA_PERIPH_TO_MEMORY
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:228
HAL_I2S_Receive_DMA
HAL_StatusTypeDef HAL_I2S_Receive_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size)
PDM_FilterConfig
PDM_Filter_Config_t PDM_FilterConfig[2]
Definition: stm32f4_discovery_audio.c:185
HAL_GPIO_Init
void HAL_GPIO_Init(GPIO_TypeDef *GPIOx, GPIO_InitTypeDef *GPIO_Init)
I2S3_DMAx_CLK_ENABLE
#define I2S3_DMAx_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:97
HAL_I2S_RxHalfCpltCallback
void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
Rx Half Transfer completed callbacks.
Definition: stm32f4_discovery_audio.c:854
PDM_FilterHandler
PDM_Filter_Handler_t PDM_FilterHandler[2]
Definition: stm32f4_discovery_audio.c:184
GPIO_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:52
I2S2_DMAx_CLK_ENABLE
#define I2S2_DMAx_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:129
AUDIO_RESET_GPIO
#define AUDIO_RESET_GPIO
Definition: stm32f4_discovery.h:252
HAL_I2S_DMAResume
HAL_StatusTypeDef HAL_I2S_DMAResume(I2S_HandleTypeDef *hi2s)
DMA_InitTypeDef::MemInc
uint32_t MemInc
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:61
BSP_AUDIO_IN_Pause
uint8_t BSP_AUDIO_IN_Pause(void)
Pauses the audio file stream.
Definition: stm32f4_discovery_audio.c:771
HAL_I2S_GetState
HAL_I2S_StateTypeDef HAL_I2S_GetState(I2S_HandleTypeDef *hi2s)
AUDIO_DrvTypeDef::SetMute
uint32_t(* SetMute)(uint16_t, uint32_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:92
I2S_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:49
GPIO_InitTypeDef::Pull
uint32_t Pull
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:55
GPIO_NOPULL
#define GPIO_NOPULL
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:154
BSP_AUDIO_OUT_SetFrequency
void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
Update the audio frequency.
Definition: stm32f4_discovery_audio.c:443
AUDIO_DrvTypeDef::Init
uint32_t(* Init)(uint16_t, uint16_t, uint8_t, uint32_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:83
PCM_OUT_SIZE
#define PCM_OUT_SIZE
Definition: stm32f4_discovery_audio.h:162
DMA_InitTypeDef::PeriphBurst
uint32_t PeriphBurst
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:92
I2S3_DMAx_CHANNEL
#define I2S3_DMAx_CHANNEL
Definition: stm32f4_discovery_audio.h:100
HAL_I2S_Init
HAL_StatusTypeDef HAL_I2S_Init(I2S_HandleTypeDef *hi2s)
I2S3_SCK_PIN
#define I2S3_SCK_PIN
Definition: stm32f4_discovery_audio.h:89
I2S2_DMAx_STREAM
#define I2S2_DMAx_STREAM
Definition: stm32f4_discovery_audio.h:131
I2S2_DMAx_PERIPH_DATA_SIZE
#define I2S2_DMAx_PERIPH_DATA_SIZE
Definition: stm32f4_discovery_audio.h:134
DMA_PRIORITY_HIGH
#define DMA_PRIORITY_HIGH
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:294
PDMDecoder_Init
static void PDMDecoder_Init(uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut)
Initializes the PDM library.
Definition: stm32f4_discovery_audio.c:1038
__DMA_HandleTypeDef::Instance
DMA_Stream_TypeDef * Instance
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:141
I2S3_SCK_SD_WS_AF
#define I2S3_SCK_SD_WS_AF
Definition: stm32f4_discovery_audio.h:84
RCC_PLLI2SInitTypeDef::PLLI2SN
uint32_t PLLI2SN
Definition: stm32f7xx_hal_rcc_ex.h:78
DMA_InitTypeDef::MemDataAlignment
uint32_t MemDataAlignment
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:67
stm32f4_discovery_audio.h
This file contains the common defines and functions prototypes for stm32f4_discovery_audio....
BSP_AUDIO_OUT_Error_CallBack
__weak void BSP_AUDIO_OUT_Error_CallBack(void)
Manages the DMA FIFO error event.
Definition: stm32f4_discovery_audio.c:651
HAL_GPIO_DeInit
void HAL_GPIO_DeInit(GPIO_TypeDef *GPIOx, uint32_t GPIO_Pin)
AUDIO_DrvTypeDef::Stop
uint32_t(* Stop)(uint16_t, uint32_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:89
HAL_I2S_ErrorCallback
void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s)
I2S error callbacks.
Definition: stm32f4_discovery_audio.c:1110
I2S3_MCK_GPIO_PORT
#define I2S3_MCK_GPIO_PORT
Definition: stm32f4_discovery_audio.h:94
BSP_AUDIO_OUT_HalfTransfer_CallBack
__weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
Definition: stm32f4_discovery_audio.c:644
I2S2_Init
static uint8_t I2S2_Init(uint32_t AudioFreq)
Initializes the Audio Codec audio interface (I2S)
Definition: stm32f4_discovery_audio.c:1070
I2S3
#define I2S3
Definition: stm32f4_discovery_audio.h:81
GPIO_InitTypeDef::Speed
uint32_t Speed
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:58
BSP_AUDIO_OUT_SetOutputMode
uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output)
Switch dynamically (while audio file is played) the output target (speaker or headphone).
Definition: stm32f4_discovery_audio.c:423
I2S2_MOSI_PIN
#define I2S2_MOSI_PIN
Definition: stm32f4_discovery_audio.h:123
I2SPLLR
const uint32_t I2SPLLR[8]
Definition: stm32f4_discovery_audio.c:161
I2S_MCLKOUTPUT_ENABLE
#define I2S_MCLKOUTPUT_ENABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:226
DMA_PBURST_SINGLE
#define DMA_PBURST_SINGLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:338
RCC_PLLI2SInitTypeDef::PLLI2SR
uint32_t PLLI2SR
Definition: stm32f7xx_hal_rcc_ex.h:82
GPIO_PIN_RESET
@ GPIO_PIN_RESET
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:70
I2S3_DMAx_IRQ
#define I2S3_DMAx_IRQ
Definition: stm32f4_discovery_audio.h:101
AUDIO_DrvTypeDef
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:81
BSP_AUDIO_IN_Record
uint8_t BSP_AUDIO_IN_Record(uint16_t *pbuf, uint32_t size)
Starts audio recording.
Definition: stm32f4_discovery_audio.c:737
BSP_AUDIO_IN_Error_Callback
__weak void BSP_AUDIO_IN_Error_Callback(void)
Audio IN Error callback function.
Definition: stm32f4_discovery_audio.c:1021
DMA_MINC_ENABLE
#define DMA_MINC_ENABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:249
DEFAULT_AUDIO_IN_VOLUME
#define DEFAULT_AUDIO_IN_VOLUME
Definition: stm32f4_discovery_audio.h:157
I2S3_WS_PIN
#define I2S3_WS_PIN
Definition: stm32f4_discovery_audio.h:88
AUDIO_DrvTypeDef::Resume
uint32_t(* Resume)(uint16_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:88
HTONS
#define HTONS(A)
Definition: stm32f4_discovery_audio.h:185
BSP_AUDIO_OUT_Stop
uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
Stops audio playing and Power down the Audio Codec.
Definition: stm32f4_discovery_audio.c:349
I2S_HandleTypeDef::hdmarx
DMA_HandleTypeDef * hdmarx
Definition: stm32f7xx_hal_i2s.h:116
DMA_InitTypeDef::MemBurst
uint32_t MemBurst
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:86
I2S_HandleTypeDef::Init
I2S_InitTypeDef Init
Definition: stm32f7xx_hal_i2s.h:96
BSP_AUDIO_IN_MspInit
__weak void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
BSP AUDIO IN MSP Init.
Definition: stm32f4_discovery_audio.c:903
BSP_AUDIO_IN_TransferComplete_CallBack
__weak void BSP_AUDIO_IN_TransferComplete_CallBack(void)
User callback when record buffer is filled.
Definition: stm32f4_discovery_audio.c:1001
BSP_AUDIO_IN_Resume
uint8_t BSP_AUDIO_IN_Resume(void)
Resumes the audio file stream.
Definition: stm32f4_discovery_audio.c:784
I2S_InitTypeDef::DataFormat
uint32_t DataFormat
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:55
CS43L22_ID
#define CS43L22_ID
CS43L22 ID
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/cs43l22/cs43l22.h:149
DMA_FIFOMODE_ENABLE
#define DMA_FIFOMODE_ENABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:305
DMA_NORMAL
#define DMA_NORMAL
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:281
I2S3_SCK_SD_CLK_ENABLE
#define I2S3_SCK_SD_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:85
DMA_InitTypeDef::FIFOMode
uint32_t FIFOMode
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:78
I2S_CPOL_LOW
#define I2S_CPOL_LOW
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:261
BSP_AUDIO_IN_HalfTransfer_CallBack
__weak void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
Definition: stm32f4_discovery_audio.c:1011
DMA_FIFOMODE_DISABLE
#define DMA_FIFOMODE_DISABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:304
AUDIO_DrvTypeDef::ReadID
uint32_t(* ReadID)(uint16_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:85
DMA_MEMORY_TO_PERIPH
#define DMA_MEMORY_TO_PERIPH
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:229
HAL_RCCEx_PeriphCLKConfig
HAL_StatusTypeDef HAL_RCCEx_PeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
I2S2_SCK_PIN
#define I2S2_SCK_PIN
Definition: stm32f4_discovery_audio.h:118
HAL_DMA_Init
HAL_StatusTypeDef HAL_DMA_Init(DMA_HandleTypeDef *hdma)
HAL_I2S_STATE_RESET
@ HAL_I2S_STATE_RESET
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:78
I2S2_DMAx_MEM_DATA_SIZE
#define I2S2_DMAx_MEM_DATA_SIZE
Definition: stm32f4_discovery_audio.h:135
I2S3_CLK_DISABLE
#define I2S3_CLK_DISABLE()
Definition: stm32f4_discovery_audio.h:83
DMA_InitTypeDef::Direction
uint32_t Direction
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:54
BSP_AUDIO_OUT_ClockConfig
__weak void BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
Clock Config.
Definition: stm32f4_discovery_audio.c:487
HAL_DMA_DeInit
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
HAL_I2S_DMAStop
HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s)
I2S_CLOCK_PLL
#define I2S_CLOCK_PLL
Definition: stm32f7xx_hal_i2s.h:284
I2S3_SCK_SD_GPIO_PORT
#define I2S3_SCK_SD_GPIO_PORT
Definition: stm32f4_discovery_audio.h:92
Output
Output
AUDIO_DrvTypeDef::Pause
uint32_t(* Pause)(uint16_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:87
AUDIO_DrvTypeDef::SetOutputMode
uint32_t(* SetOutputMode)(uint16_t, uint8_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:93
I2S3_DMAx_PERIPH_DATA_SIZE
#define I2S3_DMAx_PERIPH_DATA_SIZE
Definition: stm32f4_discovery_audio.h:102
HAL_NVIC_SetPriority
void HAL_NVIC_SetPriority(IRQn_Type IRQn, uint32_t PreemptPriority, uint32_t SubPriority)
AUDIO_OK
#define AUDIO_OK
Definition: stm32f4_discovery_audio.h:149
I2S_InitTypeDef::ClockSource
uint32_t ClockSource
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:67
RCC_PeriphCLKInitTypeDef
RCC extended clocks structure definition.
Definition: stm32f7xx_hal_rcc_ex.h:126
I2S3_SD_PIN
#define I2S3_SD_PIN
Definition: stm32f4_discovery_audio.h:90
I2S_MCLKOUTPUT_DISABLE
#define I2S_MCLKOUTPUT_DISABLE
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:227
I2S3_MCK_CLK_ENABLE
#define I2S3_MCK_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:86
DMA_InitTypeDef::Mode
uint32_t Mode
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:70
I2S3_CLK_ENABLE
#define I2S3_CLK_ENABLE()
Definition: stm32f4_discovery_audio.h:82
BSP_AUDIO_OUT_Init
uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
Configures the audio peripherals.
Definition: stm32f4_discovery_audio.c:214
BSP_AUDIO_OUT_Resume
uint8_t BSP_AUDIO_OUT_Resume(void)
Resumes the audio file streaming. WARNING: When calling BSP_AUDIO_OUT_Pause() function for pause,...
Definition: stm32f4_discovery_audio.c:325
__HAL_I2S_DISABLE
#define __HAL_I2S_DISABLE(__HANDLE__)
Disable the specified SPI peripheral (in I2S mode).
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:354
AUDIO_DrvTypeDef::SetVolume
uint32_t(* SetVolume)(uint16_t, uint8_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:91
DMA_FIFO_THRESHOLD_FULL
#define DMA_FIFO_THRESHOLD_FULL
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:317
I2S2
#define I2S2
Definition: stm32f4_discovery_audio.h:115
I2S_DATAFORMAT_16B
#define I2S_DATAFORMAT_16B
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:215
cs43l22_drv
AUDIO_DrvTypeDef cs43l22_drv
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/cs43l22/cs43l22.c:87
I2S3_MCK_PIN
#define I2S3_MCK_PIN
Definition: stm32f4_discovery_audio.h:91
HAL_I2S_Transmit_DMA
HAL_StatusTypeDef HAL_I2S_Transmit_DMA(I2S_HandleTypeDef *hi2s, uint16_t *pData, uint16_t Size)
DMA_MAX
#define DMA_MAX(_X_)
Definition: stm32f4_discovery_audio.h:184
BSP_AUDIO_OUT_MspDeInit
__weak void BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
De-Initializes BSP_AUDIO_OUT MSP.
Definition: stm32f4_discovery_audio.c:599
I2S2_DMAx_CHANNEL
#define I2S2_DMAx_CHANNEL
Definition: stm32f4_discovery_audio.h:132
HAL_RCCEx_GetPeriphCLKConfig
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
BSP_AUDIO_OUT_SetMute
uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd)
Enables or disables the MUTE mode by software.
Definition: stm32f4_discovery_audio.c:401
I2S_InitTypeDef::AudioFreq
uint32_t AudioFreq
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:61
HAL_GPIO_WritePin
void HAL_GPIO_WritePin(GPIO_TypeDef *GPIOx, uint16_t GPIO_Pin, GPIO_PinState PinState)
I2S_MODE_MASTER_RX
#define I2S_MODE_MASTER_RX
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:195
BSP_AUDIO_OUT_ChangeBuffer
void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
Sends n-Bytes on the I2S interface.
Definition: stm32f4_discovery_audio.c:288
GPIO_InitTypeDef::Pin
uint32_t Pin
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:49


picovoice_driver
Author(s):
autogenerated on Fri Apr 1 2022 02:14:51