stm32f411e_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 STM32F411xx devices on STM32F411E-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 stm32f411e_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 stm32f411e_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 stm32f411e_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 stm32f411e_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 ------------------------------------------------------------------*/
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  RCC_PeriphCLKInitTypeDef rccclkinit;
446 
447  /* Enable PLLI2S clock */
448  HAL_RCCEx_GetPeriphCLKConfig(&rccclkinit);
449  /* PLLI2S_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
450  if ((AudioFreq & 0x7) == 0)
451  {
452  /* Audio frequency multiple of 8 (8/16/32/48/96/192) */
453  /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 192 Mhz */
454  /* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 192/6 = 32 Mhz */
456  rccclkinit.PLLI2S.PLLI2SN = 192;
457  rccclkinit.PLLI2S.PLLI2SR = 6;
458  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
459  }
460  else
461  {
462  /* Other Frequency (11.025/22.500/44.100) */
463  /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 290 Mhz */
464  /* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 290/2 = 145 Mhz */
466  rccclkinit.PLLI2S.PLLI2SN = 290;
467  rccclkinit.PLLI2S.PLLI2SR = 2;
468  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
469  }
470 
471  /* Update the I2S audio frequency configuration */
472  I2S3_Init(AudioFreq);
473 }
474 
480 {
481  if(hi2s->Instance == I2S3)
482  {
483  /* Call the user function which will manage directly transfer complete */
485  }
486 }
487 
493 {
494  if(hi2s->Instance == I2S3)
495  {
496  /* Manage the remaining file size and new address offset: This function should
497  be coded by user (its prototype is already declared in stm32f4_discovery_audio.h) */
499  }
500 }
501 
510 __weak void BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
511 {
512  RCC_PeriphCLKInitTypeDef rccclkinit;
513  uint8_t index = 0, freqindex = 0xFF;
514 
515  for(index = 0; index < 8; index++)
516  {
517  if(I2SFreq[index] == AudioFreq)
518  {
519  freqindex = index;
520  }
521  }
522  /* Enable PLLI2S clock */
523  HAL_RCCEx_GetPeriphCLKConfig(&rccclkinit);
524  /* PLLI2S_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
525  if ((freqindex & 0x7) == 0)
526  {
527  /* I2S clock config
528  PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLM)
529  I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
531  rccclkinit.PLLI2S.PLLI2SM = 8;
532  rccclkinit.PLLI2S.PLLI2SN = I2SPLLN[freqindex];
533  rccclkinit.PLLI2S.PLLI2SR = I2SPLLR[freqindex];
534  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
535  }
536  else
537  {
538  /* I2S clock config
539  PLLI2S_VCO = f(VCO clock) = f(PLLI2S clock input) × (PLLI2SN/PLLM)
540  I2SCLK = f(PLLI2S clock output) = f(VCO clock) / PLLI2SR */
542  rccclkinit.PLLI2S.PLLI2SM = 8;
543  rccclkinit.PLLI2S.PLLI2SN = 258;
544  rccclkinit.PLLI2S.PLLI2SR = 3;
545  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
546  }
547 }
548 
554 __weak void BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
555 {
556  static DMA_HandleTypeDef hdma_i2sTx;
557  GPIO_InitTypeDef GPIO_InitStruct;
558 
559  /* Enable I2S3 clock */
560  I2S3_CLK_ENABLE();
561 
562  /*** Configure the GPIOs ***/
563  /* Enable I2S GPIO clocks */
566 
567  /* I2S3 pins configuration: WS, SCK and SD pins ----------------------------*/
568  GPIO_InitStruct.Pin = I2S3_SCK_PIN | I2S3_SD_PIN;
569  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
570  GPIO_InitStruct.Pull = GPIO_NOPULL;
571  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
572  GPIO_InitStruct.Alternate = I2S3_SCK_SD_WS_AF;
573  HAL_GPIO_Init(I2S3_SCK_SD_GPIO_PORT, &GPIO_InitStruct);
574 
575  GPIO_InitStruct.Pin = I2S3_WS_PIN ;
576  HAL_GPIO_Init(I2S3_WS_GPIO_PORT, &GPIO_InitStruct);
577 
578  /* I2S3 pins configuration: MCK pin */
580  GPIO_InitStruct.Pin = I2S3_MCK_PIN;
581  HAL_GPIO_Init(I2S3_MCK_GPIO_PORT, &GPIO_InitStruct);
582 
583  /* Enable the I2S DMA clock */
585 
586  if(hi2s->Instance == I2S3)
587  {
588  /* Configure the hdma_i2sTx handle parameters */
589  hdma_i2sTx.Init.Channel = I2S3_DMAx_CHANNEL;
590  hdma_i2sTx.Init.Direction = DMA_MEMORY_TO_PERIPH;
591  hdma_i2sTx.Init.PeriphInc = DMA_PINC_DISABLE;
592  hdma_i2sTx.Init.MemInc = DMA_MINC_ENABLE;
595  hdma_i2sTx.Init.Mode = DMA_NORMAL;
596  hdma_i2sTx.Init.Priority = DMA_PRIORITY_HIGH;
597  hdma_i2sTx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
599  hdma_i2sTx.Init.MemBurst = DMA_MBURST_SINGLE;
600  hdma_i2sTx.Init.PeriphBurst = DMA_PBURST_SINGLE;
601 
602  hdma_i2sTx.Instance = I2S3_DMAx_STREAM;
603 
604  /* Associate the DMA handle */
605  __HAL_LINKDMA(hi2s, hdmatx, hdma_i2sTx);
606 
607  /* Deinitialize the Stream for new transfer */
608  HAL_DMA_DeInit(&hdma_i2sTx);
609 
610  /* Configure the DMA Stream */
611  HAL_DMA_Init(&hdma_i2sTx);
612  }
613 
614  /* I2S DMA IRQ Channel configuration */
617 }
618 
624 __weak void BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
625 {
626  GPIO_InitTypeDef GPIO_InitStruct;
627 
628  /* I2S DMA IRQ Channel deactivation */
630 
631  if(hi2s->Instance == I2S3)
632  {
633  /* Deinitialize the Stream for new transfer */
634  HAL_DMA_DeInit(hi2s->hdmatx);
635  }
636 
637  /* Disable I2S block */
638  __HAL_I2S_DISABLE(hi2s);
639 
640  /* CODEC_I2S pins configuration: SCK and SD pins */
641  GPIO_InitStruct.Pin = I2S3_SCK_PIN | I2S3_SD_PIN;
642  HAL_GPIO_DeInit(I2S3_SCK_SD_GPIO_PORT, GPIO_InitStruct.Pin);
643 
644  /* CODEC_I2S pins configuration: WS pin */
645  GPIO_InitStruct.Pin = I2S3_WS_PIN;
646  HAL_GPIO_DeInit(I2S3_WS_GPIO_PORT, GPIO_InitStruct.Pin);
647 
648  /* CODEC_I2S pins configuration: MCK pin */
649  GPIO_InitStruct.Pin = I2S3_MCK_PIN;
650  HAL_GPIO_DeInit(I2S3_MCK_GPIO_PORT, GPIO_InitStruct.Pin);
651 
652  /* Disable I2S clock */
654 
655  /* GPIO pins clock and DMA clock can be shut down in the applic
656  by surcgarging this __weak function */
657 }
658 
663 {
664 }
665 
670 {
671 }
672 
677 {
678 }
679 
680 /*******************************************************************************
681  Static Functions
682 *******************************************************************************/
683 
688 static uint8_t I2S3_Init(uint32_t AudioFreq)
689 {
690  /* Initialize the hAudioOutI2s Instance parameter */
692 
693  /* Disable I2S block */
695 
696  /* I2S3 peripheral configuration */
697  hAudioOutI2s.Init.AudioFreq = AudioFreq;
704 
705  /* Initialize the I2S peripheral with the structure above */
707  {
708  return AUDIO_ERROR;
709  }
710  else
711  {
712  return AUDIO_OK;
713  }
714 }
715 
731 uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
732 {
733  /* Configure PLL clock */
735 
736  /* Configure the PDM library */
737  /* On STM32F411E-Discovery a single microphone is mounted, samples are duplicated
738  to make stereo audio streams */
739  PDMDecoder_Init(AudioFreq, ChnlNbr, 2);
740 
741  /* Configure the I2S peripheral */
744  {
745  /* Initialize the I2S Msp: this __weak function can be rewritten by the application */
747  }
748 
749  /* Configure the I2S2 */
750  I2S2_Init(AudioFreq);
751 
752  /* Return AUDIO_OK when all operations are correctly done */
753  return AUDIO_OK;
754 }
755 
762 uint8_t BSP_AUDIO_IN_Record(uint16_t* pbuf, uint32_t size)
763 {
764  uint32_t ret = AUDIO_ERROR;
765 
766  /* Start the process receive DMA */
767  HAL_I2S_Receive_DMA(&hAudioInI2s, pbuf, size);
768 
769  /* Return AUDIO_OK when all operations are correctly done */
770  ret = AUDIO_OK;
771 
772  return ret;
773 }
774 
778 uint8_t BSP_AUDIO_IN_Stop(void)
779 {
780  uint32_t ret = AUDIO_ERROR;
781 
782  /* Call the Media layer pause function */
784 
785  /* Return AUDIO_OK when all operations are correctly done */
786  ret = AUDIO_OK;
787 
788  return ret;
789 }
790 
795 uint8_t BSP_AUDIO_IN_Pause(void)
796 {
797  /* Call the Media layer pause function */
799 
800  /* Return AUDIO_OK when all operations are correctly done */
801  return AUDIO_OK;
802 }
803 
808 uint8_t BSP_AUDIO_IN_Resume(void)
809 {
810  /* Call the Media layer pause/resume function */
812 
813  /* Return AUDIO_OK when all operations are correctly done */
814  return AUDIO_OK;
815 }
816 
823 uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume)
824 {
825  /* Set the Global variable AudioInVolume */
826  AudioInVolume = Volume;
827 
828  /* Return AUDIO_OK when all operations are correctly done */
829  return AUDIO_OK;
830 }
831 
838 uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf)
839 {
840  uint16_t AppPDM[INTERNAL_BUFF_SIZE/2];
841  uint32_t index = 0;
842 
843  /* PDM Demux */
844  for(index = 0; index<INTERNAL_BUFF_SIZE/2; index++)
845  {
846  AppPDM[index] = HTONS(PDMBuf[index]);
847  }
848 
849  for(index = 0; index < DEFAULT_AUDIO_IN_CHANNEL_NBR; index++)
850  {
851  /* PDM to PCM filter */
852  PDM_Filter((uint8_t*)&AppPDM[index], (uint16_t*)&(PCMBuf[index]), &PDM_FilterHandler[index]);
853  }
854 
855  /* Duplicate samples since a single microphone in mounted on STM32F4-Discovery */
856  for(index = 0; index < PCM_OUT_SIZE; index++)
857  {
858  PCMBuf[(index<<1)+1] = PCMBuf[index<<1];
859  }
860 
861  /* Return AUDIO_OK when all operations are correctly done */
862  return AUDIO_OK;
863 }
864 
870 {
871  /* Call the record update function to get the next buffer to fill and its size (size is ignored) */
873 }
874 
880 {
881  /* Manage the remaining file size and new address offset: This function
882  should be coded by user (its prototype is already declared in stm32f4_discovery_audio.h) */
884 }
885 
894 __weak void BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
895 {
896  RCC_PeriphCLKInitTypeDef rccclkinit;
897 
898  /* Enable PLLI2S clock */
899  HAL_RCCEx_GetPeriphCLKConfig(&rccclkinit);
900  /* PLLI2S_VCO Input = HSE_VALUE/PLL_M = 1 Mhz */
901  if ((AudioFreq & 0x7) == 0)
902  {
903  /* Audio frequency multiple of 8 (8/16/32/48/96/192)*/
904  /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 192 Mhz */
905  /* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 192/6 = 32 Mhz */
907  rccclkinit.PLLI2S.PLLI2SM = 8;
908  rccclkinit.PLLI2S.PLLI2SN = 192;
909  rccclkinit.PLLI2S.PLLI2SR = 6;
910  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
911  }
912  else
913  {
914  /* Other Frequency (11.025/22.500/44.100) */
915  /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN = 290 Mhz */
916  /* I2SCLK = PLLI2S_VCO Output/PLLI2SR = 290/2 = 145 Mhz */
918  rccclkinit.PLLI2S.PLLI2SM = 8;
919  rccclkinit.PLLI2S.PLLI2SN = 290;
920  rccclkinit.PLLI2S.PLLI2SR = 2;
921  HAL_RCCEx_PeriphCLKConfig(&rccclkinit);
922  }
923 }
924 
930 __weak void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
931 {
932  static DMA_HandleTypeDef hdma_i2sRx;
933  GPIO_InitTypeDef GPIO_InitStruct;
934 
935  /* Enable the I2S2 peripheral clock */
936  I2S2_CLK_ENABLE();
937 
938  /* Enable I2S GPIO clocks */
941 
942  /* I2S2 pins configuration: SCK and MOSI pins ------------------------------*/
943  GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
944  GPIO_InitStruct.Pull = GPIO_NOPULL;
945  GPIO_InitStruct.Speed = GPIO_SPEED_FAST;
946 
947  GPIO_InitStruct.Pin = I2S2_SCK_PIN;
948  GPIO_InitStruct.Alternate = I2S2_SCK_AF;
949  HAL_GPIO_Init(I2S2_SCK_GPIO_PORT, &GPIO_InitStruct);
950 
951  GPIO_InitStruct.Pin = I2S2_MOSI_PIN ;
952  GPIO_InitStruct.Alternate = I2S2_MOSI_AF;
953  HAL_GPIO_Init(I2S2_MOSI_GPIO_PORT, &GPIO_InitStruct);
954 
955  /* Enable the DMA clock */
957 
958  if(hi2s->Instance == I2S2)
959  {
960  /* Configure the hdma_i2sRx handle parameters */
961  hdma_i2sRx.Init.Channel = I2S2_DMAx_CHANNEL;
962  hdma_i2sRx.Init.Direction = DMA_PERIPH_TO_MEMORY;
963  hdma_i2sRx.Init.PeriphInc = DMA_PINC_DISABLE;
964  hdma_i2sRx.Init.MemInc = DMA_MINC_ENABLE;
967  hdma_i2sRx.Init.Mode = DMA_CIRCULAR;
968  hdma_i2sRx.Init.Priority = DMA_PRIORITY_HIGH;
969  hdma_i2sRx.Init.FIFOMode = DMA_FIFOMODE_DISABLE;
971  hdma_i2sRx.Init.MemBurst = DMA_MBURST_SINGLE;
972  hdma_i2sRx.Init.PeriphBurst = DMA_MBURST_SINGLE;
973 
974  hdma_i2sRx.Instance = I2S2_DMAx_STREAM;
975 
976  /* Associate the DMA handle */
977  __HAL_LINKDMA(hi2s, hdmarx, hdma_i2sRx);
978 
979  /* Deinitialize the Stream for new transfer */
980  HAL_DMA_DeInit(&hdma_i2sRx);
981 
982  /* Configure the DMA Stream */
983  HAL_DMA_Init(&hdma_i2sRx);
984  }
985 
986  /* I2S DMA IRQ Channel configuration */
989 }
990 
996 __weak void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
997 {
998  GPIO_InitTypeDef gpio_init_structure;
999 
1000  /* I2S DMA IRQ Channel deactivation */
1002 
1003  if(hi2s->Instance == I2S2)
1004  {
1005  /* Deinitialize the Stream for new transfer */
1006  HAL_DMA_DeInit(hi2s->hdmarx);
1007  }
1008 
1009  /* Disable I2S block */
1010  __HAL_I2S_DISABLE(hi2s);
1011 
1012  /* Disable pins: SCK and SD pins */
1013  gpio_init_structure.Pin = I2S2_SCK_PIN;
1014  HAL_GPIO_DeInit(I2S2_SCK_GPIO_PORT, gpio_init_structure.Pin);
1015  gpio_init_structure.Pin = I2S2_MOSI_PIN;
1016  HAL_GPIO_DeInit(I2S2_MOSI_GPIO_PORT, gpio_init_structure.Pin);
1017 
1018  /* Disable I2S clock */
1019  I2S2_CLK_DISABLE();
1020 
1021  /* GPIO pins clock and DMA clock can be shut down in the applic
1022  by surcgarging this __weak function */
1023 }
1024 
1029 {
1030  /* This function should be implemented by the user application.
1031  It is called into this driver when the current buffer is filled
1032  to prepare the next buffer pointer and its size. */
1033 }
1034 
1039 {
1040  /* This function should be implemented by the user application.
1041  It is called into this driver when the current buffer is filled
1042  to prepare the next buffer pointer and its size. */
1043 }
1044 
1049 {
1050  /* This function is called when an Interrupt due to transfer error on or peripheral
1051  error occurs. */
1052 }
1053 
1054 /*******************************************************************************
1055  Static Functions
1056 *******************************************************************************/
1057 
1065 static void PDMDecoder_Init(uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut)
1066 {
1067  uint32_t index = 0;
1068 
1069  /* Enable CRC peripheral to unlock the PDM library */
1071 
1072  for(index = 0; index < ChnlNbrIn; index++)
1073  {
1074  /* Init PDM filters */
1075  PDM_FilterHandler[index].bit_order = PDM_FILTER_BIT_ORDER_LSB;
1076  PDM_FilterHandler[index].endianness = PDM_FILTER_ENDIANNESS_LE;
1077  PDM_FilterHandler[index].high_pass_tap = 2122358088;
1078  PDM_FilterHandler[index].out_ptr_channels = ChnlNbrOut;
1079  PDM_FilterHandler[index].in_ptr_channels = ChnlNbrIn;
1080  PDM_Filter_Init((PDM_Filter_Handler_t *)(&PDM_FilterHandler[index]));
1081 
1082  /* PDM lib config phase */
1083  PDM_FilterConfig[index].output_samples_number = AudioFreq/1000;
1084  PDM_FilterConfig[index].mic_gain = 24;
1085  PDM_FilterConfig[index].decimation_factor = PDM_FILTER_DEC_FACTOR_64;
1086  PDM_Filter_setConfig((PDM_Filter_Handler_t *)&PDM_FilterHandler[index], &PDM_FilterConfig[index]);
1087  }
1088 }
1089 
1097 static uint8_t I2S2_Init(uint32_t AudioFreq)
1098 {
1099  /* Initialize the hAudioInI2s Instance parameter */
1101 
1102  /* Disable I2S block */
1104 
1105  /* I2S2 peripheral configuration */
1106  hAudioInI2s.Init.AudioFreq = 2 * AudioFreq;
1113 
1114  /* Initialize the I2S peripheral with the structure above */
1116  {
1117  return AUDIO_ERROR;
1118  }
1119  else
1120  {
1121  return AUDIO_OK;
1122  }
1123 }
1137 {
1138  /* Manage the error generated on DMA FIFO: This function
1139  should be coded by user (its prototype is already declared in stm32f411e_discovery_audio.h) */
1140  if(hi2s->Instance == I2S3)
1141  {
1143  }
1144  if(hi2s->Instance == I2S2)
1145  {
1147  }
1148 }
1149 
1166 /************************ (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
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
__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
HAL_I2S_TxCpltCallback
void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s)
Tx Transfer completed callbacks.
Definition: stm32f411e_discovery_audio.c:479
I2S3_WS_GPIO_PORT
#define I2S3_WS_GPIO_PORT
Definition: stm32f4_discovery_audio.h:93
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)
pAudioDrv
static AUDIO_DrvTypeDef * pAudioDrv
Definition: stm32f411e_discovery_audio.c:177
__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_Error_Callback
__weak void BSP_AUDIO_IN_Error_Callback(void)
Audio IN Error callback function.
Definition: stm32f411e_discovery_audio.c:1048
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
I2S2_MOSI_AF
#define I2S2_MOSI_AF
Definition: stm32f4_discovery_audio.h:126
BSP_AUDIO_OUT_SetFrequency
void BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq)
Update the audio frequency.
Definition: stm32f411e_discovery_audio.c:443
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
PDMDecoder_Init
static void PDMDecoder_Init(uint32_t AudioFreq, uint32_t ChnlNbrIn, uint32_t ChnlNbrOut)
Initializes the PDM library.
Definition: stm32f411e_discovery_audio.c:1065
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
BSP_AUDIO_IN_PDMToPCM
uint8_t BSP_AUDIO_IN_PDMToPCM(uint16_t *PDMBuf, uint16_t *PCMBuf)
Converts audio format from PDM to PCM.
Definition: stm32f411e_discovery_audio.c:838
BSP_AUDIO_OUT_MspInit
__weak void BSP_AUDIO_OUT_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
AUDIO OUT I2S MSP Init.
Definition: stm32f411e_discovery_audio.c:554
BSP_AUDIO_IN_ClockConfig
__weak void BSP_AUDIO_IN_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
Audio In Clock Config.
Definition: stm32f411e_discovery_audio.c:894
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
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
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
CS43L22_ID_MASK
#define CS43L22_ID_MASK
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/cs43l22/cs43l22.h:150
BSP_AUDIO_IN_HalfTransfer_CallBack
__weak void BSP_AUDIO_IN_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
Definition: stm32f411e_discovery_audio.c:1038
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
__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_OUT_Stop
uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option)
Stops audio playing and Power down the Audio Codec.
Definition: stm32f411e_discovery_audio.c:349
HAL_I2S_RxCpltCallback
void HAL_I2S_RxCpltCallback(I2S_HandleTypeDef *hi2s)
Rx Transfer completed callbacks.
Definition: stm32f411e_discovery_audio.c:869
DMA_InitTypeDef::PeriphDataAlignment
uint32_t PeriphDataAlignment
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:64
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_ChangeBuffer
void BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size)
Sends n-Bytes on the I2S interface.
Definition: stm32f411e_discovery_audio.c:288
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
I2S2_Init
static uint8_t I2S2_Init(uint32_t AudioFreq)
Initializes the Audio Codec audio interface (I2S)
Definition: stm32f411e_discovery_audio.c:1097
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
stm32f411e_discovery_audio.h
This file contains the common defines and functions prototypes for stm32f411e_discovery_audio....
hAudioInI2s
I2S_HandleTypeDef hAudioInI2s
Definition: stm32f411e_discovery_audio.c:181
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)
BSP_AUDIO_IN_Stop
uint8_t BSP_AUDIO_IN_Stop(void)
Stops audio recording.
Definition: stm32f411e_discovery_audio.c:778
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
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_TransferComplete_CallBack
__weak void BSP_AUDIO_IN_TransferComplete_CallBack(void)
User callback when record buffer is filled.
Definition: stm32f411e_discovery_audio.c:1028
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
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
BSP_AUDIO_OUT_ClockConfig
__weak void BSP_AUDIO_OUT_ClockConfig(I2S_HandleTypeDef *hi2s, uint32_t AudioFreq, void *Params)
Clock Config.
Definition: stm32f411e_discovery_audio.c:510
__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
BSP_AUDIO_IN_Pause
uint8_t BSP_AUDIO_IN_Pause(void)
Pauses the audio file stream.
Definition: stm32f411e_discovery_audio.c:795
DMA_InitTypeDef::MemDataAlignment
uint32_t MemDataAlignment
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_dma.h:67
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
I2S3_MCK_GPIO_PORT
#define I2S3_MCK_GPIO_PORT
Definition: stm32f4_discovery_audio.h:94
HAL_I2S_ErrorCallback
void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s)
I2S error callbacks.
Definition: stm32f411e_discovery_audio.c:1136
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
I2S2_MOSI_PIN
#define I2S2_MOSI_PIN
Definition: stm32f4_discovery_audio.h:123
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
BSP_AUDIO_OUT_Init
uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq)
Configures the audio peripherals.
Definition: stm32f411e_discovery_audio.c:214
GPIO_PIN_RESET
@ GPIO_PIN_RESET
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:70
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: stm32f411e_discovery_audio.c:301
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_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: stm32f411e_discovery_audio.c:423
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_IN_MspDeInit
__weak void BSP_AUDIO_IN_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
DeInitializes BSP_AUDIO_IN MSP.
Definition: stm32f411e_discovery_audio.c:996
I2S_HandleTypeDef::hdmarx
DMA_HandleTypeDef * hdmarx
Definition: stm32f7xx_hal_i2s.h:116
PDM_FilterHandler
PDM_Filter_Handler_t PDM_FilterHandler[2]
Definition: stm32f411e_discovery_audio.c:184
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
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
HAL_I2S_RxHalfCpltCallback
void HAL_I2S_RxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
Rx Half Transfer completed callbacks.
Definition: stm32f411e_discovery_audio.c:879
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
PDM_FilterConfig
PDM_Filter_Config_t PDM_FilterConfig[2]
Definition: stm32f411e_discovery_audio.c:185
I2S_CPOL_LOW
#define I2S_CPOL_LOW
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_i2s.h:261
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
I2SPLLN
const uint32_t I2SPLLN[8]
Definition: stm32f411e_discovery_audio.c:160
hAudioOutI2s
I2S_HandleTypeDef hAudioOutI2s
Definition: stm32f411e_discovery_audio.c:178
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
HAL_DMA_DeInit
HAL_StatusTypeDef HAL_DMA_DeInit(DMA_HandleTypeDef *hdma)
BSP_AUDIO_IN_Resume
uint8_t BSP_AUDIO_IN_Resume(void)
Resumes the audio file stream.
Definition: stm32f411e_discovery_audio.c:808
HAL_I2S_DMAStop
HAL_StatusTypeDef HAL_I2S_DMAStop(I2S_HandleTypeDef *hi2s)
I2S_CLOCK_PLL
#define I2S_CLOCK_PLL
Definition: stm32f7xx_hal_i2s.h:284
BSP_AUDIO_IN_Record
uint8_t BSP_AUDIO_IN_Record(uint16_t *pbuf, uint32_t size)
Starts audio recording.
Definition: stm32f411e_discovery_audio.c:762
I2S3_SCK_SD_GPIO_PORT
#define I2S3_SCK_SD_GPIO_PORT
Definition: stm32f4_discovery_audio.h:92
Output
Output
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: stm32f411e_discovery_audio.c:266
AUDIO_DrvTypeDef::Pause
uint32_t(* Pause)(uint16_t)
Definition: stm32f407/stm32f407g-disc1/Drivers/BSP/Components/Common/audio.h:87
BSP_AUDIO_OUT_Error_CallBack
__weak void BSP_AUDIO_OUT_Error_CallBack(void)
Manages the DMA FIFO error event.
Definition: stm32f411e_discovery_audio.c:676
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
AudioInVolume
__IO uint16_t AudioInVolume
Definition: stm32f411e_discovery_audio.c:187
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
BSP_AUDIO_OUT_HalfTransfer_CallBack
__weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void)
Manages the DMA Half Transfer complete event.
Definition: stm32f411e_discovery_audio.c:669
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
I2SFreq
const uint32_t I2SFreq[8]
Definition: stm32f411e_discovery_audio.c:159
BSP_AUDIO_OUT_MspDeInit
__weak void BSP_AUDIO_OUT_MspDeInit(I2S_HandleTypeDef *hi2s, void *Params)
De-Initializes BSP_AUDIO_OUT MSP.
Definition: stm32f411e_discovery_audio.c:624
BSP_AUDIO_OUT_TransferComplete_CallBack
__weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void)
Manages the DMA full Transfer complete event.
Definition: stm32f411e_discovery_audio.c:662
BSP_AUDIO_OUT_SetMute
uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd)
Enables or disables the MUTE mode by software.
Definition: stm32f411e_discovery_audio.c:401
__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
BSP_AUDIO_IN_Init
uint8_t BSP_AUDIO_IN_Init(uint32_t AudioFreq, uint32_t BitRes, uint32_t ChnlNbr)
Initializes wave recording.
Definition: stm32f411e_discovery_audio.c:731
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
HAL_I2S_TxHalfCpltCallback
void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s)
Tx Half Transfer completed callbacks.
Definition: stm32f411e_discovery_audio.c:492
I2S3_Init
static uint8_t I2S3_Init(uint32_t AudioFreq)
Initializes the Audio Codec audio interface (I2S).
Definition: stm32f411e_discovery_audio.c:688
BSP_AUDIO_OUT_SetVolume
uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume)
Controls the current audio volume level.
Definition: stm32f411e_discovery_audio.c:381
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_Resume
uint8_t BSP_AUDIO_OUT_Resume(void)
Resumes the audio file streaming. WARNING: When calling BSP_AUDIO_OUT_Pause() function for pause,...
Definition: stm32f411e_discovery_audio.c:325
BSP_AUDIO_IN_MspInit
__weak void BSP_AUDIO_IN_MspInit(I2S_HandleTypeDef *hi2s, void *Params)
BSP AUDIO IN MSP Init.
Definition: stm32f411e_discovery_audio.c:930
I2S2_DMAx_CHANNEL
#define I2S2_DMAx_CHANNEL
Definition: stm32f4_discovery_audio.h:132
HAL_RCCEx_GetPeriphCLKConfig
void HAL_RCCEx_GetPeriphCLKConfig(RCC_PeriphCLKInitTypeDef *PeriphClkInit)
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_IN_SetVolume
uint8_t BSP_AUDIO_IN_SetVolume(uint8_t Volume)
Controls the audio in volume level.
Definition: stm32f411e_discovery_audio.c:823
GPIO_InitTypeDef::Pin
uint32_t Pin
Definition: stm32f407/stm32f407g-disc1/Drivers/STM32F4xx_HAL_Driver/Inc/stm32f4xx_hal_gpio.h:49
I2SPLLR
const uint32_t I2SPLLR[8]
Definition: stm32f411e_discovery_audio.c:161


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