209 lines
7.1 KiB
C
209 lines
7.1 KiB
C
|
/**
|
||
|
******************************************************************************
|
||
|
* File Name : I2S.c
|
||
|
* Description : This file provides code for the configuration
|
||
|
* of the I2S instances.
|
||
|
******************************************************************************
|
||
|
*
|
||
|
* Copyright (c) 2017 STMicroelectronics International N.V.
|
||
|
* All rights reserved.
|
||
|
*
|
||
|
* Redistribution and use in source and binary forms, with or without
|
||
|
* modification, are permitted, provided that the following conditions are met:
|
||
|
*
|
||
|
* 1. Redistribution of source code must retain the above copyright notice,
|
||
|
* this list of conditions and the following disclaimer.
|
||
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||
|
* this list of conditions and the following disclaimer in the documentation
|
||
|
* and/or other materials provided with the distribution.
|
||
|
* 3. Neither the name of STMicroelectronics nor the names of other
|
||
|
* contributors to this software may be used to endorse or promote products
|
||
|
* derived from this software without specific written permission.
|
||
|
* 4. This software, including modifications and/or derivative works of this
|
||
|
* software, must execute solely and exclusively on microcontroller or
|
||
|
* microprocessor devices manufactured by or for STMicroelectronics.
|
||
|
* 5. Redistribution and use of this software other than as permitted under
|
||
|
* this license is void and will automatically terminate your rights under
|
||
|
* this license.
|
||
|
*
|
||
|
* THIS SOFTWARE IS PROVIDED BY STMICROELECTRONICS AND CONTRIBUTORS "AS IS"
|
||
|
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
||
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
||
|
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
||
|
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
||
|
* SHALL STMICROELECTRONICS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
||
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
||
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
||
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||
|
*
|
||
|
******************************************************************************
|
||
|
*/
|
||
|
|
||
|
/* Includes ------------------------------------------------------------------*/
|
||
|
#include "i2s.h"
|
||
|
|
||
|
#include "gpio.h"
|
||
|
#include "dma.h"
|
||
|
|
||
|
/* USER CODE BEGIN 0 */
|
||
|
|
||
|
/* USER CODE END 0 */
|
||
|
|
||
|
I2S_HandleTypeDef hi2s3;
|
||
|
DMA_HandleTypeDef hdma_spi3_tx;
|
||
|
DMA_HandleTypeDef hdma_i2s3_ext_rx;
|
||
|
|
||
|
/* I2S3 init function */
|
||
|
void MX_I2S3_Init(void)
|
||
|
{
|
||
|
|
||
|
hi2s3.Instance = SPI3;
|
||
|
hi2s3.Init.Mode = I2S_MODE_MASTER_TX;
|
||
|
hi2s3.Init.Standard = I2S_STANDARD_PHILIPS;
|
||
|
hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;
|
||
|
hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;
|
||
|
hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_48K;
|
||
|
hi2s3.Init.CPOL = I2S_CPOL_LOW;
|
||
|
hi2s3.Init.ClockSource = I2S_CLOCK_PLL;
|
||
|
hi2s3.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_ENABLE;
|
||
|
if (HAL_I2S_Init(&hi2s3) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void HAL_I2S_MspInit(I2S_HandleTypeDef* i2sHandle)
|
||
|
{
|
||
|
|
||
|
GPIO_InitTypeDef GPIO_InitStruct;
|
||
|
if(i2sHandle->Instance==SPI3)
|
||
|
{
|
||
|
/* USER CODE BEGIN SPI3_MspInit 0 */
|
||
|
|
||
|
/* USER CODE END SPI3_MspInit 0 */
|
||
|
/* Peripheral clock enable */
|
||
|
__HAL_RCC_SPI3_CLK_ENABLE();
|
||
|
|
||
|
/**I2S3 GPIO Configuration
|
||
|
PA15 ------> I2S3_WS
|
||
|
PC10 ------> I2S3_CK
|
||
|
PC11 ------> I2S3_ext_SD
|
||
|
PC12 ------> I2S3_SD
|
||
|
*/
|
||
|
GPIO_InitStruct.Pin = GPIO_PIN_15;
|
||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||
|
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
|
||
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
||
|
|
||
|
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_12;
|
||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||
|
GPIO_InitStruct.Alternate = GPIO_AF6_SPI3;
|
||
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||
|
|
||
|
GPIO_InitStruct.Pin = GPIO_PIN_11;
|
||
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
||
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
||
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
||
|
GPIO_InitStruct.Alternate = GPIO_AF5_I2S3ext;
|
||
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
||
|
|
||
|
/* Peripheral DMA init*/
|
||
|
|
||
|
hdma_spi3_tx.Instance = DMA1_Stream5;
|
||
|
hdma_spi3_tx.Init.Channel = DMA_CHANNEL_0;
|
||
|
hdma_spi3_tx.Init.Direction = DMA_MEMORY_TO_PERIPH;
|
||
|
hdma_spi3_tx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||
|
hdma_spi3_tx.Init.MemInc = DMA_MINC_ENABLE;
|
||
|
hdma_spi3_tx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||
|
hdma_spi3_tx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
|
||
|
hdma_spi3_tx.Init.Mode = DMA_CIRCULAR;
|
||
|
hdma_spi3_tx.Init.Priority = DMA_PRIORITY_HIGH;
|
||
|
hdma_spi3_tx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
||
|
hdma_spi3_tx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||
|
hdma_spi3_tx.Init.MemBurst = DMA_MBURST_SINGLE;
|
||
|
hdma_spi3_tx.Init.PeriphBurst = DMA_PBURST_SINGLE;
|
||
|
if (HAL_DMA_Init(&hdma_spi3_tx) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
__HAL_LINKDMA(i2sHandle,hdmatx,hdma_spi3_tx);
|
||
|
|
||
|
hdma_i2s3_ext_rx.Instance = DMA1_Stream2;
|
||
|
hdma_i2s3_ext_rx.Init.Channel = DMA_CHANNEL_2;
|
||
|
hdma_i2s3_ext_rx.Init.Direction = DMA_PERIPH_TO_MEMORY;
|
||
|
hdma_i2s3_ext_rx.Init.PeriphInc = DMA_PINC_DISABLE;
|
||
|
hdma_i2s3_ext_rx.Init.MemInc = DMA_MINC_ENABLE;
|
||
|
hdma_i2s3_ext_rx.Init.PeriphDataAlignment = DMA_PDATAALIGN_HALFWORD;
|
||
|
hdma_i2s3_ext_rx.Init.MemDataAlignment = DMA_MDATAALIGN_HALFWORD;
|
||
|
hdma_i2s3_ext_rx.Init.Mode = DMA_CIRCULAR;
|
||
|
hdma_i2s3_ext_rx.Init.Priority = DMA_PRIORITY_HIGH;
|
||
|
hdma_i2s3_ext_rx.Init.FIFOMode = DMA_FIFOMODE_ENABLE;
|
||
|
hdma_i2s3_ext_rx.Init.FIFOThreshold = DMA_FIFO_THRESHOLD_FULL;
|
||
|
hdma_i2s3_ext_rx.Init.MemBurst = DMA_MBURST_INC4;
|
||
|
hdma_i2s3_ext_rx.Init.PeriphBurst = DMA_PBURST_SINGLE;
|
||
|
if (HAL_DMA_Init(&hdma_i2s3_ext_rx) != HAL_OK)
|
||
|
{
|
||
|
Error_Handler();
|
||
|
}
|
||
|
|
||
|
__HAL_LINKDMA(i2sHandle,hdmarx,hdma_i2s3_ext_rx);
|
||
|
|
||
|
/* USER CODE BEGIN SPI3_MspInit 1 */
|
||
|
|
||
|
/* USER CODE END SPI3_MspInit 1 */
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void HAL_I2S_MspDeInit(I2S_HandleTypeDef* i2sHandle)
|
||
|
{
|
||
|
|
||
|
if(i2sHandle->Instance==SPI3)
|
||
|
{
|
||
|
/* USER CODE BEGIN SPI3_MspDeInit 0 */
|
||
|
|
||
|
/* USER CODE END SPI3_MspDeInit 0 */
|
||
|
/* Peripheral clock disable */
|
||
|
__HAL_RCC_SPI3_CLK_DISABLE();
|
||
|
|
||
|
/**I2S3 GPIO Configuration
|
||
|
PA15 ------> I2S3_WS
|
||
|
PC10 ------> I2S3_CK
|
||
|
PC11 ------> I2S3_ext_SD
|
||
|
PC12 ------> I2S3_SD
|
||
|
*/
|
||
|
HAL_GPIO_DeInit(GPIOA, GPIO_PIN_15);
|
||
|
|
||
|
HAL_GPIO_DeInit(GPIOC, GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12);
|
||
|
|
||
|
/* Peripheral DMA DeInit*/
|
||
|
HAL_DMA_DeInit(i2sHandle->hdmatx);
|
||
|
HAL_DMA_DeInit(i2sHandle->hdmarx);
|
||
|
}
|
||
|
/* USER CODE BEGIN SPI3_MspDeInit 1 */
|
||
|
|
||
|
/* USER CODE END SPI3_MspDeInit 1 */
|
||
|
}
|
||
|
|
||
|
/* USER CODE BEGIN 1 */
|
||
|
|
||
|
/* USER CODE END 1 */
|
||
|
|
||
|
/**
|
||
|
* @}
|
||
|
*/
|
||
|
|
||
|
/**
|
||
|
* @}
|
||
|
*/
|
||
|
|
||
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|