mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Thu Jul 02 16:30:08 2015 +0100
Revision:
581:39197bcd20f2
Parent:
532:fe11edbda85c
Child:
613:bc40b8d2aec4
Synchronized with git revision ae2d3cdffe70184eb8736d94f76c45c93f4b7724

Full URL: https://github.com/mbedmicro/mbed/commit/ae2d3cdffe70184eb8736d94f76c45c93f4b7724/

Make it possible to build the core mbed library with yotta

Who changed what in which revision?

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