mirror of
https://github.com/Ai-Thinker-Open/Ai-Thinker-Open_RTL8710BX_ALIOS_SDK.git
synced 2025-01-30 17:05:23 +00:00
776 lines
24 KiB
C
776 lines
24 KiB
C
|
|
/**
|
|
******************************************************************************
|
|
* @file : main.c
|
|
* @brief : Main program body
|
|
******************************************************************************
|
|
** This notice applies to any and all portions of this file
|
|
* that are not between comment pairs USER CODE BEGIN and
|
|
* USER CODE END. Other portions of this file, whether
|
|
* inserted by the user or by software development tools
|
|
* are owned by their respective copyright owners.
|
|
*
|
|
* COPYRIGHT(c) 2018 STMicroelectronics
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without modification,
|
|
* are permitted provided that the following conditions are met:
|
|
* 1. Redistributions 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 its contributors
|
|
* may be used to endorse or promote products derived from this software
|
|
* without specific prior written permission.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER 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 "main.h"
|
|
#include "stm32l4xx_hal.h"
|
|
|
|
/* USER CODE BEGIN Includes */
|
|
|
|
/* USER CODE END Includes */
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
ADC_HandleTypeDef hadc3;
|
|
|
|
CRC_HandleTypeDef hcrc;
|
|
|
|
DCMI_HandleTypeDef hdcmi;
|
|
|
|
I2C_HandleTypeDef hi2c1;
|
|
I2C_HandleTypeDef hi2c2;
|
|
I2C_HandleTypeDef hi2c3;
|
|
|
|
UART_HandleTypeDef hlpuart1;
|
|
UART_HandleTypeDef huart2;
|
|
UART_HandleTypeDef huart3;
|
|
|
|
SAI_HandleTypeDef hsai_BlockA2;
|
|
|
|
SPI_HandleTypeDef hspi1;
|
|
|
|
/* USER CODE BEGIN PV */
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
void SystemClock_Config(void);
|
|
static void MX_GPIO_Init(void);
|
|
static void MX_I2C3_Init(void);
|
|
static void MX_I2C1_Init(void);
|
|
static void MX_I2C2_Init(void);
|
|
static void MX_ADC3_Init(void);
|
|
static void MX_USART2_UART_Init(void);
|
|
static void MX_SPI1_Init(void);
|
|
static void MX_USART3_UART_Init(void);
|
|
static void MX_LPUART1_UART_Init(void);
|
|
static void MX_SAI2_Init(void);
|
|
static void MX_DCMI_Init(void);
|
|
static void MX_USB_OTG_FS_USB_Init(void);
|
|
static void MX_SDMMC1_Init(void);
|
|
static void MX_CRC_Init(void);
|
|
|
|
/* USER CODE BEGIN PFP */
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
/* USER CODE BEGIN 0 */
|
|
|
|
/* USER CODE END 0 */
|
|
|
|
/**
|
|
* @brief The application entry point.
|
|
*
|
|
* @retval None
|
|
*/
|
|
int main(void)
|
|
{
|
|
/* USER CODE BEGIN 1 */
|
|
|
|
/* USER CODE END 1 */
|
|
|
|
/* MCU Configuration----------------------------------------------------------*/
|
|
|
|
/* Reset of all peripherals, Initializes the Flash interface and the Systick. */
|
|
HAL_Init();
|
|
|
|
/* USER CODE BEGIN Init */
|
|
|
|
/* USER CODE END Init */
|
|
|
|
/* Configure the system clock */
|
|
SystemClock_Config();
|
|
|
|
/* USER CODE BEGIN SysInit */
|
|
|
|
/* USER CODE END SysInit */
|
|
|
|
/* Initialize all configured peripherals */
|
|
MX_GPIO_Init();
|
|
MX_I2C3_Init();
|
|
MX_I2C1_Init();
|
|
MX_I2C2_Init();
|
|
MX_ADC3_Init();
|
|
MX_USART2_UART_Init();
|
|
MX_SPI1_Init();
|
|
MX_USART3_UART_Init();
|
|
MX_LPUART1_UART_Init();
|
|
MX_SAI2_Init();
|
|
MX_DCMI_Init();
|
|
MX_USB_OTG_FS_USB_Init();
|
|
MX_SDMMC1_Init();
|
|
MX_CRC_Init();
|
|
/* USER CODE BEGIN 2 */
|
|
|
|
/* USER CODE END 2 */
|
|
|
|
/* Infinite loop */
|
|
/* USER CODE BEGIN WHILE */
|
|
while (1)
|
|
{
|
|
|
|
/* USER CODE END WHILE */
|
|
|
|
/* USER CODE BEGIN 3 */
|
|
|
|
}
|
|
/* USER CODE END 3 */
|
|
|
|
}
|
|
|
|
/**
|
|
* @brief System Clock Configuration
|
|
* @retval None
|
|
*/
|
|
void SystemClock_Config(void)
|
|
{
|
|
|
|
RCC_OscInitTypeDef RCC_OscInitStruct;
|
|
RCC_ClkInitTypeDef RCC_ClkInitStruct;
|
|
RCC_PeriphCLKInitTypeDef PeriphClkInit;
|
|
|
|
/**Configure LSE Drive Capability
|
|
*/
|
|
HAL_PWR_EnableBkUpAccess();
|
|
|
|
__HAL_RCC_LSEDRIVE_CONFIG(RCC_LSEDRIVE_LOW);
|
|
|
|
/**Initializes the CPU, AHB and APB busses clocks
|
|
*/
|
|
RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_LSE|RCC_OSCILLATORTYPE_MSI;
|
|
RCC_OscInitStruct.LSEState = RCC_LSE_ON;
|
|
RCC_OscInitStruct.MSIState = RCC_MSI_ON;
|
|
RCC_OscInitStruct.MSICalibrationValue = 0;
|
|
RCC_OscInitStruct.MSIClockRange = RCC_MSIRANGE_6;
|
|
RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
|
|
RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_MSI;
|
|
RCC_OscInitStruct.PLL.PLLN = 40;
|
|
RCC_OscInitStruct.PLL.PLLM = 1;
|
|
RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
|
|
RCC_OscInitStruct.PLL.PLLQ = RCC_PLLQ_DIV2;
|
|
RCC_OscInitStruct.PLL.PLLR = RCC_PLLR_DIV2;
|
|
if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Initializes the CPU, AHB and APB busses clocks
|
|
*/
|
|
RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_HCLK|RCC_CLOCKTYPE_SYSCLK
|
|
|RCC_CLOCKTYPE_PCLK1|RCC_CLOCKTYPE_PCLK2;
|
|
RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK;
|
|
RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1;
|
|
RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV1;
|
|
RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1;
|
|
|
|
if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_4) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
PeriphClkInit.PeriphClockSelection = RCC_PERIPHCLK_USART2|RCC_PERIPHCLK_USART3
|
|
|RCC_PERIPHCLK_LPUART1|RCC_PERIPHCLK_SAI2
|
|
|RCC_PERIPHCLK_I2C1|RCC_PERIPHCLK_I2C2
|
|
|RCC_PERIPHCLK_I2C3|RCC_PERIPHCLK_USB
|
|
|RCC_PERIPHCLK_SDMMC1|RCC_PERIPHCLK_ADC;
|
|
PeriphClkInit.Usart2ClockSelection = RCC_USART2CLKSOURCE_PCLK1;
|
|
PeriphClkInit.Usart3ClockSelection = RCC_USART3CLKSOURCE_PCLK1;
|
|
PeriphClkInit.Lpuart1ClockSelection = RCC_LPUART1CLKSOURCE_PCLK1;
|
|
PeriphClkInit.I2c1ClockSelection = RCC_I2C1CLKSOURCE_PCLK1;
|
|
PeriphClkInit.I2c2ClockSelection = RCC_I2C2CLKSOURCE_PCLK1;
|
|
PeriphClkInit.I2c3ClockSelection = RCC_I2C3CLKSOURCE_PCLK1;
|
|
PeriphClkInit.Sai2ClockSelection = RCC_SAI2CLKSOURCE_PLLSAI1;
|
|
PeriphClkInit.AdcClockSelection = RCC_ADCCLKSOURCE_PLLSAI1;
|
|
PeriphClkInit.UsbClockSelection = RCC_USBCLKSOURCE_PLLSAI1;
|
|
PeriphClkInit.Sdmmc1ClockSelection = RCC_SDMMC1CLKSOURCE_PLLSAI1;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1Source = RCC_PLLSOURCE_MSI;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1M = 1;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1N = 24;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1P = RCC_PLLP_DIV2;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1Q = RCC_PLLQ_DIV2;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1R = RCC_PLLR_DIV2;
|
|
PeriphClkInit.PLLSAI1.PLLSAI1ClockOut = RCC_PLLSAI1_SAI1CLK|RCC_PLLSAI1_48M2CLK
|
|
|RCC_PLLSAI1_ADC1CLK;
|
|
if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInit) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure the main internal regulator output voltage
|
|
*/
|
|
if (HAL_PWREx_ControlVoltageScaling(PWR_REGULATOR_VOLTAGE_SCALE1) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure the Systick interrupt time
|
|
*/
|
|
HAL_SYSTICK_Config(HAL_RCC_GetHCLKFreq()/8000);
|
|
|
|
/**Configure the Systick
|
|
*/
|
|
HAL_SYSTICK_CLKSourceConfig(SYSTICK_CLKSOURCE_HCLK_DIV8);
|
|
|
|
/**Enable MSI Auto calibration
|
|
*/
|
|
HAL_RCCEx_EnableMSIPLLMode();
|
|
|
|
/* SysTick_IRQn interrupt configuration */
|
|
HAL_NVIC_SetPriority(SysTick_IRQn, 0, 0);
|
|
}
|
|
|
|
/* ADC3 init function */
|
|
static void MX_ADC3_Init(void)
|
|
{
|
|
|
|
ADC_ChannelConfTypeDef sConfig;
|
|
|
|
/**Common config
|
|
*/
|
|
hadc3.Instance = ADC3;
|
|
hadc3.Init.ClockPrescaler = ADC_CLOCK_ASYNC_DIV1;
|
|
hadc3.Init.Resolution = ADC_RESOLUTION_12B;
|
|
hadc3.Init.DataAlign = ADC_DATAALIGN_RIGHT;
|
|
hadc3.Init.ScanConvMode = ADC_SCAN_DISABLE;
|
|
hadc3.Init.EOCSelection = ADC_EOC_SINGLE_CONV;
|
|
hadc3.Init.LowPowerAutoWait = DISABLE;
|
|
hadc3.Init.ContinuousConvMode = DISABLE;
|
|
hadc3.Init.NbrOfConversion = 1;
|
|
hadc3.Init.DiscontinuousConvMode = DISABLE;
|
|
hadc3.Init.NbrOfDiscConversion = 1;
|
|
hadc3.Init.ExternalTrigConv = ADC_SOFTWARE_START;
|
|
hadc3.Init.ExternalTrigConvEdge = ADC_EXTERNALTRIGCONVEDGE_NONE;
|
|
hadc3.Init.DMAContinuousRequests = DISABLE;
|
|
hadc3.Init.Overrun = ADC_OVR_DATA_PRESERVED;
|
|
hadc3.Init.OversamplingMode = DISABLE;
|
|
if (HAL_ADC_Init(&hadc3) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure Regular Channel
|
|
*/
|
|
sConfig.Channel = ADC_CHANNEL_3;
|
|
sConfig.Rank = ADC_REGULAR_RANK_1;
|
|
sConfig.SamplingTime = ADC_SAMPLETIME_2CYCLES_5;
|
|
sConfig.SingleDiff = ADC_DIFFERENTIAL_ENDED;
|
|
sConfig.OffsetNumber = ADC_OFFSET_NONE;
|
|
sConfig.Offset = 0;
|
|
if (HAL_ADC_ConfigChannel(&hadc3, &sConfig) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* CRC init function */
|
|
static void MX_CRC_Init(void)
|
|
{
|
|
|
|
hcrc.Instance = CRC;
|
|
hcrc.Init.DefaultPolynomialUse = DEFAULT_POLYNOMIAL_ENABLE;
|
|
hcrc.Init.DefaultInitValueUse = DEFAULT_INIT_VALUE_ENABLE;
|
|
hcrc.Init.InputDataInversionMode = CRC_INPUTDATA_INVERSION_NONE;
|
|
hcrc.Init.OutputDataInversionMode = CRC_OUTPUTDATA_INVERSION_DISABLE;
|
|
hcrc.InputDataFormat = CRC_INPUTDATA_FORMAT_BYTES;
|
|
if (HAL_CRC_Init(&hcrc) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* DCMI init function */
|
|
static void MX_DCMI_Init(void)
|
|
{
|
|
|
|
hdcmi.Instance = DCMI;
|
|
hdcmi.Init.SynchroMode = DCMI_SYNCHRO_HARDWARE;
|
|
hdcmi.Init.PCKPolarity = DCMI_PCKPOLARITY_FALLING;
|
|
hdcmi.Init.VSPolarity = DCMI_VSPOLARITY_LOW;
|
|
hdcmi.Init.HSPolarity = DCMI_HSPOLARITY_LOW;
|
|
hdcmi.Init.CaptureRate = DCMI_CR_ALL_FRAME;
|
|
hdcmi.Init.ExtendedDataMode = DCMI_EXTEND_DATA_8B;
|
|
hdcmi.Init.JPEGMode = DCMI_JPEG_DISABLE;
|
|
hdcmi.Init.ByteSelectMode = DCMI_BSM_ALL;
|
|
hdcmi.Init.ByteSelectStart = DCMI_OEBS_ODD;
|
|
hdcmi.Init.LineSelectMode = DCMI_LSM_ALL;
|
|
hdcmi.Init.LineSelectStart = DCMI_OELS_ODD;
|
|
if (HAL_DCMI_Init(&hdcmi) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* I2C1 init function */
|
|
static void MX_I2C1_Init(void)
|
|
{
|
|
|
|
hi2c1.Instance = I2C1;
|
|
hi2c1.Init.Timing = 0x10909CEC;
|
|
hi2c1.Init.OwnAddress1 = 0;
|
|
hi2c1.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
hi2c1.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
hi2c1.Init.OwnAddress2 = 0;
|
|
hi2c1.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
|
hi2c1.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
hi2c1.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
if (HAL_I2C_Init(&hi2c1) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure Analogue filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c1, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure Digital filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c1, 0) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* I2C2 init function */
|
|
static void MX_I2C2_Init(void)
|
|
{
|
|
|
|
hi2c2.Instance = I2C2;
|
|
hi2c2.Init.Timing = 0x10909CEC;
|
|
hi2c2.Init.OwnAddress1 = 0;
|
|
hi2c2.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
hi2c2.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
hi2c2.Init.OwnAddress2 = 0;
|
|
hi2c2.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
|
hi2c2.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
hi2c2.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
if (HAL_I2C_Init(&hi2c2) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure Analogue filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c2, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure Digital filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c2, 0) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* I2C3 init function */
|
|
static void MX_I2C3_Init(void)
|
|
{
|
|
|
|
hi2c3.Instance = I2C3;
|
|
hi2c3.Init.Timing = 0x10909CEC;
|
|
hi2c3.Init.OwnAddress1 = 0;
|
|
hi2c3.Init.AddressingMode = I2C_ADDRESSINGMODE_7BIT;
|
|
hi2c3.Init.DualAddressMode = I2C_DUALADDRESS_DISABLE;
|
|
hi2c3.Init.OwnAddress2 = 0;
|
|
hi2c3.Init.OwnAddress2Masks = I2C_OA2_NOMASK;
|
|
hi2c3.Init.GeneralCallMode = I2C_GENERALCALL_DISABLE;
|
|
hi2c3.Init.NoStretchMode = I2C_NOSTRETCH_DISABLE;
|
|
if (HAL_I2C_Init(&hi2c3) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure Analogue filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigAnalogFilter(&hi2c3, I2C_ANALOGFILTER_ENABLE) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
/**Configure Digital filter
|
|
*/
|
|
if (HAL_I2CEx_ConfigDigitalFilter(&hi2c3, 0) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* LPUART1 init function */
|
|
static void MX_LPUART1_UART_Init(void)
|
|
{
|
|
|
|
hlpuart1.Instance = LPUART1;
|
|
hlpuart1.Init.BaudRate = 115200;
|
|
hlpuart1.Init.WordLength = UART_WORDLENGTH_8B;
|
|
hlpuart1.Init.StopBits = UART_STOPBITS_1;
|
|
hlpuart1.Init.Parity = UART_PARITY_NONE;
|
|
hlpuart1.Init.Mode = UART_MODE_TX_RX;
|
|
hlpuart1.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
hlpuart1.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
hlpuart1.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
if (HAL_UART_Init(&hlpuart1) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* USART2 init function */
|
|
static void MX_USART2_UART_Init(void)
|
|
{
|
|
|
|
huart2.Instance = USART2;
|
|
huart2.Init.BaudRate = 115200;
|
|
huart2.Init.WordLength = UART_WORDLENGTH_8B;
|
|
huart2.Init.StopBits = UART_STOPBITS_1;
|
|
huart2.Init.Parity = UART_PARITY_NONE;
|
|
huart2.Init.Mode = UART_MODE_TX_RX;
|
|
huart2.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
huart2.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
huart2.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
huart2.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
if (HAL_UART_Init(&huart2) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* USART3 init function */
|
|
static void MX_USART3_UART_Init(void)
|
|
{
|
|
|
|
huart3.Instance = USART3;
|
|
huart3.Init.BaudRate = 115200;
|
|
huart3.Init.WordLength = UART_WORDLENGTH_8B;
|
|
huart3.Init.StopBits = UART_STOPBITS_1;
|
|
huart3.Init.Parity = UART_PARITY_NONE;
|
|
huart3.Init.Mode = UART_MODE_TX_RX;
|
|
huart3.Init.HwFlowCtl = UART_HWCONTROL_NONE;
|
|
huart3.Init.OverSampling = UART_OVERSAMPLING_16;
|
|
huart3.Init.OneBitSampling = UART_ONE_BIT_SAMPLE_DISABLE;
|
|
huart3.AdvancedInit.AdvFeatureInit = UART_ADVFEATURE_NO_INIT;
|
|
if (HAL_UART_Init(&huart3) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* SAI2 init function */
|
|
static void MX_SAI2_Init(void)
|
|
{
|
|
|
|
hsai_BlockA2.Instance = SAI2_Block_A;
|
|
hsai_BlockA2.Init.Protocol = SAI_FREE_PROTOCOL;
|
|
hsai_BlockA2.Init.AudioMode = SAI_MODEMASTER_TX;
|
|
hsai_BlockA2.Init.DataSize = SAI_DATASIZE_24;
|
|
hsai_BlockA2.Init.FirstBit = SAI_FIRSTBIT_MSB;
|
|
hsai_BlockA2.Init.ClockStrobing = SAI_CLOCKSTROBING_FALLINGEDGE;
|
|
hsai_BlockA2.Init.Synchro = SAI_ASYNCHRONOUS;
|
|
hsai_BlockA2.Init.OutputDrive = SAI_OUTPUTDRIVE_DISABLE;
|
|
hsai_BlockA2.Init.NoDivider = SAI_MASTERDIVIDER_ENABLE;
|
|
hsai_BlockA2.Init.FIFOThreshold = SAI_FIFOTHRESHOLD_EMPTY;
|
|
hsai_BlockA2.Init.AudioFrequency = SAI_AUDIO_FREQUENCY_192K;
|
|
hsai_BlockA2.Init.SynchroExt = SAI_SYNCEXT_DISABLE;
|
|
hsai_BlockA2.Init.MonoStereoMode = SAI_STEREOMODE;
|
|
hsai_BlockA2.Init.CompandingMode = SAI_NOCOMPANDING;
|
|
hsai_BlockA2.Init.TriState = SAI_OUTPUT_NOTRELEASED;
|
|
hsai_BlockA2.FrameInit.FrameLength = 8;
|
|
hsai_BlockA2.FrameInit.ActiveFrameLength = 1;
|
|
hsai_BlockA2.FrameInit.FSDefinition = SAI_FS_STARTFRAME;
|
|
hsai_BlockA2.FrameInit.FSPolarity = SAI_FS_ACTIVE_LOW;
|
|
hsai_BlockA2.FrameInit.FSOffset = SAI_FS_FIRSTBIT;
|
|
hsai_BlockA2.SlotInit.FirstBitOffset = 0;
|
|
hsai_BlockA2.SlotInit.SlotSize = SAI_SLOTSIZE_DATASIZE;
|
|
hsai_BlockA2.SlotInit.SlotNumber = 1;
|
|
hsai_BlockA2.SlotInit.SlotActive = 0x00000000;
|
|
if (HAL_SAI_Init(&hsai_BlockA2) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* SDMMC1 init function */
|
|
static void MX_SDMMC1_Init(void)
|
|
{
|
|
|
|
}
|
|
|
|
/* SPI1 init function */
|
|
static void MX_SPI1_Init(void)
|
|
{
|
|
|
|
/* SPI1 parameter configuration*/
|
|
hspi1.Instance = SPI1;
|
|
hspi1.Init.Mode = SPI_MODE_MASTER;
|
|
hspi1.Init.Direction = SPI_DIRECTION_1LINE;
|
|
hspi1.Init.DataSize = SPI_DATASIZE_8BIT;
|
|
hspi1.Init.CLKPolarity = SPI_POLARITY_LOW;
|
|
hspi1.Init.CLKPhase = SPI_PHASE_1EDGE;
|
|
hspi1.Init.NSS = SPI_NSS_HARD_OUTPUT;
|
|
hspi1.Init.BaudRatePrescaler = SPI_BAUDRATEPRESCALER_2;
|
|
hspi1.Init.FirstBit = SPI_FIRSTBIT_MSB;
|
|
hspi1.Init.TIMode = SPI_TIMODE_DISABLE;
|
|
hspi1.Init.CRCCalculation = SPI_CRCCALCULATION_DISABLE;
|
|
hspi1.Init.CRCPolynomial = 7;
|
|
hspi1.Init.CRCLength = SPI_CRC_LENGTH_DATASIZE;
|
|
hspi1.Init.NSSPMode = SPI_NSS_PULSE_ENABLE;
|
|
if (HAL_SPI_Init(&hspi1) != HAL_OK)
|
|
{
|
|
_Error_Handler(__FILE__, __LINE__);
|
|
}
|
|
|
|
}
|
|
|
|
/* USB_OTG_FS init function */
|
|
static void MX_USB_OTG_FS_USB_Init(void)
|
|
{
|
|
|
|
}
|
|
|
|
/** Configure pins as
|
|
* Analog
|
|
* Input
|
|
* Output
|
|
* EVENT_OUT
|
|
* EXTI
|
|
PC8 ------> SDMMC1_D0
|
|
PC9 ------> SDMMC1_D1
|
|
PA10 ------> USB_OTG_FS_ID
|
|
PA11 ------> USB_OTG_FS_DM
|
|
PA12 ------> USB_OTG_FS_DP
|
|
PC10 ------> SDMMC1_D2
|
|
PC11 ------> SDMMC1_D3
|
|
PC12 ------> SDMMC1_CK
|
|
PD2 ------> SDMMC1_CMD
|
|
*/
|
|
static void MX_GPIO_Init(void)
|
|
{
|
|
|
|
GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
/* GPIO Ports Clock Enable */
|
|
__HAL_RCC_GPIOE_CLK_ENABLE();
|
|
__HAL_RCC_GPIOC_CLK_ENABLE();
|
|
__HAL_RCC_GPIOH_CLK_ENABLE();
|
|
__HAL_RCC_GPIOA_CLK_ENABLE();
|
|
__HAL_RCC_GPIOB_CLK_ENABLE();
|
|
__HAL_RCC_GPIOD_CLK_ENABLE();
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOE, AUDIO_CTL_Pin|LCD_PWR_Pin, GPIO_PIN_RESET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(PCIE_RST_GPIO_Port, PCIE_RST_Pin, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOA, SECURE_IO_Pin|SECURE_RST_Pin|LCD_DCX_Pin|CAM_MCLK_Pin, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOB, WIFI_RST_Pin|WIFI_WU_Pin|LCD_RST_Pin|USB_PCIE_SW_Pin
|
|
|CAM_RST_Pin, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOE, CAM_PD_Pin|AUDIO_RST_Pin|SECURE_CLK_Pin, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(GPIOD, HTS_LED_Pin|GS_LED_Pin|ALS_LED_Pin|PS_LED_Pin
|
|
|COMPASS_LED_Pin|AUDIO_WU_Pin|ZIGBEE_RST_Pin, GPIO_PIN_SET);
|
|
|
|
/*Configure GPIO pin Output Level */
|
|
HAL_GPIO_WritePin(IRDA_CTL_GPIO_Port, IRDA_CTL_Pin, GPIO_PIN_RESET);
|
|
|
|
/*Configure GPIO pin : SIM_DET_Pin */
|
|
GPIO_InitStruct.Pin = SIM_DET_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(SIM_DET_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : AUDIO_CTL_Pin LCD_PWR_Pin CAM_PD_Pin AUDIO_RST_Pin
|
|
SECURE_CLK_Pin */
|
|
GPIO_InitStruct.Pin = AUDIO_CTL_Pin|LCD_PWR_Pin|CAM_PD_Pin|AUDIO_RST_Pin
|
|
|SECURE_CLK_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PCIE_RST_Pin */
|
|
GPIO_InitStruct.Pin = PCIE_RST_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(PCIE_RST_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : SECURE_IO_Pin SECURE_RST_Pin LCD_DCX_Pin CAM_MCLK_Pin */
|
|
GPIO_InitStruct.Pin = SECURE_IO_Pin|SECURE_RST_Pin|LCD_DCX_Pin|CAM_MCLK_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : WIFI_RST_Pin WIFI_WU_Pin LCD_RST_Pin USB_PCIE_SW_Pin
|
|
CAM_RST_Pin */
|
|
GPIO_InitStruct.Pin = WIFI_RST_Pin|WIFI_WU_Pin|LCD_RST_Pin|USB_PCIE_SW_Pin
|
|
|CAM_RST_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(GPIOB, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : ZIGBEE_INT_Pin KEY_2_Pin KEY_3_Pin KEY_1_Pin */
|
|
GPIO_InitStruct.Pin = ZIGBEE_INT_Pin|KEY_2_Pin|KEY_3_Pin|KEY_1_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(GPIOE, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : HTS_LED_Pin GS_LED_Pin ALS_LED_Pin PS_LED_Pin
|
|
COMPASS_LED_Pin AUDIO_WU_Pin IRDA_CTL_Pin ZIGBEE_RST_Pin */
|
|
GPIO_InitStruct.Pin = HTS_LED_Pin|GS_LED_Pin|ALS_LED_Pin|PS_LED_Pin
|
|
|COMPASS_LED_Pin|AUDIO_WU_Pin|IRDA_CTL_Pin|ZIGBEE_RST_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PC8 PC9 PC10 PC11
|
|
PC12 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_8|GPIO_PIN_9|GPIO_PIN_10|GPIO_PIN_11
|
|
|GPIO_PIN_12;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
|
|
HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pins : PA10 PA11 PA12 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_10|GPIO_PIN_11|GPIO_PIN_12;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF10_OTG_FS;
|
|
HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : ALS_INT_Pin */
|
|
GPIO_InitStruct.Pin = ALS_INT_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(ALS_INT_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : PD2 */
|
|
GPIO_InitStruct.Pin = GPIO_PIN_2;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_AF_PP;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
|
|
GPIO_InitStruct.Alternate = GPIO_AF12_SDMMC1;
|
|
HAL_GPIO_Init(GPIOD, &GPIO_InitStruct);
|
|
|
|
/*Configure GPIO pin : IRDA_RX_Pin */
|
|
GPIO_InitStruct.Pin = IRDA_RX_Pin;
|
|
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
|
|
GPIO_InitStruct.Pull = GPIO_NOPULL;
|
|
HAL_GPIO_Init(IRDA_RX_GPIO_Port, &GPIO_InitStruct);
|
|
|
|
/* EXTI interrupt init*/
|
|
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
|
|
|
|
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 0, 0);
|
|
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
|
|
|
|
}
|
|
|
|
/* USER CODE BEGIN 4 */
|
|
|
|
/* USER CODE END 4 */
|
|
|
|
/**
|
|
* @brief This function is executed in case of error occurrence.
|
|
* @param file: The file name as string.
|
|
* @param line: The line in file as a number.
|
|
* @retval None
|
|
*/
|
|
void _Error_Handler(char *file, int line)
|
|
{
|
|
/* USER CODE BEGIN Error_Handler_Debug */
|
|
/* User can add his own implementation to report the HAL error return state */
|
|
while(1)
|
|
{
|
|
}
|
|
/* USER CODE END Error_Handler_Debug */
|
|
}
|
|
|
|
#ifdef USE_FULL_ASSERT
|
|
/**
|
|
* @brief Reports the name of the source file and the source line number
|
|
* where the assert_param error has occurred.
|
|
* @param file: pointer to the source file name
|
|
* @param line: assert_param error line source number
|
|
* @retval None
|
|
*/
|
|
void assert_failed(uint8_t* file, uint32_t line)
|
|
{
|
|
/* USER CODE BEGIN 6 */
|
|
/* User can add his own implementation to report the file name and line number,
|
|
tex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
|
|
/* USER CODE END 6 */
|
|
}
|
|
#endif /* USE_FULL_ASSERT */
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/**
|
|
* @}
|
|
*/
|
|
|
|
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|