STM32373C_EVAL BSP User Manual
|
stm32373c_eval_audio.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32373c_eval_audio.c 00004 * @author MCD Application Team 00005 * @brief This file provides the Audio driver for the STM32373C_EVAL 00006 * evaluation board(MB988). 00007 ****************************************************************************** 00008 * @attention 00009 * 00010 * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> 00011 * 00012 * Redistribution and use in source and binary forms, with or without modification, 00013 * are permitted provided that the following conditions are met: 00014 * 1. Redistributions of source code must retain the above copyright notice, 00015 * this list of conditions and the following disclaimer. 00016 * 2. Redistributions in binary form must reproduce the above copyright notice, 00017 * this list of conditions and the following disclaimer in the documentation 00018 * and/or other materials provided with the distribution. 00019 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00020 * may be used to endorse or promote products derived from this software 00021 * without specific prior written permission. 00022 * 00023 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00024 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00025 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00026 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00027 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00028 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00029 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00030 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00031 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00032 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00033 * 00034 ****************************************************************************** 00035 */ 00036 00037 /*============================================================================== 00038 User NOTES 00039 How To use this driver: 00040 ----------------------- 00041 + This driver supports STM32F37x devices on STM32373C_EVAL Evaluation boards: 00042 + Call the function BSP_AUDIO_OUT_Init( 00043 OutputDevice: physical output mode (OUTPUT_DEVICE_SPEAKER, 00044 OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_AUTO or 00045 OUTPUT_DEVICE_BOTH) 00046 Volume: initial volume to be set (0 is min (mute), 100 is max (100%) 00047 AudioFreq: Audio frequency in Hz (8000, 16000, 22500, 32000 ...) 00048 this parameter is relative to the audio file/stream type. 00049 ) 00050 This function configures all the hardware required for the audio application (codec, I2C, I2S, 00051 GPIOs, DMA and interrupt if needed). This function returns 0 if configuration is OK. 00052 if the returned value is different from 0 or the function is stuck then the communication with 00053 the codec has failed (try to un-plug the power or reset device in this case). 00054 - OUTPUT_DEVICE_SPEAKER: only speaker will be set as output for the audio stream. 00055 - OUTPUT_DEVICE_HEADPHONE: only headphones will be set as output for the audio stream. 00056 - OUTPUT_DEVICE_AUTO: Selection of output device is made through external switch (implemented 00057 into the audio jack on the evaluation board). When the Headphone is connected it is used 00058 as output. When the headphone is disconnected from the audio jack, the output is 00059 automatically switched to Speaker. 00060 - OUTPUT_DEVICE_BOTH: both Speaker and Headphone are used as outputs for the audio stream 00061 at the same time. 00062 + Call the function BSP_AUDIO_OUT_Play( 00063 pBuffer: pointer to the audio data file address 00064 Size: size of the buffer to be sent in Bytes 00065 ) 00066 to start playing (for the first time) from the audio file/stream. 00067 + Call the function BSP_AUDIO_OUT_Pause() to pause playing 00068 + Call the function BSP_AUDIO_OUT_Resume() to resume playing. 00069 Note. After calling BSP_AUDIO_OUT_Pause() function for pause, only BSP_AUDIO_OUT_Resume() should be called 00070 for resume (it is not allowed to call BSP_AUDIO_OUT_Play() in this case). 00071 Note. This function should be called only when the audio file is played or paused (not stopped). 00072 + For each mode, you may need to implement the relative callback functions into your code. 00073 The Callback functions are named BSP_AUDIO_OUT_XXX_CallBack() and only their prototypes are declared in 00074 the stm32373c_eval_audio.h file. (refer to the example for more details on the callbacks implementations) 00075 + To Stop playing, to modify the volume level or to mute, use the functions 00076 BSP_AUDIO_OUT_Stop(), BSP_AUDIO_OUT_SetVolume(), BSP_AUDIO_OUT_SetFrequency(), BSP_AUDIO_OUT_SetOutputMode() and BSP_AUDIO_OUT_SetMute(). 00077 + The driver API and the callback functions are at the end of the stm32373c_eval_audio.h file. 00078 00079 Driver architecture: 00080 ------------------- 00081 + This driver provide the High Audio Layer: consists of the function API exported in the stm32373c_eval_audio.h file 00082 (BSP_AUDIO_OUT_Init(), BSP_AUDIO_OUT_Play() ...) 00083 + This driver provide also the Media Access Layer (MAL): which consists of functions allowing to access the media containing/ 00084 providing the audio file/stream. These functions are also included as local functions into 00085 the stm32373c_eval_audio.c file (I2Sx_MspInit() and I2Sx_Init()) 00086 00087 Known Limitations: 00088 ----------------- 00089 1- When using the Speaker, if the audio file quality is not high enough, the speaker output 00090 may produce high and uncomfortable noise level. To avoid this issue, to use speaker 00091 output properly, try to increase audio file sampling rate (typically higher than 48KHz). 00092 This operation will lead to larger file size. 00093 2- Communication with the audio codec (through I2C) may be corrupted if it is interrupted by some 00094 user interrupt routines (in this case, interrupts could be disabled just before the start of 00095 communication then re-enabled when it is over). Note that this communication is only done at 00096 the configuration phase (BSP_AUDIO_OUT_Init() or BSP_AUDIO_OUT_Stop()) and when Volume control modification is 00097 performed (BSP_AUDIO_OUT_SetVolume() or AUDIO_OUT_Mute() or BSP_AUDIO_OUT_SetOutputMode()). 00098 When the audio data is played, no communication is required with the audio codec. 00099 3- Parsing of audio file is not implemented (in order to determine audio file properties: Mono/Stereo, Data size, 00100 File size, Audio Frequency, Audio Data header size ...). The configuration is fixed for the given audio file. 00101 4- Mono audio streaming is not supported (in order to play mono audio streams, each data should be sent twice 00102 on the I2S or should be duplicated on the source buffer. Or convert the stream in stereo before playing). 00103 5- Supports only 16-bits audio data size. 00104 ==============================================================================*/ 00105 00106 /* Includes ------------------------------------------------------------------*/ 00107 #include "stm32373c_eval_audio.h" 00108 00109 /** @addtogroup BSP 00110 * @{ 00111 */ 00112 00113 /** @addtogroup STM32373C_EVAL 00114 * @{ 00115 */ 00116 00117 /** @defgroup STM32373C_EVAL_AUDIO STM32373C_EVAL AUDIO 00118 * @brief This file includes the low layer audio driver available on STM32373C_EVAL 00119 * evaluation board(MB988). 00120 * @{ 00121 */ 00122 00123 /** @defgroup STM32373C_EVAL_AUDIO_Private_Types Private Types 00124 * @{ 00125 */ 00126 /** 00127 * @} 00128 */ 00129 00130 /* Private defines ------------------------------------------------------------*/ 00131 /** @defgroup STM32373C_EVAL_AUDIO_Private_Constants Private Constants 00132 * @{ 00133 */ 00134 /** 00135 * @} 00136 */ 00137 00138 /* Private macros ------------------------------------------------------------*/ 00139 /** @defgroup STM32373C_EVAL_AUDIO_Private_Macros Private Macros 00140 * @{ 00141 */ 00142 /** 00143 * @} 00144 */ 00145 00146 /* Private variables ---------------------------------------------------------*/ 00147 /** @defgroup STM32373C_EVAL_AUDIO_Private_Variables Private Variables 00148 * @{ 00149 */ 00150 00151 /*### PLAY ###*/ 00152 static AUDIO_DrvTypeDef *pAudioDrv = NULL; 00153 I2S_HandleTypeDef hAudioOutI2s; 00154 00155 /** 00156 * @} 00157 */ 00158 00159 /* Private function prototypes -----------------------------------------------*/ 00160 /** @defgroup STM32373C_EVAL_AUDIO_Private_Functions Private Functions 00161 * @{ 00162 */ 00163 static void I2Sx_MspInit(void); 00164 static AUDIO_StatusTypeDef I2Sx_Init(uint32_t AudioFreq); 00165 /** 00166 * @} 00167 */ 00168 00169 /* Exported functions --------------------------------------------------------*/ 00170 /** @addtogroup STM32373C_EVAL_AUDIO_Exported_Functions 00171 * @{ 00172 */ 00173 00174 /** 00175 * @brief Configure the audio peripherals. 00176 * @param OutputDevice OUTPUT_DEVICE_SPEAKER, OUTPUT_DEVICE_HEADPHONE, 00177 * OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO . 00178 * @param Volume Initial volume level (from 0 (Mute) to 100 (Max)) 00179 * @param AudioFreq Audio frequency used to play the audio stream. 00180 * @retval AUDIO_OK if correct communication, else wrong communication 00181 */ 00182 uint8_t BSP_AUDIO_OUT_Init(uint16_t OutputDevice, uint8_t Volume, uint32_t AudioFreq) 00183 { 00184 uint8_t ret = AUDIO_OK; 00185 uint32_t deviceid = 0x00; 00186 00187 if(pAudioDrv == NULL) 00188 { 00189 deviceid = cs43l22_drv.ReadID(AUDIO_I2C_ADDRESS); 00190 00191 if((deviceid & CS43L22_ID_MASK) == CS43L22_ID) 00192 { 00193 /* Initialize the audio driver structure */ 00194 pAudioDrv = &cs43l22_drv; 00195 ret = AUDIO_OK; 00196 } 00197 else 00198 { 00199 ret = AUDIO_ERROR; 00200 } 00201 } 00202 00203 if(ret == AUDIO_OK) 00204 { 00205 if(pAudioDrv->Init(AUDIO_I2C_ADDRESS, OutputDevice, Volume, AudioFreq) != 0) 00206 { 00207 ret = AUDIO_ERROR; 00208 } 00209 else 00210 { 00211 /* I2S data transfer preparation: 00212 Prepare the Media to be used for the audio transfer from memory to I2S peripheral */ 00213 /* Configure the I2S peripheral */ 00214 ret = I2Sx_Init(AudioFreq); 00215 } 00216 } 00217 00218 return ret; 00219 } 00220 00221 /** 00222 * @brief Starts playing audio stream from a data buffer for a determined size. 00223 * @param pBuffer Pointer to the buffer 00224 * @param Size Number of audio data BYTES. 00225 * @retval AUDIO_OK if correct communication, else wrong communication 00226 */ 00227 uint8_t BSP_AUDIO_OUT_Play(uint16_t* pBuffer, uint32_t Size) 00228 { 00229 /* Call the audio Codec Play function */ 00230 if (pAudioDrv->Play(AUDIO_I2C_ADDRESS, pBuffer, Size) != 0) 00231 { 00232 return AUDIO_ERROR; 00233 } 00234 else 00235 { 00236 /* Update the Media layer and enable it for play */ 00237 return (HAL_I2S_Transmit_DMA(&hAudioOutI2s, pBuffer, DMA_MAX(Size))); 00238 } 00239 } 00240 00241 /** 00242 * @brief Sends n-Bytes on the I2S interface. 00243 * @param pData pointer on data address 00244 * @param Size number of data to be written 00245 * @retval AUDIO_OK if correct communication, else wrong communication 00246 */ 00247 uint8_t BSP_AUDIO_OUT_ChangeBuffer(uint16_t *pData, uint16_t Size) 00248 { 00249 return (HAL_I2S_Transmit_DMA(&hAudioOutI2s, pData, Size)); 00250 } 00251 00252 /** 00253 * @brief This function Pauses the audio file stream. In case 00254 * of using DMA, the DMA Pause feature is used. 00255 * @note When calling BSP_AUDIO_OUT_Pause() function for pause, only 00256 * BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play() 00257 * function for resume could lead to unexpected behavior). 00258 * @retval AUDIO_OK if correct communication, else wrong communication 00259 */ 00260 uint8_t BSP_AUDIO_OUT_Pause(void) 00261 { 00262 /* Call the Audio Codec Pause/Resume function */ 00263 if (pAudioDrv->Pause(AUDIO_I2C_ADDRESS) != 0) 00264 { 00265 return AUDIO_ERROR; 00266 } 00267 else 00268 { 00269 /* Call the Media layer pause function */ 00270 return (HAL_I2S_DMAPause(&hAudioOutI2s)); 00271 } 00272 } 00273 00274 /** 00275 * @brief This function Resumes the audio file stream. 00276 * @note When calling BSP_AUDIO_OUT_Pause() function for pause, only 00277 * BSP_AUDIO_OUT_Resume() function should be called for resume (use of BSP_AUDIO_OUT_Play() 00278 * function for resume could lead to unexpected behavior). 00279 * @retval AUDIO_OK if correct communication, else wrong communication 00280 */ 00281 uint8_t BSP_AUDIO_OUT_Resume(void) 00282 { 00283 /* Call the Audio Codec Pause/Resume function */ 00284 if(pAudioDrv->Resume(AUDIO_I2C_ADDRESS) != 0) 00285 { 00286 return AUDIO_ERROR; 00287 } 00288 else 00289 { 00290 /* Call the Media layer resume function */ 00291 return (HAL_I2S_DMAResume(&hAudioOutI2s)); 00292 } 00293 } 00294 00295 /** 00296 * @brief Stops audio playing and Power down the Audio Codec. 00297 * @param Option could be one of the following parameters 00298 * - CODEC_PDWN_SW: for software power off (by writing registers). 00299 * Then no need to reconfigure the Codec after power on. 00300 * - CODEC_PDWN_HW: completely shut down the codec (physically). 00301 * Then need to reconfigure the Codec after power on. 00302 * @retval AUDIO_OK if correct communication, else wrong communication 00303 */ 00304 uint8_t BSP_AUDIO_OUT_Stop(uint32_t Option) 00305 { 00306 /* Call DMA Stop to disable DMA stream before stopping codec */ 00307 HAL_I2S_DMAStop(&hAudioOutI2s); 00308 00309 /* Call Audio Codec Stop function */ 00310 if(pAudioDrv->Stop(AUDIO_I2C_ADDRESS, Option) != 0) 00311 { 00312 return AUDIO_ERROR; 00313 } 00314 else 00315 { 00316 if(Option == CODEC_PDWN_HW) 00317 { 00318 /* Wait at least 100us */ 00319 HAL_Delay(1); 00320 00321 /* Reset The pin */ 00322 CODEC_AUDIO_POWER_OFF(); 00323 } 00324 /* Return AUDIO_OK when all operations are correctly done */ 00325 return AUDIO_OK; 00326 } 00327 } 00328 00329 /** 00330 * @brief Controls the current audio volume level. 00331 * @param Volume Volume level to be set in percentage from 0% to 100% (0 for 00332 * Mute and 100 for Max volume level). 00333 * @retval AUDIO_OK if correct communication, else wrong communication 00334 */ 00335 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume) 00336 { 00337 /* Call the codec volume control function with converted volume value */ 00338 if(pAudioDrv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0) 00339 { 00340 return AUDIO_ERROR; 00341 } 00342 else 00343 { 00344 /* Return AUDIO_OK when all operations are correctly done */ 00345 return AUDIO_OK; 00346 } 00347 } 00348 00349 /** 00350 * @brief Enables or disables the MUTE mode by software 00351 * @param Cmd could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to 00352 * unmute the codec and restore previous volume level. 00353 * @retval AUDIO_OK if correct communication, else wrong communication 00354 */ 00355 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd) 00356 { 00357 /* Call the Codec Mute function */ 00358 if(pAudioDrv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0) 00359 { 00360 return AUDIO_ERROR; 00361 } 00362 else 00363 { 00364 /* Return AUDIO_OK when all operations are correctly done */ 00365 return AUDIO_OK; 00366 } 00367 } 00368 00369 /** 00370 * @brief Switch dynamically (while audio file is played) the output target 00371 * (speaker or headphone). 00372 * @note This function modifies a global variable of the audio codec driver: OutputDev. 00373 * @param Output specifies the audio output target: OUTPUT_DEVICE_SPEAKER, 00374 * OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO 00375 * @retval AUDIO_OK if correct communication, else wrong communication 00376 */ 00377 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output) 00378 { 00379 /* Call the Codec output Device function */ 00380 if(pAudioDrv->SetOutputMode(AUDIO_I2C_ADDRESS, Output) != 0) 00381 { 00382 return AUDIO_ERROR; 00383 } 00384 else 00385 { 00386 /* Return AUDIO_OK when all operations are correctly done */ 00387 return AUDIO_OK; 00388 } 00389 } 00390 00391 /** 00392 * @brief Update the audio frequency. 00393 * @param AudioFreq Audio frequency used to play the audio stream. 00394 * @retval AUDIO_OK if correct communication, else wrong communication 00395 */ 00396 uint8_t BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq) 00397 { 00398 /* Update the I2S audio frequency configuration */ 00399 return (I2Sx_Init(AudioFreq)); 00400 } 00401 00402 /** 00403 * @brief Tx Transfer completed callbacks 00404 * @param hi2s I2S handle 00405 * @retval None 00406 */ 00407 void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) 00408 { 00409 if(hi2s->Instance == I2Sx) 00410 { 00411 /* Call the user function which will manage directly transfer complete*/ 00412 BSP_AUDIO_OUT_TransferComplete_CallBack(); 00413 } 00414 } 00415 00416 /** 00417 * @brief Tx Transfer Half completed callbacks 00418 * @param hi2s I2S handle 00419 * @retval None 00420 */ 00421 void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) 00422 { 00423 if(hi2s->Instance == I2Sx) 00424 { 00425 /* Manage the remaining file size and new address offset: This function 00426 should be coded by user (its prototype is already declared in stm32373c_eval_audio.h) */ 00427 BSP_AUDIO_OUT_HalfTransfer_CallBack(); 00428 } 00429 } 00430 00431 /** 00432 * @brief I2S error callbacks 00433 * @param hi2s I2S handle 00434 * @retval None 00435 */ 00436 void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s) 00437 { 00438 /* Manage the error generated on DMA: This function 00439 should be coded by user (its prototype is already declared in stm32373c_eval_audio.h) */ 00440 if(hi2s->Instance == I2Sx) 00441 { 00442 BSP_AUDIO_OUT_Error_CallBack(); 00443 } 00444 } 00445 00446 /** 00447 * @brief Manages the DMA full Transfer complete event. 00448 * @retval None 00449 */ 00450 __weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void) 00451 { 00452 } 00453 00454 /** 00455 * @brief Manages the DMA Half Transfer complete event. 00456 * @retval None 00457 */ 00458 __weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void) 00459 { 00460 } 00461 00462 /** 00463 * @brief Audio OUT Error callback function 00464 * @retval None 00465 */ 00466 __weak void BSP_AUDIO_OUT_Error_CallBack(void) 00467 { 00468 } 00469 00470 /** 00471 * @} 00472 */ 00473 00474 /** @addtogroup STM32373C_EVAL_AUDIO_Private_Functions 00475 * @{ 00476 */ 00477 00478 /****************************************************************************** 00479 Static Function 00480 *******************************************************************************/ 00481 00482 /** 00483 * @brief AUDIO OUT I2S MSP Init 00484 * @retval None 00485 */ 00486 static void I2Sx_MspInit(void) 00487 { 00488 static DMA_HandleTypeDef hdma_i2sTx; 00489 GPIO_InitTypeDef GPIO_InitStruct; 00490 I2S_HandleTypeDef *hi2s = &hAudioOutI2s; 00491 00492 /* Enable I2S GPIO clocks */ 00493 I2Sx_GPIO_CLK_ENABLE(); 00494 00495 /* I2S pins configuration: WS, SCK, MCK and SD pins -----------------------------*/ 00496 GPIO_InitStruct.Pin = (I2Sx_WS_PIN | I2Sx_SCK_PIN | I2Sx_MCK_PIN| I2Sx_SD_PIN); 00497 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00498 GPIO_InitStruct.Pull = GPIO_NOPULL; 00499 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 00500 GPIO_InitStruct.Alternate = I2Sx_AF; 00501 HAL_GPIO_Init(I2Sx_GPIO_PORT, &GPIO_InitStruct); 00502 00503 /* Enable I2S clock */ 00504 I2Sx_CLK_ENABLE(); 00505 00506 /* Force the I2S peripheral clock reset */ 00507 I2Sx_FORCE_RESET(); 00508 00509 /* Release the I2S peripheral clock reset */ 00510 I2Sx_RELEASE_RESET(); 00511 00512 /* Enable the I2S DMA clock */ 00513 I2Sx_DMAx_CLK_ENABLE(); 00514 00515 /* Configure the hdma_i2sTx handle parameters */ 00516 hdma_i2sTx.Init.Direction = DMA_MEMORY_TO_PERIPH; 00517 hdma_i2sTx.Init.PeriphInc = DMA_PINC_DISABLE; 00518 hdma_i2sTx.Init.MemInc = DMA_MINC_ENABLE; 00519 hdma_i2sTx.Init.PeriphDataAlignment = I2Sx_DMAx_PERIPH_DATA_SIZE; 00520 hdma_i2sTx.Init.MemDataAlignment = I2Sx_DMAx_MEM_DATA_SIZE; 00521 hdma_i2sTx.Init.Mode = DMA_NORMAL; 00522 hdma_i2sTx.Init.Priority = DMA_PRIORITY_HIGH; 00523 00524 hdma_i2sTx.Instance = I2Sx_DMAx_CHANNEL; 00525 00526 /* Associate the DMA handle */ 00527 __HAL_LINKDMA(hi2s, hdmatx, hdma_i2sTx); 00528 00529 /* Configure the DMA Stream */ 00530 HAL_DMA_Init(&hdma_i2sTx); 00531 00532 /* I2S DMA IRQ Channel configuration */ 00533 HAL_NVIC_SetPriority((IRQn_Type)I2Sx_DMAx_IRQ, AUDIO_OUT_IRQ_PREPRIO, AUDIO_OUT_IRQ_SUBPRIO); 00534 HAL_NVIC_EnableIRQ((IRQn_Type)I2Sx_DMAx_IRQ); 00535 } 00536 00537 /** 00538 * @brief Initializes the Audio Codec audio interface (I2S) 00539 * @param AudioFreq Audio frequency to be configured for the I2S peripheral. 00540 * @retval AUDIO_StatusTypeDef AUDIO Status 00541 */ 00542 static AUDIO_StatusTypeDef I2Sx_Init(uint32_t AudioFreq) 00543 { 00544 /* I2S peripheral configuration */ 00545 hAudioOutI2s.Init.AudioFreq = AudioFreq; 00546 hAudioOutI2s.Init.ClockSource = I2S_CLOCK_SYSCLK; 00547 hAudioOutI2s.Init.CPOL = I2S_CPOL_LOW; 00548 hAudioOutI2s.Init.DataFormat = I2S_DATAFORMAT_16B; 00549 hAudioOutI2s.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE; 00550 hAudioOutI2s.Init.Mode = I2S_MODE_MASTER_TX; 00551 hAudioOutI2s.Init.Standard = I2S_STANDARD; 00552 hAudioOutI2s.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE; 00553 hAudioOutI2s.Instance = I2Sx; 00554 00555 /* Disable I2S block */ 00556 __HAL_I2S_DISABLE(&hAudioOutI2s); 00557 00558 /* Initialize the I2S peripheral with the structure above */ 00559 if(HAL_I2S_GetState(&hAudioOutI2s) == HAL_I2S_STATE_RESET) 00560 { 00561 I2Sx_MspInit(); 00562 } 00563 00564 if (HAL_I2S_Init(&hAudioOutI2s) != HAL_OK) 00565 { 00566 return AUDIO_ERROR; 00567 } 00568 00569 return AUDIO_OK; 00570 } 00571 /** 00572 * @} 00573 */ 00574 00575 /** 00576 * @} 00577 */ 00578 00579 /** 00580 * @} 00581 */ 00582 00583 /** 00584 * @} 00585 */ 00586 00587 /** 00588 * @} 00589 */ 00590 00591 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed May 31 2017 11:20:44 for STM32373C_EVAL BSP User Manual by
