STM32L443xx HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32l4xx_ll_spi.h 00004 * @author MCD Application Team 00005 * @brief Header file of SPI LL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * Copyright (c) 2017 STMicroelectronics. 00010 * All rights reserved. 00011 * 00012 * This software is licensed under terms that can be found in the LICENSE file 00013 * in the root directory of this software component. 00014 * If no LICENSE file comes with this software, it is provided AS-IS. 00015 * 00016 ****************************************************************************** 00017 */ 00018 00019 /* Define to prevent recursive inclusion -------------------------------------*/ 00020 #ifndef STM32L4xx_LL_SPI_H 00021 #define STM32L4xx_LL_SPI_H 00022 00023 #ifdef __cplusplus 00024 extern "C" { 00025 #endif 00026 00027 /* Includes ------------------------------------------------------------------*/ 00028 #include "stm32l4xx.h" 00029 00030 /** @addtogroup STM32L4xx_LL_Driver 00031 * @{ 00032 */ 00033 00034 #if defined (SPI1) || defined (SPI2) || defined (SPI3) 00035 00036 /** @defgroup SPI_LL SPI 00037 * @{ 00038 */ 00039 00040 /* Private types -------------------------------------------------------------*/ 00041 /* Private variables ---------------------------------------------------------*/ 00042 /* Private macros ------------------------------------------------------------*/ 00043 00044 /* Exported types ------------------------------------------------------------*/ 00045 #if defined(USE_FULL_LL_DRIVER) 00046 /** @defgroup SPI_LL_ES_INIT SPI Exported Init structure 00047 * @{ 00048 */ 00049 00050 /** 00051 * @brief SPI Init structures definition 00052 */ 00053 typedef struct 00054 { 00055 uint32_t TransferDirection; /*!< Specifies the SPI unidirectional or bidirectional data mode. 00056 This parameter can be a value of @ref SPI_LL_EC_TRANSFER_MODE. 00057 00058 This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferDirection().*/ 00059 00060 uint32_t Mode; /*!< Specifies the SPI mode (Master/Slave). 00061 This parameter can be a value of @ref SPI_LL_EC_MODE. 00062 00063 This feature can be modified afterwards using unitary function @ref LL_SPI_SetMode().*/ 00064 00065 uint32_t DataWidth; /*!< Specifies the SPI data width. 00066 This parameter can be a value of @ref SPI_LL_EC_DATAWIDTH. 00067 00068 This feature can be modified afterwards using unitary function @ref LL_SPI_SetDataWidth().*/ 00069 00070 uint32_t ClockPolarity; /*!< Specifies the serial clock steady state. 00071 This parameter can be a value of @ref SPI_LL_EC_POLARITY. 00072 00073 This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPolarity().*/ 00074 00075 uint32_t ClockPhase; /*!< Specifies the clock active edge for the bit capture. 00076 This parameter can be a value of @ref SPI_LL_EC_PHASE. 00077 00078 This feature can be modified afterwards using unitary function @ref LL_SPI_SetClockPhase().*/ 00079 00080 uint32_t NSS; /*!< Specifies whether the NSS signal is managed by hardware (NSS pin) or by software using the SSI bit. 00081 This parameter can be a value of @ref SPI_LL_EC_NSS_MODE. 00082 00083 This feature can be modified afterwards using unitary function @ref LL_SPI_SetNSSMode().*/ 00084 00085 uint32_t BaudRate; /*!< Specifies the BaudRate prescaler value which will be used to configure the transmit and receive SCK clock. 00086 This parameter can be a value of @ref SPI_LL_EC_BAUDRATEPRESCALER. 00087 @note The communication clock is derived from the master clock. The slave clock does not need to be set. 00088 00089 This feature can be modified afterwards using unitary function @ref LL_SPI_SetBaudRatePrescaler().*/ 00090 00091 uint32_t BitOrder; /*!< Specifies whether data transfers start from MSB or LSB bit. 00092 This parameter can be a value of @ref SPI_LL_EC_BIT_ORDER. 00093 00094 This feature can be modified afterwards using unitary function @ref LL_SPI_SetTransferBitOrder().*/ 00095 00096 uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not. 00097 This parameter can be a value of @ref SPI_LL_EC_CRC_CALCULATION. 00098 00099 This feature can be modified afterwards using unitary functions @ref LL_SPI_EnableCRC() and @ref LL_SPI_DisableCRC().*/ 00100 00101 uint32_t CRCPoly; /*!< Specifies the polynomial used for the CRC calculation. 00102 This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF. 00103 00104 This feature can be modified afterwards using unitary function @ref LL_SPI_SetCRCPolynomial().*/ 00105 00106 } LL_SPI_InitTypeDef; 00107 00108 /** 00109 * @} 00110 */ 00111 #endif /* USE_FULL_LL_DRIVER */ 00112 00113 /* Exported constants --------------------------------------------------------*/ 00114 /** @defgroup SPI_LL_Exported_Constants SPI Exported Constants 00115 * @{ 00116 */ 00117 00118 /** @defgroup SPI_LL_EC_GET_FLAG Get Flags Defines 00119 * @brief Flags defines which can be used with LL_SPI_ReadReg function 00120 * @{ 00121 */ 00122 #define LL_SPI_SR_RXNE SPI_SR_RXNE /*!< Rx buffer not empty flag */ 00123 #define LL_SPI_SR_TXE SPI_SR_TXE /*!< Tx buffer empty flag */ 00124 #define LL_SPI_SR_BSY SPI_SR_BSY /*!< Busy flag */ 00125 #define LL_SPI_SR_CRCERR SPI_SR_CRCERR /*!< CRC error flag */ 00126 #define LL_SPI_SR_MODF SPI_SR_MODF /*!< Mode fault flag */ 00127 #define LL_SPI_SR_OVR SPI_SR_OVR /*!< Overrun flag */ 00128 #define LL_SPI_SR_FRE SPI_SR_FRE /*!< TI mode frame format error flag */ 00129 /** 00130 * @} 00131 */ 00132 00133 /** @defgroup SPI_LL_EC_IT IT Defines 00134 * @brief IT defines which can be used with LL_SPI_ReadReg and LL_SPI_WriteReg functions 00135 * @{ 00136 */ 00137 #define LL_SPI_CR2_RXNEIE SPI_CR2_RXNEIE /*!< Rx buffer not empty interrupt enable */ 00138 #define LL_SPI_CR2_TXEIE SPI_CR2_TXEIE /*!< Tx buffer empty interrupt enable */ 00139 #define LL_SPI_CR2_ERRIE SPI_CR2_ERRIE /*!< Error interrupt enable */ 00140 /** 00141 * @} 00142 */ 00143 00144 /** @defgroup SPI_LL_EC_MODE Operation Mode 00145 * @{ 00146 */ 00147 #define LL_SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI) /*!< Master configuration */ 00148 #define LL_SPI_MODE_SLAVE 0x00000000U /*!< Slave configuration */ 00149 /** 00150 * @} 00151 */ 00152 00153 /** @defgroup SPI_LL_EC_PROTOCOL Serial Protocol 00154 * @{ 00155 */ 00156 #define LL_SPI_PROTOCOL_MOTOROLA 0x00000000U /*!< Motorola mode. Used as default value */ 00157 #define LL_SPI_PROTOCOL_TI (SPI_CR2_FRF) /*!< TI mode */ 00158 /** 00159 * @} 00160 */ 00161 00162 /** @defgroup SPI_LL_EC_PHASE Clock Phase 00163 * @{ 00164 */ 00165 #define LL_SPI_PHASE_1EDGE 0x00000000U /*!< First clock transition is the first data capture edge */ 00166 #define LL_SPI_PHASE_2EDGE (SPI_CR1_CPHA) /*!< Second clock transition is the first data capture edge */ 00167 /** 00168 * @} 00169 */ 00170 00171 /** @defgroup SPI_LL_EC_POLARITY Clock Polarity 00172 * @{ 00173 */ 00174 #define LL_SPI_POLARITY_LOW 0x00000000U /*!< Clock to 0 when idle */ 00175 #define LL_SPI_POLARITY_HIGH (SPI_CR1_CPOL) /*!< Clock to 1 when idle */ 00176 /** 00177 * @} 00178 */ 00179 00180 /** @defgroup SPI_LL_EC_BAUDRATEPRESCALER Baud Rate Prescaler 00181 * @{ 00182 */ 00183 #define LL_SPI_BAUDRATEPRESCALER_DIV2 0x00000000U /*!< BaudRate control equal to fPCLK/2 */ 00184 #define LL_SPI_BAUDRATEPRESCALER_DIV4 (SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/4 */ 00185 #define LL_SPI_BAUDRATEPRESCALER_DIV8 (SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/8 */ 00186 #define LL_SPI_BAUDRATEPRESCALER_DIV16 (SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/16 */ 00187 #define LL_SPI_BAUDRATEPRESCALER_DIV32 (SPI_CR1_BR_2) /*!< BaudRate control equal to fPCLK/32 */ 00188 #define LL_SPI_BAUDRATEPRESCALER_DIV64 (SPI_CR1_BR_2 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/64 */ 00189 #define LL_SPI_BAUDRATEPRESCALER_DIV128 (SPI_CR1_BR_2 | SPI_CR1_BR_1) /*!< BaudRate control equal to fPCLK/128 */ 00190 #define LL_SPI_BAUDRATEPRESCALER_DIV256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0) /*!< BaudRate control equal to fPCLK/256 */ 00191 /** 00192 * @} 00193 */ 00194 00195 /** @defgroup SPI_LL_EC_BIT_ORDER Transmission Bit Order 00196 * @{ 00197 */ 00198 #define LL_SPI_LSB_FIRST (SPI_CR1_LSBFIRST) /*!< Data is transmitted/received with the LSB first */ 00199 #define LL_SPI_MSB_FIRST 0x00000000U /*!< Data is transmitted/received with the MSB first */ 00200 /** 00201 * @} 00202 */ 00203 00204 /** @defgroup SPI_LL_EC_TRANSFER_MODE Transfer Mode 00205 * @{ 00206 */ 00207 #define LL_SPI_FULL_DUPLEX 0x00000000U /*!< Full-Duplex mode. Rx and Tx transfer on 2 lines */ 00208 #define LL_SPI_SIMPLEX_RX (SPI_CR1_RXONLY) /*!< Simplex Rx mode. Rx transfer only on 1 line */ 00209 #define LL_SPI_HALF_DUPLEX_RX (SPI_CR1_BIDIMODE) /*!< Half-Duplex Rx mode. Rx transfer on 1 line */ 00210 #define LL_SPI_HALF_DUPLEX_TX (SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE) /*!< Half-Duplex Tx mode. Tx transfer on 1 line */ 00211 /** 00212 * @} 00213 */ 00214 00215 /** @defgroup SPI_LL_EC_NSS_MODE Slave Select Pin Mode 00216 * @{ 00217 */ 00218 #define LL_SPI_NSS_SOFT (SPI_CR1_SSM) /*!< NSS managed internally. NSS pin not used and free */ 00219 #define LL_SPI_NSS_HARD_INPUT 0x00000000U /*!< NSS pin used in Input. Only used in Master mode */ 00220 #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 */ 00221 /** 00222 * @} 00223 */ 00224 00225 /** @defgroup SPI_LL_EC_DATAWIDTH Datawidth 00226 * @{ 00227 */ 00228 #define LL_SPI_DATAWIDTH_4BIT (SPI_CR2_DS_0 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 4 bits */ 00229 #define LL_SPI_DATAWIDTH_5BIT (SPI_CR2_DS_2) /*!< Data length for SPI transfer: 5 bits */ 00230 #define LL_SPI_DATAWIDTH_6BIT (SPI_CR2_DS_2 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 6 bits */ 00231 #define LL_SPI_DATAWIDTH_7BIT (SPI_CR2_DS_2 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 7 bits */ 00232 #define LL_SPI_DATAWIDTH_8BIT (SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 8 bits */ 00233 #define LL_SPI_DATAWIDTH_9BIT (SPI_CR2_DS_3) /*!< Data length for SPI transfer: 9 bits */ 00234 #define LL_SPI_DATAWIDTH_10BIT (SPI_CR2_DS_3 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 10 bits */ 00235 #define LL_SPI_DATAWIDTH_11BIT (SPI_CR2_DS_3 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 11 bits */ 00236 #define LL_SPI_DATAWIDTH_12BIT (SPI_CR2_DS_3 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 12 bits */ 00237 #define LL_SPI_DATAWIDTH_13BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2) /*!< Data length for SPI transfer: 13 bits */ 00238 #define LL_SPI_DATAWIDTH_14BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 14 bits */ 00239 #define LL_SPI_DATAWIDTH_15BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1) /*!< Data length for SPI transfer: 15 bits */ 00240 #define LL_SPI_DATAWIDTH_16BIT (SPI_CR2_DS_3 | SPI_CR2_DS_2 | SPI_CR2_DS_1 | SPI_CR2_DS_0) /*!< Data length for SPI transfer: 16 bits */ 00241 /** 00242 * @} 00243 */ 00244 #if defined(USE_FULL_LL_DRIVER) 00245 00246 /** @defgroup SPI_LL_EC_CRC_CALCULATION CRC Calculation 00247 * @{ 00248 */ 00249 #define LL_SPI_CRCCALCULATION_DISABLE 0x00000000U /*!< CRC calculation disabled */ 00250 #define LL_SPI_CRCCALCULATION_ENABLE (SPI_CR1_CRCEN) /*!< CRC calculation enabled */ 00251 /** 00252 * @} 00253 */ 00254 #endif /* USE_FULL_LL_DRIVER */ 00255 00256 /** @defgroup SPI_LL_EC_CRC_LENGTH CRC Length 00257 * @{ 00258 */ 00259 #define LL_SPI_CRC_8BIT 0x00000000U /*!< 8-bit CRC length */ 00260 #define LL_SPI_CRC_16BIT (SPI_CR1_CRCL) /*!< 16-bit CRC length */ 00261 /** 00262 * @} 00263 */ 00264 00265 /** @defgroup SPI_LL_EC_RX_FIFO_TH RX FIFO Threshold 00266 * @{ 00267 */ 00268 #define LL_SPI_RX_FIFO_TH_HALF 0x00000000U /*!< RXNE event is generated if FIFO level is greater than or equal to 1/2 (16-bit) */ 00269 #define LL_SPI_RX_FIFO_TH_QUARTER (SPI_CR2_FRXTH) /*!< RXNE event is generated if FIFO level is greater than or equal to 1/4 (8-bit) */ 00270 /** 00271 * @} 00272 */ 00273 00274 /** @defgroup SPI_LL_EC_RX_FIFO RX FIFO Level 00275 * @{ 00276 */ 00277 #define LL_SPI_RX_FIFO_EMPTY 0x00000000U /*!< FIFO reception empty */ 00278 #define LL_SPI_RX_FIFO_QUARTER_FULL (SPI_SR_FRLVL_0) /*!< FIFO reception 1/4 */ 00279 #define LL_SPI_RX_FIFO_HALF_FULL (SPI_SR_FRLVL_1) /*!< FIFO reception 1/2 */ 00280 #define LL_SPI_RX_FIFO_FULL (SPI_SR_FRLVL_1 | SPI_SR_FRLVL_0) /*!< FIFO reception full */ 00281 /** 00282 * @} 00283 */ 00284 00285 /** @defgroup SPI_LL_EC_TX_FIFO TX FIFO Level 00286 * @{ 00287 */ 00288 #define LL_SPI_TX_FIFO_EMPTY 0x00000000U /*!< FIFO transmission empty */ 00289 #define LL_SPI_TX_FIFO_QUARTER_FULL (SPI_SR_FTLVL_0) /*!< FIFO transmission 1/4 */ 00290 #define LL_SPI_TX_FIFO_HALF_FULL (SPI_SR_FTLVL_1) /*!< FIFO transmission 1/2 */ 00291 #define LL_SPI_TX_FIFO_FULL (SPI_SR_FTLVL_1 | SPI_SR_FTLVL_0) /*!< FIFO transmission full */ 00292 /** 00293 * @} 00294 */ 00295 00296 /** @defgroup SPI_LL_EC_DMA_PARITY DMA Parity 00297 * @{ 00298 */ 00299 #define LL_SPI_DMA_PARITY_EVEN 0x00000000U /*!< Select DMA parity Even */ 00300 #define LL_SPI_DMA_PARITY_ODD 0x00000001U /*!< Select DMA parity Odd */ 00301 00302 /** 00303 * @} 00304 */ 00305 00306 /** 00307 * @} 00308 */ 00309 00310 /* Exported macro ------------------------------------------------------------*/ 00311 /** @defgroup SPI_LL_Exported_Macros SPI Exported Macros 00312 * @{ 00313 */ 00314 00315 /** @defgroup SPI_LL_EM_WRITE_READ Common Write and read registers Macros 00316 * @{ 00317 */ 00318 00319 /** 00320 * @brief Write a value in SPI register 00321 * @param __INSTANCE__ SPI Instance 00322 * @param __REG__ Register to be written 00323 * @param __VALUE__ Value to be written in the register 00324 * @retval None 00325 */ 00326 #define LL_SPI_WriteReg(__INSTANCE__, __REG__, __VALUE__) WRITE_REG(__INSTANCE__->__REG__, (__VALUE__)) 00327 00328 /** 00329 * @brief Read a value in SPI register 00330 * @param __INSTANCE__ SPI Instance 00331 * @param __REG__ Register to be read 00332 * @retval Register value 00333 */ 00334 #define LL_SPI_ReadReg(__INSTANCE__, __REG__) READ_REG(__INSTANCE__->__REG__) 00335 /** 00336 * @} 00337 */ 00338 00339 /** 00340 * @} 00341 */ 00342 00343 /* Exported functions --------------------------------------------------------*/ 00344 /** @defgroup SPI_LL_Exported_Functions SPI Exported Functions 00345 * @{ 00346 */ 00347 00348 /** @defgroup SPI_LL_EF_Configuration Configuration 00349 * @{ 00350 */ 00351 00352 /** 00353 * @brief Enable SPI peripheral 00354 * @rmtoll CR1 SPE LL_SPI_Enable 00355 * @param SPIx SPI Instance 00356 * @retval None 00357 */ 00358 __STATIC_INLINE void LL_SPI_Enable(SPI_TypeDef *SPIx) 00359 { 00360 SET_BIT(SPIx->CR1, SPI_CR1_SPE); 00361 } 00362 00363 /** 00364 * @brief Disable SPI peripheral 00365 * @note When disabling the SPI, follow the procedure described in the Reference Manual. 00366 * @rmtoll CR1 SPE LL_SPI_Disable 00367 * @param SPIx SPI Instance 00368 * @retval None 00369 */ 00370 __STATIC_INLINE void LL_SPI_Disable(SPI_TypeDef *SPIx) 00371 { 00372 CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE); 00373 } 00374 00375 /** 00376 * @brief Check if SPI peripheral is enabled 00377 * @rmtoll CR1 SPE LL_SPI_IsEnabled 00378 * @param SPIx SPI Instance 00379 * @retval State of bit (1 or 0). 00380 */ 00381 __STATIC_INLINE uint32_t LL_SPI_IsEnabled(SPI_TypeDef *SPIx) 00382 { 00383 return ((READ_BIT(SPIx->CR1, SPI_CR1_SPE) == (SPI_CR1_SPE)) ? 1UL : 0UL); 00384 } 00385 00386 /** 00387 * @brief Set SPI operation mode to Master or Slave 00388 * @note This bit should not be changed when communication is ongoing. 00389 * @rmtoll CR1 MSTR LL_SPI_SetMode\n 00390 * CR1 SSI LL_SPI_SetMode 00391 * @param SPIx SPI Instance 00392 * @param Mode This parameter can be one of the following values: 00393 * @arg @ref LL_SPI_MODE_MASTER 00394 * @arg @ref LL_SPI_MODE_SLAVE 00395 * @retval None 00396 */ 00397 __STATIC_INLINE void LL_SPI_SetMode(SPI_TypeDef *SPIx, uint32_t Mode) 00398 { 00399 MODIFY_REG(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI, Mode); 00400 } 00401 00402 /** 00403 * @brief Get SPI operation mode (Master or Slave) 00404 * @rmtoll CR1 MSTR LL_SPI_GetMode\n 00405 * CR1 SSI LL_SPI_GetMode 00406 * @param SPIx SPI Instance 00407 * @retval Returned value can be one of the following values: 00408 * @arg @ref LL_SPI_MODE_MASTER 00409 * @arg @ref LL_SPI_MODE_SLAVE 00410 */ 00411 __STATIC_INLINE uint32_t LL_SPI_GetMode(SPI_TypeDef *SPIx) 00412 { 00413 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_MSTR | SPI_CR1_SSI)); 00414 } 00415 00416 /** 00417 * @brief Set serial protocol used 00418 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00419 * @rmtoll CR2 FRF LL_SPI_SetStandard 00420 * @param SPIx SPI Instance 00421 * @param Standard This parameter can be one of the following values: 00422 * @arg @ref LL_SPI_PROTOCOL_MOTOROLA 00423 * @arg @ref LL_SPI_PROTOCOL_TI 00424 * @retval None 00425 */ 00426 __STATIC_INLINE void LL_SPI_SetStandard(SPI_TypeDef *SPIx, uint32_t Standard) 00427 { 00428 MODIFY_REG(SPIx->CR2, SPI_CR2_FRF, Standard); 00429 } 00430 00431 /** 00432 * @brief Get serial protocol used 00433 * @rmtoll CR2 FRF LL_SPI_GetStandard 00434 * @param SPIx SPI Instance 00435 * @retval Returned value can be one of the following values: 00436 * @arg @ref LL_SPI_PROTOCOL_MOTOROLA 00437 * @arg @ref LL_SPI_PROTOCOL_TI 00438 */ 00439 __STATIC_INLINE uint32_t LL_SPI_GetStandard(SPI_TypeDef *SPIx) 00440 { 00441 return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_FRF)); 00442 } 00443 00444 /** 00445 * @brief Set clock phase 00446 * @note This bit should not be changed when communication is ongoing. 00447 * This bit is not used in SPI TI mode. 00448 * @rmtoll CR1 CPHA LL_SPI_SetClockPhase 00449 * @param SPIx SPI Instance 00450 * @param ClockPhase This parameter can be one of the following values: 00451 * @arg @ref LL_SPI_PHASE_1EDGE 00452 * @arg @ref LL_SPI_PHASE_2EDGE 00453 * @retval None 00454 */ 00455 __STATIC_INLINE void LL_SPI_SetClockPhase(SPI_TypeDef *SPIx, uint32_t ClockPhase) 00456 { 00457 MODIFY_REG(SPIx->CR1, SPI_CR1_CPHA, ClockPhase); 00458 } 00459 00460 /** 00461 * @brief Get clock phase 00462 * @rmtoll CR1 CPHA LL_SPI_GetClockPhase 00463 * @param SPIx SPI Instance 00464 * @retval Returned value can be one of the following values: 00465 * @arg @ref LL_SPI_PHASE_1EDGE 00466 * @arg @ref LL_SPI_PHASE_2EDGE 00467 */ 00468 __STATIC_INLINE uint32_t LL_SPI_GetClockPhase(SPI_TypeDef *SPIx) 00469 { 00470 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPHA)); 00471 } 00472 00473 /** 00474 * @brief Set clock polarity 00475 * @note This bit should not be changed when communication is ongoing. 00476 * This bit is not used in SPI TI mode. 00477 * @rmtoll CR1 CPOL LL_SPI_SetClockPolarity 00478 * @param SPIx SPI Instance 00479 * @param ClockPolarity This parameter can be one of the following values: 00480 * @arg @ref LL_SPI_POLARITY_LOW 00481 * @arg @ref LL_SPI_POLARITY_HIGH 00482 * @retval None 00483 */ 00484 __STATIC_INLINE void LL_SPI_SetClockPolarity(SPI_TypeDef *SPIx, uint32_t ClockPolarity) 00485 { 00486 MODIFY_REG(SPIx->CR1, SPI_CR1_CPOL, ClockPolarity); 00487 } 00488 00489 /** 00490 * @brief Get clock polarity 00491 * @rmtoll CR1 CPOL LL_SPI_GetClockPolarity 00492 * @param SPIx SPI Instance 00493 * @retval Returned value can be one of the following values: 00494 * @arg @ref LL_SPI_POLARITY_LOW 00495 * @arg @ref LL_SPI_POLARITY_HIGH 00496 */ 00497 __STATIC_INLINE uint32_t LL_SPI_GetClockPolarity(SPI_TypeDef *SPIx) 00498 { 00499 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CPOL)); 00500 } 00501 00502 /** 00503 * @brief Set baud rate prescaler 00504 * @note These bits should not be changed when communication is ongoing. SPI BaudRate = fPCLK/Prescaler. 00505 * @rmtoll CR1 BR LL_SPI_SetBaudRatePrescaler 00506 * @param SPIx SPI Instance 00507 * @param BaudRate This parameter can be one of the following values: 00508 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2 00509 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4 00510 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8 00511 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16 00512 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32 00513 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64 00514 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128 00515 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256 00516 * @retval None 00517 */ 00518 __STATIC_INLINE void LL_SPI_SetBaudRatePrescaler(SPI_TypeDef *SPIx, uint32_t BaudRate) 00519 { 00520 MODIFY_REG(SPIx->CR1, SPI_CR1_BR, BaudRate); 00521 } 00522 00523 /** 00524 * @brief Get baud rate prescaler 00525 * @rmtoll CR1 BR LL_SPI_GetBaudRatePrescaler 00526 * @param SPIx SPI Instance 00527 * @retval Returned value can be one of the following values: 00528 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV2 00529 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV4 00530 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV8 00531 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV16 00532 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV32 00533 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV64 00534 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV128 00535 * @arg @ref LL_SPI_BAUDRATEPRESCALER_DIV256 00536 */ 00537 __STATIC_INLINE uint32_t LL_SPI_GetBaudRatePrescaler(SPI_TypeDef *SPIx) 00538 { 00539 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_BR)); 00540 } 00541 00542 /** 00543 * @brief Set transfer bit order 00544 * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode. 00545 * @rmtoll CR1 LSBFIRST LL_SPI_SetTransferBitOrder 00546 * @param SPIx SPI Instance 00547 * @param BitOrder This parameter can be one of the following values: 00548 * @arg @ref LL_SPI_LSB_FIRST 00549 * @arg @ref LL_SPI_MSB_FIRST 00550 * @retval None 00551 */ 00552 __STATIC_INLINE void LL_SPI_SetTransferBitOrder(SPI_TypeDef *SPIx, uint32_t BitOrder) 00553 { 00554 MODIFY_REG(SPIx->CR1, SPI_CR1_LSBFIRST, BitOrder); 00555 } 00556 00557 /** 00558 * @brief Get transfer bit order 00559 * @rmtoll CR1 LSBFIRST LL_SPI_GetTransferBitOrder 00560 * @param SPIx SPI Instance 00561 * @retval Returned value can be one of the following values: 00562 * @arg @ref LL_SPI_LSB_FIRST 00563 * @arg @ref LL_SPI_MSB_FIRST 00564 */ 00565 __STATIC_INLINE uint32_t LL_SPI_GetTransferBitOrder(SPI_TypeDef *SPIx) 00566 { 00567 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_LSBFIRST)); 00568 } 00569 00570 /** 00571 * @brief Set transfer direction mode 00572 * @note For Half-Duplex mode, Rx Direction is set by default. 00573 * In master mode, the MOSI pin is used and in slave mode, the MISO pin is used for Half-Duplex. 00574 * @rmtoll CR1 RXONLY LL_SPI_SetTransferDirection\n 00575 * CR1 BIDIMODE LL_SPI_SetTransferDirection\n 00576 * CR1 BIDIOE LL_SPI_SetTransferDirection 00577 * @param SPIx SPI Instance 00578 * @param TransferDirection This parameter can be one of the following values: 00579 * @arg @ref LL_SPI_FULL_DUPLEX 00580 * @arg @ref LL_SPI_SIMPLEX_RX 00581 * @arg @ref LL_SPI_HALF_DUPLEX_RX 00582 * @arg @ref LL_SPI_HALF_DUPLEX_TX 00583 * @retval None 00584 */ 00585 __STATIC_INLINE void LL_SPI_SetTransferDirection(SPI_TypeDef *SPIx, uint32_t TransferDirection) 00586 { 00587 MODIFY_REG(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE, TransferDirection); 00588 } 00589 00590 /** 00591 * @brief Get transfer direction mode 00592 * @rmtoll CR1 RXONLY LL_SPI_GetTransferDirection\n 00593 * CR1 BIDIMODE LL_SPI_GetTransferDirection\n 00594 * CR1 BIDIOE LL_SPI_GetTransferDirection 00595 * @param SPIx SPI Instance 00596 * @retval Returned value can be one of the following values: 00597 * @arg @ref LL_SPI_FULL_DUPLEX 00598 * @arg @ref LL_SPI_SIMPLEX_RX 00599 * @arg @ref LL_SPI_HALF_DUPLEX_RX 00600 * @arg @ref LL_SPI_HALF_DUPLEX_TX 00601 */ 00602 __STATIC_INLINE uint32_t LL_SPI_GetTransferDirection(SPI_TypeDef *SPIx) 00603 { 00604 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_RXONLY | SPI_CR1_BIDIMODE | SPI_CR1_BIDIOE)); 00605 } 00606 00607 /** 00608 * @brief Set frame data width 00609 * @rmtoll CR2 DS LL_SPI_SetDataWidth 00610 * @param SPIx SPI Instance 00611 * @param DataWidth This parameter can be one of the following values: 00612 * @arg @ref LL_SPI_DATAWIDTH_4BIT 00613 * @arg @ref LL_SPI_DATAWIDTH_5BIT 00614 * @arg @ref LL_SPI_DATAWIDTH_6BIT 00615 * @arg @ref LL_SPI_DATAWIDTH_7BIT 00616 * @arg @ref LL_SPI_DATAWIDTH_8BIT 00617 * @arg @ref LL_SPI_DATAWIDTH_9BIT 00618 * @arg @ref LL_SPI_DATAWIDTH_10BIT 00619 * @arg @ref LL_SPI_DATAWIDTH_11BIT 00620 * @arg @ref LL_SPI_DATAWIDTH_12BIT 00621 * @arg @ref LL_SPI_DATAWIDTH_13BIT 00622 * @arg @ref LL_SPI_DATAWIDTH_14BIT 00623 * @arg @ref LL_SPI_DATAWIDTH_15BIT 00624 * @arg @ref LL_SPI_DATAWIDTH_16BIT 00625 * @retval None 00626 */ 00627 __STATIC_INLINE void LL_SPI_SetDataWidth(SPI_TypeDef *SPIx, uint32_t DataWidth) 00628 { 00629 MODIFY_REG(SPIx->CR2, SPI_CR2_DS, DataWidth); 00630 } 00631 00632 /** 00633 * @brief Get frame data width 00634 * @rmtoll CR2 DS LL_SPI_GetDataWidth 00635 * @param SPIx SPI Instance 00636 * @retval Returned value can be one of the following values: 00637 * @arg @ref LL_SPI_DATAWIDTH_4BIT 00638 * @arg @ref LL_SPI_DATAWIDTH_5BIT 00639 * @arg @ref LL_SPI_DATAWIDTH_6BIT 00640 * @arg @ref LL_SPI_DATAWIDTH_7BIT 00641 * @arg @ref LL_SPI_DATAWIDTH_8BIT 00642 * @arg @ref LL_SPI_DATAWIDTH_9BIT 00643 * @arg @ref LL_SPI_DATAWIDTH_10BIT 00644 * @arg @ref LL_SPI_DATAWIDTH_11BIT 00645 * @arg @ref LL_SPI_DATAWIDTH_12BIT 00646 * @arg @ref LL_SPI_DATAWIDTH_13BIT 00647 * @arg @ref LL_SPI_DATAWIDTH_14BIT 00648 * @arg @ref LL_SPI_DATAWIDTH_15BIT 00649 * @arg @ref LL_SPI_DATAWIDTH_16BIT 00650 */ 00651 __STATIC_INLINE uint32_t LL_SPI_GetDataWidth(SPI_TypeDef *SPIx) 00652 { 00653 return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_DS)); 00654 } 00655 00656 /** 00657 * @brief Set threshold of RXFIFO that triggers an RXNE event 00658 * @rmtoll CR2 FRXTH LL_SPI_SetRxFIFOThreshold 00659 * @param SPIx SPI Instance 00660 * @param Threshold This parameter can be one of the following values: 00661 * @arg @ref LL_SPI_RX_FIFO_TH_HALF 00662 * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER 00663 * @retval None 00664 */ 00665 __STATIC_INLINE void LL_SPI_SetRxFIFOThreshold(SPI_TypeDef *SPIx, uint32_t Threshold) 00666 { 00667 MODIFY_REG(SPIx->CR2, SPI_CR2_FRXTH, Threshold); 00668 } 00669 00670 /** 00671 * @brief Get threshold of RXFIFO that triggers an RXNE event 00672 * @rmtoll CR2 FRXTH LL_SPI_GetRxFIFOThreshold 00673 * @param SPIx SPI Instance 00674 * @retval Returned value can be one of the following values: 00675 * @arg @ref LL_SPI_RX_FIFO_TH_HALF 00676 * @arg @ref LL_SPI_RX_FIFO_TH_QUARTER 00677 */ 00678 __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOThreshold(SPI_TypeDef *SPIx) 00679 { 00680 return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_FRXTH)); 00681 } 00682 00683 /** 00684 * @} 00685 */ 00686 00687 /** @defgroup SPI_LL_EF_CRC_Management CRC Management 00688 * @{ 00689 */ 00690 00691 /** 00692 * @brief Enable CRC 00693 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00694 * @rmtoll CR1 CRCEN LL_SPI_EnableCRC 00695 * @param SPIx SPI Instance 00696 * @retval None 00697 */ 00698 __STATIC_INLINE void LL_SPI_EnableCRC(SPI_TypeDef *SPIx) 00699 { 00700 SET_BIT(SPIx->CR1, SPI_CR1_CRCEN); 00701 } 00702 00703 /** 00704 * @brief Disable CRC 00705 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00706 * @rmtoll CR1 CRCEN LL_SPI_DisableCRC 00707 * @param SPIx SPI Instance 00708 * @retval None 00709 */ 00710 __STATIC_INLINE void LL_SPI_DisableCRC(SPI_TypeDef *SPIx) 00711 { 00712 CLEAR_BIT(SPIx->CR1, SPI_CR1_CRCEN); 00713 } 00714 00715 /** 00716 * @brief Check if CRC is enabled 00717 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00718 * @rmtoll CR1 CRCEN LL_SPI_IsEnabledCRC 00719 * @param SPIx SPI Instance 00720 * @retval State of bit (1 or 0). 00721 */ 00722 __STATIC_INLINE uint32_t LL_SPI_IsEnabledCRC(SPI_TypeDef *SPIx) 00723 { 00724 return ((READ_BIT(SPIx->CR1, SPI_CR1_CRCEN) == (SPI_CR1_CRCEN)) ? 1UL : 0UL); 00725 } 00726 00727 /** 00728 * @brief Set CRC Length 00729 * @note This bit should be written only when SPI is disabled (SPE = 0) for correct operation. 00730 * @rmtoll CR1 CRCL LL_SPI_SetCRCWidth 00731 * @param SPIx SPI Instance 00732 * @param CRCLength This parameter can be one of the following values: 00733 * @arg @ref LL_SPI_CRC_8BIT 00734 * @arg @ref LL_SPI_CRC_16BIT 00735 * @retval None 00736 */ 00737 __STATIC_INLINE void LL_SPI_SetCRCWidth(SPI_TypeDef *SPIx, uint32_t CRCLength) 00738 { 00739 MODIFY_REG(SPIx->CR1, SPI_CR1_CRCL, CRCLength); 00740 } 00741 00742 /** 00743 * @brief Get CRC Length 00744 * @rmtoll CR1 CRCL LL_SPI_GetCRCWidth 00745 * @param SPIx SPI Instance 00746 * @retval Returned value can be one of the following values: 00747 * @arg @ref LL_SPI_CRC_8BIT 00748 * @arg @ref LL_SPI_CRC_16BIT 00749 */ 00750 __STATIC_INLINE uint32_t LL_SPI_GetCRCWidth(SPI_TypeDef *SPIx) 00751 { 00752 return (uint32_t)(READ_BIT(SPIx->CR1, SPI_CR1_CRCL)); 00753 } 00754 00755 /** 00756 * @brief Set CRCNext to transfer CRC on the line 00757 * @note This bit has to be written as soon as the last data is written in the SPIx_DR register. 00758 * @rmtoll CR1 CRCNEXT LL_SPI_SetCRCNext 00759 * @param SPIx SPI Instance 00760 * @retval None 00761 */ 00762 __STATIC_INLINE void LL_SPI_SetCRCNext(SPI_TypeDef *SPIx) 00763 { 00764 SET_BIT(SPIx->CR1, SPI_CR1_CRCNEXT); 00765 } 00766 00767 /** 00768 * @brief Set polynomial for CRC calculation 00769 * @rmtoll CRCPR CRCPOLY LL_SPI_SetCRCPolynomial 00770 * @param SPIx SPI Instance 00771 * @param CRCPoly This parameter must be a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00772 * @retval None 00773 */ 00774 __STATIC_INLINE void LL_SPI_SetCRCPolynomial(SPI_TypeDef *SPIx, uint32_t CRCPoly) 00775 { 00776 WRITE_REG(SPIx->CRCPR, (uint16_t)CRCPoly); 00777 } 00778 00779 /** 00780 * @brief Get polynomial for CRC calculation 00781 * @rmtoll CRCPR CRCPOLY LL_SPI_GetCRCPolynomial 00782 * @param SPIx SPI Instance 00783 * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00784 */ 00785 __STATIC_INLINE uint32_t LL_SPI_GetCRCPolynomial(SPI_TypeDef *SPIx) 00786 { 00787 return (uint32_t)(READ_REG(SPIx->CRCPR)); 00788 } 00789 00790 /** 00791 * @brief Get Rx CRC 00792 * @rmtoll RXCRCR RXCRC LL_SPI_GetRxCRC 00793 * @param SPIx SPI Instance 00794 * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00795 */ 00796 __STATIC_INLINE uint32_t LL_SPI_GetRxCRC(SPI_TypeDef *SPIx) 00797 { 00798 return (uint32_t)(READ_REG(SPIx->RXCRCR)); 00799 } 00800 00801 /** 00802 * @brief Get Tx CRC 00803 * @rmtoll TXCRCR TXCRC LL_SPI_GetTxCRC 00804 * @param SPIx SPI Instance 00805 * @retval Returned value is a number between Min_Data = 0x00 and Max_Data = 0xFFFF 00806 */ 00807 __STATIC_INLINE uint32_t LL_SPI_GetTxCRC(SPI_TypeDef *SPIx) 00808 { 00809 return (uint32_t)(READ_REG(SPIx->TXCRCR)); 00810 } 00811 00812 /** 00813 * @} 00814 */ 00815 00816 /** @defgroup SPI_LL_EF_NSS_Management Slave Select Pin Management 00817 * @{ 00818 */ 00819 00820 /** 00821 * @brief Set NSS mode 00822 * @note LL_SPI_NSS_SOFT Mode is not used in SPI TI mode. 00823 * @rmtoll CR1 SSM LL_SPI_SetNSSMode\n 00824 * @rmtoll CR2 SSOE LL_SPI_SetNSSMode 00825 * @param SPIx SPI Instance 00826 * @param NSS This parameter can be one of the following values: 00827 * @arg @ref LL_SPI_NSS_SOFT 00828 * @arg @ref LL_SPI_NSS_HARD_INPUT 00829 * @arg @ref LL_SPI_NSS_HARD_OUTPUT 00830 * @retval None 00831 */ 00832 __STATIC_INLINE void LL_SPI_SetNSSMode(SPI_TypeDef *SPIx, uint32_t NSS) 00833 { 00834 MODIFY_REG(SPIx->CR1, SPI_CR1_SSM, NSS); 00835 MODIFY_REG(SPIx->CR2, SPI_CR2_SSOE, ((uint32_t)(NSS >> 16U))); 00836 } 00837 00838 /** 00839 * @brief Get NSS mode 00840 * @rmtoll CR1 SSM LL_SPI_GetNSSMode\n 00841 * @rmtoll CR2 SSOE LL_SPI_GetNSSMode 00842 * @param SPIx SPI Instance 00843 * @retval Returned value can be one of the following values: 00844 * @arg @ref LL_SPI_NSS_SOFT 00845 * @arg @ref LL_SPI_NSS_HARD_INPUT 00846 * @arg @ref LL_SPI_NSS_HARD_OUTPUT 00847 */ 00848 __STATIC_INLINE uint32_t LL_SPI_GetNSSMode(SPI_TypeDef *SPIx) 00849 { 00850 uint32_t Ssm = (READ_BIT(SPIx->CR1, SPI_CR1_SSM)); 00851 uint32_t Ssoe = (READ_BIT(SPIx->CR2, SPI_CR2_SSOE) << 16U); 00852 return (Ssm | Ssoe); 00853 } 00854 00855 /** 00856 * @brief Enable NSS pulse management 00857 * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode. 00858 * @rmtoll CR2 NSSP LL_SPI_EnableNSSPulseMgt 00859 * @param SPIx SPI Instance 00860 * @retval None 00861 */ 00862 __STATIC_INLINE void LL_SPI_EnableNSSPulseMgt(SPI_TypeDef *SPIx) 00863 { 00864 SET_BIT(SPIx->CR2, SPI_CR2_NSSP); 00865 } 00866 00867 /** 00868 * @brief Disable NSS pulse management 00869 * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode. 00870 * @rmtoll CR2 NSSP LL_SPI_DisableNSSPulseMgt 00871 * @param SPIx SPI Instance 00872 * @retval None 00873 */ 00874 __STATIC_INLINE void LL_SPI_DisableNSSPulseMgt(SPI_TypeDef *SPIx) 00875 { 00876 CLEAR_BIT(SPIx->CR2, SPI_CR2_NSSP); 00877 } 00878 00879 /** 00880 * @brief Check if NSS pulse is enabled 00881 * @note This bit should not be changed when communication is ongoing. This bit is not used in SPI TI mode. 00882 * @rmtoll CR2 NSSP LL_SPI_IsEnabledNSSPulse 00883 * @param SPIx SPI Instance 00884 * @retval State of bit (1 or 0). 00885 */ 00886 __STATIC_INLINE uint32_t LL_SPI_IsEnabledNSSPulse(SPI_TypeDef *SPIx) 00887 { 00888 return ((READ_BIT(SPIx->CR2, SPI_CR2_NSSP) == (SPI_CR2_NSSP)) ? 1UL : 0UL); 00889 } 00890 00891 /** 00892 * @} 00893 */ 00894 00895 /** @defgroup SPI_LL_EF_FLAG_Management FLAG Management 00896 * @{ 00897 */ 00898 00899 /** 00900 * @brief Check if Rx buffer is not empty 00901 * @rmtoll SR RXNE LL_SPI_IsActiveFlag_RXNE 00902 * @param SPIx SPI Instance 00903 * @retval State of bit (1 or 0). 00904 */ 00905 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_RXNE(SPI_TypeDef *SPIx) 00906 { 00907 return ((READ_BIT(SPIx->SR, SPI_SR_RXNE) == (SPI_SR_RXNE)) ? 1UL : 0UL); 00908 } 00909 00910 /** 00911 * @brief Check if Tx buffer is empty 00912 * @rmtoll SR TXE LL_SPI_IsActiveFlag_TXE 00913 * @param SPIx SPI Instance 00914 * @retval State of bit (1 or 0). 00915 */ 00916 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_TXE(SPI_TypeDef *SPIx) 00917 { 00918 return ((READ_BIT(SPIx->SR, SPI_SR_TXE) == (SPI_SR_TXE)) ? 1UL : 0UL); 00919 } 00920 00921 /** 00922 * @brief Get CRC error flag 00923 * @rmtoll SR CRCERR LL_SPI_IsActiveFlag_CRCERR 00924 * @param SPIx SPI Instance 00925 * @retval State of bit (1 or 0). 00926 */ 00927 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_CRCERR(SPI_TypeDef *SPIx) 00928 { 00929 return ((READ_BIT(SPIx->SR, SPI_SR_CRCERR) == (SPI_SR_CRCERR)) ? 1UL : 0UL); 00930 } 00931 00932 /** 00933 * @brief Get mode fault error flag 00934 * @rmtoll SR MODF LL_SPI_IsActiveFlag_MODF 00935 * @param SPIx SPI Instance 00936 * @retval State of bit (1 or 0). 00937 */ 00938 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_MODF(SPI_TypeDef *SPIx) 00939 { 00940 return ((READ_BIT(SPIx->SR, SPI_SR_MODF) == (SPI_SR_MODF)) ? 1UL : 0UL); 00941 } 00942 00943 /** 00944 * @brief Get overrun error flag 00945 * @rmtoll SR OVR LL_SPI_IsActiveFlag_OVR 00946 * @param SPIx SPI Instance 00947 * @retval State of bit (1 or 0). 00948 */ 00949 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_OVR(SPI_TypeDef *SPIx) 00950 { 00951 return ((READ_BIT(SPIx->SR, SPI_SR_OVR) == (SPI_SR_OVR)) ? 1UL : 0UL); 00952 } 00953 00954 /** 00955 * @brief Get busy flag 00956 * @note The BSY flag is cleared under any one of the following conditions: 00957 * -When the SPI is correctly disabled 00958 * -When a fault is detected in Master mode (MODF bit set to 1) 00959 * -In Master mode, when it finishes a data transmission and no new data is ready to be 00960 * sent 00961 * -In Slave mode, when the BSY flag is set to '0' for at least one SPI clock cycle between 00962 * each data transfer. 00963 * @rmtoll SR BSY LL_SPI_IsActiveFlag_BSY 00964 * @param SPIx SPI Instance 00965 * @retval State of bit (1 or 0). 00966 */ 00967 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_BSY(SPI_TypeDef *SPIx) 00968 { 00969 return ((READ_BIT(SPIx->SR, SPI_SR_BSY) == (SPI_SR_BSY)) ? 1UL : 0UL); 00970 } 00971 00972 /** 00973 * @brief Get frame format error flag 00974 * @rmtoll SR FRE LL_SPI_IsActiveFlag_FRE 00975 * @param SPIx SPI Instance 00976 * @retval State of bit (1 or 0). 00977 */ 00978 __STATIC_INLINE uint32_t LL_SPI_IsActiveFlag_FRE(SPI_TypeDef *SPIx) 00979 { 00980 return ((READ_BIT(SPIx->SR, SPI_SR_FRE) == (SPI_SR_FRE)) ? 1UL : 0UL); 00981 } 00982 00983 /** 00984 * @brief Get FIFO reception Level 00985 * @rmtoll SR FRLVL LL_SPI_GetRxFIFOLevel 00986 * @param SPIx SPI Instance 00987 * @retval Returned value can be one of the following values: 00988 * @arg @ref LL_SPI_RX_FIFO_EMPTY 00989 * @arg @ref LL_SPI_RX_FIFO_QUARTER_FULL 00990 * @arg @ref LL_SPI_RX_FIFO_HALF_FULL 00991 * @arg @ref LL_SPI_RX_FIFO_FULL 00992 */ 00993 __STATIC_INLINE uint32_t LL_SPI_GetRxFIFOLevel(SPI_TypeDef *SPIx) 00994 { 00995 return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FRLVL)); 00996 } 00997 00998 /** 00999 * @brief Get FIFO Transmission Level 01000 * @rmtoll SR FTLVL LL_SPI_GetTxFIFOLevel 01001 * @param SPIx SPI Instance 01002 * @retval Returned value can be one of the following values: 01003 * @arg @ref LL_SPI_TX_FIFO_EMPTY 01004 * @arg @ref LL_SPI_TX_FIFO_QUARTER_FULL 01005 * @arg @ref LL_SPI_TX_FIFO_HALF_FULL 01006 * @arg @ref LL_SPI_TX_FIFO_FULL 01007 */ 01008 __STATIC_INLINE uint32_t LL_SPI_GetTxFIFOLevel(SPI_TypeDef *SPIx) 01009 { 01010 return (uint32_t)(READ_BIT(SPIx->SR, SPI_SR_FTLVL)); 01011 } 01012 01013 /** 01014 * @brief Clear CRC error flag 01015 * @rmtoll SR CRCERR LL_SPI_ClearFlag_CRCERR 01016 * @param SPIx SPI Instance 01017 * @retval None 01018 */ 01019 __STATIC_INLINE void LL_SPI_ClearFlag_CRCERR(SPI_TypeDef *SPIx) 01020 { 01021 CLEAR_BIT(SPIx->SR, SPI_SR_CRCERR); 01022 } 01023 01024 /** 01025 * @brief Clear mode fault error flag 01026 * @note Clearing this flag is done by a read access to the SPIx_SR 01027 * register followed by a write access to the SPIx_CR1 register 01028 * @rmtoll SR MODF LL_SPI_ClearFlag_MODF 01029 * @param SPIx SPI Instance 01030 * @retval None 01031 */ 01032 __STATIC_INLINE void LL_SPI_ClearFlag_MODF(SPI_TypeDef *SPIx) 01033 { 01034 __IO uint32_t tmpreg_sr; 01035 tmpreg_sr = SPIx->SR; 01036 (void) tmpreg_sr; 01037 CLEAR_BIT(SPIx->CR1, SPI_CR1_SPE); 01038 } 01039 01040 /** 01041 * @brief Clear overrun error flag 01042 * @note Clearing this flag is done by a read access to the SPIx_DR 01043 * register followed by a read access to the SPIx_SR register 01044 * @rmtoll SR OVR LL_SPI_ClearFlag_OVR 01045 * @param SPIx SPI Instance 01046 * @retval None 01047 */ 01048 __STATIC_INLINE void LL_SPI_ClearFlag_OVR(SPI_TypeDef *SPIx) 01049 { 01050 __IO uint32_t tmpreg; 01051 tmpreg = SPIx->DR; 01052 (void) tmpreg; 01053 tmpreg = SPIx->SR; 01054 (void) tmpreg; 01055 } 01056 01057 /** 01058 * @brief Clear frame format error flag 01059 * @note Clearing this flag is done by reading SPIx_SR register 01060 * @rmtoll SR FRE LL_SPI_ClearFlag_FRE 01061 * @param SPIx SPI Instance 01062 * @retval None 01063 */ 01064 __STATIC_INLINE void LL_SPI_ClearFlag_FRE(SPI_TypeDef *SPIx) 01065 { 01066 __IO uint32_t tmpreg; 01067 tmpreg = SPIx->SR; 01068 (void) tmpreg; 01069 } 01070 01071 /** 01072 * @} 01073 */ 01074 01075 /** @defgroup SPI_LL_EF_IT_Management Interrupt Management 01076 * @{ 01077 */ 01078 01079 /** 01080 * @brief Enable error interrupt 01081 * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode). 01082 * @rmtoll CR2 ERRIE LL_SPI_EnableIT_ERR 01083 * @param SPIx SPI Instance 01084 * @retval None 01085 */ 01086 __STATIC_INLINE void LL_SPI_EnableIT_ERR(SPI_TypeDef *SPIx) 01087 { 01088 SET_BIT(SPIx->CR2, SPI_CR2_ERRIE); 01089 } 01090 01091 /** 01092 * @brief Enable Rx buffer not empty interrupt 01093 * @rmtoll CR2 RXNEIE LL_SPI_EnableIT_RXNE 01094 * @param SPIx SPI Instance 01095 * @retval None 01096 */ 01097 __STATIC_INLINE void LL_SPI_EnableIT_RXNE(SPI_TypeDef *SPIx) 01098 { 01099 SET_BIT(SPIx->CR2, SPI_CR2_RXNEIE); 01100 } 01101 01102 /** 01103 * @brief Enable Tx buffer empty interrupt 01104 * @rmtoll CR2 TXEIE LL_SPI_EnableIT_TXE 01105 * @param SPIx SPI Instance 01106 * @retval None 01107 */ 01108 __STATIC_INLINE void LL_SPI_EnableIT_TXE(SPI_TypeDef *SPIx) 01109 { 01110 SET_BIT(SPIx->CR2, SPI_CR2_TXEIE); 01111 } 01112 01113 /** 01114 * @brief Disable error interrupt 01115 * @note This bit controls the generation of an interrupt when an error condition occurs (CRCERR, OVR, MODF in SPI mode, FRE at TI mode). 01116 * @rmtoll CR2 ERRIE LL_SPI_DisableIT_ERR 01117 * @param SPIx SPI Instance 01118 * @retval None 01119 */ 01120 __STATIC_INLINE void LL_SPI_DisableIT_ERR(SPI_TypeDef *SPIx) 01121 { 01122 CLEAR_BIT(SPIx->CR2, SPI_CR2_ERRIE); 01123 } 01124 01125 /** 01126 * @brief Disable Rx buffer not empty interrupt 01127 * @rmtoll CR2 RXNEIE LL_SPI_DisableIT_RXNE 01128 * @param SPIx SPI Instance 01129 * @retval None 01130 */ 01131 __STATIC_INLINE void LL_SPI_DisableIT_RXNE(SPI_TypeDef *SPIx) 01132 { 01133 CLEAR_BIT(SPIx->CR2, SPI_CR2_RXNEIE); 01134 } 01135 01136 /** 01137 * @brief Disable Tx buffer empty interrupt 01138 * @rmtoll CR2 TXEIE LL_SPI_DisableIT_TXE 01139 * @param SPIx SPI Instance 01140 * @retval None 01141 */ 01142 __STATIC_INLINE void LL_SPI_DisableIT_TXE(SPI_TypeDef *SPIx) 01143 { 01144 CLEAR_BIT(SPIx->CR2, SPI_CR2_TXEIE); 01145 } 01146 01147 /** 01148 * @brief Check if error interrupt is enabled 01149 * @rmtoll CR2 ERRIE LL_SPI_IsEnabledIT_ERR 01150 * @param SPIx SPI Instance 01151 * @retval State of bit (1 or 0). 01152 */ 01153 __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_ERR(SPI_TypeDef *SPIx) 01154 { 01155 return ((READ_BIT(SPIx->CR2, SPI_CR2_ERRIE) == (SPI_CR2_ERRIE)) ? 1UL : 0UL); 01156 } 01157 01158 /** 01159 * @brief Check if Rx buffer not empty interrupt is enabled 01160 * @rmtoll CR2 RXNEIE LL_SPI_IsEnabledIT_RXNE 01161 * @param SPIx SPI Instance 01162 * @retval State of bit (1 or 0). 01163 */ 01164 __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_RXNE(SPI_TypeDef *SPIx) 01165 { 01166 return ((READ_BIT(SPIx->CR2, SPI_CR2_RXNEIE) == (SPI_CR2_RXNEIE)) ? 1UL : 0UL); 01167 } 01168 01169 /** 01170 * @brief Check if Tx buffer empty interrupt 01171 * @rmtoll CR2 TXEIE LL_SPI_IsEnabledIT_TXE 01172 * @param SPIx SPI Instance 01173 * @retval State of bit (1 or 0). 01174 */ 01175 __STATIC_INLINE uint32_t LL_SPI_IsEnabledIT_TXE(SPI_TypeDef *SPIx) 01176 { 01177 return ((READ_BIT(SPIx->CR2, SPI_CR2_TXEIE) == (SPI_CR2_TXEIE)) ? 1UL : 0UL); 01178 } 01179 01180 /** 01181 * @} 01182 */ 01183 01184 /** @defgroup SPI_LL_EF_DMA_Management DMA Management 01185 * @{ 01186 */ 01187 01188 /** 01189 * @brief Enable DMA Rx 01190 * @rmtoll CR2 RXDMAEN LL_SPI_EnableDMAReq_RX 01191 * @param SPIx SPI Instance 01192 * @retval None 01193 */ 01194 __STATIC_INLINE void LL_SPI_EnableDMAReq_RX(SPI_TypeDef *SPIx) 01195 { 01196 SET_BIT(SPIx->CR2, SPI_CR2_RXDMAEN); 01197 } 01198 01199 /** 01200 * @brief Disable DMA Rx 01201 * @rmtoll CR2 RXDMAEN LL_SPI_DisableDMAReq_RX 01202 * @param SPIx SPI Instance 01203 * @retval None 01204 */ 01205 __STATIC_INLINE void LL_SPI_DisableDMAReq_RX(SPI_TypeDef *SPIx) 01206 { 01207 CLEAR_BIT(SPIx->CR2, SPI_CR2_RXDMAEN); 01208 } 01209 01210 /** 01211 * @brief Check if DMA Rx is enabled 01212 * @rmtoll CR2 RXDMAEN LL_SPI_IsEnabledDMAReq_RX 01213 * @param SPIx SPI Instance 01214 * @retval State of bit (1 or 0). 01215 */ 01216 __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_RX(SPI_TypeDef *SPIx) 01217 { 01218 return ((READ_BIT(SPIx->CR2, SPI_CR2_RXDMAEN) == (SPI_CR2_RXDMAEN)) ? 1UL : 0UL); 01219 } 01220 01221 /** 01222 * @brief Enable DMA Tx 01223 * @rmtoll CR2 TXDMAEN LL_SPI_EnableDMAReq_TX 01224 * @param SPIx SPI Instance 01225 * @retval None 01226 */ 01227 __STATIC_INLINE void LL_SPI_EnableDMAReq_TX(SPI_TypeDef *SPIx) 01228 { 01229 SET_BIT(SPIx->CR2, SPI_CR2_TXDMAEN); 01230 } 01231 01232 /** 01233 * @brief Disable DMA Tx 01234 * @rmtoll CR2 TXDMAEN LL_SPI_DisableDMAReq_TX 01235 * @param SPIx SPI Instance 01236 * @retval None 01237 */ 01238 __STATIC_INLINE void LL_SPI_DisableDMAReq_TX(SPI_TypeDef *SPIx) 01239 { 01240 CLEAR_BIT(SPIx->CR2, SPI_CR2_TXDMAEN); 01241 } 01242 01243 /** 01244 * @brief Check if DMA Tx is enabled 01245 * @rmtoll CR2 TXDMAEN LL_SPI_IsEnabledDMAReq_TX 01246 * @param SPIx SPI Instance 01247 * @retval State of bit (1 or 0). 01248 */ 01249 __STATIC_INLINE uint32_t LL_SPI_IsEnabledDMAReq_TX(SPI_TypeDef *SPIx) 01250 { 01251 return ((READ_BIT(SPIx->CR2, SPI_CR2_TXDMAEN) == (SPI_CR2_TXDMAEN)) ? 1UL : 0UL); 01252 } 01253 01254 /** 01255 * @brief Set parity of Last DMA reception 01256 * @rmtoll CR2 LDMARX LL_SPI_SetDMAParity_RX 01257 * @param SPIx SPI Instance 01258 * @param Parity This parameter can be one of the following values: 01259 * @arg @ref LL_SPI_DMA_PARITY_ODD 01260 * @arg @ref LL_SPI_DMA_PARITY_EVEN 01261 * @retval None 01262 */ 01263 __STATIC_INLINE void LL_SPI_SetDMAParity_RX(SPI_TypeDef *SPIx, uint32_t Parity) 01264 { 01265 MODIFY_REG(SPIx->CR2, SPI_CR2_LDMARX, (Parity << SPI_CR2_LDMARX_Pos)); 01266 } 01267 01268 /** 01269 * @brief Get parity configuration for Last DMA reception 01270 * @rmtoll CR2 LDMARX LL_SPI_GetDMAParity_RX 01271 * @param SPIx SPI Instance 01272 * @retval Returned value can be one of the following values: 01273 * @arg @ref LL_SPI_DMA_PARITY_ODD 01274 * @arg @ref LL_SPI_DMA_PARITY_EVEN 01275 */ 01276 __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_RX(SPI_TypeDef *SPIx) 01277 { 01278 return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMARX) >> SPI_CR2_LDMARX_Pos); 01279 } 01280 01281 /** 01282 * @brief Set parity of Last DMA transmission 01283 * @rmtoll CR2 LDMATX LL_SPI_SetDMAParity_TX 01284 * @param SPIx SPI Instance 01285 * @param Parity This parameter can be one of the following values: 01286 * @arg @ref LL_SPI_DMA_PARITY_ODD 01287 * @arg @ref LL_SPI_DMA_PARITY_EVEN 01288 * @retval None 01289 */ 01290 __STATIC_INLINE void LL_SPI_SetDMAParity_TX(SPI_TypeDef *SPIx, uint32_t Parity) 01291 { 01292 MODIFY_REG(SPIx->CR2, SPI_CR2_LDMATX, (Parity << SPI_CR2_LDMATX_Pos)); 01293 } 01294 01295 /** 01296 * @brief Get parity configuration for Last DMA transmission 01297 * @rmtoll CR2 LDMATX LL_SPI_GetDMAParity_TX 01298 * @param SPIx SPI Instance 01299 * @retval Returned value can be one of the following values: 01300 * @arg @ref LL_SPI_DMA_PARITY_ODD 01301 * @arg @ref LL_SPI_DMA_PARITY_EVEN 01302 */ 01303 __STATIC_INLINE uint32_t LL_SPI_GetDMAParity_TX(SPI_TypeDef *SPIx) 01304 { 01305 return (uint32_t)(READ_BIT(SPIx->CR2, SPI_CR2_LDMATX) >> SPI_CR2_LDMATX_Pos); 01306 } 01307 01308 /** 01309 * @brief Get the data register address used for DMA transfer 01310 * @rmtoll DR DR LL_SPI_DMA_GetRegAddr 01311 * @param SPIx SPI Instance 01312 * @retval Address of data register 01313 */ 01314 __STATIC_INLINE uint32_t LL_SPI_DMA_GetRegAddr(SPI_TypeDef *SPIx) 01315 { 01316 return (uint32_t) &(SPIx->DR); 01317 } 01318 01319 /** 01320 * @} 01321 */ 01322 01323 /** @defgroup SPI_LL_EF_DATA_Management DATA Management 01324 * @{ 01325 */ 01326 01327 /** 01328 * @brief Read 8-Bits in the data register 01329 * @rmtoll DR DR LL_SPI_ReceiveData8 01330 * @param SPIx SPI Instance 01331 * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFF 01332 */ 01333 __STATIC_INLINE uint8_t LL_SPI_ReceiveData8(SPI_TypeDef *SPIx) 01334 { 01335 return (*((__IO uint8_t *)&SPIx->DR)); 01336 } 01337 01338 /** 01339 * @brief Read 16-Bits in the data register 01340 * @rmtoll DR DR LL_SPI_ReceiveData16 01341 * @param SPIx SPI Instance 01342 * @retval RxData Value between Min_Data=0x00 and Max_Data=0xFFFF 01343 */ 01344 __STATIC_INLINE uint16_t LL_SPI_ReceiveData16(SPI_TypeDef *SPIx) 01345 { 01346 return (uint16_t)(READ_REG(SPIx->DR)); 01347 } 01348 01349 /** 01350 * @brief Write 8-Bits in the data register 01351 * @rmtoll DR DR LL_SPI_TransmitData8 01352 * @param SPIx SPI Instance 01353 * @param TxData Value between Min_Data=0x00 and Max_Data=0xFF 01354 * @retval None 01355 */ 01356 __STATIC_INLINE void LL_SPI_TransmitData8(SPI_TypeDef *SPIx, uint8_t TxData) 01357 { 01358 #if defined (__GNUC__) 01359 __IO uint8_t *spidr = ((__IO uint8_t *)&SPIx->DR); 01360 *spidr = TxData; 01361 #else 01362 *((__IO uint8_t *)&SPIx->DR) = TxData; 01363 #endif /* __GNUC__ */ 01364 } 01365 01366 /** 01367 * @brief Write 16-Bits in the data register 01368 * @rmtoll DR DR LL_SPI_TransmitData16 01369 * @param SPIx SPI Instance 01370 * @param TxData Value between Min_Data=0x00 and Max_Data=0xFFFF 01371 * @retval None 01372 */ 01373 __STATIC_INLINE void LL_SPI_TransmitData16(SPI_TypeDef *SPIx, uint16_t TxData) 01374 { 01375 #if defined (__GNUC__) 01376 __IO uint16_t *spidr = ((__IO uint16_t *)&SPIx->DR); 01377 *spidr = TxData; 01378 #else 01379 SPIx->DR = TxData; 01380 #endif /* __GNUC__ */ 01381 } 01382 01383 /** 01384 * @} 01385 */ 01386 #if defined(USE_FULL_LL_DRIVER) 01387 /** @defgroup SPI_LL_EF_Init Initialization and de-initialization functions 01388 * @{ 01389 */ 01390 01391 ErrorStatus LL_SPI_DeInit(SPI_TypeDef *SPIx); 01392 ErrorStatus LL_SPI_Init(SPI_TypeDef *SPIx, LL_SPI_InitTypeDef *SPI_InitStruct); 01393 void LL_SPI_StructInit(LL_SPI_InitTypeDef *SPI_InitStruct); 01394 01395 /** 01396 * @} 01397 */ 01398 #endif /* USE_FULL_LL_DRIVER */ 01399 /** 01400 * @} 01401 */ 01402 01403 /** 01404 * @} 01405 */ 01406 01407 #endif /* defined (SPI1) || defined (SPI2) || defined (SPI3) */ 01408 01409 /** 01410 * @} 01411 */ 01412 01413 #ifdef __cplusplus 01414 } 01415 #endif 01416 01417 #endif /* STM32L4xx_LL_SPI_H */ 01418