123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534 |
- /* USER CODE BEGIN Header */
- /**
- ******************************************************************************
- * @file : main.c
- * @brief : Main program body
- ******************************************************************************
- * @attention
- *
- * <h2><center>© Copyright (c) 2019 STMicroelectronics.
- * All rights reserved.</center></h2>
- *
- * This software component is licensed by ST under BSD 3-Clause license,
- * the "License"; You may not use this file except in compliance with the
- * License. You may obtain a copy of the License at:
- * opensource.org/licenses/BSD-3-Clause
- *
- ******************************************************************************
- */
- /* USER CODE END Header */
- /* Includes ------------------------------------------------------------------*/
- #include "main.h"
- #include "pdm2pcm.h"
- /* Private includes ----------------------------------------------------------*/
- /* USER CODE BEGIN Includes */
- /* USER CODE END Includes */
- /* Private typedef -----------------------------------------------------------*/
- /* USER CODE BEGIN PTD */
- /* USER CODE END PTD */
- /* Private define ------------------------------------------------------------*/
- /* USER CODE BEGIN PD */
- /* USER CODE END PD */
- /* Private macro -------------------------------------------------------------*/
- /* USER CODE BEGIN PM */
- /* USER CODE END PM */
- /* Private variables ---------------------------------------------------------*/
- CRC_HandleTypeDef hcrc;
- I2S_HandleTypeDef hi2s3;
- QSPI_HandleTypeDef hqspi;
- TIM_HandleTypeDef htim4;
- UART_HandleTypeDef huart3;
- PCD_HandleTypeDef hpcd_USB_OTG_FS;
- SDRAM_HandleTypeDef hsdram1;
- /* USER CODE BEGIN PV */
- /* USER CODE END PV */
- /* Private function prototypes -----------------------------------------------*/
- void SystemClock_Config(void);
- static void MX_GPIO_Init(void);
- static void MX_USART3_UART_Init(void);
- static void MX_FMC_Init(void);
- static void MX_QUADSPI_Init(void);
- static void MX_GFXSIMULATOR_Init(void);
- static void MX_CRC_Init(void);
- static void MX_I2S3_Init(void);
- static void MX_TIM4_Init(void);
- static void MX_USB_OTG_FS_PCD_Init(void);
- /* USER CODE BEGIN PFP */
- /* USER CODE END PFP */
- /* Private user code ---------------------------------------------------------*/
- /* USER CODE BEGIN 0 */
- /* USER CODE END 0 */
- /**
- * @brief The application entry point.
- * @retval int
- */
- 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_USART3_UART_Init();
- MX_FMC_Init();
- MX_QUADSPI_Init();
- MX_GFXSIMULATOR_Init();
- MX_CRC_Init();
- MX_I2S3_Init();
- MX_TIM4_Init();
- MX_PDM2PCM_Init();
- MX_USB_OTG_FS_PCD_Init();
- /* USER CODE BEGIN 2 */
- /* USER CODE END 2 */
- /* Infinite loop */
- /* USER CODE BEGIN WHILE */
- while (1)
- {
- // HAL_GPIO_WritePin(GPIOG, 6, GPIO_PIN_SET);
- HAL_GPIO_WritePin(GPIOG, 6, GPIO_PIN_RESET);
- /* 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 = {0};
- RCC_ClkInitTypeDef RCC_ClkInitStruct = {0};
- RCC_PeriphCLKInitTypeDef PeriphClkInitStruct = {0};
- /** Configure the main internal regulator output voltage
- */
- __HAL_RCC_PWR_CLK_ENABLE();
- __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE1);
- /** Initializes the CPU, AHB and APB busses clocks
- */
- RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSE;
- RCC_OscInitStruct.HSEState = RCC_HSE_ON;
- RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON;
- RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSE;
- RCC_OscInitStruct.PLL.PLLM = 4;
- RCC_OscInitStruct.PLL.PLLN = 180;
- RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV2;
- RCC_OscInitStruct.PLL.PLLQ = 3;
- RCC_OscInitStruct.PLL.PLLR = 2;
- if (HAL_RCC_OscConfig(&RCC_OscInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- /** Activate the Over-Drive mode
- */
- if (HAL_PWREx_EnableOverDrive() != HAL_OK)
- {
- Error_Handler();
- }
- /** 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_DIV4;
- RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV2;
- if (HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_5) != HAL_OK)
- {
- Error_Handler();
- }
- PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S|RCC_PERIPHCLK_CLK48;
- PeriphClkInitStruct.PLLI2S.PLLI2SN = 192;
- PeriphClkInitStruct.PLLI2S.PLLI2SR = 2;
- PeriphClkInitStruct.PLLSAI.PLLSAIN = 96;
- PeriphClkInitStruct.PLLSAI.PLLSAIP = RCC_PLLSAIP_DIV4;
- PeriphClkInitStruct.Clk48ClockSelection = RCC_CLK48CLKSOURCE_PLLSAIP;
- if (HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct) != HAL_OK)
- {
- Error_Handler();
- }
- }
- /**
- * @brief CRC Initialization Function
- * @param None
- * @retval None
- */
- static void MX_CRC_Init(void)
- {
- /* USER CODE BEGIN CRC_Init 0 */
- /* USER CODE END CRC_Init 0 */
- /* USER CODE BEGIN CRC_Init 1 */
- /* USER CODE END CRC_Init 1 */
- hcrc.Instance = CRC;
- if (HAL_CRC_Init(&hcrc) != HAL_OK)
- {
- Error_Handler();
- }
- __HAL_CRC_DR_RESET(&hcrc);
- /* USER CODE BEGIN CRC_Init 2 */
- /* USER CODE END CRC_Init 2 */
- }
- /**
- * @brief GFXSIMULATOR Initialization Function
- * @param None
- * @retval None
- */
- static void MX_GFXSIMULATOR_Init(void)
- {
- /* USER CODE BEGIN GFXSIMULATOR_Init 0 */
- /* USER CODE END GFXSIMULATOR_Init 0 */
- /* USER CODE BEGIN GFXSIMULATOR_Init 1 */
- /* USER CODE END GFXSIMULATOR_Init 1 */
- /* USER CODE BEGIN GFXSIMULATOR_Init 2 */
- /* USER CODE END GFXSIMULATOR_Init 2 */
- }
- /**
- * @brief I2S3 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_I2S3_Init(void)
- {
- /* USER CODE BEGIN I2S3_Init 0 */
- /* USER CODE END I2S3_Init 0 */
- /* USER CODE BEGIN I2S3_Init 1 */
- /* USER CODE END I2S3_Init 1 */
- hi2s3.Instance = SPI3;
- hi2s3.Init.Mode = I2S_MODE_MASTER_RX;
- hi2s3.Init.Standard = I2S_STANDARD_LSB;
- hi2s3.Init.DataFormat = I2S_DATAFORMAT_16B;
- hi2s3.Init.MCLKOutput = I2S_MCLKOUTPUT_DISABLE;
- hi2s3.Init.AudioFreq = I2S_AUDIOFREQ_16K;
- hi2s3.Init.CPOL = I2S_CPOL_LOW;
- hi2s3.Init.ClockSource = I2S_CLOCK_PLL;
- hi2s3.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE;
- if (HAL_I2S_Init(&hi2s3) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN I2S3_Init 2 */
- /* USER CODE END I2S3_Init 2 */
- }
- /**
- * @brief QUADSPI Initialization Function
- * @param None
- * @retval None
- */
- static void MX_QUADSPI_Init(void)
- {
- /* USER CODE BEGIN QUADSPI_Init 0 */
- /* USER CODE END QUADSPI_Init 0 */
- /* USER CODE BEGIN QUADSPI_Init 1 */
- /* USER CODE END QUADSPI_Init 1 */
- /* QUADSPI parameter configuration*/
- hqspi.Instance = QUADSPI;
- hqspi.Init.ClockPrescaler = 1;
- hqspi.Init.FifoThreshold = 4;
- hqspi.Init.SampleShifting = QSPI_SAMPLE_SHIFTING_HALFCYCLE;
- hqspi.Init.FlashSize = 24;
- hqspi.Init.ChipSelectHighTime = QSPI_CS_HIGH_TIME_5_CYCLE;
- hqspi.Init.ClockMode = QSPI_CLOCK_MODE_0;
- hqspi.Init.FlashID = QSPI_FLASH_ID_1;
- hqspi.Init.DualFlash = QSPI_DUALFLASH_DISABLE;
- if (HAL_QSPI_Init(&hqspi) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN QUADSPI_Init 2 */
- /* USER CODE END QUADSPI_Init 2 */
- }
- /**
- * @brief TIM4 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_TIM4_Init(void)
- {
- /* USER CODE BEGIN TIM4_Init 0 */
- /* USER CODE END TIM4_Init 0 */
- TIM_SlaveConfigTypeDef sSlaveConfig = {0};
- TIM_MasterConfigTypeDef sMasterConfig = {0};
- TIM_OC_InitTypeDef sConfigOC = {0};
- /* USER CODE BEGIN TIM4_Init 1 */
- /* USER CODE END TIM4_Init 1 */
- htim4.Instance = TIM4;
- htim4.Init.Prescaler = 0;
- htim4.Init.CounterMode = TIM_COUNTERMODE_UP;
- htim4.Init.Period = 1;
- htim4.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
- htim4.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
- if (HAL_TIM_Base_Init(&htim4) != HAL_OK)
- {
- Error_Handler();
- }
- if (HAL_TIM_PWM_Init(&htim4) != HAL_OK)
- {
- Error_Handler();
- }
- sSlaveConfig.SlaveMode = TIM_SLAVEMODE_EXTERNAL1;
- sSlaveConfig.InputTrigger = TIM_TS_TI1FP1;
- sSlaveConfig.TriggerPolarity = TIM_TRIGGERPOLARITY_FALLING;
- sSlaveConfig.TriggerFilter = 0;
- if (HAL_TIM_SlaveConfigSynchro(&htim4, &sSlaveConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sMasterConfig.MasterOutputTrigger = TIM_TRGO_RESET;
- sMasterConfig.MasterSlaveMode = TIM_MASTERSLAVEMODE_DISABLE;
- if (HAL_TIMEx_MasterConfigSynchronization(&htim4, &sMasterConfig) != HAL_OK)
- {
- Error_Handler();
- }
- sConfigOC.OCMode = TIM_OCMODE_PWM1;
- sConfigOC.Pulse = 1;
- sConfigOC.OCPolarity = TIM_OCPOLARITY_HIGH;
- sConfigOC.OCFastMode = TIM_OCFAST_DISABLE;
- if (HAL_TIM_PWM_ConfigChannel(&htim4, &sConfigOC, TIM_CHANNEL_2) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN TIM4_Init 2 */
- /* USER CODE END TIM4_Init 2 */
- HAL_TIM_MspPostInit(&htim4);
- }
- /**
- * @brief USART3 Initialization Function
- * @param None
- * @retval None
- */
- static void MX_USART3_UART_Init(void)
- {
- /* USER CODE BEGIN USART3_Init 0 */
- /* USER CODE END USART3_Init 0 */
- /* USER CODE BEGIN USART3_Init 1 */
- /* USER CODE END USART3_Init 1 */
- 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;
- if (HAL_UART_Init(&huart3) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USART3_Init 2 */
- /* USER CODE END USART3_Init 2 */
- }
- /**
- * @brief USB_OTG_FS Initialization Function
- * @param None
- * @retval None
- */
- static void MX_USB_OTG_FS_PCD_Init(void)
- {
- /* USER CODE BEGIN USB_OTG_FS_Init 0 */
- /* USER CODE END USB_OTG_FS_Init 0 */
- /* USER CODE BEGIN USB_OTG_FS_Init 1 */
- /* USER CODE END USB_OTG_FS_Init 1 */
- hpcd_USB_OTG_FS.Instance = USB_OTG_FS;
- hpcd_USB_OTG_FS.Init.dev_endpoints = 6;
- hpcd_USB_OTG_FS.Init.speed = PCD_SPEED_FULL;
- hpcd_USB_OTG_FS.Init.dma_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.phy_itface = PCD_PHY_EMBEDDED;
- hpcd_USB_OTG_FS.Init.Sof_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.low_power_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.lpm_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.vbus_sensing_enable = DISABLE;
- hpcd_USB_OTG_FS.Init.use_dedicated_ep1 = DISABLE;
- if (HAL_PCD_Init(&hpcd_USB_OTG_FS) != HAL_OK)
- {
- Error_Handler();
- }
- /* USER CODE BEGIN USB_OTG_FS_Init 2 */
- /* USER CODE END USB_OTG_FS_Init 2 */
- }
- /* FMC initialization function */
- static void MX_FMC_Init(void)
- {
- FMC_SDRAM_TimingTypeDef SdramTiming;
- /** Perform the SDRAM1 memory initialization sequence
- */
- hsdram1.Instance = FMC_SDRAM_DEVICE;
- /* hsdram1.Init */
- hsdram1.Init.SDBank = FMC_SDRAM_BANK1;
- hsdram1.Init.ColumnBitsNumber = FMC_SDRAM_COLUMN_BITS_NUM_8;
- hsdram1.Init.RowBitsNumber = FMC_SDRAM_ROW_BITS_NUM_12;
- hsdram1.Init.MemoryDataWidth = FMC_SDRAM_MEM_BUS_WIDTH_32;
- hsdram1.Init.InternalBankNumber = FMC_SDRAM_INTERN_BANKS_NUM_4;
- hsdram1.Init.CASLatency = FMC_SDRAM_CAS_LATENCY_3;
- hsdram1.Init.WriteProtection = FMC_SDRAM_WRITE_PROTECTION_DISABLE;
- hsdram1.Init.SDClockPeriod = FMC_SDRAM_CLOCK_PERIOD_2;
- hsdram1.Init.ReadBurst = FMC_SDRAM_RBURST_ENABLE;
- hsdram1.Init.ReadPipeDelay = FMC_SDRAM_RPIPE_DELAY_0;
- /* SdramTiming */
- SdramTiming.LoadToActiveDelay = 2;
- SdramTiming.ExitSelfRefreshDelay = 7;
- SdramTiming.SelfRefreshTime = 4;
- SdramTiming.RowCycleDelay = 7;
- SdramTiming.WriteRecoveryTime = 3;
- SdramTiming.RPDelay = 2;
- SdramTiming.RCDDelay = 2;
- if (HAL_SDRAM_Init(&hsdram1, &SdramTiming) != HAL_OK)
- {
- Error_Handler( );
- }
- }
- /**
- * @brief GPIO Initialization Function
- * @param None
- * @retval None
- */
- static void MX_GPIO_Init(void)
- {
- /* GPIO Ports Clock Enable */
- __HAL_RCC_GPIOE_CLK_ENABLE();
- __HAL_RCC_GPIOB_CLK_ENABLE();
- __HAL_RCC_GPIOA_CLK_ENABLE();
- __HAL_RCC_GPIOG_CLK_ENABLE();
- __HAL_RCC_GPIOD_CLK_ENABLE();
- __HAL_RCC_GPIOI_CLK_ENABLE();
- __HAL_RCC_GPIOF_CLK_ENABLE();
- __HAL_RCC_GPIOH_CLK_ENABLE();
- __HAL_RCC_GPIOC_CLK_ENABLE();
- }
- /* USER CODE BEGIN 4 */
- /* USER CODE END 4 */
- /**
- * @brief This function is executed in case of error occurrence.
- * @retval None
- */
- void Error_Handler(void)
- {
- /* USER CODE BEGIN Error_Handler_Debug */
- /* User can add his own implementation to report the HAL error return state */
- /* 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****/
|