Part of MicroGen4 Music Synthesizer Program. (But not test it yet.) I2S ,DMA ,Stereo ,16Bit Dac(PCM1781) See detail: http://www.geocities.jp/micro_diys/index2
device.cpp
00001 /** 00002 * COPYRIGHT(c) 2014 STMicroelectronics 00003 * 00004 * Redistribution and use in source and binary forms, with or without modification, 00005 * are permitted provided that the following conditions are met: 00006 * 1. Redistributions of source code must retain the above copyright notice, 00007 * this list of conditions and the following disclaimer. 00008 * 2. Redistributions in binary form must reproduce the above copyright notice, 00009 * this list of conditions and the following disclaimer in the documentation 00010 * and/or other materials provided with the distribution. 00011 * 3. Neither the name of STMicroelectronics nor the names of its contributors 00012 * may be used to endorse or promote products derived from this software 00013 * without specific prior written permission. 00014 * 00015 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 00016 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00017 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00018 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE 00019 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 00020 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 00021 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 00022 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 00023 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 00024 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00025 * 00026 ****************************************************************************** 00027 */ 00028 00029 #include "synthesizer.h" 00030 00031 /* Private variables ---------------------------------------------------------*/ 00032 I2S_HandleTypeDef hi2s2; 00033 DMA_HandleTypeDef hdma_i2s2_ext_tx; 00034 00035 00036 /* Private function prototypes -----------------------------------------------*/ 00037 static void SystemClock_Config(void); 00038 static void MX_DMA_Init(void); 00039 static void MX_I2S2_Init(void); 00040 00041 00042 void uGen4_device_init(void) 00043 { 00044 /* Reset of all peripherals, Initializes the Flash interface and the Systick. */ 00045 HAL_Init(); 00046 00047 /* Configure the system clock */ 00048 SystemClock_Config();// Set RCC I2S Clock 00049 00050 /* Initialize all configured peripherals */ 00051 MX_GPIO_Init();// GPIO CLOCK Enable 00052 MX_DMA_Init(); 00053 MX_I2S2_Init(); 00054 } 00055 00056 00057 /** System Clock Configuration 00058 */ 00059 static void SystemClock_Config(void) 00060 { 00061 00062 RCC_ClkInitTypeDef RCC_ClkInitStruct; 00063 RCC_PeriphCLKInitTypeDef PeriphClkInitStruct; 00064 RCC_OscInitTypeDef RCC_OscInitStruct; 00065 00066 __PWR_CLK_ENABLE(); 00067 00068 __HAL_PWR_VOLTAGESCALING_CONFIG(PWR_REGULATOR_VOLTAGE_SCALE2); 00069 00070 RCC_OscInitStruct.OscillatorType = RCC_OSCILLATORTYPE_HSI; 00071 RCC_OscInitStruct.HSIState = RCC_HSI_ON; 00072 RCC_OscInitStruct.HSICalibrationValue = 6; 00073 RCC_OscInitStruct.PLL.PLLState = RCC_PLL_ON; 00074 RCC_OscInitStruct.PLL.PLLSource = RCC_PLLSOURCE_HSI; 00075 RCC_OscInitStruct.PLL.PLLM = 16; 00076 RCC_OscInitStruct.PLL.PLLN = 336; 00077 RCC_OscInitStruct.PLL.PLLP = RCC_PLLP_DIV4; 00078 RCC_OscInitStruct.PLL.PLLQ = 4; 00079 HAL_RCC_OscConfig(&RCC_OscInitStruct); 00080 00081 RCC_ClkInitStruct.ClockType = RCC_CLOCKTYPE_SYSCLK|RCC_CLOCKTYPE_PCLK1; 00082 RCC_ClkInitStruct.SYSCLKSource = RCC_SYSCLKSOURCE_PLLCLK; 00083 RCC_ClkInitStruct.AHBCLKDivider = RCC_SYSCLK_DIV1; 00084 RCC_ClkInitStruct.APB1CLKDivider = RCC_HCLK_DIV2; 00085 RCC_ClkInitStruct.APB2CLKDivider = RCC_HCLK_DIV1; 00086 HAL_RCC_ClockConfig(&RCC_ClkInitStruct, FLASH_LATENCY_2); 00087 00088 PeriphClkInitStruct.PeriphClockSelection = RCC_PERIPHCLK_I2S; 00089 PeriphClkInitStruct.PLLI2S.PLLI2SN = 290; 00090 PeriphClkInitStruct.PLLI2S.PLLI2SR = 2; 00091 HAL_RCCEx_PeriphCLKConfig(&PeriphClkInitStruct); 00092 00093 } 00094 00095 /* I2S2 init function */ 00096 void MX_I2S2_Init(void) 00097 { 00098 00099 hi2s2.Instance = SPI2; 00100 hi2s2.Init.Mode = I2S_MODE_MASTER_TX; 00101 hi2s2.Init.Standard = I2S_STANDARD_PHILLIPS; 00102 hi2s2.Init.DataFormat = I2S_DATAFORMAT_16B; 00103 hi2s2.Init.MCLKOutput = I2S_MCLKOUTPUT_ENABLE; 00104 hi2s2.Init.AudioFreq = I2S_AUDIOFREQ_44K; 00105 hi2s2.Init.CPOL = I2S_CPOL_LOW; 00106 hi2s2.Init.ClockSource = I2S_CLOCK_PLL; 00107 hi2s2.Init.FullDuplexMode = I2S_FULLDUPLEXMODE_DISABLE; 00108 HAL_I2S_Init(&hi2s2); 00109 00110 } 00111 00112 00113 /** 00114 * Enable DMA controller clock 00115 */ 00116 void MX_DMA_Init(void) 00117 { 00118 /* DMA controller clock enable */ 00119 __DMA1_CLK_ENABLE(); 00120 00121 /* DMA interrupt init */ 00122 NVIC_SetVector(DMA1_Stream4_IRQn, (uint32_t )&DMA1_Stream4_IRQHandler); 00123 /* Sets the priority grouping field */ 00124 HAL_NVIC_SetPriorityGrouping(NVIC_PRIORITYGROUP_0); 00125 HAL_NVIC_SetPriority(DMA1_Stream4_IRQn, 0, 0); 00126 HAL_NVIC_EnableIRQ(DMA1_Stream4_IRQn); 00127 } 00128 00129 /** Pinout Configuration 00130 */ 00131 void MX_GPIO_Init(void) 00132 { 00133 00134 /* GPIO Ports Clock Enable */ 00135 __GPIOC_CLK_ENABLE(); 00136 __GPIOB_CLK_ENABLE(); 00137 __GPIOA_CLK_ENABLE(); 00138 00139 } 00140 00141 00142 #ifdef USE_FULL_ASSERT 00143 00144 /** 00145 * @brief Reports the name of the source file and the source line number 00146 * where the assert_param error has occurred. 00147 * @param file: pointer to the source file name 00148 * @param line: assert_param error line source number 00149 * @retval None 00150 */ 00151 void assert_failed(uint8_t* file, uint32_t line) 00152 { 00153 /* User can add his own implementation to report the file name and line number, 00154 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */ 00155 00156 } 00157 00158 #endif 00159 00160 00161 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ 00162 00163 00164 00165
Generated on Wed Jul 13 2022 10:27:32 by 1.7.2