STM32F103xB HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_ll_spi.c 00004 * @author MCD Application Team 00005 * @brief SPI LL module driver. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 #if defined(USE_FULL_LL_DRIVER) 00020 00021 /* Includes ------------------------------------------------------------------*/ 00022 #include "stm32f1xx_ll_spi.h" 00023 #include "stm32f1xx_ll_bus.h" 00024 #include "stm32f1xx_ll_rcc.h" 00025 00026 #ifdef USE_FULL_ASSERT 00027 #include "stm32_assert.h" 00028 #else 00029 #define assert_param(expr) ((void)0U) 00030 #endif 00031 00032 /** @addtogroup STM32F1xx_LL_Driver 00033 * @{ 00034 */ 00035 00036 #if defined (SPI1) || defined (SPI2) || defined (SPI3) 00037 00038 /** @addtogroup SPI_LL 00039 * @{ 00040 */ 00041 00042 /* Private types -------------------------------------------------------------*/ 00043 /* Private variables ---------------------------------------------------------*/ 00044 00045 /* Private constants ---------------------------------------------------------*/ 00046 /** @defgroup SPI_LL_Private_Constants SPI Private Constants 00047 * @{ 00048 */ 00049 /* SPI registers Masks */ 00050 #define SPI_CR1_CLEAR_MASK (SPI_CR1_CPHA | SPI_CR1_CPOL | SPI_CR1_MSTR | \ 00051 SPI_CR1_BR | SPI_CR1_LSBFIRST | SPI_CR1_SSI | \ 00052 SPI_CR1_SSM | SPI_CR1_RXONLY | SPI_CR1_DFF | \ 00053 SPI_CR1_CRCNEXT | SPI_CR1_CRCEN | SPI_CR1_BIDIOE | \ 00054 SPI_CR1_BIDIMODE) 00055 /** 00056 * @} 00057 */ 00058 00059 /* Private macros ------------------------------------------------------------*/ 00060 /** @defgroup SPI_LL_Private_Macros SPI Private Macros 00061 * @{ 00062 */ 00063 #define IS_LL_SPI_TRANSFER_DIRECTION(__VALUE__) (((__VALUE__) == LL_SPI_FULL_DUPLEX) \ 00064 || ((__VALUE__) == LL_SPI_SIMPLEX_RX) \ 00065 || ((__VALUE__) == LL_SPI_HALF_DUPLEX_RX) \ 00066 || ((__VALUE__) == LL_SPI_HALF_DUPLEX_TX)) 00067 00068 #define IS_LL_SPI_MODE(__VALUE__) (((__VALUE__) == LL_SPI_MODE_MASTER) \ 00069 || ((__VALUE__) == LL_SPI_MODE_SLAVE)) 00070 00071 #define IS_LL_SPI_DATAWIDTH(__VALUE__) (((__VALUE__) == LL_SPI_DATAWIDTH_8BIT) \ 00072 || ((__VALUE__) == LL_SPI_DATAWIDTH_16BIT)) 00073 00074 #define IS_LL_SPI_POLARITY(__VALUE__) (((__VALUE__) == LL_SPI_POLARITY_LOW) \ 00075 || ((__VALUE__) == LL_SPI_POLARITY_HIGH)) 00076 00077 #define IS_LL_SPI_PHASE(__VALUE__) (((__VALUE__) == LL_SPI_PHASE_1EDGE) \ 00078 || ((__VALUE__) == LL_SPI_PHASE_2EDGE)) 00079 00080 #define IS_LL_SPI_NSS(__VALUE__) (((__VALUE__) == LL_SPI_NSS_SOFT) \ 00081 || ((__VALUE__) == LL_SPI_NSS_HARD_INPUT) \ 00082 || ((__VALUE__) == LL_SPI_NSS_HARD_OUTPUT)) 00083 00084 #define IS_LL_SPI_BAUDRATE(__VALUE__) (((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV2) \ 00085 || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV4) \ 00086 || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV8) \ 00087 || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV16) \ 00088 || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV32) \ 00089 || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV64) \ 00090 || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV128) \ 00091 || ((__VALUE__) == LL_SPI_BAUDRATEPRESCALER_DIV256)) 00092 00093 #define IS_LL_SPI_BITORDER(__VALUE__) (((__VALUE__) == LL_SPI_LSB_FIRST) \ 00094 || ((__VALUE__) == LL_SPI_MSB_FIRST)) 00095 00096 #define IS_LL_SPI_CRCCALCULATION(__VALUE__) (((__VALUE__) == LL_SPI_CRCCALCULATION_ENABLE) \ 00097 || ((__VALUE__) == LL_SPI_CRCCALCULATION_DISABLE)) 00098 00099 #define IS_LL_SPI_CRC_POLYNOMIAL(__VALUE__) ((__VALUE__) >= 0x1U) 00100 00101 /** 00102 * @} 00103 */ 00104 00105 /* Private function prototypes -----------------------------------------------*/ 00106 00107 /* Exported functions --------------------------------------------------------*/ 00108 /** @addtogroup SPI_LL_Exported_Functions 00109 * @{ 00110 */ 00111 00112 /** @addtogroup SPI_LL_EF_Init 00113 * @{ 00114 */ 00115 00116 /** 00117 * @brief De-initialize the SPI registers to their default reset values. 00118 * @param SPIx SPI Instance 00119 * @retval An ErrorStatus enumeration value: 00120 * - SUCCESS: SPI registers are de-initialized 00121 * - ERROR: SPI registers are not de-initialized 00122 */ 00123 ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx) 00124 { 00125 ErrorStatus status = ERROR; 00126 00127 /* Check the parameters */ 00128 assert_param(IS_SPI_ALL_INSTANCE(SPIx)); 00129 00130 #if defined(SPI1) 00131 if (SPIx == SPI1) 00132 { 00133 /* Force reset of SPI clock */ 00134 LL_APB2_GRP1_ForceReset(LL_APB2_GRP1_PERIPH_SPI1); 00135 00136 /* Release reset of SPI clock */ 00137 LL_APB2_GRP1_ReleaseReset(LL_APB2_GRP1_PERIPH_SPI1); 00138 00139 status = SUCCESS; 00140 } 00141 #endif /* SPI1 */ 00142 #if defined(SPI2) 00143 if (SPIx == SPI2) 00144 { 00145 /* Force reset of SPI clock */ 00146 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI2); 00147 00148 /* Release reset of SPI clock */ 00149 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI2); 00150 00151 status = SUCCESS; 00152 } 00153 #endif /* SPI2 */ 00154 #if defined(SPI3) 00155 if (SPIx == SPI3) 00156 { 00157 /* Force reset of SPI clock */ 00158 LL_APB1_GRP1_ForceReset(LL_APB1_GRP1_PERIPH_SPI3); 00159 00160 /* Release reset of SPI clock */ 00161 LL_APB1_GRP1_ReleaseReset(LL_APB1_GRP1_PERIPH_SPI3); 00162 00163 status = SUCCESS; 00164 } 00165 #endif /* SPI3 */ 00166 00167 return status; 00168 } 00169 00170 /** 00171 * @brief Initialize the SPI registers according to the specified parameters in SPI_InitStruct. 00172 * @note As some bits in SPI configuration registers can only be written when the SPI is disabled (SPI_CR1_SPE bit =0), 00173 * SPI peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. 00174 * @param SPIx SPI Instance 00175 * @param SPI_InitStruct pointer to a @ref LL_SPI_InitTypeDef structure 00176 * @retval An ErrorStatus enumeration value. (Return always SUCCESS) 00177 */ 00178 ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct) 00179 { 00180 ErrorStatus status = ERROR; 00181 00182 /* Check the SPI Instance SPIx*/ 00183 assert_param(IS_SPI_ALL_INSTANCE(SPIx)); 00184 00185 /* Check the SPI parameters from SPI_InitStruct*/ 00186 assert_param(IS_LL_SPI_TRANSFER_DIRECTION(SPI_InitStruct->TransferDirection)); 00187 assert_param(IS_LL_SPI_MODE(SPI_InitStruct->Mode)); 00188 assert_param(IS_LL_SPI_DATAWIDTH(SPI_InitStruct->DataWidth)); 00189 assert_param(IS_LL_SPI_POLARITY(SPI_InitStruct->ClockPolarity)); 00190 assert_param(IS_LL_SPI_PHASE(SPI_InitStruct->ClockPhase)); 00191 assert_param(IS_LL_SPI_NSS(SPI_InitStruct->NSS)); 00192 assert_param(IS_LL_SPI_BAUDRATE(SPI_InitStruct->BaudRate)); 00193 assert_param(IS_LL_SPI_BITORDER(SPI_InitStruct->BitOrder)); 00194 assert_param(IS_LL_SPI_CRCCALCULATION(SPI_InitStruct->CRCCalculation)); 00195 00196 if (LL_SPI_IsEnabled(SPIx) == 0x00000000U) 00197 { 00198 /*---------------------------- SPIx CR1 Configuration ------------------------ 00199 * Configure SPIx CR1 with parameters: 00200 * - TransferDirection: SPI_CR1_BIDIMODE, SPI_CR1_BIDIOE and SPI_CR1_RXONLY bits 00201 * - Master/Slave Mode: SPI_CR1_MSTR bit 00202 * - DataWidth: SPI_CR1_DFF bit 00203 * - ClockPolarity: SPI_CR1_CPOL bit 00204 * - ClockPhase: SPI_CR1_CPHA bit 00205 * - NSS management: SPI_CR1_SSM bit 00206 * - BaudRate prescaler: SPI_CR1_BR[2:0] bits 00207 * - BitOrder: SPI_CR1_LSBFIRST bit 00208 * - CRCCalculation: SPI_CR1_CRCEN bit 00209 */ 00210 MODIFY_REG(SPIx->CR1, 00211 SPI_CR1_CLEAR_MASK, 00212 SPI_InitStruct->TransferDirection | SPI_InitStruct->Mode | SPI_InitStruct->DataWidth | 00213 SPI_InitStruct->ClockPolarity | SPI_InitStruct->ClockPhase | 00214 SPI_InitStruct->NSS | SPI_InitStruct->BaudRate | 00215 SPI_InitStruct->BitOrder | SPI_InitStruct->CRCCalculation); 00216 00217 /*---------------------------- SPIx CR2 Configuration ------------------------ 00218 * Configure SPIx CR2 with parameters: 00219 * - NSS management: SSOE bit 00220 */ 00221 MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, (SPI_InitStruct->NSS >> 16U)); 00222 00223 /*---------------------------- SPIx CRCPR Configuration ---------------------- 00224 * Configure SPIx CRCPR with parameters: 00225 * - CRCPoly: CRCPOLY[15:0] bits 00226 */ 00227 if (SPI_InitStruct->CRCCalculation == LL_SPI_CRCCALCULATION_ENABLE) 00228 { 00229 assert_param(IS_LL_SPI_CRC_POLYNOMIAL(SPI_InitStruct->CRCPoly)); 00230 LL_SPI_SetCRCPolynomial(SPIx, SPI_InitStruct->CRCPoly); 00231 } 00232 status = SUCCESS; 00233 } 00234 00235 #if defined (SPI_I2S_SUPPORT) 00236 /* Activate the SPI mode (Reset I2SMOD bit in I2SCFGR register) */ 00237 CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD); 00238 #endif /* SPI_I2S_SUPPORT */ 00239 return status; 00240 } 00241 00242 /** 00243 * @brief Set each @ref LL_SPI_InitTypeDef field to default value. 00244 * @param SPI_InitStruct pointer to a @ref LL_SPI_InitTypeDef structure 00245 * whose fields will be set to default values. 00246 * @retval None 00247 */ 00248 void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct) 00249 { 00250 /* Set SPI_InitStruct fields to default values */ 00251 SPI_InitStruct->TransferDirection = LL_SPI_FULL_DUPLEX; 00252 SPI_InitStruct->Mode = LL_SPI_MODE_SLAVE; 00253 SPI_InitStruct->DataWidth = LL_SPI_DATAWIDTH_8BIT; 00254 SPI_InitStruct->ClockPolarity = LL_SPI_POLARITY_LOW; 00255 SPI_InitStruct->ClockPhase = LL_SPI_PHASE_1EDGE; 00256 SPI_InitStruct->NSS = LL_SPI_NSS_HARD_INPUT; 00257 SPI_InitStruct->BaudRate = LL_SPI_BAUDRATEPRESCALER_DIV2; 00258 SPI_InitStruct->BitOrder = LL_SPI_MSB_FIRST; 00259 SPI_InitStruct->CRCCalculation = LL_SPI_CRCCALCULATION_DISABLE; 00260 SPI_InitStruct->CRCPoly = 7U; 00261 } 00262 00263 /** 00264 * @} 00265 */ 00266 00267 /** 00268 * @} 00269 */ 00270 00271 /** 00272 * @} 00273 */ 00274 00275 #if defined(SPI_I2S_SUPPORT) 00276 /** @addtogroup I2S_LL 00277 * @{ 00278 */ 00279 00280 /* Private types -------------------------------------------------------------*/ 00281 /* Private variables ---------------------------------------------------------*/ 00282 /* Private constants ---------------------------------------------------------*/ 00283 /** @defgroup I2S_LL_Private_Constants I2S Private Constants 00284 * @{ 00285 */ 00286 /* I2S registers Masks */ 00287 #define I2S_I2SCFGR_CLEAR_MASK (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN | \ 00288 SPI_I2SCFGR_CKPOL | SPI_I2SCFGR_I2SSTD | \ 00289 SPI_I2SCFGR_I2SCFG | SPI_I2SCFGR_I2SMOD ) 00290 00291 #define I2S_I2SPR_CLEAR_MASK 0x0002U 00292 /** 00293 * @} 00294 */ 00295 /* Private macros ------------------------------------------------------------*/ 00296 /** @defgroup I2S_LL_Private_Macros I2S Private Macros 00297 * @{ 00298 */ 00299 00300 #define IS_LL_I2S_DATAFORMAT(__VALUE__) (((__VALUE__) == LL_I2S_DATAFORMAT_16B) \ 00301 || ((__VALUE__) == LL_I2S_DATAFORMAT_16B_EXTENDED) \ 00302 || ((__VALUE__) == LL_I2S_DATAFORMAT_24B) \ 00303 || ((__VALUE__) == LL_I2S_DATAFORMAT_32B)) 00304 00305 #define IS_LL_I2S_CPOL(__VALUE__) (((__VALUE__) == LL_I2S_POLARITY_LOW) \ 00306 || ((__VALUE__) == LL_I2S_POLARITY_HIGH)) 00307 00308 #define IS_LL_I2S_STANDARD(__VALUE__) (((__VALUE__) == LL_I2S_STANDARD_PHILIPS) \ 00309 || ((__VALUE__) == LL_I2S_STANDARD_MSB) \ 00310 || ((__VALUE__) == LL_I2S_STANDARD_LSB) \ 00311 || ((__VALUE__) == LL_I2S_STANDARD_PCM_SHORT) \ 00312 || ((__VALUE__) == LL_I2S_STANDARD_PCM_LONG)) 00313 00314 #define IS_LL_I2S_MODE(__VALUE__) (((__VALUE__) == LL_I2S_MODE_SLAVE_TX) \ 00315 || ((__VALUE__) == LL_I2S_MODE_SLAVE_RX) \ 00316 || ((__VALUE__) == LL_I2S_MODE_MASTER_TX) \ 00317 || ((__VALUE__) == LL_I2S_MODE_MASTER_RX)) 00318 00319 #define IS_LL_I2S_MCLK_OUTPUT(__VALUE__) (((__VALUE__) == LL_I2S_MCLK_OUTPUT_ENABLE) \ 00320 || ((__VALUE__) == LL_I2S_MCLK_OUTPUT_DISABLE)) 00321 00322 #define IS_LL_I2S_AUDIO_FREQ(__VALUE__) ((((__VALUE__) >= LL_I2S_AUDIOFREQ_8K) \ 00323 && ((__VALUE__) <= LL_I2S_AUDIOFREQ_192K)) \ 00324 || ((__VALUE__) == LL_I2S_AUDIOFREQ_DEFAULT)) 00325 00326 #define IS_LL_I2S_PRESCALER_LINEAR(__VALUE__) ((__VALUE__) >= 0x2U) 00327 00328 #define IS_LL_I2S_PRESCALER_PARITY(__VALUE__) (((__VALUE__) == LL_I2S_PRESCALER_PARITY_EVEN) \ 00329 || ((__VALUE__) == LL_I2S_PRESCALER_PARITY_ODD)) 00330 /** 00331 * @} 00332 */ 00333 00334 /* Private function prototypes -----------------------------------------------*/ 00335 00336 /* Exported functions --------------------------------------------------------*/ 00337 /** @addtogroup I2S_LL_Exported_Functions 00338 * @{ 00339 */ 00340 00341 /** @addtogroup I2S_LL_EF_Init 00342 * @{ 00343 */ 00344 00345 /** 00346 * @brief De-initialize the SPI/I2S registers to their default reset values. 00347 * @param SPIx SPI Instance 00348 * @retval An ErrorStatus enumeration value: 00349 * - SUCCESS: SPI registers are de-initialized 00350 * - ERROR: SPI registers are not de-initialized 00351 */ 00352 ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx) 00353 { 00354 return LL_SPI_DeInit(SPIx); 00355 } 00356 00357 /** 00358 * @brief Initializes the SPI/I2S registers according to the specified parameters in I2S_InitStruct. 00359 * @note As some bits in SPI configuration registers can only be written when the SPI is disabled (SPI_CR1_SPE bit =0), 00360 * SPI peripheral should be in disabled state prior calling this function. Otherwise, ERROR result will be returned. 00361 * @param SPIx SPI Instance 00362 * @param I2S_InitStruct pointer to a @ref LL_I2S_InitTypeDef structure 00363 * @retval An ErrorStatus enumeration value: 00364 * - SUCCESS: SPI registers are Initialized 00365 * - ERROR: SPI registers are not Initialized 00366 */ 00367 ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct) 00368 { 00369 uint32_t i2sdiv = 2U; 00370 uint32_t i2sodd = 0U; 00371 uint32_t packetlength = 1U; 00372 uint32_t tmp; 00373 LL_RCC_ClocksTypeDef rcc_clocks; 00374 uint32_t sourceclock; 00375 ErrorStatus status = ERROR; 00376 00377 /* Check the I2S parameters */ 00378 assert_param(IS_I2S_ALL_INSTANCE(SPIx)); 00379 assert_param(IS_LL_I2S_MODE(I2S_InitStruct->Mode)); 00380 assert_param(IS_LL_I2S_STANDARD(I2S_InitStruct->Standard)); 00381 assert_param(IS_LL_I2S_DATAFORMAT(I2S_InitStruct->DataFormat)); 00382 assert_param(IS_LL_I2S_MCLK_OUTPUT(I2S_InitStruct->MCLKOutput)); 00383 assert_param(IS_LL_I2S_AUDIO_FREQ(I2S_InitStruct->AudioFreq)); 00384 assert_param(IS_LL_I2S_CPOL(I2S_InitStruct->ClockPolarity)); 00385 00386 if (LL_I2S_IsEnabled(SPIx) == 0x00000000U) 00387 { 00388 /*---------------------------- SPIx I2SCFGR Configuration -------------------- 00389 * Configure SPIx I2SCFGR with parameters: 00390 * - Mode: SPI_I2SCFGR_I2SCFG[1:0] bit 00391 * - Standard: SPI_I2SCFGR_I2SSTD[1:0] and SPI_I2SCFGR_PCMSYNC bits 00392 * - DataFormat: SPI_I2SCFGR_CHLEN and SPI_I2SCFGR_DATLEN bits 00393 * - ClockPolarity: SPI_I2SCFGR_CKPOL bit 00394 */ 00395 00396 /* Write to SPIx I2SCFGR */ 00397 MODIFY_REG(SPIx->I2SCFGR, 00398 I2S_I2SCFGR_CLEAR_MASK, 00399 I2S_InitStruct->Mode | I2S_InitStruct->Standard | 00400 I2S_InitStruct->DataFormat | I2S_InitStruct->ClockPolarity | 00401 SPI_I2SCFGR_I2SMOD); 00402 00403 /*---------------------------- SPIx I2SPR Configuration ---------------------- 00404 * Configure SPIx I2SPR with parameters: 00405 * - MCLKOutput: SPI_I2SPR_MCKOE bit 00406 * - AudioFreq: SPI_I2SPR_I2SDIV[7:0] and SPI_I2SPR_ODD bits 00407 */ 00408 00409 /* If the requested audio frequency is not the default, compute the prescaler (i2sodd, i2sdiv) 00410 * else, default values are used: i2sodd = 0U, i2sdiv = 2U. 00411 */ 00412 if (I2S_InitStruct->AudioFreq != LL_I2S_AUDIOFREQ_DEFAULT) 00413 { 00414 /* Check the frame length (For the Prescaler computing) 00415 * Default value: LL_I2S_DATAFORMAT_16B (packetlength = 1U). 00416 */ 00417 if (I2S_InitStruct->DataFormat != LL_I2S_DATAFORMAT_16B) 00418 { 00419 /* Packet length is 32 bits */ 00420 packetlength = 2U; 00421 } 00422 00423 /* I2S Clock source is System clock: Get System Clock frequency */ 00424 LL_RCC_GetSystemClocksFreq(&rcc_clocks); 00425 00426 /* Get the source clock value: based on System Clock value */ 00427 sourceclock = rcc_clocks.SYSCLK_Frequency; 00428 00429 /* Compute the Real divider depending on the MCLK output state with a floating point */ 00430 if (I2S_InitStruct->MCLKOutput == LL_I2S_MCLK_OUTPUT_ENABLE) 00431 { 00432 /* MCLK output is enabled */ 00433 tmp = (((((sourceclock / 256U) * 10U) / I2S_InitStruct->AudioFreq)) + 5U); 00434 } 00435 else 00436 { 00437 /* MCLK output is disabled */ 00438 tmp = (((((sourceclock / (32U * packetlength)) * 10U) / I2S_InitStruct->AudioFreq)) + 5U); 00439 } 00440 00441 /* Remove the floating point */ 00442 tmp = tmp / 10U; 00443 00444 /* Check the parity of the divider */ 00445 i2sodd = (tmp & (uint16_t)0x0001U); 00446 00447 /* Compute the i2sdiv prescaler */ 00448 i2sdiv = ((tmp - i2sodd) / 2U); 00449 00450 /* Get the Mask for the Odd bit (SPI_I2SPR[8]) register */ 00451 i2sodd = (i2sodd << 8U); 00452 } 00453 00454 /* Test if the divider is 1 or 0 or greater than 0xFF */ 00455 if ((i2sdiv < 2U) || (i2sdiv > 0xFFU)) 00456 { 00457 /* Set the default values */ 00458 i2sdiv = 2U; 00459 i2sodd = 0U; 00460 } 00461 00462 /* Write to SPIx I2SPR register the computed value */ 00463 WRITE_REG(SPIx->I2SPR, i2sdiv | i2sodd | I2S_InitStruct->MCLKOutput); 00464 00465 status = SUCCESS; 00466 } 00467 return status; 00468 } 00469 00470 /** 00471 * @brief Set each @ref LL_I2S_InitTypeDef field to default value. 00472 * @param I2S_InitStruct pointer to a @ref LL_I2S_InitTypeDef structure 00473 * whose fields will be set to default values. 00474 * @retval None 00475 */ 00476 void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct) 00477 { 00478 /*--------------- Reset I2S init structure parameters values -----------------*/ 00479 I2S_InitStruct->Mode = LL_I2S_MODE_SLAVE_TX; 00480 I2S_InitStruct->Standard = LL_I2S_STANDARD_PHILIPS; 00481 I2S_InitStruct->DataFormat = LL_I2S_DATAFORMAT_16B; 00482 I2S_InitStruct->MCLKOutput = LL_I2S_MCLK_OUTPUT_DISABLE; 00483 I2S_InitStruct->AudioFreq = LL_I2S_AUDIOFREQ_DEFAULT; 00484 I2S_InitStruct->ClockPolarity = LL_I2S_POLARITY_LOW; 00485 } 00486 00487 /** 00488 * @brief Set linear and parity prescaler. 00489 * @note To calculate value of PrescalerLinear(I2SDIV[7:0] bits) and PrescalerParity(ODD bit)\n 00490 * Check Audio frequency table and formulas inside Reference Manual (SPI/I2S). 00491 * @param SPIx SPI Instance 00492 * @param PrescalerLinear value Min_Data=0x02 and Max_Data=0xFF. 00493 * @param PrescalerParity This parameter can be one of the following values: 00494 * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN 00495 * @arg @ref LL_I2S_PRESCALER_PARITY_ODD 00496 * @retval None 00497 */ 00498 void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity) 00499 { 00500 /* Check the I2S parameters */ 00501 assert_param(IS_I2S_ALL_INSTANCE(SPIx)); 00502 assert_param(IS_LL_I2S_PRESCALER_LINEAR(PrescalerLinear)); 00503 assert_param(IS_LL_I2S_PRESCALER_PARITY(PrescalerParity)); 00504 00505 /* Write to SPIx I2SPR */ 00506 MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_I2SDIV | SPI_I2SPR_ODD, PrescalerLinear | (PrescalerParity << 8U)); 00507 } 00508 00509 /** 00510 * @} 00511 */ 00512 00513 /** 00514 * @} 00515 */ 00516 00517 /** 00518 * @} 00519 */ 00520 #endif /* SPI_I2S_SUPPORT */ 00521 00522 #endif /* defined (SPI1) || defined (SPI2) || defined (SPI3) */ 00523 00524 /** 00525 * @} 00526 */ 00527 00528 #endif /* USE_FULL_LL_DRIVER */ 00529 00530 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/