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