Mouse code for the MacroRat
mbed-dev/targets/TARGET_STM/TARGET_STM32F4/device/stm32f4xx_hal_sai_ex.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /** |
sahilmgandhi | 18:6a4db94011d3 | 2 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 3 | * @file stm32f4xx_hal_sai_ex.c |
sahilmgandhi | 18:6a4db94011d3 | 4 | * @author MCD Application Team |
sahilmgandhi | 18:6a4db94011d3 | 5 | * @version V1.5.0 |
sahilmgandhi | 18:6a4db94011d3 | 6 | * @date 06-May-2016 |
sahilmgandhi | 18:6a4db94011d3 | 7 | * @brief SAI Extension HAL module driver. |
sahilmgandhi | 18:6a4db94011d3 | 8 | * This file provides firmware functions to manage the following |
sahilmgandhi | 18:6a4db94011d3 | 9 | * functionalities of SAI extension peripheral: |
sahilmgandhi | 18:6a4db94011d3 | 10 | * + Extension features functions |
sahilmgandhi | 18:6a4db94011d3 | 11 | * |
sahilmgandhi | 18:6a4db94011d3 | 12 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 13 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 14 | ##### SAI peripheral extension features ##### |
sahilmgandhi | 18:6a4db94011d3 | 15 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 16 | |
sahilmgandhi | 18:6a4db94011d3 | 17 | [..] Comparing to other previous devices, the SAI interface for STM32F446xx |
sahilmgandhi | 18:6a4db94011d3 | 18 | devices contains the following additional features : |
sahilmgandhi | 18:6a4db94011d3 | 19 | |
sahilmgandhi | 18:6a4db94011d3 | 20 | (+) Possibility to be clocked from PLLR |
sahilmgandhi | 18:6a4db94011d3 | 21 | |
sahilmgandhi | 18:6a4db94011d3 | 22 | ##### How to use this driver ##### |
sahilmgandhi | 18:6a4db94011d3 | 23 | ============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 24 | [..] This driver provides functions to manage several sources to clock SAI |
sahilmgandhi | 18:6a4db94011d3 | 25 | |
sahilmgandhi | 18:6a4db94011d3 | 26 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 27 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 28 | * @attention |
sahilmgandhi | 18:6a4db94011d3 | 29 | * |
sahilmgandhi | 18:6a4db94011d3 | 30 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
sahilmgandhi | 18:6a4db94011d3 | 31 | * |
sahilmgandhi | 18:6a4db94011d3 | 32 | * Redistribution and use in source and binary forms, with or without modification, |
sahilmgandhi | 18:6a4db94011d3 | 33 | * are permitted provided that the following conditions are met: |
sahilmgandhi | 18:6a4db94011d3 | 34 | * 1. Redistributions of source code must retain the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 35 | * this list of conditions and the following disclaimer. |
sahilmgandhi | 18:6a4db94011d3 | 36 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
sahilmgandhi | 18:6a4db94011d3 | 37 | * this list of conditions and the following disclaimer in the documentation |
sahilmgandhi | 18:6a4db94011d3 | 38 | * and/or other materials provided with the distribution. |
sahilmgandhi | 18:6a4db94011d3 | 39 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
sahilmgandhi | 18:6a4db94011d3 | 40 | * may be used to endorse or promote products derived from this software |
sahilmgandhi | 18:6a4db94011d3 | 41 | * without specific prior written permission. |
sahilmgandhi | 18:6a4db94011d3 | 42 | * |
sahilmgandhi | 18:6a4db94011d3 | 43 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
sahilmgandhi | 18:6a4db94011d3 | 44 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
sahilmgandhi | 18:6a4db94011d3 | 45 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
sahilmgandhi | 18:6a4db94011d3 | 46 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
sahilmgandhi | 18:6a4db94011d3 | 47 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
sahilmgandhi | 18:6a4db94011d3 | 48 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
sahilmgandhi | 18:6a4db94011d3 | 49 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
sahilmgandhi | 18:6a4db94011d3 | 50 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
sahilmgandhi | 18:6a4db94011d3 | 51 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
sahilmgandhi | 18:6a4db94011d3 | 52 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
sahilmgandhi | 18:6a4db94011d3 | 53 | * |
sahilmgandhi | 18:6a4db94011d3 | 54 | ****************************************************************************** |
sahilmgandhi | 18:6a4db94011d3 | 55 | */ |
sahilmgandhi | 18:6a4db94011d3 | 56 | |
sahilmgandhi | 18:6a4db94011d3 | 57 | /* Includes ------------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 58 | #include "stm32f4xx_hal.h" |
sahilmgandhi | 18:6a4db94011d3 | 59 | |
sahilmgandhi | 18:6a4db94011d3 | 60 | /** @addtogroup STM32F4xx_HAL_Driver |
sahilmgandhi | 18:6a4db94011d3 | 61 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 62 | */ |
sahilmgandhi | 18:6a4db94011d3 | 63 | |
sahilmgandhi | 18:6a4db94011d3 | 64 | /** @defgroup SAIEx SAIEx |
sahilmgandhi | 18:6a4db94011d3 | 65 | * @brief SAI Extension HAL module driver |
sahilmgandhi | 18:6a4db94011d3 | 66 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 67 | */ |
sahilmgandhi | 18:6a4db94011d3 | 68 | |
sahilmgandhi | 18:6a4db94011d3 | 69 | #ifdef HAL_SAI_MODULE_ENABLED |
sahilmgandhi | 18:6a4db94011d3 | 70 | |
sahilmgandhi | 18:6a4db94011d3 | 71 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \ |
sahilmgandhi | 18:6a4db94011d3 | 72 | defined(STM32F446xx) || defined(STM32F469xx) || defined(STM32F479xx) |
sahilmgandhi | 18:6a4db94011d3 | 73 | |
sahilmgandhi | 18:6a4db94011d3 | 74 | /* Private typedef -----------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 75 | /* Private define ------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 76 | /* SAI registers Masks */ |
sahilmgandhi | 18:6a4db94011d3 | 77 | /* Private macro -------------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 78 | /* Private variables ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 79 | /* Private function prototypes -----------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 80 | /* Private functions ---------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 81 | |
sahilmgandhi | 18:6a4db94011d3 | 82 | /** @defgroup SAI_Private_Functions SAI Private Functions |
sahilmgandhi | 18:6a4db94011d3 | 83 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 84 | */ |
sahilmgandhi | 18:6a4db94011d3 | 85 | /** |
sahilmgandhi | 18:6a4db94011d3 | 86 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 87 | */ |
sahilmgandhi | 18:6a4db94011d3 | 88 | |
sahilmgandhi | 18:6a4db94011d3 | 89 | /* Exported functions --------------------------------------------------------*/ |
sahilmgandhi | 18:6a4db94011d3 | 90 | /** @defgroup SAIEx_Exported_Functions SAI Extended Exported Functions |
sahilmgandhi | 18:6a4db94011d3 | 91 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 92 | */ |
sahilmgandhi | 18:6a4db94011d3 | 93 | |
sahilmgandhi | 18:6a4db94011d3 | 94 | /** @defgroup SAIEx_Exported_Functions_Group1 Extension features functions |
sahilmgandhi | 18:6a4db94011d3 | 95 | * @brief Extension features functions |
sahilmgandhi | 18:6a4db94011d3 | 96 | * |
sahilmgandhi | 18:6a4db94011d3 | 97 | @verbatim |
sahilmgandhi | 18:6a4db94011d3 | 98 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 99 | ##### Extension features Functions ##### |
sahilmgandhi | 18:6a4db94011d3 | 100 | =============================================================================== |
sahilmgandhi | 18:6a4db94011d3 | 101 | [..] |
sahilmgandhi | 18:6a4db94011d3 | 102 | This subsection provides a set of functions allowing to manage the possible |
sahilmgandhi | 18:6a4db94011d3 | 103 | SAI clock sources. |
sahilmgandhi | 18:6a4db94011d3 | 104 | |
sahilmgandhi | 18:6a4db94011d3 | 105 | @endverbatim |
sahilmgandhi | 18:6a4db94011d3 | 106 | * @{ |
sahilmgandhi | 18:6a4db94011d3 | 107 | */ |
sahilmgandhi | 18:6a4db94011d3 | 108 | |
sahilmgandhi | 18:6a4db94011d3 | 109 | /** |
sahilmgandhi | 18:6a4db94011d3 | 110 | * @brief Configure SAI Block synchronization mode |
sahilmgandhi | 18:6a4db94011d3 | 111 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 112 | * the configuration information for SAI module. |
sahilmgandhi | 18:6a4db94011d3 | 113 | * @retval SAI Clock Input |
sahilmgandhi | 18:6a4db94011d3 | 114 | */ |
sahilmgandhi | 18:6a4db94011d3 | 115 | void SAI_BlockSynchroConfig(SAI_HandleTypeDef *hsai) |
sahilmgandhi | 18:6a4db94011d3 | 116 | { |
sahilmgandhi | 18:6a4db94011d3 | 117 | uint32_t tmpregisterGCR = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 118 | |
sahilmgandhi | 18:6a4db94011d3 | 119 | #if defined(STM32F446xx) |
sahilmgandhi | 18:6a4db94011d3 | 120 | /* This setting must be done with both audio block (A & B) disabled */ |
sahilmgandhi | 18:6a4db94011d3 | 121 | switch(hsai->Init.SynchroExt) |
sahilmgandhi | 18:6a4db94011d3 | 122 | { |
sahilmgandhi | 18:6a4db94011d3 | 123 | case SAI_SYNCEXT_DISABLE : |
sahilmgandhi | 18:6a4db94011d3 | 124 | tmpregisterGCR = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 125 | break; |
sahilmgandhi | 18:6a4db94011d3 | 126 | case SAI_SYNCEXT_OUTBLOCKA_ENABLE : |
sahilmgandhi | 18:6a4db94011d3 | 127 | tmpregisterGCR = SAI_GCR_SYNCOUT_0; |
sahilmgandhi | 18:6a4db94011d3 | 128 | break; |
sahilmgandhi | 18:6a4db94011d3 | 129 | case SAI_SYNCEXT_OUTBLOCKB_ENABLE : |
sahilmgandhi | 18:6a4db94011d3 | 130 | tmpregisterGCR = SAI_GCR_SYNCOUT_1; |
sahilmgandhi | 18:6a4db94011d3 | 131 | break; |
sahilmgandhi | 18:6a4db94011d3 | 132 | default: |
sahilmgandhi | 18:6a4db94011d3 | 133 | break; |
sahilmgandhi | 18:6a4db94011d3 | 134 | } |
sahilmgandhi | 18:6a4db94011d3 | 135 | |
sahilmgandhi | 18:6a4db94011d3 | 136 | if((hsai->Init.Synchro) == SAI_SYNCHRONOUS_EXT_SAI2) |
sahilmgandhi | 18:6a4db94011d3 | 137 | { |
sahilmgandhi | 18:6a4db94011d3 | 138 | tmpregisterGCR |= SAI_GCR_SYNCIN_0; |
sahilmgandhi | 18:6a4db94011d3 | 139 | } |
sahilmgandhi | 18:6a4db94011d3 | 140 | |
sahilmgandhi | 18:6a4db94011d3 | 141 | if((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B)) |
sahilmgandhi | 18:6a4db94011d3 | 142 | { |
sahilmgandhi | 18:6a4db94011d3 | 143 | SAI1->GCR = tmpregisterGCR; |
sahilmgandhi | 18:6a4db94011d3 | 144 | } |
sahilmgandhi | 18:6a4db94011d3 | 145 | else |
sahilmgandhi | 18:6a4db94011d3 | 146 | { |
sahilmgandhi | 18:6a4db94011d3 | 147 | SAI2->GCR = tmpregisterGCR; |
sahilmgandhi | 18:6a4db94011d3 | 148 | } |
sahilmgandhi | 18:6a4db94011d3 | 149 | #endif /* STM32F446xx */ |
sahilmgandhi | 18:6a4db94011d3 | 150 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \ |
sahilmgandhi | 18:6a4db94011d3 | 151 | defined(STM32F469xx) || defined(STM32F479xx) |
sahilmgandhi | 18:6a4db94011d3 | 152 | /* This setting must be done with both audio block (A & B) disabled */ |
sahilmgandhi | 18:6a4db94011d3 | 153 | switch(hsai->Init.SynchroExt) |
sahilmgandhi | 18:6a4db94011d3 | 154 | { |
sahilmgandhi | 18:6a4db94011d3 | 155 | case SAI_SYNCEXT_DISABLE : |
sahilmgandhi | 18:6a4db94011d3 | 156 | tmpregisterGCR = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 157 | break; |
sahilmgandhi | 18:6a4db94011d3 | 158 | case SAI_SYNCEXT_OUTBLOCKA_ENABLE : |
sahilmgandhi | 18:6a4db94011d3 | 159 | tmpregisterGCR = SAI_GCR_SYNCOUT_0; |
sahilmgandhi | 18:6a4db94011d3 | 160 | break; |
sahilmgandhi | 18:6a4db94011d3 | 161 | case SAI_SYNCEXT_OUTBLOCKB_ENABLE : |
sahilmgandhi | 18:6a4db94011d3 | 162 | tmpregisterGCR = SAI_GCR_SYNCOUT_1; |
sahilmgandhi | 18:6a4db94011d3 | 163 | break; |
sahilmgandhi | 18:6a4db94011d3 | 164 | default: |
sahilmgandhi | 18:6a4db94011d3 | 165 | break; |
sahilmgandhi | 18:6a4db94011d3 | 166 | } |
sahilmgandhi | 18:6a4db94011d3 | 167 | SAI1->GCR = tmpregisterGCR; |
sahilmgandhi | 18:6a4db94011d3 | 168 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
sahilmgandhi | 18:6a4db94011d3 | 169 | } |
sahilmgandhi | 18:6a4db94011d3 | 170 | /** |
sahilmgandhi | 18:6a4db94011d3 | 171 | * @brief Get SAI Input Clock based on SAI source clock selection |
sahilmgandhi | 18:6a4db94011d3 | 172 | * @param hsai: pointer to a SAI_HandleTypeDef structure that contains |
sahilmgandhi | 18:6a4db94011d3 | 173 | * the configuration information for SAI module. |
sahilmgandhi | 18:6a4db94011d3 | 174 | * @retval SAI Clock Input |
sahilmgandhi | 18:6a4db94011d3 | 175 | */ |
sahilmgandhi | 18:6a4db94011d3 | 176 | uint32_t SAI_GetInputClock(SAI_HandleTypeDef *hsai) |
sahilmgandhi | 18:6a4db94011d3 | 177 | { |
sahilmgandhi | 18:6a4db94011d3 | 178 | /* This variable used to store the SAI_CK_x (value in Hz) */ |
sahilmgandhi | 18:6a4db94011d3 | 179 | uint32_t saiclocksource = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 180 | |
sahilmgandhi | 18:6a4db94011d3 | 181 | #if defined(STM32F446xx) |
sahilmgandhi | 18:6a4db94011d3 | 182 | if ((hsai->Instance == SAI1_Block_A) || (hsai->Instance == SAI1_Block_B)) |
sahilmgandhi | 18:6a4db94011d3 | 183 | { |
sahilmgandhi | 18:6a4db94011d3 | 184 | saiclocksource = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI1); |
sahilmgandhi | 18:6a4db94011d3 | 185 | } |
sahilmgandhi | 18:6a4db94011d3 | 186 | else /* SAI2_Block_A || SAI2_Block_B*/ |
sahilmgandhi | 18:6a4db94011d3 | 187 | { |
sahilmgandhi | 18:6a4db94011d3 | 188 | saiclocksource = HAL_RCCEx_GetPeriphCLKFreq(RCC_PERIPHCLK_SAI2); |
sahilmgandhi | 18:6a4db94011d3 | 189 | } |
sahilmgandhi | 18:6a4db94011d3 | 190 | #endif /* STM32F446xx */ |
sahilmgandhi | 18:6a4db94011d3 | 191 | #if defined(STM32F427xx) || defined(STM32F437xx) || defined(STM32F429xx) || defined(STM32F439xx) || \ |
sahilmgandhi | 18:6a4db94011d3 | 192 | defined(STM32F469xx) || defined(STM32F479xx) |
sahilmgandhi | 18:6a4db94011d3 | 193 | uint32_t vcoinput = 0U, tmpreg = 0U; |
sahilmgandhi | 18:6a4db94011d3 | 194 | |
sahilmgandhi | 18:6a4db94011d3 | 195 | /* Check the SAI Block parameters */ |
sahilmgandhi | 18:6a4db94011d3 | 196 | assert_param(IS_SAI_CLK_SOURCE(hsai->Init.ClockSource)); |
sahilmgandhi | 18:6a4db94011d3 | 197 | |
sahilmgandhi | 18:6a4db94011d3 | 198 | /* SAI Block clock source selection */ |
sahilmgandhi | 18:6a4db94011d3 | 199 | if(hsai->Instance == SAI1_Block_A) |
sahilmgandhi | 18:6a4db94011d3 | 200 | { |
sahilmgandhi | 18:6a4db94011d3 | 201 | __HAL_RCC_SAI_BLOCKACLKSOURCE_CONFIG(hsai->Init.ClockSource); |
sahilmgandhi | 18:6a4db94011d3 | 202 | } |
sahilmgandhi | 18:6a4db94011d3 | 203 | else |
sahilmgandhi | 18:6a4db94011d3 | 204 | { |
sahilmgandhi | 18:6a4db94011d3 | 205 | __HAL_RCC_SAI_BLOCKBCLKSOURCE_CONFIG((uint32_t)(hsai->Init.ClockSource << 2U)); |
sahilmgandhi | 18:6a4db94011d3 | 206 | } |
sahilmgandhi | 18:6a4db94011d3 | 207 | |
sahilmgandhi | 18:6a4db94011d3 | 208 | /* VCO Input Clock value calculation */ |
sahilmgandhi | 18:6a4db94011d3 | 209 | if((RCC->PLLCFGR & RCC_PLLCFGR_PLLSRC) == RCC_PLLSOURCE_HSI) |
sahilmgandhi | 18:6a4db94011d3 | 210 | { |
sahilmgandhi | 18:6a4db94011d3 | 211 | /* In Case the PLL Source is HSI (Internal Clock) */ |
sahilmgandhi | 18:6a4db94011d3 | 212 | vcoinput = (HSI_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM)); |
sahilmgandhi | 18:6a4db94011d3 | 213 | } |
sahilmgandhi | 18:6a4db94011d3 | 214 | else |
sahilmgandhi | 18:6a4db94011d3 | 215 | { |
sahilmgandhi | 18:6a4db94011d3 | 216 | /* In Case the PLL Source is HSE (External Clock) */ |
sahilmgandhi | 18:6a4db94011d3 | 217 | vcoinput = ((HSE_VALUE / (uint32_t)(RCC->PLLCFGR & RCC_PLLCFGR_PLLM))); |
sahilmgandhi | 18:6a4db94011d3 | 218 | } |
sahilmgandhi | 18:6a4db94011d3 | 219 | |
sahilmgandhi | 18:6a4db94011d3 | 220 | /* SAI_CLK_x : SAI Block Clock configuration for different clock sources selected */ |
sahilmgandhi | 18:6a4db94011d3 | 221 | if(hsai->Init.ClockSource == SAI_CLKSOURCE_PLLSAI) |
sahilmgandhi | 18:6a4db94011d3 | 222 | { |
sahilmgandhi | 18:6a4db94011d3 | 223 | /* Configure the PLLI2S division factor */ |
sahilmgandhi | 18:6a4db94011d3 | 224 | /* PLLSAI_VCO Input = PLL_SOURCE/PLLM */ |
sahilmgandhi | 18:6a4db94011d3 | 225 | /* PLLSAI_VCO Output = PLLSAI_VCO Input * PLLSAIN */ |
sahilmgandhi | 18:6a4db94011d3 | 226 | /* SAI_CLK(first level) = PLLSAI_VCO Output/PLLSAIQ */ |
sahilmgandhi | 18:6a4db94011d3 | 227 | tmpreg = (RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIQ) >> 24U; |
sahilmgandhi | 18:6a4db94011d3 | 228 | saiclocksource = (vcoinput * ((RCC->PLLSAICFGR & RCC_PLLSAICFGR_PLLSAIN) >> 6U))/(tmpreg); |
sahilmgandhi | 18:6a4db94011d3 | 229 | |
sahilmgandhi | 18:6a4db94011d3 | 230 | /* SAI_CLK_x = SAI_CLK(first level)/PLLSAIDIVQ */ |
sahilmgandhi | 18:6a4db94011d3 | 231 | tmpreg = (((RCC->DCKCFGR & RCC_DCKCFGR_PLLSAIDIVQ) >> 8U) + 1U); |
sahilmgandhi | 18:6a4db94011d3 | 232 | saiclocksource = saiclocksource/(tmpreg); |
sahilmgandhi | 18:6a4db94011d3 | 233 | |
sahilmgandhi | 18:6a4db94011d3 | 234 | } |
sahilmgandhi | 18:6a4db94011d3 | 235 | else if(hsai->Init.ClockSource == SAI_CLKSOURCE_PLLI2S) |
sahilmgandhi | 18:6a4db94011d3 | 236 | { |
sahilmgandhi | 18:6a4db94011d3 | 237 | /* Configure the PLLI2S division factor */ |
sahilmgandhi | 18:6a4db94011d3 | 238 | /* PLLI2S_VCO Input = PLL_SOURCE/PLLM */ |
sahilmgandhi | 18:6a4db94011d3 | 239 | /* PLLI2S_VCO Output = PLLI2S_VCO Input * PLLI2SN */ |
sahilmgandhi | 18:6a4db94011d3 | 240 | /* SAI_CLK(first level) = PLLI2S_VCO Output/PLLI2SQ */ |
sahilmgandhi | 18:6a4db94011d3 | 241 | tmpreg = (RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SQ) >> 24U; |
sahilmgandhi | 18:6a4db94011d3 | 242 | saiclocksource = (vcoinput * ((RCC->PLLI2SCFGR & RCC_PLLI2SCFGR_PLLI2SN) >> 6U))/(tmpreg); |
sahilmgandhi | 18:6a4db94011d3 | 243 | |
sahilmgandhi | 18:6a4db94011d3 | 244 | /* SAI_CLK_x = SAI_CLK(first level)/PLLI2SDIVQ */ |
sahilmgandhi | 18:6a4db94011d3 | 245 | tmpreg = ((RCC->DCKCFGR & RCC_DCKCFGR_PLLI2SDIVQ) + 1U); |
sahilmgandhi | 18:6a4db94011d3 | 246 | saiclocksource = saiclocksource/(tmpreg); |
sahilmgandhi | 18:6a4db94011d3 | 247 | } |
sahilmgandhi | 18:6a4db94011d3 | 248 | else /* sConfig->ClockSource == SAI_CLKSource_Ext */ |
sahilmgandhi | 18:6a4db94011d3 | 249 | { |
sahilmgandhi | 18:6a4db94011d3 | 250 | /* Enable the External Clock selection */ |
sahilmgandhi | 18:6a4db94011d3 | 251 | __HAL_RCC_I2S_CONFIG(RCC_I2SCLKSOURCE_EXT); |
sahilmgandhi | 18:6a4db94011d3 | 252 | |
sahilmgandhi | 18:6a4db94011d3 | 253 | saiclocksource = EXTERNAL_CLOCK_VALUE; |
sahilmgandhi | 18:6a4db94011d3 | 254 | } |
sahilmgandhi | 18:6a4db94011d3 | 255 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F469xx || STM32F479xx */ |
sahilmgandhi | 18:6a4db94011d3 | 256 | /* the return result is the value of SAI clock */ |
sahilmgandhi | 18:6a4db94011d3 | 257 | return saiclocksource; |
sahilmgandhi | 18:6a4db94011d3 | 258 | } |
sahilmgandhi | 18:6a4db94011d3 | 259 | |
sahilmgandhi | 18:6a4db94011d3 | 260 | /** |
sahilmgandhi | 18:6a4db94011d3 | 261 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 262 | */ |
sahilmgandhi | 18:6a4db94011d3 | 263 | |
sahilmgandhi | 18:6a4db94011d3 | 264 | /** |
sahilmgandhi | 18:6a4db94011d3 | 265 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 266 | */ |
sahilmgandhi | 18:6a4db94011d3 | 267 | |
sahilmgandhi | 18:6a4db94011d3 | 268 | #endif /* STM32F427xx || STM32F437xx || STM32F429xx || STM32F439xx || STM32F446xx || STM32F469xx || STM32F479xx */ |
sahilmgandhi | 18:6a4db94011d3 | 269 | #endif /* HAL_SAI_MODULE_ENABLED */ |
sahilmgandhi | 18:6a4db94011d3 | 270 | /** |
sahilmgandhi | 18:6a4db94011d3 | 271 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 272 | */ |
sahilmgandhi | 18:6a4db94011d3 | 273 | |
sahilmgandhi | 18:6a4db94011d3 | 274 | /** |
sahilmgandhi | 18:6a4db94011d3 | 275 | * @} |
sahilmgandhi | 18:6a4db94011d3 | 276 | */ |
sahilmgandhi | 18:6a4db94011d3 | 277 | |
sahilmgandhi | 18:6a4db94011d3 | 278 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |