STM32F103xB HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_ll_spi.h 00004 * @author MCD Application Team 00005 * @brief Header file of SPI LL module. 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 00020 /* Define to prevent recursive inclusion -------------------------------------*/ 00021 #ifndef STM32F1xx_LL_SPI_H 00022 #define STM32F1xx_LL_SPI_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "stm32f1xx.h" 00030 00031 /** @addtogroup STM32F1xx_LL_Driver 00032 * @{ 00033 */ 00034 00035 #if defined (SPI1) || defined (SPI2) || defined (SPI3) 00036 00037 /** @defgroup SPI_LL SPI 00038 * @{ 00039 */ 00040 00041 /* Private types -------------------------------------------------------------*/ 00042 /* Private variables ---------------------------------------------------------*/ 00043 /* Private macros ------------------------------------------------------------*/ 00044 00045 /* Exported types ------------------------------------------------------------*/ 00046 #if defined(USE_FULL_LL_DRIVER) 00047 /** @defgroup SPI_LL_ES_INIT SPI Exported Init structure 00048 * @{ 00049 */ 00050 00051 /** 00052 * @brief SPI Init structures definition 00053 */ 00054 typedef struct 00055 { 00056 uint32_t TransferDirection; /*!< Specifies the SPI unidirectional or bidirectional data mode. 00057 This parameter can be a value of @ref SPI_LL_EC_TRANSFER_MODE. 00058 00059 This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferDirection().*/ 00060 00061 uint32_t Mode; /*!< Specifies the SPI mode (Master/Slave). 00062 This parameter can be a value of @ref SPI_LL_EC_MODE. 00063 00064 This feature can be modified afterwards using unitary function @ref LL_SPI_SetMode().*/ 00065 00066 uint32_t DataWidth; /*!< Specifies the SPI data width. 00067 This parameter can be a value of @ref SPI_LL_EC_DATAWIDTH. 00068 00069 This feature can be modified afterwards using unitary function @ref LL_SPI_SetDataWidth().*/ 00070 00071 uint32_t ClockPolarity; /*!< Specifies the serial clock steady state. 00072 This parameter can be a value of @ref SPI_LL_EC_POLARITY. 00073 00074 This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPolarity().*/ 00075 00076 uint32_t ClockPhase; /*!< Specifies the clock active edge for the bit capture. 00077 This parameter can be a value of @ref SPI_LL_EC_PHASE. 00078 00079 This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPhase().*/ 00080 00081 uint32_t NSS; /*!< Specifies whether the NSS signal is managed by hardware (NSS pin) or by software using the SSI bit. 00082 This parameter can be a value of @ref SPI_LL_EC_NSS_MODE. 00083 00084 This feature can be modified afterwards using unitary function @ref LL_SPI_SetNSSMode().*/ 00085 00086 uint32_t BaudRate; /*!< Specifies the BaudRate prescaler value which will be used to configure the transmit and receive SCK clock. 00087 This parameter can be a value of @ref SPI_LL_EC_BAUDRATEPRESCALER. 00088 @note The communication clock is derived from the master clock. The slave clock does not need to be set. 00089 00090 This feature can be modified afterwards using unitary function @ref LL_SPI_SetBaudRatePrescaler().*/ 00091 00092 uint32_t BitOrder; /*!< Specifies whether data transfers start from MSB or LSB bit. 00093 This parameter can be a value of @ref SPI_LL_EC_BIT_ORDER. 00094 00095 This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferBitOrder().*/ 00096 00097 uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not. 00098 This parameter can be a value of @ref SPI_LL_EC_CRC_CALCULATION. 00099 00100 This feature can be modified afterwards using unitary functions @ref LL_SPI_EnableCRC() and @ref LL_SPI_DisableCRC().*/ 00101 00102 uint32_t CRCPoly; /*!< Specifies the polynomial used for the CRC calculation. 00103 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF. 00104 00105 This feature can be modified afterwards using unitary function @ref LL_SPI_SetCRCPolynomial().*/ 00106 00107 } LL_SPI_InitTypeDef; 00108 00109 /** 00110 * @} 00111 */ 00112 #endif /* USE_FULL_LL_DRIVER */ 00113 00114 /* Exported constants --------------------------------------------------------*/ 00115 /** @defgroup SPI_LL_Exported_Constants SPI Exported Constants 00116 * @{ 00117 */ 00118 00119 /** @defgroup SPI_LL_EC_GET_FLAG Get Flags Defines 00120 * @brief Flags defines which can be used with LL_SPI_ReadReg function 00121 * @{ 00122 */ 00123 #define LL_SPI_SR_RXNE SPI_SR_RXNE /*!< Rx buffer not empty flag */ 00124 #define LL_SPI_SR_TXE SPI_SR_TXE /*!< Tx buffer empty flag */ 00125 #define LL_SPI_SR_BSY SPI_SR_BSY /*!< Busy flag */ 00126 #define LL_SPI_SR_CRCERR SPI_SR_CRCERR /*!< CRC error flag */ 00127 #define LL_SPI_SR_MODF SPI_SR_MODF /*!< Mode fault flag */ 00128 #define LL_SPI_SR_OVR SPI_SR_OVR /*!< Overrun flag */ 00129 #define LL_SPI_SR_FRE SPI_SR_FRE /*!< TI mode frame format error flag */ 00130 /** 00131 * @} 00132 */ 00133 00134 /** @defgroup SPI_LL_EC_IT IT Defines 00135 * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions 00136 * @{ 00137 */ 00138 #define LL_SPI_CR2_RXNEIE SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */ 00139 #define LL_SPI_CR2_TXEIE SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */ 00140 #define LL_SPI_CR2_ERRIE SPI_CR2_ERRIE /*!< Error interrupt enable */ 00141 /** 00142 * @} 00143 */ 00144 00145 /** @defgroup SPI_LL_EC_MODE Operation Mode 00146 * @{ 00147 */ 00148 #define LL_SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) /*!< Master configuration */ 00149 #define LL_SPI_MODE_SLAVE 0x00000000U /*!< Slave configuration */ 00150 /** 00151 * @} 00152 */ 00153 00154 00155 /** @defgroup SPI_LL_EC_PHASE Clock Phase 00156 * @{ 00157 */ 00158 #define LL_SPI_PHASE_1EDGE 0x00000000U /*!< First clock transition is the first data capture edge */ 00159 #define LL_SPI_PHASE_2EDGE (SPI_CR1_CPHA) /*!< Second clock transition is the first data capture edge */ 00160 /** 00161 * @} 00162 */ 00163 00164 /** @defgroup SPI_LL_EC_POLARITY Clock Polarity 00165 * @{ 00166 */ 00167 #define LL_SPI_POLARITY_LOW 0x00000000U /*!< Clock to 0 when idle */ 00168 #define LL_SPI_POLARITY_HIGH (SPI_CR1_CPOL) /*!< Clock to 1 when idle */ 00169 /** 00170 * @} 00171 */ 00172 00173 /** @defgroup SPI_LL_EC_BAUDRATEPRESCALER Baud Rate Prescaler 00174 * @{ 00175 */ 00176 #define LL_SPI_BAUDRATEPRESCALER_DIV2 0x00000000U /*!< BaudRate control equal to fPCLK/2 */ 00177 #define LL_SPI_BAUDRATEPRESCALER_DIV4 (SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/4 */ 00178 #define LL_SPI_BAUDRATEPRESCALER_DIV8 (SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/8 */ 00179 #define LL_SPI_BAUDRATEPRESCALER_DIV16 (SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/16 */ 00180 #define LL_SPI_BAUDRATEPRESCALER_DIV32 (SPI_CR1_BR_2) /*!< BaudRate control equal to fPCLK/32 */ 00181 #define LL_SPI_BAUDRATEPRESCALER_DIV64 (SPI_CR1_BR_2 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/64 */ 00182 #define LL_SPI_BAUDRATEPRESCALER_DIV128 (SPI_CR1_BR_2 | SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/128 */ 00183 #define LL_SPI_BAUDRATEPRESCALER_DIV256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/256 */ 00184 /** 00185 * @} 00186 */ 00187 00188 /** @defgroup SPI_LL_EC_BIT_ORDER Transmission Bit Order 00189 * @{ 00190 */ 00191 #define LL_SPI_LSB_FIRST (SPI_CR1_LSBFIRST) /*!< Data is transmitted/received with the LSB first */ 00192 #define LL_SPI_MSB_FIRST 0x00000000U /*!< Data is transmitted/received with the MSB first */ 00193 /** 00194 * @} 00195 */ 00196 00197 /** @defgroup SPI_LL_EC_TRANSFER_MODE Transfer Mode 00198 * @{ 00199 */ 00200 #define LL_SPI_FULL_DUPLEX 0x00000000U /*!< Full-Duplex mode. Rx and Tx transfer on 2 lines */ 00201 #define LL_SPI_SIMPLEX_RX (SPI_CR1_RXONLY) /*!< Simplex Rx mode. Rx transfer only on 1 line */ 00202 #define LL_SPI_HALF_DUPLEX_RX (SPI_CR1_BIDIMODE) /*!< Half-Duplex Rx mode. Rx transfer on 1 line */ 00203 #define LL_SPI_HALF_DUPLEX_TX (SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE) /*!< Half-Duplex Tx mode. Tx transfer on 1 line */ 00204 /** 00205 * @} 00206 */ 00207 00208 /** @defgroup SPI_LL_EC_NSS_MODE Slave Select Pin Mode 00209 * @{ 00210 */ 00211 #define LL_SPI_NSS_SOFT (SPI_CR1_SSM) /*!< NSS managed internally. NSS pin not used and free */ 00212 #define LL_SPI_NSS_HARD_INPUT 0x00000000U /*!< NSS pin used in Input. Only used in Master mode */ 00213 #define LL_SPI_NSS_HARD_OUTPUT (((uint32_t)SPI_CR2_SSOE << 16U)) /*!< NSS pin used in Output. Only used in Slave mode as chip select */ 00214 /** 00215 * @} 00216 */ 00217 00218 /** @defgroup SPI_LL_EC_DATAWIDTH Datawidth 00219 * @{ 00220 */ 00221 #define LL_SPI_DATAWIDTH_8BIT 0x00000000U /*!< Data length for SPI transfer: 8 bits */ 00222 #define LL_SPI_DATAWIDTH_16BIT (SPI_CR1_DFF) /*!< Data length for SPI transfer: 16 bits */ 00223 /** 00224 * @} 00225 */ 00226 #if defined(USE_FULL_LL_DRIVER) 00227 00228 /** @defgroup SPI_LL_EC_CRC_CALCULATION CRC Calculation 00229 * @{ 00230 */ 00231 #define LL_SPI_CRCCALCULATION_DISABLE 0x00000000U /*!< CRC calculation disabled */ 00232 #define LL_SPI_CRCCALCULATION_ENABLE (SPI_CR1_CRCEN) /*!< CRC calculation enabled */ 00233 /** 00234 * @} 00235 */ 00236 #endif /* USE_FULL_LL_DRIVER */ 00237 00238 /** 00239 * @} 00240 */ 00241 00242 /* Exported macro ------------------------------------------------------------*/ 00243 /** @defgroup SPI_LL_Exported_Macros SPI Exported Macros 00244 * @{ 00245 */ 00246 00247 /** @defgroup SPI_LL_EM_WRITE_READ Common Write and read registers Macros 00248 * @{ 00249 */ 00250 00251 /** 00252 * @brief Write a value in SPI register 00253 * @param __INSTANCE__ SPI Instance 00254 * @param __REG__ Register to be written 00255 * @param __VALUE__ Value to be written in the register 00256 * @retval None 00257 */ 00258 #define LL_SPI_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__)) 00259 00260 /** 00261 * @brief Read a value in SPI register 00262 * @param __INSTANCE__ SPI Instance 00263 * @param __REG__ Register to be read 00264 * @retval Register value 00265 */ 00266 #define LL_SPI_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__) 00267 /** 00268 * @} 00269 */ 00270 00271 /** 00272 * @} 00273 */ 00274 00275 /* Exported functions --------------------------------------------------------*/ 00276 /** @defgroup SPI_LL_Exported_Functions SPI Exported Functions 00277 * @{ 00278 */ 00279 00280 /** @defgroup SPI_LL_EF_Configuration Configuration 00281 * @{ 00282 */ 00283 00284 /** 00285 * @brief Enable SPI peripheral 00286 * @rmtoll CR1 SPE LL_SPI_Enable 00287 * @param SPIx SPI Instance 00288 * @retval None 00289 */ 00290 __STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx) 00291 { 00292 SET_BIT(SPIx->CR1, SPI_CR1_SPE); 00293 } 00294 00295 /** 00296 * @brief Disable SPI peripheral 00297 * @note When disabling the SPI, follow the procedure described in the Reference Manual. 00298 * @rmtoll CR1 SPE LL_SPI_Disable 00299 * @param SPIx SPI Instance 00300 * @retval None 00301 */ 00302 __STATIC_INLINE void LL_SPI_Disable(SPI_TypeDef *SPIx) 00303 { 00304 CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE); 00305 } 00306 00307 /** 00308 * @brief Check if SPI peripheral is enabled 00309 * @rmtoll CR1 SPE LL_SPI_IsEnabled 00310 * @param SPIx SPI Instance 00311 * @retval State of bit (1 or 0). 00312 */ 00313 __STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx) 00314 { 00315 return ((READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE)) ? 1UL : 0UL); 00316 } 00317 00318 /** 00319 * @brief Set SPI operation mode to Master or Slave 00320 * @note This bit should not be changed when communication is ongoing. 00321 * @rmtoll CR1 MSTR LL_SPI_SetMode\n 00322 * CR1 SSI LL_SPI_SetMode 00323 * @param SPIx SPI Instance 00324 * @param Mode This parameter can be one of the following values: 00325 * @arg @ref LL_SPI_MODE_MASTER 00326 * @arg @ref LL_SPI_MODE_SLAVE 00327 * @retval None 00328 */ 00329 __STATIC_INLINE void LL_SPI_SetMode(SPI_TypeDef *SPIx, uint32_t Mode) 00330 { 00331 MODIFY_REG(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI, Mode); 00332 } 00333 00334 /** 00335 * @brief Get SPI operation mode (Master or Slave) 00336 * @rmtoll CR1 MSTR LL_SPI_GetMode\n 00337 * CR1 SSI LL_SPI_GetMode 00338 * @param SPIx SPI Instance 00339 * @retval Returned value can be one of the following values: 00340 * @arg @ref LL_SPI_MODE_MASTER 00341 * @arg @ref LL_SPI_MODE_SLAVE 00342 */ 00343 __STATIC_INLINE uint32_t LL_SPI_GetMode(SPI_TypeDef *SPIx) 00344 { 00345 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI)); 00346 } 00347 00348 00349 /** 00350 * @brief Set clock phase 00351 * @note This bit should not be changed when communication is ongoing. 00352 * This bit is not used in SPI TI mode. 00353 * @rmtoll CR1 CPHA LL_SPI_SetClockPhase 00354 * @param SPIx SPI Instance 00355 * @param ClockPhase This parameter can be one of the following values: 00356 * @arg @ref LL_SPI_PHASE_1EDGE 00357 * @arg @ref LL_SPI_PHASE_2EDGE 00358 * @retval None 00359 */ 00360 __STATIC_INLINE void LL_SPI_SetClockPhase(SPI_TypeDef *SPIx, uint32_t ClockPhase) 00361 { 00362 MODIFY_REG(SPIx->CR1, SPI_CR1_CPHA, ClockPhase); 00363 } 00364 00365 /** 00366 * @brief Get clock phase 00367 * @rmtoll CR1 CPHA LL_SPI_GetClockPhase 00368 * @param SPIx SPI Instance 00369 * @retval Returned value can be one of the following values: 00370 * @arg @ref LL_SPI_PHASE_1EDGE 00371 * @arg @ref LL_SPI_PHASE_2EDGE 00372 */ 00373 __STATIC_INLINE uint32_t LL_SPI_GetClockPhase(SPI_TypeDef *SPIx) 00374 { 00375 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPHA)); 00376 } 00377 00378 /** 00379 * @brief Set clock polarity 00380 * @note This bit should not be changed when communication is ongoing. 00381 * This bit is not used in SPI TI mode. 00382 * @rmtoll CR1 CPOL LL_SPI_SetClockPolarity 00383 * @param SPIx SPI Instance 00384 * @param ClockPolarity This parameter can be one of the following values: 00385 * @arg @ref LL_SPI_POLARITY_LOW 00386 * @arg @ref LL_SPI_POLARITY_HIGH 00387 * @retval None 00388 */ 00389 __STATIC_INLINE void LL_SPI_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity) 00390 { 00391 MODIFY_REG(SPIx->CR1, SPI_CR1_CPOL, ClockPolarity); 00392 } 00393 00394 /** 00395 * @brief Get clock polarity 00396 * @rmtoll CR1 CPOL LL_SPI_GetClockPolarity 00397 * @param SPIx SPI Instance 00398 * @retval Returned value can be one of the following values: 00399 * @arg @ref LL_SPI_POLARITY_LOW 00400 * @arg @ref LL_SPI_POLARITY_HIGH 00401 */ 00402 __STATIC_INLINE uint32_t LL_SPI_GetClockPolarity(SPI_TypeDef *SPIx) 00403 { 00404 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPOL)); 00405 } 00406 00407 /** 00408 * @brief Set baud rate prescaler 00409 * @note These bits should not be changed when communication is ongoing. SPI BaudRate = fPCLK/Prescaler. 00410 * @rmtoll CR1 BR LL_SPI_SetBaudRatePrescaler 00411 * @param SPIx SPI Instance 00412 * @param BaudRate This parameter can be one of the following values: 00413 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2 00414 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4 00415 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8 00416 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16 00417 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32 00418 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64 00419 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128 00420 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256 00421 * @retval None 00422 */ 00423 __STATIC_INLINE void LL_SPI_SetBaudRatePrescaler(SPI_TypeDef *SPIx, uint32_t BaudRate) 00424 { 00425 MODIFY_REG(SPIx->CR1, SPI_CR1_BR, BaudRate); 00426 } 00427 00428 /** 00429 * @brief Get baud rate prescaler 00430 * @rmtoll CR1 BR LL_SPI_GetBaudRatePrescaler 00431 * @param SPIx SPI Instance 00432 * @retval Returned value can be one of the following values: 00433 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2 00434 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4 00435 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8 00436 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16 00437 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32 00438 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64 00439 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128 00440 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256 00441 */ 00442 __STATIC_INLINE uint32_t LL_SPI_GetBaudRatePrescaler(SPI_TypeDef *SPIx) 00443 { 00444 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_BR)); 00445 } 00446 00447 /** 00448 * @brief Set transfer bit order 00449 * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode. 00450 * @rmtoll CR1 LSBFIRST LL_SPI_SetTransferBitOrder 00451 * @param SPIx SPI Instance 00452 * @param BitOrder This parameter can be one of the following values: 00453 * @arg @ref LL_SPI_LSB_FIRST 00454 * @arg @ref LL_SPI_MSB_FIRST 00455 * @retval None 00456 */ 00457 __STATIC_INLINE void LL_SPI_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder) 00458 { 00459 MODIFY_REG(SPIx->CR1, SPI_CR1_LSBFIRST, BitOrder); 00460 } 00461 00462 /** 00463 * @brief Get transfer bit order 00464 * @rmtoll CR1 LSBFIRST LL_SPI_GetTransferBitOrder 00465 * @param SPIx SPI Instance 00466 * @retval Returned value can be one of the following values: 00467 * @arg @ref LL_SPI_LSB_FIRST 00468 * @arg @ref LL_SPI_MSB_FIRST 00469 */ 00470 __STATIC_INLINE uint32_t LL_SPI_GetTransferBitOrder(SPI_TypeDef *SPIx) 00471 { 00472 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_LSBFIRST)); 00473 } 00474 00475 /** 00476 * @brief Set transfer direction mode 00477 * @note For Half-Duplex mode, Rx Direction is set by default. 00478 * In master mode, the MOSI pin is used and in slave mode, the MISO pin is used for Half-Duplex. 00479 * @rmtoll CR1 RXONLY LL_SPI_SetTransferDirection\n 00480 * CR1 BIDIMODE LL_SPI_SetTransferDirection\n 00481 * CR1 BIDIOE LL_SPI_SetTransferDirection 00482 * @param SPIx SPI Instance 00483 * @param TransferDirection This parameter can be one of the following values: 00484 * @arg @ref LL_SPI_FULL_DUPLEX 00485 * @arg @ref LL_SPI_SIMPLEX_RX 00486 * @arg @ref LL_SPI_HALF_DUPLEX_RX 00487 * @arg @ref LL_SPI_HALF_DUPLEX_TX 00488 * @retval None 00489 */ 00490 __STATIC_INLINE void LL_SPI_SetTransferDirection(SPI_TypeDef *SPIx, uint32_t TransferDirection) 00491 { 00492 MODIFY_REG(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE, TransferDirection); 00493 } 00494 00495 /** 00496 * @brief Get transfer direction mode 00497 * @rmtoll CR1 RXONLY LL_SPI_GetTransferDirection\n 00498 * CR1 BIDIMODE LL_SPI_GetTransferDirection\n 00499 * CR1 BIDIOE LL_SPI_GetTransferDirection 00500 * @param SPIx SPI Instance 00501 * @retval Returned value can be one of the following values: 00502 * @arg @ref LL_SPI_FULL_DUPLEX 00503 * @arg @ref LL_SPI_SIMPLEX_RX 00504 * @arg @ref LL_SPI_HALF_DUPLEX_RX 00505 * @arg @ref LL_SPI_HALF_DUPLEX_TX 00506 */ 00507 __STATIC_INLINE uint32_t LL_SPI_GetTransferDirection(SPI_TypeDef *SPIx) 00508 { 00509 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE)); 00510 } 00511 00512 /** 00513 * @brief Set frame data width 00514 * @rmtoll CR1 DFF LL_SPI_SetDataWidth 00515 * @param SPIx SPI Instance 00516 * @param DataWidth This parameter can be one of the following values: 00517 * @arg @ref LL_SPI_DATAWIDTH_8BIT 00518 * @arg @ref LL_SPI_DATAWIDTH_16BIT 00519 * @retval None 00520 */ 00521 __STATIC_INLINE void LL_SPI_SetDataWidth(SPI_TypeDef *SPIx, uint32_t DataWidth) 00522 { 00523 MODIFY_REG(SPIx->CR1, SPI_CR1_DFF, DataWidth); 00524 } 00525 00526 /** 00527 * @brief Get frame data width 00528 * @rmtoll CR1 DFF LL_SPI_GetDataWidth 00529 * @param SPIx SPI Instance 00530 * @retval Returned value can be one of the following values: 00531 * @arg @ref LL_SPI_DATAWIDTH_8BIT 00532 * @arg @ref LL_SPI_DATAWIDTH_16BIT 00533 */ 00534 __STATIC_INLINE uint32_t LL_SPI_GetDataWidth(SPI_TypeDef *SPIx) 00535 { 00536 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_DFF)); 00537 } 00538 00539 /** 00540 * @} 00541 */ 00542 00543 /** @defgroup SPI_LL_EF_CRC_Management CRC Management 00544 * @{ 00545 */ 00546 00547 /** 00548 * @brief Enable CRC 00549 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00550 * @rmtoll CR1 CRCEN LL_SPI_EnableCRC 00551 * @param SPIx SPI Instance 00552 * @retval None 00553 */ 00554 __STATIC_INLINE void LL_SPI_EnableCRC(SPI_TypeDef *SPIx) 00555 { 00556 SET_BIT(SPIx->CR1, SPI_CR1_CRCEN); 00557 } 00558 00559 /** 00560 * @brief Disable CRC 00561 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00562 * @rmtoll CR1 CRCEN LL_SPI_DisableCRC 00563 * @param SPIx SPI Instance 00564 * @retval None 00565 */ 00566 __STATIC_INLINE void LL_SPI_DisableCRC(SPI_TypeDef *SPIx) 00567 { 00568 CLEAR_BIT(SPIx->CR1, SPI_CR1_CRCEN); 00569 } 00570 00571 /** 00572 * @brief Check if CRC is enabled 00573 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00574 * @rmtoll CR1 CRCEN LL_SPI_IsEnabledCRC 00575 * @param SPIx SPI Instance 00576 * @retval State of bit (1 or 0). 00577 */ 00578 __STATIC_INLINE uint32_t LL_SPI_IsEnabledCRC(SPI_TypeDef *SPIx) 00579 { 00580 return ((READ_BIT(SPIx->CR1, SPI_CR1_CRCEN) == (SPI_CR1_CRCEN)) ? 1UL : 0UL); 00581 } 00582 00583 /** 00584 * @brief Set CRCNext to transfer CRC on the line 00585 * @note This bit has to be written as soon as the last data is written in the SPIx_DR register. 00586 * @rmtoll CR1 CRCNEXT LL_SPI_SetCRCNext 00587 * @param SPIx SPI Instance 00588 * @retval None 00589 */ 00590 __STATIC_INLINE void LL_SPI_SetCRCNext(SPI_TypeDef *SPIx) 00591 { 00592 SET_BIT(SPIx->CR1, SPI_CR1_CRCNEXT); 00593 } 00594 00595 /** 00596 * @brief Set polynomial for CRC calculation 00597 * @rmtoll CRCPR CRCPOLY LL_SPI_SetCRCPolynomial 00598 * @param SPIx SPI Instance 00599 * @param CRCPoly This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00600 * @retval None 00601 */ 00602 __STATIC_INLINE void LL_SPI_SetCRCPolynomial(SPI_TypeDef *SPIx, uint32_t CRCPoly) 00603 { 00604 WRITE_REG(SPIx->CRCPR, (uint16_t)CRCPoly); 00605 } 00606 00607 /** 00608 * @brief Get polynomial for CRC calculation 00609 * @rmtoll CRCPR CRCPOLY LL_SPI_GetCRCPolynomial 00610 * @param SPIx SPI Instance 00611 * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00612 */ 00613 __STATIC_INLINE uint32_t LL_SPI_GetCRCPolynomial(SPI_TypeDef *SPIx) 00614 { 00615 return (uint32_t)(READ_REG(SPIx->CRCPR)); 00616 } 00617 00618 /** 00619 * @brief Get Rx CRC 00620 * @rmtoll RXCRCR RXCRC LL_SPI_GetRxCRC 00621 * @param SPIx SPI Instance 00622 * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00623 */ 00624 __STATIC_INLINE uint32_t LL_SPI_GetRxCRC(SPI_TypeDef *SPIx) 00625 { 00626 return (uint32_t)(READ_REG(SPIx->RXCRCR)); 00627 } 00628 00629 /** 00630 * @brief Get Tx CRC 00631 * @rmtoll TXCRCR TXCRC LL_SPI_GetTxCRC 00632 * @param SPIx SPI Instance 00633 * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00634 */ 00635 __STATIC_INLINE uint32_t LL_SPI_GetTxCRC(SPI_TypeDef *SPIx) 00636 { 00637 return (uint32_t)(READ_REG(SPIx->TXCRCR)); 00638 } 00639 00640 /** 00641 * @} 00642 */ 00643 00644 /** @defgroup SPI_LL_EF_NSS_Management Slave Select Pin Management 00645 * @{ 00646 */ 00647 00648 /** 00649 * @brief Set NSS mode 00650 * @note LL_SPI_NSS_SOFT Mode is not used in SPI TI mode. 00651 * @rmtoll CR1 SSM LL_SPI_SetNSSMode\n 00652 * @rmtoll CR2 SSOE LL_SPI_SetNSSMode 00653 * @param SPIx SPI Instance 00654 * @param NSS This parameter can be one of the following values: 00655 * @arg @ref LL_SPI_NSS_SOFT 00656 * @arg @ref LL_SPI_NSS_HARD_INPUT 00657 * @arg @ref LL_SPI_NSS_HARD_OUTPUT 00658 * @retval None 00659 */ 00660 __STATIC_INLINE void LL_SPI_SetNSSMode(SPI_TypeDef *SPIx, uint32_t NSS) 00661 { 00662 MODIFY_REG(SPIx->CR1, SPI_CR1_SSM, NSS); 00663 MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, ((uint32_t)(NSS >> 16U))); 00664 } 00665 00666 /** 00667 * @brief Get NSS mode 00668 * @rmtoll CR1 SSM LL_SPI_GetNSSMode\n 00669 * @rmtoll CR2 SSOE LL_SPI_GetNSSMode 00670 * @param SPIx SPI Instance 00671 * @retval Returned value can be one of the following values: 00672 * @arg @ref LL_SPI_NSS_SOFT 00673 * @arg @ref LL_SPI_NSS_HARD_INPUT 00674 * @arg @ref LL_SPI_NSS_HARD_OUTPUT 00675 */ 00676 __STATIC_INLINE uint32_t LL_SPI_GetNSSMode(SPI_TypeDef *SPIx) 00677 { 00678 uint32_t Ssm = (READ_BIT(SPIx->CR1, SPI_CR1_SSM)); 00679 uint32_t Ssoe = (READ_BIT(SPIx->CR2, SPI_CR2_SSOE) << 16U); 00680 return (Ssm | Ssoe); 00681 } 00682 00683 /** 00684 * @} 00685 */ 00686 00687 /** @defgroup SPI_LL_EF_FLAG_Management FLAG Management 00688 * @{ 00689 */ 00690 00691 /** 00692 * @brief Check if Rx buffer is not empty 00693 * @rmtoll SR RXNE LL_SPI_IsActiveFlag_RXNE 00694 * @param SPIx SPI Instance 00695 * @retval State of bit (1 or 0). 00696 */ 00697 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXNE(SPI_TypeDef *SPIx) 00698 { 00699 return ((READ_BIT(SPIx->SR, SPI_SR_RXNE) == (SPI_SR_RXNE)) ? 1UL : 0UL); 00700 } 00701 00702 /** 00703 * @brief Check if Tx buffer is empty 00704 * @rmtoll SR TXE LL_SPI_IsActiveFlag_TXE 00705 * @param SPIx SPI Instance 00706 * @retval State of bit (1 or 0). 00707 */ 00708 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXE(SPI_TypeDef *SPIx) 00709 { 00710 return ((READ_BIT(SPIx->SR, SPI_SR_TXE) == (SPI_SR_TXE)) ? 1UL : 0UL); 00711 } 00712 00713 /** 00714 * @brief Get CRC error flag 00715 * @rmtoll SR CRCERR LL_SPI_IsActiveFlag_CRCERR 00716 * @param SPIx SPI Instance 00717 * @retval State of bit (1 or 0). 00718 */ 00719 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_CRCERR(SPI_TypeDef *SPIx) 00720 { 00721 return ((READ_BIT(SPIx->SR, SPI_SR_CRCERR) == (SPI_SR_CRCERR)) ? 1UL : 0UL); 00722 } 00723 00724 /** 00725 * @brief Get mode fault error flag 00726 * @rmtoll SR MODF LL_SPI_IsActiveFlag_MODF 00727 * @param SPIx SPI Instance 00728 * @retval State of bit (1 or 0). 00729 */ 00730 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_MODF(SPI_TypeDef *SPIx) 00731 { 00732 return ((READ_BIT(SPIx->SR, SPI_SR_MODF) == (SPI_SR_MODF)) ? 1UL : 0UL); 00733 } 00734 00735 /** 00736 * @brief Get overrun error flag 00737 * @rmtoll SR OVR LL_SPI_IsActiveFlag_OVR 00738 * @param SPIx SPI Instance 00739 * @retval State of bit (1 or 0). 00740 */ 00741 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_OVR(SPI_TypeDef *SPIx) 00742 { 00743 return ((READ_BIT(SPIx->SR, SPI_SR_OVR) == (SPI_SR_OVR)) ? 1UL : 0UL); 00744 } 00745 00746 /** 00747 * @brief Get busy flag 00748 * @note The BSY flag is cleared under any one of the following conditions: 00749 * -When the SPI is correctly disabled 00750 * -When a fault is detected in Master mode (MODF bit set to 1) 00751 * -In Master mode, when it finishes a data transmission and no new data is ready to be 00752 * sent 00753 * -In Slave mode, when the BSY flag is set to '0' for at least one SPI clock cycle between 00754 * each data transfer. 00755 * @rmtoll SR BSY LL_SPI_IsActiveFlag_BSY 00756 * @param SPIx SPI Instance 00757 * @retval State of bit (1 or 0). 00758 */ 00759 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_BSY(SPI_TypeDef *SPIx) 00760 { 00761 return ((READ_BIT(SPIx->SR, SPI_SR_BSY) == (SPI_SR_BSY)) ? 1UL : 0UL); 00762 } 00763 00764 00765 /** 00766 * @brief Clear CRC error flag 00767 * @rmtoll SR CRCERR LL_SPI_ClearFlag_CRCERR 00768 * @param SPIx SPI Instance 00769 * @retval None 00770 */ 00771 __STATIC_INLINE void LL_SPI_ClearFlag_CRCERR(SPI_TypeDef *SPIx) 00772 { 00773 CLEAR_BIT(SPIx->SR, SPI_SR_CRCERR); 00774 } 00775 00776 /** 00777 * @brief Clear mode fault error flag 00778 * @note Clearing this flag is done by a read access to the SPIx_SR 00779 * register followed by a write access to the SPIx_CR1 register 00780 * @rmtoll SR MODF LL_SPI_ClearFlag_MODF 00781 * @param SPIx SPI Instance 00782 * @retval None 00783 */ 00784 __STATIC_INLINE void LL_SPI_ClearFlag_MODF(SPI_TypeDef *SPIx) 00785 { 00786 __IO uint32_t tmpreg_sr; 00787 tmpreg_sr = SPIx->SR; 00788 (void) tmpreg_sr; 00789 CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE); 00790 } 00791 00792 /** 00793 * @brief Clear overrun error flag 00794 * @note Clearing this flag is done by a read access to the SPIx_DR 00795 * register followed by a read access to the SPIx_SR register 00796 * @rmtoll SR OVR LL_SPI_ClearFlag_OVR 00797 * @param SPIx SPI Instance 00798 * @retval None 00799 */ 00800 __STATIC_INLINE void LL_SPI_ClearFlag_OVR(SPI_TypeDef *SPIx) 00801 { 00802 __IO uint32_t tmpreg; 00803 tmpreg = SPIx->DR; 00804 (void) tmpreg; 00805 tmpreg = SPIx->SR; 00806 (void) tmpreg; 00807 } 00808 00809 /** 00810 * @brief Clear frame format error flag 00811 * @note Clearing this flag is done by reading SPIx_SR register 00812 * @rmtoll SR FRE LL_SPI_ClearFlag_FRE 00813 * @param SPIx SPI Instance 00814 * @retval None 00815 */ 00816 __STATIC_INLINE void LL_SPI_ClearFlag_FRE(SPI_TypeDef *SPIx) 00817 { 00818 __IO uint32_t tmpreg; 00819 tmpreg = SPIx->SR; 00820 (void) tmpreg; 00821 } 00822 00823 /** 00824 * @} 00825 */ 00826 00827 /** @defgroup SPI_LL_EF_IT_Management Interrupt Management 00828 * @{ 00829 */ 00830 00831 /** 00832 * @brief Enable error interrupt 00833 * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode). 00834 * @rmtoll CR2 ERRIE LL_SPI_EnableIT_ERR 00835 * @param SPIx SPI Instance 00836 * @retval None 00837 */ 00838 __STATIC_INLINE void LL_SPI_EnableIT_ERR(SPI_TypeDef *SPIx) 00839 { 00840 SET_BIT(SPIx->CR2, SPI_CR2_ERRIE); 00841 } 00842 00843 /** 00844 * @brief Enable Rx buffer not empty interrupt 00845 * @rmtoll CR2 RXNEIE LL_SPI_EnableIT_RXNE 00846 * @param SPIx SPI Instance 00847 * @retval None 00848 */ 00849 __STATIC_INLINE void LL_SPI_EnableIT_RXNE(SPI_TypeDef *SPIx) 00850 { 00851 SET_BIT(SPIx->CR2, SPI_CR2_RXNEIE); 00852 } 00853 00854 /** 00855 * @brief Enable Tx buffer empty interrupt 00856 * @rmtoll CR2 TXEIE LL_SPI_EnableIT_TXE 00857 * @param SPIx SPI Instance 00858 * @retval None 00859 */ 00860 __STATIC_INLINE void LL_SPI_EnableIT_TXE(SPI_TypeDef *SPIx) 00861 { 00862 SET_BIT(SPIx->CR2, SPI_CR2_TXEIE); 00863 } 00864 00865 /** 00866 * @brief Disable error interrupt 00867 * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode). 00868 * @rmtoll CR2 ERRIE LL_SPI_DisableIT_ERR 00869 * @param SPIx SPI Instance 00870 * @retval None 00871 */ 00872 __STATIC_INLINE void LL_SPI_DisableIT_ERR(SPI_TypeDef *SPIx) 00873 { 00874 CLEAR_BIT(SPIx->CR2, SPI_CR2_ERRIE); 00875 } 00876 00877 /** 00878 * @brief Disable Rx buffer not empty interrupt 00879 * @rmtoll CR2 RXNEIE LL_SPI_DisableIT_RXNE 00880 * @param SPIx SPI Instance 00881 * @retval None 00882 */ 00883 __STATIC_INLINE void LL_SPI_DisableIT_RXNE(SPI_TypeDef *SPIx) 00884 { 00885 CLEAR_BIT(SPIx->CR2, SPI_CR2_RXNEIE); 00886 } 00887 00888 /** 00889 * @brief Disable Tx buffer empty interrupt 00890 * @rmtoll CR2 TXEIE LL_SPI_DisableIT_TXE 00891 * @param SPIx SPI Instance 00892 * @retval None 00893 */ 00894 __STATIC_INLINE void LL_SPI_DisableIT_TXE(SPI_TypeDef *SPIx) 00895 { 00896 CLEAR_BIT(SPIx->CR2, SPI_CR2_TXEIE); 00897 } 00898 00899 /** 00900 * @brief Check if error interrupt is enabled 00901 * @rmtoll CR2 ERRIE LL_SPI_IsEnabledIT_ERR 00902 * @param SPIx SPI Instance 00903 * @retval State of bit (1 or 0). 00904 */ 00905 __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_ERR(SPI_TypeDef *SPIx) 00906 { 00907 return ((READ_BIT(SPIx->CR2, SPI_CR2_ERRIE) == (SPI_CR2_ERRIE)) ? 1UL : 0UL); 00908 } 00909 00910 /** 00911 * @brief Check if Rx buffer not empty interrupt is enabled 00912 * @rmtoll CR2 RXNEIE LL_SPI_IsEnabledIT_RXNE 00913 * @param SPIx SPI Instance 00914 * @retval State of bit (1 or 0). 00915 */ 00916 __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_RXNE(SPI_TypeDef *SPIx) 00917 { 00918 return ((READ_BIT(SPIx->CR2, SPI_CR2_RXNEIE) == (SPI_CR2_RXNEIE)) ? 1UL : 0UL); 00919 } 00920 00921 /** 00922 * @brief Check if Tx buffer empty interrupt 00923 * @rmtoll CR2 TXEIE LL_SPI_IsEnabledIT_TXE 00924 * @param SPIx SPI Instance 00925 * @retval State of bit (1 or 0). 00926 */ 00927 __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXE(SPI_TypeDef *SPIx) 00928 { 00929 return ((READ_BIT(SPIx->CR2, SPI_CR2_TXEIE) == (SPI_CR2_TXEIE)) ? 1UL : 0UL); 00930 } 00931 00932 /** 00933 * @} 00934 */ 00935 00936 /** @defgroup SPI_LL_EF_DMA_Management DMA Management 00937 * @{ 00938 */ 00939 00940 /** 00941 * @brief Enable DMA Rx 00942 * @rmtoll CR2 RXDMAEN LL_SPI_EnableDMAReq_RX 00943 * @param SPIx SPI Instance 00944 * @retval None 00945 */ 00946 __STATIC_INLINE void LL_SPI_EnableDMAReq_RX(SPI_TypeDef *SPIx) 00947 { 00948 SET_BIT(SPIx->CR2, SPI_CR2_RXDMAEN); 00949 } 00950 00951 /** 00952 * @brief Disable DMA Rx 00953 * @rmtoll CR2 RXDMAEN LL_SPI_DisableDMAReq_RX 00954 * @param SPIx SPI Instance 00955 * @retval None 00956 */ 00957 __STATIC_INLINE void LL_SPI_DisableDMAReq_RX(SPI_TypeDef *SPIx) 00958 { 00959 CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN); 00960 } 00961 00962 /** 00963 * @brief Check if DMA Rx is enabled 00964 * @rmtoll CR2 RXDMAEN LL_SPI_IsEnabledDMAReq_RX 00965 * @param SPIx SPI Instance 00966 * @retval State of bit (1 or 0). 00967 */ 00968 __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx) 00969 { 00970 return ((READ_BIT(SPIx->CR2, SPI_CR2_RXDMAEN) == (SPI_CR2_RXDMAEN)) ? 1UL : 0UL); 00971 } 00972 00973 /** 00974 * @brief Enable DMA Tx 00975 * @rmtoll CR2 TXDMAEN LL_SPI_EnableDMAReq_TX 00976 * @param SPIx SPI Instance 00977 * @retval None 00978 */ 00979 __STATIC_INLINE void LL_SPI_EnableDMAReq_TX(SPI_TypeDef *SPIx) 00980 { 00981 SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN); 00982 } 00983 00984 /** 00985 * @brief Disable DMA Tx 00986 * @rmtoll CR2 TXDMAEN LL_SPI_DisableDMAReq_TX 00987 * @param SPIx SPI Instance 00988 * @retval None 00989 */ 00990 __STATIC_INLINE void LL_SPI_DisableDMAReq_TX(SPI_TypeDef *SPIx) 00991 { 00992 CLEAR_BIT(SPIx->CR2, SPI_CR2_TXDMAEN); 00993 } 00994 00995 /** 00996 * @brief Check if DMA Tx is enabled 00997 * @rmtoll CR2 TXDMAEN LL_SPI_IsEnabledDMAReq_TX 00998 * @param SPIx SPI Instance 00999 * @retval State of bit (1 or 0). 01000 */ 01001 __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx) 01002 { 01003 return ((READ_BIT(SPIx->CR2, SPI_CR2_TXDMAEN) == (SPI_CR2_TXDMAEN)) ? 1UL : 0UL); 01004 } 01005 01006 /** 01007 * @brief Get the data register address used for DMA transfer 01008 * @rmtoll DR DR LL_SPI_DMA_GetRegAddr 01009 * @param SPIx SPI Instance 01010 * @retval Address of data register 01011 */ 01012 __STATIC_INLINE uint32_t LL_SPI_DMA_GetRegAddr(SPI_TypeDef *SPIx) 01013 { 01014 return (uint32_t) &(SPIx->DR); 01015 } 01016 01017 /** 01018 * @} 01019 */ 01020 01021 /** @defgroup SPI_LL_EF_DATA_Management DATA Management 01022 * @{ 01023 */ 01024 01025 /** 01026 * @brief Read 8-Bits in the data register 01027 * @rmtoll DR DR LL_SPI_ReceiveData8 01028 * @param SPIx SPI Instance 01029 * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFF 01030 */ 01031 __STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx) 01032 { 01033 return (*((__IO uint8_t *)&SPIx->DR)); 01034 } 01035 01036 /** 01037 * @brief Read 16-Bits in the data register 01038 * @rmtoll DR DR LL_SPI_ReceiveData16 01039 * @param SPIx SPI Instance 01040 * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFFFF 01041 */ 01042 __STATIC_INLINE uint16_t LL_SPI_ReceiveData16(SPI_TypeDef *SPIx) 01043 { 01044 return (uint16_t)(READ_REG(SPIx->DR)); 01045 } 01046 01047 /** 01048 * @brief Write 8-Bits in the data register 01049 * @rmtoll DR DR LL_SPI_TransmitData8 01050 * @param SPIx SPI Instance 01051 * @param TxData Value between Min_Data=0x00 and Max_Data=0xFF 01052 * @retval None 01053 */ 01054 __STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData) 01055 { 01056 #if defined (__GNUC__) 01057 __IO uint8_t *spidr = ((__IO uint8_t *)&SPIx->DR); 01058 *spidr = TxData; 01059 #else 01060 *((__IO uint8_t *)&SPIx->DR) = TxData; 01061 #endif /* __GNUC__ */ 01062 } 01063 01064 /** 01065 * @brief Write 16-Bits in the data register 01066 * @rmtoll DR DR LL_SPI_TransmitData16 01067 * @param SPIx SPI Instance 01068 * @param TxData Value between Min_Data=0x00 and Max_Data=0xFFFF 01069 * @retval None 01070 */ 01071 __STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData) 01072 { 01073 #if defined (__GNUC__) 01074 __IO uint16_t *spidr = ((__IO uint16_t *)&SPIx->DR); 01075 *spidr = TxData; 01076 #else 01077 SPIx->DR = TxData; 01078 #endif /* __GNUC__ */ 01079 } 01080 01081 /** 01082 * @} 01083 */ 01084 #if defined(USE_FULL_LL_DRIVER) 01085 /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions 01086 * @{ 01087 */ 01088 01089 ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx); 01090 ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct); 01091 void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct); 01092 01093 /** 01094 * @} 01095 */ 01096 #endif /* USE_FULL_LL_DRIVER */ 01097 /** 01098 * @} 01099 */ 01100 01101 /** 01102 * @} 01103 */ 01104 01105 #if defined(SPI_I2S_SUPPORT) 01106 /** @defgroup I2S_LL I2S 01107 * @{ 01108 */ 01109 01110 /* Private variables ---------------------------------------------------------*/ 01111 /* Private constants ---------------------------------------------------------*/ 01112 /* Private macros ------------------------------------------------------------*/ 01113 01114 /* Exported types ------------------------------------------------------------*/ 01115 #if defined(USE_FULL_LL_DRIVER) 01116 /** @defgroup I2S_LL_ES_INIT I2S Exported Init structure 01117 * @{ 01118 */ 01119 01120 /** 01121 * @brief I2S Init structure definition 01122 */ 01123 01124 typedef struct 01125 { 01126 uint32_t Mode; /*!< Specifies the I2S operating mode. 01127 This parameter can be a value of @ref I2S_LL_EC_MODE 01128 01129 This feature can be modified afterwards using unitary function @ref LL_I2S_SetTransferMode().*/ 01130 01131 uint32_t Standard; /*!< Specifies the standard used for the I2S communication. 01132 This parameter can be a value of @ref I2S_LL_EC_STANDARD 01133 01134 This feature can be modified afterwards using unitary function @ref LL_I2S_SetStandard().*/ 01135 01136 01137 uint32_t DataFormat; /*!< Specifies the data format for the I2S communication. 01138 This parameter can be a value of @ref I2S_LL_EC_DATA_FORMAT 01139 01140 This feature can be modified afterwards using unitary function @ref LL_I2S_SetDataFormat().*/ 01141 01142 01143 uint32_t MCLKOutput; /*!< Specifies whether the I2S MCLK output is enabled or not. 01144 This parameter can be a value of @ref I2S_LL_EC_MCLK_OUTPUT 01145 01146 This feature can be modified afterwards using unitary functions @ref LL_I2S_EnableMasterClock() or @ref LL_I2S_DisableMasterClock.*/ 01147 01148 01149 uint32_t AudioFreq; /*!< Specifies the frequency selected for the I2S communication. 01150 This parameter can be a value of @ref I2S_LL_EC_AUDIO_FREQ 01151 01152 Audio Frequency can be modified afterwards using Reference manual formulas to calculate Prescaler Linear, Parity 01153 and unitary functions @ref LL_I2S_SetPrescalerLinear() and @ref LL_I2S_SetPrescalerParity() to set it.*/ 01154 01155 01156 uint32_t ClockPolarity; /*!< Specifies the idle state of the I2S clock. 01157 This parameter can be a value of @ref I2S_LL_EC_POLARITY 01158 01159 This feature can be modified afterwards using unitary function @ref LL_I2S_SetClockPolarity().*/ 01160 01161 } LL_I2S_InitTypeDef; 01162 01163 /** 01164 * @} 01165 */ 01166 #endif /*USE_FULL_LL_DRIVER*/ 01167 01168 /* Exported constants --------------------------------------------------------*/ 01169 /** @defgroup I2S_LL_Exported_Constants I2S Exported Constants 01170 * @{ 01171 */ 01172 01173 /** @defgroup I2S_LL_EC_GET_FLAG Get Flags Defines 01174 * @brief Flags defines which can be used with LL_I2S_ReadReg function 01175 * @{ 01176 */ 01177 #define LL_I2S_SR_RXNE LL_SPI_SR_RXNE /*!< Rx buffer not empty flag */ 01178 #define LL_I2S_SR_TXE LL_SPI_SR_TXE /*!< Tx buffer empty flag */ 01179 #define LL_I2S_SR_BSY LL_SPI_SR_BSY /*!< Busy flag */ 01180 #define LL_I2S_SR_UDR SPI_SR_UDR /*!< Underrun flag */ 01181 #define LL_I2S_SR_OVR LL_SPI_SR_OVR /*!< Overrun flag */ 01182 #define LL_I2S_SR_FRE LL_SPI_SR_FRE /*!< TI mode frame format error flag */ 01183 /** 01184 * @} 01185 */ 01186 01187 /** @defgroup SPI_LL_EC_IT IT Defines 01188 * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions 01189 * @{ 01190 */ 01191 #define LL_I2S_CR2_RXNEIE LL_SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */ 01192 #define LL_I2S_CR2_TXEIE LL_SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */ 01193 #define LL_I2S_CR2_ERRIE LL_SPI_CR2_ERRIE /*!< Error interrupt enable */ 01194 /** 01195 * @} 01196 */ 01197 01198 /** @defgroup I2S_LL_EC_DATA_FORMAT Data format 01199 * @{ 01200 */ 01201 #define LL_I2S_DATAFORMAT_16B 0x00000000U /*!< Data length 16 bits, Channel length 16bit */ 01202 #define LL_I2S_DATAFORMAT_16B_EXTENDED (SPI_I2SCFGR_CHLEN) /*!< Data length 16 bits, Channel length 32bit */ 01203 #define LL_I2S_DATAFORMAT_24B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_0) /*!< Data length 24 bits, Channel length 32bit */ 01204 #define LL_I2S_DATAFORMAT_32B (SPI_I2SCFGR_CHLEN | SPI_I2SCFGR_DATLEN_1) /*!< Data length 16 bits, Channel length 32bit */ 01205 /** 01206 * @} 01207 */ 01208 01209 /** @defgroup I2S_LL_EC_POLARITY Clock Polarity 01210 * @{ 01211 */ 01212 #define LL_I2S_POLARITY_LOW 0x00000000U /*!< Clock steady state is low level */ 01213 #define LL_I2S_POLARITY_HIGH (SPI_I2SCFGR_CKPOL) /*!< Clock steady state is high level */ 01214 /** 01215 * @} 01216 */ 01217 01218 /** @defgroup I2S_LL_EC_STANDARD I2s Standard 01219 * @{ 01220 */ 01221 #define LL_I2S_STANDARD_PHILIPS 0x00000000U /*!< I2S standard philips */ 01222 #define LL_I2S_STANDARD_MSB (SPI_I2SCFGR_I2SSTD_0) /*!< MSB justified standard (left justified) */ 01223 #define LL_I2S_STANDARD_LSB (SPI_I2SCFGR_I2SSTD_1) /*!< LSB justified standard (right justified) */ 01224 #define LL_I2S_STANDARD_PCM_SHORT (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1) /*!< PCM standard, short frame synchronization */ 01225 #define LL_I2S_STANDARD_PCM_LONG (SPI_I2SCFGR_I2SSTD_0 | SPI_I2SCFGR_I2SSTD_1 | SPI_I2SCFGR_PCMSYNC) /*!< PCM standard, long frame synchronization */ 01226 /** 01227 * @} 01228 */ 01229 01230 /** @defgroup I2S_LL_EC_MODE Operation Mode 01231 * @{ 01232 */ 01233 #define LL_I2S_MODE_SLAVE_TX 0x00000000U /*!< Slave Tx configuration */ 01234 #define LL_I2S_MODE_SLAVE_RX (SPI_I2SCFGR_I2SCFG_0) /*!< Slave Rx configuration */ 01235 #define LL_I2S_MODE_MASTER_TX (SPI_I2SCFGR_I2SCFG_1) /*!< Master Tx configuration */ 01236 #define LL_I2S_MODE_MASTER_RX (SPI_I2SCFGR_I2SCFG_0 | SPI_I2SCFGR_I2SCFG_1) /*!< Master Rx configuration */ 01237 /** 01238 * @} 01239 */ 01240 01241 /** @defgroup I2S_LL_EC_PRESCALER_FACTOR Prescaler Factor 01242 * @{ 01243 */ 01244 #define LL_I2S_PRESCALER_PARITY_EVEN 0x00000000U /*!< Odd factor: Real divider value is = I2SDIV * 2 */ 01245 #define LL_I2S_PRESCALER_PARITY_ODD (SPI_I2SPR_ODD >> 8U) /*!< Odd factor: Real divider value is = (I2SDIV * 2)+1 */ 01246 /** 01247 * @} 01248 */ 01249 01250 #if defined(USE_FULL_LL_DRIVER) 01251 01252 /** @defgroup I2S_LL_EC_MCLK_OUTPUT MCLK Output 01253 * @{ 01254 */ 01255 #define LL_I2S_MCLK_OUTPUT_DISABLE 0x00000000U /*!< Master clock output is disabled */ 01256 #define LL_I2S_MCLK_OUTPUT_ENABLE (SPI_I2SPR_MCKOE) /*!< Master clock output is enabled */ 01257 /** 01258 * @} 01259 */ 01260 01261 /** @defgroup I2S_LL_EC_AUDIO_FREQ Audio Frequency 01262 * @{ 01263 */ 01264 01265 #define LL_I2S_AUDIOFREQ_192K 192000U /*!< Audio Frequency configuration 192000 Hz */ 01266 #define LL_I2S_AUDIOFREQ_96K 96000U /*!< Audio Frequency configuration 96000 Hz */ 01267 #define LL_I2S_AUDIOFREQ_48K 48000U /*!< Audio Frequency configuration 48000 Hz */ 01268 #define LL_I2S_AUDIOFREQ_44K 44100U /*!< Audio Frequency configuration 44100 Hz */ 01269 #define LL_I2S_AUDIOFREQ_32K 32000U /*!< Audio Frequency configuration 32000 Hz */ 01270 #define LL_I2S_AUDIOFREQ_22K 22050U /*!< Audio Frequency configuration 22050 Hz */ 01271 #define LL_I2S_AUDIOFREQ_16K 16000U /*!< Audio Frequency configuration 16000 Hz */ 01272 #define LL_I2S_AUDIOFREQ_11K 11025U /*!< Audio Frequency configuration 11025 Hz */ 01273 #define LL_I2S_AUDIOFREQ_8K 8000U /*!< Audio Frequency configuration 8000 Hz */ 01274 #define LL_I2S_AUDIOFREQ_DEFAULT 2U /*!< Audio Freq not specified. Register I2SDIV = 2 */ 01275 /** 01276 * @} 01277 */ 01278 #endif /* USE_FULL_LL_DRIVER */ 01279 01280 /** 01281 * @} 01282 */ 01283 01284 /* Exported macro ------------------------------------------------------------*/ 01285 /** @defgroup I2S_LL_Exported_Macros I2S Exported Macros 01286 * @{ 01287 */ 01288 01289 /** @defgroup I2S_LL_EM_WRITE_READ Common Write and read registers Macros 01290 * @{ 01291 */ 01292 01293 /** 01294 * @brief Write a value in I2S register 01295 * @param __INSTANCE__ I2S Instance 01296 * @param __REG__ Register to be written 01297 * @param __VALUE__ Value to be written in the register 01298 * @retval None 01299 */ 01300 #define LL_I2S_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__)) 01301 01302 /** 01303 * @brief Read a value in I2S register 01304 * @param __INSTANCE__ I2S Instance 01305 * @param __REG__ Register to be read 01306 * @retval Register value 01307 */ 01308 #define LL_I2S_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__) 01309 /** 01310 * @} 01311 */ 01312 01313 /** 01314 * @} 01315 */ 01316 01317 01318 /* Exported functions --------------------------------------------------------*/ 01319 01320 /** @defgroup I2S_LL_Exported_Functions I2S Exported Functions 01321 * @{ 01322 */ 01323 01324 /** @defgroup I2S_LL_EF_Configuration Configuration 01325 * @{ 01326 */ 01327 01328 /** 01329 * @brief Select I2S mode and Enable I2S peripheral 01330 * @rmtoll I2SCFGR I2SMOD LL_I2S_Enable\n 01331 * I2SCFGR I2SE LL_I2S_Enable 01332 * @param SPIx SPI Instance 01333 * @retval None 01334 */ 01335 __STATIC_INLINE void LL_I2S_Enable(SPI_TypeDef *SPIx) 01336 { 01337 SET_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE); 01338 } 01339 01340 /** 01341 * @brief Disable I2S peripheral 01342 * @rmtoll I2SCFGR I2SE LL_I2S_Disable 01343 * @param SPIx SPI Instance 01344 * @retval None 01345 */ 01346 __STATIC_INLINE void LL_I2S_Disable(SPI_TypeDef *SPIx) 01347 { 01348 CLEAR_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SMOD | SPI_I2SCFGR_I2SE); 01349 } 01350 01351 /** 01352 * @brief Check if I2S peripheral is enabled 01353 * @rmtoll I2SCFGR I2SE LL_I2S_IsEnabled 01354 * @param SPIx SPI Instance 01355 * @retval State of bit (1 or 0). 01356 */ 01357 __STATIC_INLINE uint32_t LL_I2S_IsEnabled(SPI_TypeDef *SPIx) 01358 { 01359 return ((READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SE) == (SPI_I2SCFGR_I2SE)) ? 1UL : 0UL); 01360 } 01361 01362 /** 01363 * @brief Set I2S data frame length 01364 * @rmtoll I2SCFGR DATLEN LL_I2S_SetDataFormat\n 01365 * I2SCFGR CHLEN LL_I2S_SetDataFormat 01366 * @param SPIx SPI Instance 01367 * @param DataFormat This parameter can be one of the following values: 01368 * @arg @ref LL_I2S_DATAFORMAT_16B 01369 * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED 01370 * @arg @ref LL_I2S_DATAFORMAT_24B 01371 * @arg @ref LL_I2S_DATAFORMAT_32B 01372 * @retval None 01373 */ 01374 __STATIC_INLINE void LL_I2S_SetDataFormat(SPI_TypeDef *SPIx, uint32_t DataFormat) 01375 { 01376 MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN, DataFormat); 01377 } 01378 01379 /** 01380 * @brief Get I2S data frame length 01381 * @rmtoll I2SCFGR DATLEN LL_I2S_GetDataFormat\n 01382 * I2SCFGR CHLEN LL_I2S_GetDataFormat 01383 * @param SPIx SPI Instance 01384 * @retval Returned value can be one of the following values: 01385 * @arg @ref LL_I2S_DATAFORMAT_16B 01386 * @arg @ref LL_I2S_DATAFORMAT_16B_EXTENDED 01387 * @arg @ref LL_I2S_DATAFORMAT_24B 01388 * @arg @ref LL_I2S_DATAFORMAT_32B 01389 */ 01390 __STATIC_INLINE uint32_t LL_I2S_GetDataFormat(SPI_TypeDef *SPIx) 01391 { 01392 return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_DATLEN | SPI_I2SCFGR_CHLEN)); 01393 } 01394 01395 /** 01396 * @brief Set I2S clock polarity 01397 * @rmtoll I2SCFGR CKPOL LL_I2S_SetClockPolarity 01398 * @param SPIx SPI Instance 01399 * @param ClockPolarity This parameter can be one of the following values: 01400 * @arg @ref LL_I2S_POLARITY_LOW 01401 * @arg @ref LL_I2S_POLARITY_HIGH 01402 * @retval None 01403 */ 01404 __STATIC_INLINE void LL_I2S_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity) 01405 { 01406 SET_BIT(SPIx->I2SCFGR, ClockPolarity); 01407 } 01408 01409 /** 01410 * @brief Get I2S clock polarity 01411 * @rmtoll I2SCFGR CKPOL LL_I2S_GetClockPolarity 01412 * @param SPIx SPI Instance 01413 * @retval Returned value can be one of the following values: 01414 * @arg @ref LL_I2S_POLARITY_LOW 01415 * @arg @ref LL_I2S_POLARITY_HIGH 01416 */ 01417 __STATIC_INLINE uint32_t LL_I2S_GetClockPolarity(SPI_TypeDef *SPIx) 01418 { 01419 return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_CKPOL)); 01420 } 01421 01422 /** 01423 * @brief Set I2S standard protocol 01424 * @rmtoll I2SCFGR I2SSTD LL_I2S_SetStandard\n 01425 * I2SCFGR PCMSYNC LL_I2S_SetStandard 01426 * @param SPIx SPI Instance 01427 * @param Standard This parameter can be one of the following values: 01428 * @arg @ref LL_I2S_STANDARD_PHILIPS 01429 * @arg @ref LL_I2S_STANDARD_MSB 01430 * @arg @ref LL_I2S_STANDARD_LSB 01431 * @arg @ref LL_I2S_STANDARD_PCM_SHORT 01432 * @arg @ref LL_I2S_STANDARD_PCM_LONG 01433 * @retval None 01434 */ 01435 __STATIC_INLINE void LL_I2S_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard) 01436 { 01437 MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC, Standard); 01438 } 01439 01440 /** 01441 * @brief Get I2S standard protocol 01442 * @rmtoll I2SCFGR I2SSTD LL_I2S_GetStandard\n 01443 * I2SCFGR PCMSYNC LL_I2S_GetStandard 01444 * @param SPIx SPI Instance 01445 * @retval Returned value can be one of the following values: 01446 * @arg @ref LL_I2S_STANDARD_PHILIPS 01447 * @arg @ref LL_I2S_STANDARD_MSB 01448 * @arg @ref LL_I2S_STANDARD_LSB 01449 * @arg @ref LL_I2S_STANDARD_PCM_SHORT 01450 * @arg @ref LL_I2S_STANDARD_PCM_LONG 01451 */ 01452 __STATIC_INLINE uint32_t LL_I2S_GetStandard(SPI_TypeDef *SPIx) 01453 { 01454 return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SSTD | SPI_I2SCFGR_PCMSYNC)); 01455 } 01456 01457 /** 01458 * @brief Set I2S transfer mode 01459 * @rmtoll I2SCFGR I2SCFG LL_I2S_SetTransferMode 01460 * @param SPIx SPI Instance 01461 * @param Mode This parameter can be one of the following values: 01462 * @arg @ref LL_I2S_MODE_SLAVE_TX 01463 * @arg @ref LL_I2S_MODE_SLAVE_RX 01464 * @arg @ref LL_I2S_MODE_MASTER_TX 01465 * @arg @ref LL_I2S_MODE_MASTER_RX 01466 * @retval None 01467 */ 01468 __STATIC_INLINE void LL_I2S_SetTransferMode(SPI_TypeDef *SPIx, uint32_t Mode) 01469 { 01470 MODIFY_REG(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG, Mode); 01471 } 01472 01473 /** 01474 * @brief Get I2S transfer mode 01475 * @rmtoll I2SCFGR I2SCFG LL_I2S_GetTransferMode 01476 * @param SPIx SPI Instance 01477 * @retval Returned value can be one of the following values: 01478 * @arg @ref LL_I2S_MODE_SLAVE_TX 01479 * @arg @ref LL_I2S_MODE_SLAVE_RX 01480 * @arg @ref LL_I2S_MODE_MASTER_TX 01481 * @arg @ref LL_I2S_MODE_MASTER_RX 01482 */ 01483 __STATIC_INLINE uint32_t LL_I2S_GetTransferMode(SPI_TypeDef *SPIx) 01484 { 01485 return (uint32_t)(READ_BIT(SPIx->I2SCFGR, SPI_I2SCFGR_I2SCFG)); 01486 } 01487 01488 /** 01489 * @brief Set I2S linear prescaler 01490 * @rmtoll I2SPR I2SDIV LL_I2S_SetPrescalerLinear 01491 * @param SPIx SPI Instance 01492 * @param PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF 01493 * @retval None 01494 */ 01495 __STATIC_INLINE void LL_I2S_SetPrescalerLinear(SPI_TypeDef *SPIx, uint8_t PrescalerLinear) 01496 { 01497 MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_I2SDIV, PrescalerLinear); 01498 } 01499 01500 /** 01501 * @brief Get I2S linear prescaler 01502 * @rmtoll I2SPR I2SDIV LL_I2S_GetPrescalerLinear 01503 * @param SPIx SPI Instance 01504 * @retval PrescalerLinear Value between Min_Data=0x02 and Max_Data=0xFF 01505 */ 01506 __STATIC_INLINE uint32_t LL_I2S_GetPrescalerLinear(SPI_TypeDef *SPIx) 01507 { 01508 return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_I2SDIV)); 01509 } 01510 01511 /** 01512 * @brief Set I2S parity prescaler 01513 * @rmtoll I2SPR ODD LL_I2S_SetPrescalerParity 01514 * @param SPIx SPI Instance 01515 * @param PrescalerParity This parameter can be one of the following values: 01516 * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN 01517 * @arg @ref LL_I2S_PRESCALER_PARITY_ODD 01518 * @retval None 01519 */ 01520 __STATIC_INLINE void LL_I2S_SetPrescalerParity(SPI_TypeDef *SPIx, uint32_t PrescalerParity) 01521 { 01522 MODIFY_REG(SPIx->I2SPR, SPI_I2SPR_ODD, PrescalerParity << 8U); 01523 } 01524 01525 /** 01526 * @brief Get I2S parity prescaler 01527 * @rmtoll I2SPR ODD LL_I2S_GetPrescalerParity 01528 * @param SPIx SPI Instance 01529 * @retval Returned value can be one of the following values: 01530 * @arg @ref LL_I2S_PRESCALER_PARITY_EVEN 01531 * @arg @ref LL_I2S_PRESCALER_PARITY_ODD 01532 */ 01533 __STATIC_INLINE uint32_t LL_I2S_GetPrescalerParity(SPI_TypeDef *SPIx) 01534 { 01535 return (uint32_t)(READ_BIT(SPIx->I2SPR, SPI_I2SPR_ODD) >> 8U); 01536 } 01537 01538 /** 01539 * @brief Enable the master clock output (Pin MCK) 01540 * @rmtoll I2SPR MCKOE LL_I2S_EnableMasterClock 01541 * @param SPIx SPI Instance 01542 * @retval None 01543 */ 01544 __STATIC_INLINE void LL_I2S_EnableMasterClock(SPI_TypeDef *SPIx) 01545 { 01546 SET_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE); 01547 } 01548 01549 /** 01550 * @brief Disable the master clock output (Pin MCK) 01551 * @rmtoll I2SPR MCKOE LL_I2S_DisableMasterClock 01552 * @param SPIx SPI Instance 01553 * @retval None 01554 */ 01555 __STATIC_INLINE void LL_I2S_DisableMasterClock(SPI_TypeDef *SPIx) 01556 { 01557 CLEAR_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE); 01558 } 01559 01560 /** 01561 * @brief Check if the master clock output (Pin MCK) is enabled 01562 * @rmtoll I2SPR MCKOE LL_I2S_IsEnabledMasterClock 01563 * @param SPIx SPI Instance 01564 * @retval State of bit (1 or 0). 01565 */ 01566 __STATIC_INLINE uint32_t LL_I2S_IsEnabledMasterClock(SPI_TypeDef *SPIx) 01567 { 01568 return ((READ_BIT(SPIx->I2SPR, SPI_I2SPR_MCKOE) == (SPI_I2SPR_MCKOE)) ? 1UL : 0UL); 01569 } 01570 01571 /** 01572 * @} 01573 */ 01574 01575 /** @defgroup I2S_LL_EF_FLAG FLAG Management 01576 * @{ 01577 */ 01578 01579 /** 01580 * @brief Check if Rx buffer is not empty 01581 * @rmtoll SR RXNE LL_I2S_IsActiveFlag_RXNE 01582 * @param SPIx SPI Instance 01583 * @retval State of bit (1 or 0). 01584 */ 01585 __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_RXNE(SPI_TypeDef *SPIx) 01586 { 01587 return LL_SPI_IsActiveFlag_RXNE(SPIx); 01588 } 01589 01590 /** 01591 * @brief Check if Tx buffer is empty 01592 * @rmtoll SR TXE LL_I2S_IsActiveFlag_TXE 01593 * @param SPIx SPI Instance 01594 * @retval State of bit (1 or 0). 01595 */ 01596 __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_TXE(SPI_TypeDef *SPIx) 01597 { 01598 return LL_SPI_IsActiveFlag_TXE(SPIx); 01599 } 01600 01601 /** 01602 * @brief Get busy flag 01603 * @rmtoll SR BSY LL_I2S_IsActiveFlag_BSY 01604 * @param SPIx SPI Instance 01605 * @retval State of bit (1 or 0). 01606 */ 01607 __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_BSY(SPI_TypeDef *SPIx) 01608 { 01609 return LL_SPI_IsActiveFlag_BSY(SPIx); 01610 } 01611 01612 /** 01613 * @brief Get overrun error flag 01614 * @rmtoll SR OVR LL_I2S_IsActiveFlag_OVR 01615 * @param SPIx SPI Instance 01616 * @retval State of bit (1 or 0). 01617 */ 01618 __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_OVR(SPI_TypeDef *SPIx) 01619 { 01620 return LL_SPI_IsActiveFlag_OVR(SPIx); 01621 } 01622 01623 /** 01624 * @brief Get underrun error flag 01625 * @rmtoll SR UDR LL_I2S_IsActiveFlag_UDR 01626 * @param SPIx SPI Instance 01627 * @retval State of bit (1 or 0). 01628 */ 01629 __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_UDR(SPI_TypeDef *SPIx) 01630 { 01631 return ((READ_BIT(SPIx->SR, SPI_SR_UDR) == (SPI_SR_UDR)) ? 1UL : 0UL); 01632 } 01633 01634 01635 /** 01636 * @brief Get channel side flag. 01637 * @note 0: Channel Left has to be transmitted or has been received\n 01638 * 1: Channel Right has to be transmitted or has been received\n 01639 * It has no significance in PCM mode. 01640 * @rmtoll SR CHSIDE LL_I2S_IsActiveFlag_CHSIDE 01641 * @param SPIx SPI Instance 01642 * @retval State of bit (1 or 0). 01643 */ 01644 __STATIC_INLINE uint32_t LL_I2S_IsActiveFlag_CHSIDE(SPI_TypeDef *SPIx) 01645 { 01646 return ((READ_BIT(SPIx->SR, SPI_SR_CHSIDE) == (SPI_SR_CHSIDE)) ? 1UL : 0UL); 01647 } 01648 01649 /** 01650 * @brief Clear overrun error flag 01651 * @rmtoll SR OVR LL_I2S_ClearFlag_OVR 01652 * @param SPIx SPI Instance 01653 * @retval None 01654 */ 01655 __STATIC_INLINE void LL_I2S_ClearFlag_OVR(SPI_TypeDef *SPIx) 01656 { 01657 LL_SPI_ClearFlag_OVR(SPIx); 01658 } 01659 01660 /** 01661 * @brief Clear underrun error flag 01662 * @rmtoll SR UDR LL_I2S_ClearFlag_UDR 01663 * @param SPIx SPI Instance 01664 * @retval None 01665 */ 01666 __STATIC_INLINE void LL_I2S_ClearFlag_UDR(SPI_TypeDef *SPIx) 01667 { 01668 __IO uint32_t tmpreg; 01669 tmpreg = SPIx->SR; 01670 (void)tmpreg; 01671 } 01672 01673 /** 01674 * @brief Clear frame format error flag 01675 * @rmtoll SR FRE LL_I2S_ClearFlag_FRE 01676 * @param SPIx SPI Instance 01677 * @retval None 01678 */ 01679 __STATIC_INLINE void LL_I2S_ClearFlag_FRE(SPI_TypeDef *SPIx) 01680 { 01681 LL_SPI_ClearFlag_FRE(SPIx); 01682 } 01683 01684 /** 01685 * @} 01686 */ 01687 01688 /** @defgroup I2S_LL_EF_IT Interrupt Management 01689 * @{ 01690 */ 01691 01692 /** 01693 * @brief Enable error IT 01694 * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode). 01695 * @rmtoll CR2 ERRIE LL_I2S_EnableIT_ERR 01696 * @param SPIx SPI Instance 01697 * @retval None 01698 */ 01699 __STATIC_INLINE void LL_I2S_EnableIT_ERR(SPI_TypeDef *SPIx) 01700 { 01701 LL_SPI_EnableIT_ERR(SPIx); 01702 } 01703 01704 /** 01705 * @brief Enable Rx buffer not empty IT 01706 * @rmtoll CR2 RXNEIE LL_I2S_EnableIT_RXNE 01707 * @param SPIx SPI Instance 01708 * @retval None 01709 */ 01710 __STATIC_INLINE void LL_I2S_EnableIT_RXNE(SPI_TypeDef *SPIx) 01711 { 01712 LL_SPI_EnableIT_RXNE(SPIx); 01713 } 01714 01715 /** 01716 * @brief Enable Tx buffer empty IT 01717 * @rmtoll CR2 TXEIE LL_I2S_EnableIT_TXE 01718 * @param SPIx SPI Instance 01719 * @retval None 01720 */ 01721 __STATIC_INLINE void LL_I2S_EnableIT_TXE(SPI_TypeDef *SPIx) 01722 { 01723 LL_SPI_EnableIT_TXE(SPIx); 01724 } 01725 01726 /** 01727 * @brief Disable error IT 01728 * @note This bit controls the generation of an interrupt when an error condition occurs (OVR, UDR and FRE in I2S mode). 01729 * @rmtoll CR2 ERRIE LL_I2S_DisableIT_ERR 01730 * @param SPIx SPI Instance 01731 * @retval None 01732 */ 01733 __STATIC_INLINE void LL_I2S_DisableIT_ERR(SPI_TypeDef *SPIx) 01734 { 01735 LL_SPI_DisableIT_ERR(SPIx); 01736 } 01737 01738 /** 01739 * @brief Disable Rx buffer not empty IT 01740 * @rmtoll CR2 RXNEIE LL_I2S_DisableIT_RXNE 01741 * @param SPIx SPI Instance 01742 * @retval None 01743 */ 01744 __STATIC_INLINE void LL_I2S_DisableIT_RXNE(SPI_TypeDef *SPIx) 01745 { 01746 LL_SPI_DisableIT_RXNE(SPIx); 01747 } 01748 01749 /** 01750 * @brief Disable Tx buffer empty IT 01751 * @rmtoll CR2 TXEIE LL_I2S_DisableIT_TXE 01752 * @param SPIx SPI Instance 01753 * @retval None 01754 */ 01755 __STATIC_INLINE void LL_I2S_DisableIT_TXE(SPI_TypeDef *SPIx) 01756 { 01757 LL_SPI_DisableIT_TXE(SPIx); 01758 } 01759 01760 /** 01761 * @brief Check if ERR IT is enabled 01762 * @rmtoll CR2 ERRIE LL_I2S_IsEnabledIT_ERR 01763 * @param SPIx SPI Instance 01764 * @retval State of bit (1 or 0). 01765 */ 01766 __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_ERR(SPI_TypeDef *SPIx) 01767 { 01768 return LL_SPI_IsEnabledIT_ERR(SPIx); 01769 } 01770 01771 /** 01772 * @brief Check if RXNE IT is enabled 01773 * @rmtoll CR2 RXNEIE LL_I2S_IsEnabledIT_RXNE 01774 * @param SPIx SPI Instance 01775 * @retval State of bit (1 or 0). 01776 */ 01777 __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_RXNE(SPI_TypeDef *SPIx) 01778 { 01779 return LL_SPI_IsEnabledIT_RXNE(SPIx); 01780 } 01781 01782 /** 01783 * @brief Check if TXE IT is enabled 01784 * @rmtoll CR2 TXEIE LL_I2S_IsEnabledIT_TXE 01785 * @param SPIx SPI Instance 01786 * @retval State of bit (1 or 0). 01787 */ 01788 __STATIC_INLINE uint32_t LL_I2S_IsEnabledIT_TXE(SPI_TypeDef *SPIx) 01789 { 01790 return LL_SPI_IsEnabledIT_TXE(SPIx); 01791 } 01792 01793 /** 01794 * @} 01795 */ 01796 01797 /** @defgroup I2S_LL_EF_DMA DMA Management 01798 * @{ 01799 */ 01800 01801 /** 01802 * @brief Enable DMA Rx 01803 * @rmtoll CR2 RXDMAEN LL_I2S_EnableDMAReq_RX 01804 * @param SPIx SPI Instance 01805 * @retval None 01806 */ 01807 __STATIC_INLINE void LL_I2S_EnableDMAReq_RX(SPI_TypeDef *SPIx) 01808 { 01809 LL_SPI_EnableDMAReq_RX(SPIx); 01810 } 01811 01812 /** 01813 * @brief Disable DMA Rx 01814 * @rmtoll CR2 RXDMAEN LL_I2S_DisableDMAReq_RX 01815 * @param SPIx SPI Instance 01816 * @retval None 01817 */ 01818 __STATIC_INLINE void LL_I2S_DisableDMAReq_RX(SPI_TypeDef *SPIx) 01819 { 01820 LL_SPI_DisableDMAReq_RX(SPIx); 01821 } 01822 01823 /** 01824 * @brief Check if DMA Rx is enabled 01825 * @rmtoll CR2 RXDMAEN LL_I2S_IsEnabledDMAReq_RX 01826 * @param SPIx SPI Instance 01827 * @retval State of bit (1 or 0). 01828 */ 01829 __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx) 01830 { 01831 return LL_SPI_IsEnabledDMAReq_RX(SPIx); 01832 } 01833 01834 /** 01835 * @brief Enable DMA Tx 01836 * @rmtoll CR2 TXDMAEN LL_I2S_EnableDMAReq_TX 01837 * @param SPIx SPI Instance 01838 * @retval None 01839 */ 01840 __STATIC_INLINE void LL_I2S_EnableDMAReq_TX(SPI_TypeDef *SPIx) 01841 { 01842 LL_SPI_EnableDMAReq_TX(SPIx); 01843 } 01844 01845 /** 01846 * @brief Disable DMA Tx 01847 * @rmtoll CR2 TXDMAEN LL_I2S_DisableDMAReq_TX 01848 * @param SPIx SPI Instance 01849 * @retval None 01850 */ 01851 __STATIC_INLINE void LL_I2S_DisableDMAReq_TX(SPI_TypeDef *SPIx) 01852 { 01853 LL_SPI_DisableDMAReq_TX(SPIx); 01854 } 01855 01856 /** 01857 * @brief Check if DMA Tx is enabled 01858 * @rmtoll CR2 TXDMAEN LL_I2S_IsEnabledDMAReq_TX 01859 * @param SPIx SPI Instance 01860 * @retval State of bit (1 or 0). 01861 */ 01862 __STATIC_INLINE uint32_t LL_I2S_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx) 01863 { 01864 return LL_SPI_IsEnabledDMAReq_TX(SPIx); 01865 } 01866 01867 /** 01868 * @} 01869 */ 01870 01871 /** @defgroup I2S_LL_EF_DATA DATA Management 01872 * @{ 01873 */ 01874 01875 /** 01876 * @brief Read 16-Bits in data register 01877 * @rmtoll DR DR LL_I2S_ReceiveData16 01878 * @param SPIx SPI Instance 01879 * @retval RxData Value between Min_Data=0x0000 and Max_Data=0xFFFF 01880 */ 01881 __STATIC_INLINE uint16_t LL_I2S_ReceiveData16(SPI_TypeDef *SPIx) 01882 { 01883 return LL_SPI_ReceiveData16(SPIx); 01884 } 01885 01886 /** 01887 * @brief Write 16-Bits in data register 01888 * @rmtoll DR DR LL_I2S_TransmitData16 01889 * @param SPIx SPI Instance 01890 * @param TxData Value between Min_Data=0x0000 and Max_Data=0xFFFF 01891 * @retval None 01892 */ 01893 __STATIC_INLINE void LL_I2S_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData) 01894 { 01895 LL_SPI_TransmitData16(SPIx, TxData); 01896 } 01897 01898 /** 01899 * @} 01900 */ 01901 01902 #if defined(USE_FULL_LL_DRIVER) 01903 /** @defgroup I2S_LL_EF_Init Initialization and de-initialization functions 01904 * @{ 01905 */ 01906 01907 ErrorStatus LL_I2S_DeInit(SPI_TypeDef *SPIx); 01908 ErrorStatus LL_I2S_Init(SPI_TypeDef *SPIx, LL_I2S_InitTypeDef *I2S_InitStruct); 01909 void LL_I2S_StructInit(LL_I2S_InitTypeDef *I2S_InitStruct); 01910 void LL_I2S_ConfigPrescaler(SPI_TypeDef *SPIx, uint32_t PrescalerLinear, uint32_t PrescalerParity); 01911 01912 /** 01913 * @} 01914 */ 01915 #endif /* USE_FULL_LL_DRIVER */ 01916 01917 /** 01918 * @} 01919 */ 01920 01921 /** 01922 * @} 01923 */ 01924 #endif /* SPI_I2S_SUPPORT */ 01925 01926 #endif /* defined (SPI1) || defined (SPI2) || defined (SPI3) */ 01927 01928 /** 01929 * @} 01930 */ 01931 01932 #ifdef __cplusplus 01933 } 01934 #endif 01935 01936 #endif /* STM32F1xx_LL_SPI_H */ 01937 01938 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/