STM32303E_EVAL BSP User Manual
|
stm32303e_eval_audio.c
Go to the documentation of this file.
00001 /** 00002 ****************************************************************************** 00003 * @file stm32303e_eval_audio.c 00004 * @author MCD Application Team 00005 * @brief This file provides the Audio driver for the STM32303E_EVAL 00006 * evaluation board(MB1019). 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 STM32F30x devices on STM32303E_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 stm32303e_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 stm32303e_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 stm32303e_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 stm32303e_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 "stm32303e_eval_audio.h" 00108 00109 /** @addtogroup BSP 00110 * @{ 00111 */ 00112 00113 /** @addtogroup STM32303E_EVAL 00114 * @{ 00115 */ 00116 00117 /** @defgroup STM32303E_EVAL_AUDIO STM32303E_EVAL AUDIO 00118 * @brief This file includes the low layer audio driver available on STM32303E_EVAL 00119 * evaluation board(MB1019). 00120 * @{ 00121 */ 00122 00123 /** @defgroup STM32303E_EVAL_AUDIO_Private_Types Private Types 00124 * @{ 00125 */ 00126 /** 00127 * @} 00128 */ 00129 00130 /* Private defines ------------------------------------------------------------*/ 00131 /** @defgroup STM32303E_EVAL_AUDIO_Private_Constants Private Constants 00132 * @{ 00133 */ 00134 /** 00135 * @} 00136 */ 00137 00138 /* Private macros ------------------------------------------------------------*/ 00139 /** @defgroup STM32303E_EVAL_AUDIO_Private_Macros Private Macros 00140 * @{ 00141 */ 00142 /** 00143 * @} 00144 */ 00145 00146 /* Private variables ---------------------------------------------------------*/ 00147 /** @defgroup STM32303E_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 STM32303E_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 STM32303E_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 = cs42l52_drv.ReadID(AUDIO_I2C_ADDRESS); 00190 00191 if((deviceid & CS42L52_ID_MASK) == CS42L52_ID) 00192 { 00193 /* Initialize the audio driver structure */ 00194 pAudioDrv = &cs42l52_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 /* Return AUDIO_OK when all operations are correctly done */ 00322 return AUDIO_OK; 00323 } 00324 } 00325 00326 /** 00327 * @brief Controls the current audio volume level. 00328 * @param Volume Volume level to be set in percentage from 0% to 100% (0 for 00329 * Mute and 100 for Max volume level). 00330 * @retval AUDIO_OK if correct communication, else wrong communication 00331 */ 00332 uint8_t BSP_AUDIO_OUT_SetVolume(uint8_t Volume) 00333 { 00334 /* Call the codec volume control function with converted volume value */ 00335 if(pAudioDrv->SetVolume(AUDIO_I2C_ADDRESS, Volume) != 0) 00336 { 00337 return AUDIO_ERROR; 00338 } 00339 else 00340 { 00341 /* Return AUDIO_OK when all operations are correctly done */ 00342 return AUDIO_OK; 00343 } 00344 } 00345 00346 /** 00347 * @brief Enables or disables the MUTE mode by software 00348 * @param Cmd could be AUDIO_MUTE_ON to mute sound or AUDIO_MUTE_OFF to 00349 * unmute the codec and restore previous volume level. 00350 * @retval AUDIO_OK if correct communication, else wrong communication 00351 */ 00352 uint8_t BSP_AUDIO_OUT_SetMute(uint32_t Cmd) 00353 { 00354 /* Call the Codec Mute function */ 00355 if(pAudioDrv->SetMute(AUDIO_I2C_ADDRESS, Cmd) != 0) 00356 { 00357 return AUDIO_ERROR; 00358 } 00359 else 00360 { 00361 /* Return AUDIO_OK when all operations are correctly done */ 00362 return AUDIO_OK; 00363 } 00364 } 00365 00366 /** 00367 * @brief Switch dynamically (while audio file is played) the output target 00368 * (speaker or headphone). 00369 * @note This function modifies a global variable of the audio codec driver: OutputDev. 00370 * @param Output specifies the audio output target: OUTPUT_DEVICE_SPEAKER, 00371 * OUTPUT_DEVICE_HEADPHONE, OUTPUT_DEVICE_BOTH or OUTPUT_DEVICE_AUTO 00372 * @retval AUDIO_OK if correct communication, else wrong communication 00373 */ 00374 uint8_t BSP_AUDIO_OUT_SetOutputMode(uint8_t Output) 00375 { 00376 /* Call the Codec output Device function */ 00377 if(pAudioDrv->SetOutputMode(AUDIO_I2C_ADDRESS, Output) != 0) 00378 { 00379 return AUDIO_ERROR; 00380 } 00381 else 00382 { 00383 /* Return AUDIO_OK when all operations are correctly done */ 00384 return AUDIO_OK; 00385 } 00386 } 00387 00388 /** 00389 * @brief Update the audio frequency. 00390 * @param AudioFreq Audio frequency used to play the audio stream. 00391 * @retval AUDIO_OK if correct communication, else wrong communication 00392 */ 00393 uint8_t BSP_AUDIO_OUT_SetFrequency(uint32_t AudioFreq) 00394 { 00395 /* Update the I2S audio frequency configuration */ 00396 return (I2Sx_Init(AudioFreq)); 00397 } 00398 00399 /** 00400 * @brief Tx Transfer completed callbacks 00401 * @param hi2s I2S handle 00402 * @retval None 00403 */ 00404 void HAL_I2S_TxCpltCallback(I2S_HandleTypeDef *hi2s) 00405 { 00406 if(hi2s->Instance == I2Sx) 00407 { 00408 /* Call the user function which will manage directly transfer complete*/ 00409 BSP_AUDIO_OUT_TransferComplete_CallBack(); 00410 } 00411 } 00412 00413 /** 00414 * @brief Tx Transfer Half completed callbacks 00415 * @param hi2s I2S handle 00416 * @retval None 00417 */ 00418 void HAL_I2S_TxHalfCpltCallback(I2S_HandleTypeDef *hi2s) 00419 { 00420 if(hi2s->Instance == I2Sx) 00421 { 00422 /* Manage the remaining file size and new address offset: This function 00423 should be coded by user (its prototype is already declared in stm32303e_eval_audio.h) */ 00424 BSP_AUDIO_OUT_HalfTransfer_CallBack(); 00425 } 00426 } 00427 00428 /** 00429 * @brief I2S error callbacks 00430 * @param hi2s I2S handle 00431 * @retval None 00432 */ 00433 void HAL_I2S_ErrorCallback(I2S_HandleTypeDef *hi2s) 00434 { 00435 /* Manage the error generated on DMA: This function 00436 should be coded by user (its prototype is already declared in stm32303e_eval_audio.h) */ 00437 if(hi2s->Instance == I2Sx) 00438 { 00439 BSP_AUDIO_OUT_Error_CallBack(); 00440 } 00441 } 00442 00443 /** 00444 * @brief Manages the DMA full Transfer complete event. 00445 * @retval None 00446 */ 00447 __weak void BSP_AUDIO_OUT_TransferComplete_CallBack(void) 00448 { 00449 } 00450 00451 /** 00452 * @brief Manages the DMA Half Transfer complete event. 00453 * @retval None 00454 */ 00455 __weak void BSP_AUDIO_OUT_HalfTransfer_CallBack(void) 00456 { 00457 } 00458 00459 /** 00460 * @brief Audio OUT Error callback function 00461 * @retval None 00462 */ 00463 __weak void BSP_AUDIO_OUT_Error_CallBack(void) 00464 { 00465 } 00466 00467 /** 00468 * @} 00469 */ 00470 00471 /** @addtogroup STM32303E_EVAL_AUDIO_Private_Functions 00472 * @{ 00473 */ 00474 00475 /****************************************************************************** 00476 Static Function 00477 *******************************************************************************/ 00478 00479 /** 00480 * @brief AUDIO OUT I2S MSP Init 00481 * @retval None 00482 */ 00483 static void I2Sx_MspInit(void) 00484 { 00485 static DMA_HandleTypeDef hdma_i2sTx; 00486 GPIO_InitTypeDef GPIO_InitStruct; 00487 I2S_HandleTypeDef *hi2s = &hAudioOutI2s; 00488 00489 /* Enable I2S GPIO clocks */ 00490 I2Sx_MCK_WS_GPIO_CLK_ENABLE(); 00491 I2Sx_SCK_DIN_GPIO_CLK_ENABLE(); 00492 00493 /* I2S pins configuration: SCK and DIN pins -----------------------------*/ 00494 GPIO_InitStruct.Pin = (I2Sx_SCK_PIN | I2Sx_DIN_PIN); 00495 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00496 GPIO_InitStruct.Pull = GPIO_NOPULL; 00497 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 00498 GPIO_InitStruct.Alternate = I2Sx_SCK_DIN_AF; 00499 HAL_GPIO_Init(I2Sx_SCK_DIN_GPIO_PORT, &GPIO_InitStruct); 00500 00501 /* I2S pins configuration: WS pin -----------------------------*/ 00502 GPIO_InitStruct.Pin = I2Sx_WS_PIN; 00503 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00504 GPIO_InitStruct.Pull = GPIO_NOPULL; 00505 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 00506 GPIO_InitStruct.Alternate = I2Sx_WS_AF; 00507 HAL_GPIO_Init(I2Sx_WS_GPIO_PORT, &GPIO_InitStruct); 00508 00509 /* I2S pins configuration: MCK pin -----------------------------*/ 00510 GPIO_InitStruct.Pin = I2Sx_MCK_PIN; 00511 GPIO_InitStruct.Mode = GPIO_MODE_AF_PP; 00512 GPIO_InitStruct.Pull = GPIO_NOPULL; 00513 GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_HIGH; 00514 GPIO_InitStruct.Alternate = I2Sx_MCK_AF; 00515 HAL_GPIO_Init(I2Sx_MCK_GPIO_PORT, &GPIO_InitStruct); 00516 00517 /* Enable I2S clock */ 00518 I2Sx_CLK_ENABLE(); 00519 00520 /* Force the I2S peripheral clock reset */ 00521 I2Sx_FORCE_RESET(); 00522 00523 /* Release the I2S peripheral clock reset */ 00524 I2Sx_RELEASE_RESET(); 00525 00526 /* Enable the I2S DMA clock */ 00527 I2Sx_DMAx_CLK_ENABLE(); 00528 00529 /* Configure the hdma_i2sTx handle parameters */ 00530 hdma_i2sTx.Init.Direction = DMA_MEMORY_TO_PERIPH; 00531 hdma_i2sTx.Init.PeriphInc = DMA_PINC_DISABLE; 00532 hdma_i2sTx.Init.MemInc = DMA_MINC_ENABLE; 00533 hdma_i2sTx.Init.PeriphDataAlignment = I2Sx_DMAx_PERIPH_DATA_SIZE; 00534 hdma_i2sTx.Init.MemDataAlignment = I2Sx_DMAx_MEM_DATA_SIZE; 00535 hdma_i2sTx.Init.Mode = DMA_NORMAL; 00536 hdma_i2sTx.Init.Priority = DMA_PRIORITY_HIGH; 00537 00538 hdma_i2sTx.Instance = I2Sx_DMAx_CHANNEL; 00539 00540 /* Associate the DMA handle */ 00541 __HAL_LINKDMA(hi2s, hdmatx, hdma_i2sTx); 00542 00543 /* Configure the DMA Stream */ 00544 HAL_DMA_Init(&hdma_i2sTx); 00545 00546 /* I2S DMA IRQ Channel configuration */ 00547 HAL_NVIC_SetPriority((IRQn_Type)I2Sx_DMAx_IRQ, AUDIO_OUT_IRQ_PREPRIO, AUDIO_OUT_IRQ_SUBPRIO); 00548 HAL_NVIC_EnableIRQ((IRQn_Type)I2Sx_DMAx_IRQ); 00549 } 00550 00551 /** 00552 * @brief Initializes the Audio Codec audio interface (I2S) 00553 * @param AudioFreq Audio frequency to be configured for the I2S peripheral. 00554 * @retval AUDIO_StatusTypeDef AUDIO Status 00555 */ 00556 static AUDIO_StatusTypeDef I2Sx_Init(uint32_t AudioFreq) 00557 { 00558 /* I2S peripheral configuration */ 00559 hAudioOutI2s.Init.AudioFreq = AudioFreq; 00560 hAudioOutI2s.Init.ClockSource = I2S_CLOCK_SYSCLK; 00561 hAudioOutI2s.Init.CPOL = I2S_CPOL_LOW; 00562 hAudioOutI2s.Init.DataFormat = I2S_DATAFORMAT_16B; 00563 hAudioOutI2s.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE; 00564 hAudioOutI2s.Init.Mode = I2S_MODE_MASTER_TX; 00565 hAudioOutI2s.Init.Standard = I2S_STANDARD; 00566 hAudioOutI2s.Instance = I2Sx; 00567 00568 /* Disable I2S block */ 00569 __HAL_I2S_DISABLE(&hAudioOutI2s); 00570 00571 /* Initialize the I2S peripheral with the structure above */ 00572 if(HAL_I2S_GetState(&hAudioOutI2s) == HAL_I2S_STATE_RESET) 00573 { 00574 I2Sx_MspInit(); 00575 } 00576 00577 if (HAL_I2S_Init(&hAudioOutI2s) != HAL_OK) 00578 { 00579 return AUDIO_ERROR; 00580 } 00581 00582 return AUDIO_OK; 00583 } 00584 /** 00585 * @} 00586 */ 00587 00588 /** 00589 * @} 00590 */ 00591 00592 /** 00593 * @} 00594 */ 00595 00596 /** 00597 * @} 00598 */ 00599 00600 /** 00601 * @} 00602 */ 00603 00604 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Wed May 31 2017 11:17:16 for STM32303E_EVAL BSP User Manual by 1.7.6.1