2 ******************************************************************************
\r
3 * @file stm32l4xx_hal_spi.h
\r
4 * @author MCD Application Team
\r
5 * @brief Header file of SPI HAL module.
\r
6 ******************************************************************************
\r
9 * <h2><center>© Copyright (c) 2017 STMicroelectronics.
\r
10 * All rights reserved.</center></h2>
\r
12 * This software component is licensed by ST under BSD 3-Clause license,
\r
13 * the "License"; You may not use this file except in compliance with the
\r
14 * License. You may obtain a copy of the License at:
\r
15 * opensource.org/licenses/BSD-3-Clause
\r
17 ******************************************************************************
\r
20 /* Define to prevent recursive inclusion -------------------------------------*/
\r
21 #ifndef STM32L4xx_HAL_SPI_H
\r
22 #define STM32L4xx_HAL_SPI_H
\r
28 /* Includes ------------------------------------------------------------------*/
\r
29 #include "stm32l4xx_hal_def.h"
\r
31 /** @addtogroup STM32L4xx_HAL_Driver
\r
39 /* Exported types ------------------------------------------------------------*/
\r
40 /** @defgroup SPI_Exported_Types SPI Exported Types
\r
45 * @brief SPI Configuration Structure definition
\r
49 uint32_t Mode; /*!< Specifies the SPI operating mode.
\r
50 This parameter can be a value of @ref SPI_Mode */
\r
52 uint32_t Direction; /*!< Specifies the SPI bidirectional mode state.
\r
53 This parameter can be a value of @ref SPI_Direction */
\r
55 uint32_t DataSize; /*!< Specifies the SPI data size.
\r
56 This parameter can be a value of @ref SPI_Data_Size */
\r
58 uint32_t CLKPolarity; /*!< Specifies the serial clock steady state.
\r
59 This parameter can be a value of @ref SPI_Clock_Polarity */
\r
61 uint32_t CLKPhase; /*!< Specifies the clock active edge for the bit capture.
\r
62 This parameter can be a value of @ref SPI_Clock_Phase */
\r
64 uint32_t NSS; /*!< Specifies whether the NSS signal is managed by
\r
65 hardware (NSS pin) or by software using the SSI bit.
\r
66 This parameter can be a value of @ref SPI_Slave_Select_management */
\r
68 uint32_t BaudRatePrescaler; /*!< Specifies the Baud Rate prescaler value which will be
\r
69 used to configure the transmit and receive SCK clock.
\r
70 This parameter can be a value of @ref SPI_BaudRate_Prescaler
\r
71 @note The communication clock is derived from the master
\r
72 clock. The slave clock does not need to be set. */
\r
74 uint32_t FirstBit; /*!< Specifies whether data transfers start from MSB or LSB bit.
\r
75 This parameter can be a value of @ref SPI_MSB_LSB_transmission */
\r
77 uint32_t TIMode; /*!< Specifies if the TI mode is enabled or not.
\r
78 This parameter can be a value of @ref SPI_TI_mode */
\r
80 uint32_t CRCCalculation; /*!< Specifies if the CRC calculation is enabled or not.
\r
81 This parameter can be a value of @ref SPI_CRC_Calculation */
\r
83 uint32_t CRCPolynomial; /*!< Specifies the polynomial used for the CRC calculation.
\r
84 This parameter must be an odd number between Min_Data = 1 and Max_Data = 65535 */
\r
86 uint32_t CRCLength; /*!< Specifies the CRC Length used for the CRC calculation.
\r
87 CRC Length is only used with Data8 and Data16, not other data size
\r
88 This parameter can be a value of @ref SPI_CRC_length */
\r
90 uint32_t NSSPMode; /*!< Specifies whether the NSSP signal is enabled or not .
\r
91 This parameter can be a value of @ref SPI_NSSP_Mode
\r
92 This mode is activated by the NSSP bit in the SPIx_CR2 register and
\r
93 it takes effect only if the SPI interface is configured as Motorola SPI
\r
94 master (FRF=0) with capture on the first edge (SPIx_CR1 CPHA = 0,
\r
95 CPOL setting is ignored).. */
\r
99 * @brief HAL SPI State structure definition
\r
103 HAL_SPI_STATE_RESET = 0x00U, /*!< Peripheral not Initialized */
\r
104 HAL_SPI_STATE_READY = 0x01U, /*!< Peripheral Initialized and ready for use */
\r
105 HAL_SPI_STATE_BUSY = 0x02U, /*!< an internal process is ongoing */
\r
106 HAL_SPI_STATE_BUSY_TX = 0x03U, /*!< Data Transmission process is ongoing */
\r
107 HAL_SPI_STATE_BUSY_RX = 0x04U, /*!< Data Reception process is ongoing */
\r
108 HAL_SPI_STATE_BUSY_TX_RX = 0x05U, /*!< Data Transmission and Reception process is ongoing */
\r
109 HAL_SPI_STATE_ERROR = 0x06U, /*!< SPI error state */
\r
110 HAL_SPI_STATE_ABORT = 0x07U /*!< SPI abort is ongoing */
\r
111 } HAL_SPI_StateTypeDef;
\r
114 * @brief SPI handle Structure definition
\r
116 typedef struct __SPI_HandleTypeDef
\r
118 SPI_TypeDef *Instance; /*!< SPI registers base address */
\r
120 SPI_InitTypeDef Init; /*!< SPI communication parameters */
\r
122 uint8_t *pTxBuffPtr; /*!< Pointer to SPI Tx transfer Buffer */
\r
124 uint16_t TxXferSize; /*!< SPI Tx Transfer size */
\r
126 __IO uint16_t TxXferCount; /*!< SPI Tx Transfer Counter */
\r
128 uint8_t *pRxBuffPtr; /*!< Pointer to SPI Rx transfer Buffer */
\r
130 uint16_t RxXferSize; /*!< SPI Rx Transfer size */
\r
132 __IO uint16_t RxXferCount; /*!< SPI Rx Transfer Counter */
\r
134 uint32_t CRCSize; /*!< SPI CRC size used for the transfer */
\r
136 void (*RxISR)(struct __SPI_HandleTypeDef *hspi); /*!< function pointer on Rx ISR */
\r
138 void (*TxISR)(struct __SPI_HandleTypeDef *hspi); /*!< function pointer on Tx ISR */
\r
140 DMA_HandleTypeDef *hdmatx; /*!< SPI Tx DMA Handle parameters */
\r
142 DMA_HandleTypeDef *hdmarx; /*!< SPI Rx DMA Handle parameters */
\r
144 HAL_LockTypeDef Lock; /*!< Locking object */
\r
146 __IO HAL_SPI_StateTypeDef State; /*!< SPI communication state */
\r
148 __IO uint32_t ErrorCode; /*!< SPI Error code */
\r
150 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
\r
151 void (* TxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Tx Completed callback */
\r
152 void (* RxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Rx Completed callback */
\r
153 void (* TxRxCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI TxRx Completed callback */
\r
154 void (* TxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Tx Half Completed callback */
\r
155 void (* RxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Rx Half Completed callback */
\r
156 void (* TxRxHalfCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI TxRx Half Completed callback */
\r
157 void (* ErrorCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Error callback */
\r
158 void (* AbortCpltCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Abort callback */
\r
159 void (* MspInitCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Msp Init callback */
\r
160 void (* MspDeInitCallback)(struct __SPI_HandleTypeDef *hspi); /*!< SPI Msp DeInit callback */
\r
162 #endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
\r
163 } SPI_HandleTypeDef;
\r
165 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
\r
167 * @brief HAL SPI Callback ID enumeration definition
\r
171 HAL_SPI_TX_COMPLETE_CB_ID = 0x00U, /*!< SPI Tx Completed callback ID */
\r
172 HAL_SPI_RX_COMPLETE_CB_ID = 0x01U, /*!< SPI Rx Completed callback ID */
\r
173 HAL_SPI_TX_RX_COMPLETE_CB_ID = 0x02U, /*!< SPI TxRx Completed callback ID */
\r
174 HAL_SPI_TX_HALF_COMPLETE_CB_ID = 0x03U, /*!< SPI Tx Half Completed callback ID */
\r
175 HAL_SPI_RX_HALF_COMPLETE_CB_ID = 0x04U, /*!< SPI Rx Half Completed callback ID */
\r
176 HAL_SPI_TX_RX_HALF_COMPLETE_CB_ID = 0x05U, /*!< SPI TxRx Half Completed callback ID */
\r
177 HAL_SPI_ERROR_CB_ID = 0x06U, /*!< SPI Error callback ID */
\r
178 HAL_SPI_ABORT_CB_ID = 0x07U, /*!< SPI Abort callback ID */
\r
179 HAL_SPI_MSPINIT_CB_ID = 0x08U, /*!< SPI Msp Init callback ID */
\r
180 HAL_SPI_MSPDEINIT_CB_ID = 0x09U /*!< SPI Msp DeInit callback ID */
\r
182 } HAL_SPI_CallbackIDTypeDef;
\r
185 * @brief HAL SPI Callback pointer definition
\r
187 typedef void (*pSPI_CallbackTypeDef)(SPI_HandleTypeDef *hspi); /*!< pointer to an SPI callback function */
\r
189 #endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
\r
194 /* Exported constants --------------------------------------------------------*/
\r
195 /** @defgroup SPI_Exported_Constants SPI Exported Constants
\r
199 /** @defgroup SPI_Error_Code SPI Error Code
\r
202 #define HAL_SPI_ERROR_NONE (0x00000000U) /*!< No error */
\r
203 #define HAL_SPI_ERROR_MODF (0x00000001U) /*!< MODF error */
\r
204 #define HAL_SPI_ERROR_CRC (0x00000002U) /*!< CRC error */
\r
205 #define HAL_SPI_ERROR_OVR (0x00000004U) /*!< OVR error */
\r
206 #define HAL_SPI_ERROR_FRE (0x00000008U) /*!< FRE error */
\r
207 #define HAL_SPI_ERROR_DMA (0x00000010U) /*!< DMA transfer error */
\r
208 #define HAL_SPI_ERROR_FLAG (0x00000020U) /*!< Error on RXNE/TXE/BSY/FTLVL/FRLVL Flag */
\r
209 #define HAL_SPI_ERROR_ABORT (0x00000040U) /*!< Error during SPI Abort procedure */
\r
210 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
\r
211 #define HAL_SPI_ERROR_INVALID_CALLBACK (0x00000080U) /*!< Invalid Callback error */
\r
212 #endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
\r
217 /** @defgroup SPI_Mode SPI Mode
\r
220 #define SPI_MODE_SLAVE (0x00000000U)
\r
221 #define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI)
\r
226 /** @defgroup SPI_Direction SPI Direction Mode
\r
229 #define SPI_DIRECTION_2LINES (0x00000000U)
\r
230 #define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY
\r
231 #define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE
\r
236 /** @defgroup SPI_Data_Size SPI Data Size
\r
239 #define SPI_DATASIZE_4BIT (0x00000300U)
\r
240 #define SPI_DATASIZE_5BIT (0x00000400U)
\r
241 #define SPI_DATASIZE_6BIT (0x00000500U)
\r
242 #define SPI_DATASIZE_7BIT (0x00000600U)
\r
243 #define SPI_DATASIZE_8BIT (0x00000700U)
\r
244 #define SPI_DATASIZE_9BIT (0x00000800U)
\r
245 #define SPI_DATASIZE_10BIT (0x00000900U)
\r
246 #define SPI_DATASIZE_11BIT (0x00000A00U)
\r
247 #define SPI_DATASIZE_12BIT (0x00000B00U)
\r
248 #define SPI_DATASIZE_13BIT (0x00000C00U)
\r
249 #define SPI_DATASIZE_14BIT (0x00000D00U)
\r
250 #define SPI_DATASIZE_15BIT (0x00000E00U)
\r
251 #define SPI_DATASIZE_16BIT (0x00000F00U)
\r
256 /** @defgroup SPI_Clock_Polarity SPI Clock Polarity
\r
259 #define SPI_POLARITY_LOW (0x00000000U)
\r
260 #define SPI_POLARITY_HIGH SPI_CR1_CPOL
\r
265 /** @defgroup SPI_Clock_Phase SPI Clock Phase
\r
268 #define SPI_PHASE_1EDGE (0x00000000U)
\r
269 #define SPI_PHASE_2EDGE SPI_CR1_CPHA
\r
274 /** @defgroup SPI_Slave_Select_management SPI Slave Select Management
\r
277 #define SPI_NSS_SOFT SPI_CR1_SSM
\r
278 #define SPI_NSS_HARD_INPUT (0x00000000U)
\r
279 #define SPI_NSS_HARD_OUTPUT (SPI_CR2_SSOE << 16U)
\r
284 /** @defgroup SPI_NSSP_Mode SPI NSS Pulse Mode
\r
287 #define SPI_NSS_PULSE_ENABLE SPI_CR2_NSSP
\r
288 #define SPI_NSS_PULSE_DISABLE (0x00000000U)
\r
293 /** @defgroup SPI_BaudRate_Prescaler SPI BaudRate Prescaler
\r
296 #define SPI_BAUDRATEPRESCALER_2 (0x00000000U)
\r
297 #define SPI_BAUDRATEPRESCALER_4 (SPI_CR1_BR_0)
\r
298 #define SPI_BAUDRATEPRESCALER_8 (SPI_CR1_BR_1)
\r
299 #define SPI_BAUDRATEPRESCALER_16 (SPI_CR1_BR_1 | SPI_CR1_BR_0)
\r
300 #define SPI_BAUDRATEPRESCALER_32 (SPI_CR1_BR_2)
\r
301 #define SPI_BAUDRATEPRESCALER_64 (SPI_CR1_BR_2 | SPI_CR1_BR_0)
\r
302 #define SPI_BAUDRATEPRESCALER_128 (SPI_CR1_BR_2 | SPI_CR1_BR_1)
\r
303 #define SPI_BAUDRATEPRESCALER_256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0)
\r
308 /** @defgroup SPI_MSB_LSB_transmission SPI MSB LSB Transmission
\r
311 #define SPI_FIRSTBIT_MSB (0x00000000U)
\r
312 #define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST
\r
317 /** @defgroup SPI_TI_mode SPI TI Mode
\r
320 #define SPI_TIMODE_DISABLE (0x00000000U)
\r
321 #define SPI_TIMODE_ENABLE SPI_CR2_FRF
\r
326 /** @defgroup SPI_CRC_Calculation SPI CRC Calculation
\r
329 #define SPI_CRCCALCULATION_DISABLE (0x00000000U)
\r
330 #define SPI_CRCCALCULATION_ENABLE SPI_CR1_CRCEN
\r
335 /** @defgroup SPI_CRC_length SPI CRC Length
\r
337 * This parameter can be one of the following values:
\r
338 * SPI_CRC_LENGTH_DATASIZE: aligned with the data size
\r
339 * SPI_CRC_LENGTH_8BIT : CRC 8bit
\r
340 * SPI_CRC_LENGTH_16BIT : CRC 16bit
\r
342 #define SPI_CRC_LENGTH_DATASIZE (0x00000000U)
\r
343 #define SPI_CRC_LENGTH_8BIT (0x00000001U)
\r
344 #define SPI_CRC_LENGTH_16BIT (0x00000002U)
\r
349 /** @defgroup SPI_FIFO_reception_threshold SPI FIFO Reception Threshold
\r
351 * This parameter can be one of the following values:
\r
352 * SPI_RXFIFO_THRESHOLD or SPI_RXFIFO_THRESHOLD_QF :
\r
353 * RXNE event is generated if the FIFO
\r
354 * level is greater or equal to 1/4(8-bits).
\r
355 * SPI_RXFIFO_THRESHOLD_HF: RXNE event is generated if the FIFO
\r
356 * level is greater or equal to 1/2(16 bits). */
\r
357 #define SPI_RXFIFO_THRESHOLD SPI_CR2_FRXTH
\r
358 #define SPI_RXFIFO_THRESHOLD_QF SPI_CR2_FRXTH
\r
359 #define SPI_RXFIFO_THRESHOLD_HF (0x00000000U)
\r
364 /** @defgroup SPI_Interrupt_definition SPI Interrupt Definition
\r
367 #define SPI_IT_TXE SPI_CR2_TXEIE
\r
368 #define SPI_IT_RXNE SPI_CR2_RXNEIE
\r
369 #define SPI_IT_ERR SPI_CR2_ERRIE
\r
374 /** @defgroup SPI_Flags_definition SPI Flags Definition
\r
377 #define SPI_FLAG_RXNE SPI_SR_RXNE /* SPI status flag: Rx buffer not empty flag */
\r
378 #define SPI_FLAG_TXE SPI_SR_TXE /* SPI status flag: Tx buffer empty flag */
\r
379 #define SPI_FLAG_BSY SPI_SR_BSY /* SPI status flag: Busy flag */
\r
380 #define SPI_FLAG_CRCERR SPI_SR_CRCERR /* SPI Error flag: CRC error flag */
\r
381 #define SPI_FLAG_MODF SPI_SR_MODF /* SPI Error flag: Mode fault flag */
\r
382 #define SPI_FLAG_OVR SPI_SR_OVR /* SPI Error flag: Overrun flag */
\r
383 #define SPI_FLAG_FRE SPI_SR_FRE /* SPI Error flag: TI mode frame format error flag */
\r
384 #define SPI_FLAG_FTLVL SPI_SR_FTLVL /* SPI fifo transmission level */
\r
385 #define SPI_FLAG_FRLVL SPI_SR_FRLVL /* SPI fifo reception level */
\r
386 #define SPI_FLAG_MASK (SPI_SR_RXNE | SPI_SR_TXE | SPI_SR_BSY | SPI_SR_CRCERR | SPI_SR_MODF | SPI_SR_OVR | SPI_SR_FRE | SPI_SR_FTLVL | SPI_SR_FRLVL)
\r
391 /** @defgroup SPI_transmission_fifo_status_level SPI Transmission FIFO Status Level
\r
394 #define SPI_FTLVL_EMPTY (0x00000000U)
\r
395 #define SPI_FTLVL_QUARTER_FULL (0x00000800U)
\r
396 #define SPI_FTLVL_HALF_FULL (0x00001000U)
\r
397 #define SPI_FTLVL_FULL (0x00001800U)
\r
403 /** @defgroup SPI_reception_fifo_status_level SPI Reception FIFO Status Level
\r
406 #define SPI_FRLVL_EMPTY (0x00000000U)
\r
407 #define SPI_FRLVL_QUARTER_FULL (0x00000200U)
\r
408 #define SPI_FRLVL_HALF_FULL (0x00000400U)
\r
409 #define SPI_FRLVL_FULL (0x00000600U)
\r
418 /* Exported macros -----------------------------------------------------------*/
\r
419 /** @defgroup SPI_Exported_Macros SPI Exported Macros
\r
423 /** @brief Reset SPI handle state.
\r
424 * @param __HANDLE__ specifies the SPI Handle.
\r
425 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
428 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
\r
429 #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) do{ \
\r
430 (__HANDLE__)->State = HAL_SPI_STATE_RESET; \
\r
431 (__HANDLE__)->MspInitCallback = NULL; \
\r
432 (__HANDLE__)->MspDeInitCallback = NULL; \
\r
435 #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET)
\r
438 /** @brief Enable the specified SPI interrupts.
\r
439 * @param __HANDLE__ specifies the SPI Handle.
\r
440 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
441 * @param __INTERRUPT__ specifies the interrupt source to enable.
\r
442 * This parameter can be one of the following values:
\r
443 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
\r
444 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
\r
445 * @arg SPI_IT_ERR: Error interrupt enable
\r
448 #define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))
\r
450 /** @brief Disable the specified SPI interrupts.
\r
451 * @param __HANDLE__ specifies the SPI handle.
\r
452 * This parameter can be SPIx where x: 1, 2, or 3 to select the SPI peripheral.
\r
453 * @param __INTERRUPT__ specifies the interrupt source to disable.
\r
454 * This parameter can be one of the following values:
\r
455 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
\r
456 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
\r
457 * @arg SPI_IT_ERR: Error interrupt enable
\r
460 #define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))
\r
462 /** @brief Check whether the specified SPI interrupt source is enabled or not.
\r
463 * @param __HANDLE__ specifies the SPI Handle.
\r
464 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
465 * @param __INTERRUPT__ specifies the SPI interrupt source to check.
\r
466 * This parameter can be one of the following values:
\r
467 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
\r
468 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
\r
469 * @arg SPI_IT_ERR: Error interrupt enable
\r
470 * @retval The new state of __IT__ (TRUE or FALSE).
\r
472 #define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
\r
474 /** @brief Check whether the specified SPI flag is set or not.
\r
475 * @param __HANDLE__ specifies the SPI Handle.
\r
476 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
477 * @param __FLAG__ specifies the flag to check.
\r
478 * This parameter can be one of the following values:
\r
479 * @arg SPI_FLAG_RXNE: Receive buffer not empty flag
\r
480 * @arg SPI_FLAG_TXE: Transmit buffer empty flag
\r
481 * @arg SPI_FLAG_CRCERR: CRC error flag
\r
482 * @arg SPI_FLAG_MODF: Mode fault flag
\r
483 * @arg SPI_FLAG_OVR: Overrun flag
\r
484 * @arg SPI_FLAG_BSY: Busy flag
\r
485 * @arg SPI_FLAG_FRE: Frame format error flag
\r
486 * @arg SPI_FLAG_FTLVL: SPI fifo transmission level
\r
487 * @arg SPI_FLAG_FRLVL: SPI fifo reception level
\r
488 * @retval The new state of __FLAG__ (TRUE or FALSE).
\r
490 #define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
\r
492 /** @brief Clear the SPI CRCERR pending flag.
\r
493 * @param __HANDLE__ specifies the SPI Handle.
\r
494 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
497 #define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = (uint16_t)(~SPI_FLAG_CRCERR))
\r
499 /** @brief Clear the SPI MODF pending flag.
\r
500 * @param __HANDLE__ specifies the SPI Handle.
\r
501 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
504 #define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) \
\r
506 __IO uint32_t tmpreg_modf = 0x00U; \
\r
507 tmpreg_modf = (__HANDLE__)->Instance->SR; \
\r
508 CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE); \
\r
509 UNUSED(tmpreg_modf); \
\r
512 /** @brief Clear the SPI OVR pending flag.
\r
513 * @param __HANDLE__ specifies the SPI Handle.
\r
514 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
517 #define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) \
\r
519 __IO uint32_t tmpreg_ovr = 0x00U; \
\r
520 tmpreg_ovr = (__HANDLE__)->Instance->DR; \
\r
521 tmpreg_ovr = (__HANDLE__)->Instance->SR; \
\r
522 UNUSED(tmpreg_ovr); \
\r
525 /** @brief Clear the SPI FRE pending flag.
\r
526 * @param __HANDLE__ specifies the SPI Handle.
\r
527 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
530 #define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) \
\r
532 __IO uint32_t tmpreg_fre = 0x00U; \
\r
533 tmpreg_fre = (__HANDLE__)->Instance->SR; \
\r
534 UNUSED(tmpreg_fre); \
\r
537 /** @brief Enable the SPI peripheral.
\r
538 * @param __HANDLE__ specifies the SPI Handle.
\r
539 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
542 #define __HAL_SPI_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE)
\r
544 /** @brief Disable the SPI peripheral.
\r
545 * @param __HANDLE__ specifies the SPI Handle.
\r
546 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
549 #define __HAL_SPI_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE)
\r
555 /* Private macros ------------------------------------------------------------*/
\r
556 /** @defgroup SPI_Private_Macros SPI Private Macros
\r
560 /** @brief Set the SPI transmit-only mode.
\r
561 * @param __HANDLE__ specifies the SPI Handle.
\r
562 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
565 #define SPI_1LINE_TX(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE)
\r
567 /** @brief Set the SPI receive-only mode.
\r
568 * @param __HANDLE__ specifies the SPI Handle.
\r
569 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
572 #define SPI_1LINE_RX(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE)
\r
574 /** @brief Reset the CRC calculation of the SPI.
\r
575 * @param __HANDLE__ specifies the SPI Handle.
\r
576 * This parameter can be SPI where x: 1, 2, or 3 to select the SPI peripheral.
\r
579 #define SPI_RESET_CRC(__HANDLE__) do{CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN);\
\r
580 SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN);}while(0U)
\r
582 /** @brief Check whether the specified SPI flag is set or not.
\r
583 * @param __SR__ copy of SPI SR regsiter.
\r
584 * @param __FLAG__ specifies the flag to check.
\r
585 * This parameter can be one of the following values:
\r
586 * @arg SPI_FLAG_RXNE: Receive buffer not empty flag
\r
587 * @arg SPI_FLAG_TXE: Transmit buffer empty flag
\r
588 * @arg SPI_FLAG_CRCERR: CRC error flag
\r
589 * @arg SPI_FLAG_MODF: Mode fault flag
\r
590 * @arg SPI_FLAG_OVR: Overrun flag
\r
591 * @arg SPI_FLAG_BSY: Busy flag
\r
592 * @arg SPI_FLAG_FRE: Frame format error flag
\r
593 * @arg SPI_FLAG_FTLVL: SPI fifo transmission level
\r
594 * @arg SPI_FLAG_FRLVL: SPI fifo reception level
\r
595 * @retval SET or RESET.
\r
597 #define SPI_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__) & ((__FLAG__) & SPI_FLAG_MASK)) == ((__FLAG__) & SPI_FLAG_MASK)) ? SET : RESET)
\r
599 /** @brief Check whether the specified SPI Interrupt is set or not.
\r
600 * @param __CR2__ copy of SPI CR2 regsiter.
\r
601 * @param __INTERRUPT__ specifies the SPI interrupt source to check.
\r
602 * This parameter can be one of the following values:
\r
603 * @arg SPI_IT_TXE: Tx buffer empty interrupt enable
\r
604 * @arg SPI_IT_RXNE: RX buffer not empty interrupt enable
\r
605 * @arg SPI_IT_ERR: Error interrupt enable
\r
606 * @retval SET or RESET.
\r
608 #define SPI_CHECK_IT_SOURCE(__CR2__, __INTERRUPT__) ((((__CR2__) & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
\r
610 /** @brief Checks if SPI Mode parameter is in allowed range.
\r
611 * @param __MODE__ specifies the SPI Mode.
\r
612 * This parameter can be a value of @ref SPI_Mode
\r
615 #define IS_SPI_MODE(__MODE__) (((__MODE__) == SPI_MODE_SLAVE) || \
\r
616 ((__MODE__) == SPI_MODE_MASTER))
\r
618 /** @brief Checks if SPI Direction Mode parameter is in allowed range.
\r
619 * @param __MODE__ specifies the SPI Direction Mode.
\r
620 * This parameter can be a value of @ref SPI_Direction
\r
623 #define IS_SPI_DIRECTION(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \
\r
624 ((__MODE__) == SPI_DIRECTION_2LINES_RXONLY) || \
\r
625 ((__MODE__) == SPI_DIRECTION_1LINE))
\r
627 /** @brief Checks if SPI Direction Mode parameter is 2 lines.
\r
628 * @param __MODE__ specifies the SPI Direction Mode.
\r
631 #define IS_SPI_DIRECTION_2LINES(__MODE__) ((__MODE__) == SPI_DIRECTION_2LINES)
\r
633 /** @brief Checks if SPI Direction Mode parameter is 1 or 2 lines.
\r
634 * @param __MODE__ specifies the SPI Direction Mode.
\r
637 #define IS_SPI_DIRECTION_2LINES_OR_1LINE(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \
\r
638 ((__MODE__) == SPI_DIRECTION_1LINE))
\r
640 /** @brief Checks if SPI Data Size parameter is in allowed range.
\r
641 * @param __DATASIZE__ specifies the SPI Data Size.
\r
642 * This parameter can be a value of @ref SPI_Data_Size
\r
645 #define IS_SPI_DATASIZE(__DATASIZE__) (((__DATASIZE__) == SPI_DATASIZE_16BIT) || \
\r
646 ((__DATASIZE__) == SPI_DATASIZE_15BIT) || \
\r
647 ((__DATASIZE__) == SPI_DATASIZE_14BIT) || \
\r
648 ((__DATASIZE__) == SPI_DATASIZE_13BIT) || \
\r
649 ((__DATASIZE__) == SPI_DATASIZE_12BIT) || \
\r
650 ((__DATASIZE__) == SPI_DATASIZE_11BIT) || \
\r
651 ((__DATASIZE__) == SPI_DATASIZE_10BIT) || \
\r
652 ((__DATASIZE__) == SPI_DATASIZE_9BIT) || \
\r
653 ((__DATASIZE__) == SPI_DATASIZE_8BIT) || \
\r
654 ((__DATASIZE__) == SPI_DATASIZE_7BIT) || \
\r
655 ((__DATASIZE__) == SPI_DATASIZE_6BIT) || \
\r
656 ((__DATASIZE__) == SPI_DATASIZE_5BIT) || \
\r
657 ((__DATASIZE__) == SPI_DATASIZE_4BIT))
\r
659 /** @brief Checks if SPI Serial clock steady state parameter is in allowed range.
\r
660 * @param __CPOL__ specifies the SPI serial clock steady state.
\r
661 * This parameter can be a value of @ref SPI_Clock_Polarity
\r
664 #define IS_SPI_CPOL(__CPOL__) (((__CPOL__) == SPI_POLARITY_LOW) || \
\r
665 ((__CPOL__) == SPI_POLARITY_HIGH))
\r
667 /** @brief Checks if SPI Clock Phase parameter is in allowed range.
\r
668 * @param __CPHA__ specifies the SPI Clock Phase.
\r
669 * This parameter can be a value of @ref SPI_Clock_Phase
\r
672 #define IS_SPI_CPHA(__CPHA__) (((__CPHA__) == SPI_PHASE_1EDGE) || \
\r
673 ((__CPHA__) == SPI_PHASE_2EDGE))
\r
675 /** @brief Checks if SPI Slave Select parameter is in allowed range.
\r
676 * @param __NSS__ specifies the SPI Slave Select management parameter.
\r
677 * This parameter can be a value of @ref SPI_Slave_Select_management
\r
680 #define IS_SPI_NSS(__NSS__) (((__NSS__) == SPI_NSS_SOFT) || \
\r
681 ((__NSS__) == SPI_NSS_HARD_INPUT) || \
\r
682 ((__NSS__) == SPI_NSS_HARD_OUTPUT))
\r
684 /** @brief Checks if SPI NSS Pulse parameter is in allowed range.
\r
685 * @param __NSSP__ specifies the SPI NSS Pulse Mode parameter.
\r
686 * This parameter can be a value of @ref SPI_NSSP_Mode
\r
689 #define IS_SPI_NSSP(__NSSP__) (((__NSSP__) == SPI_NSS_PULSE_ENABLE) || \
\r
690 ((__NSSP__) == SPI_NSS_PULSE_DISABLE))
\r
692 /** @brief Checks if SPI Baudrate prescaler parameter is in allowed range.
\r
693 * @param __PRESCALER__ specifies the SPI Baudrate prescaler.
\r
694 * This parameter can be a value of @ref SPI_BaudRate_Prescaler
\r
697 #define IS_SPI_BAUDRATE_PRESCALER(__PRESCALER__) (((__PRESCALER__) == SPI_BAUDRATEPRESCALER_2) || \
\r
698 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_4) || \
\r
699 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_8) || \
\r
700 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_16) || \
\r
701 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_32) || \
\r
702 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_64) || \
\r
703 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_128) || \
\r
704 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_256))
\r
706 /** @brief Checks if SPI MSB LSB transmission parameter is in allowed range.
\r
707 * @param __BIT__ specifies the SPI MSB LSB transmission (whether data transfer starts from MSB or LSB bit).
\r
708 * This parameter can be a value of @ref SPI_MSB_LSB_transmission
\r
711 #define IS_SPI_FIRST_BIT(__BIT__) (((__BIT__) == SPI_FIRSTBIT_MSB) || \
\r
712 ((__BIT__) == SPI_FIRSTBIT_LSB))
\r
714 /** @brief Checks if SPI TI mode parameter is in allowed range.
\r
715 * @param __MODE__ specifies the SPI TI mode.
\r
716 * This parameter can be a value of @ref SPI_TI_mode
\r
719 #define IS_SPI_TIMODE(__MODE__) (((__MODE__) == SPI_TIMODE_DISABLE) || \
\r
720 ((__MODE__) == SPI_TIMODE_ENABLE))
\r
722 /** @brief Checks if SPI CRC calculation enabled state is in allowed range.
\r
723 * @param __CALCULATION__ specifies the SPI CRC calculation enable state.
\r
724 * This parameter can be a value of @ref SPI_CRC_Calculation
\r
727 #define IS_SPI_CRC_CALCULATION(__CALCULATION__) (((__CALCULATION__) == SPI_CRCCALCULATION_DISABLE) || \
\r
728 ((__CALCULATION__) == SPI_CRCCALCULATION_ENABLE))
\r
730 /** @brief Checks if SPI CRC length is in allowed range.
\r
731 * @param __LENGTH__ specifies the SPI CRC length.
\r
732 * This parameter can be a value of @ref SPI_CRC_length
\r
735 #define IS_SPI_CRC_LENGTH(__LENGTH__) (((__LENGTH__) == SPI_CRC_LENGTH_DATASIZE) ||\
\r
736 ((__LENGTH__) == SPI_CRC_LENGTH_8BIT) || \
\r
737 ((__LENGTH__) == SPI_CRC_LENGTH_16BIT))
\r
739 /** @brief Checks if SPI polynomial value to be used for the CRC calculation, is in allowed range.
\r
740 * @param __POLYNOMIAL__ specifies the SPI polynomial value to be used for the CRC calculation.
\r
741 * This parameter must be a number between Min_Data = 0 and Max_Data = 65535
\r
744 #define IS_SPI_CRC_POLYNOMIAL(__POLYNOMIAL__) (((__POLYNOMIAL__) >= 0x1U) && ((__POLYNOMIAL__) <= 0xFFFFU) && (((__POLYNOMIAL__)&0x1U) != 0U))
\r
746 /** @brief Checks if DMA handle is valid.
\r
747 * @param __HANDLE__ specifies a DMA Handle.
\r
750 #define IS_SPI_DMA_HANDLE(__HANDLE__) ((__HANDLE__) != NULL)
\r
756 /* Include SPI HAL Extended module */
\r
757 #include "stm32l4xx_hal_spi_ex.h"
\r
759 /* Exported functions --------------------------------------------------------*/
\r
760 /** @addtogroup SPI_Exported_Functions
\r
764 /** @addtogroup SPI_Exported_Functions_Group1
\r
767 /* Initialization/de-initialization functions ********************************/
\r
768 HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi);
\r
769 HAL_StatusTypeDef HAL_SPI_DeInit(SPI_HandleTypeDef *hspi);
\r
770 void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi);
\r
771 void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi);
\r
773 /* Callbacks Register/UnRegister functions ***********************************/
\r
774 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
\r
775 HAL_StatusTypeDef HAL_SPI_RegisterCallback(SPI_HandleTypeDef *hspi, HAL_SPI_CallbackIDTypeDef CallbackID, pSPI_CallbackTypeDef pCallback);
\r
776 HAL_StatusTypeDef HAL_SPI_UnRegisterCallback(SPI_HandleTypeDef *hspi, HAL_SPI_CallbackIDTypeDef CallbackID);
\r
777 #endif /* USE_HAL_SPI_REGISTER_CALLBACKS */
\r
782 /** @addtogroup SPI_Exported_Functions_Group2
\r
785 /* I/O operation functions ***************************************************/
\r
786 HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
\r
787 HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout);
\r
788 HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size,
\r
790 HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
\r
791 HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
\r
792 HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData,
\r
794 HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
\r
795 HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size);
\r
796 HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData,
\r
798 HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi);
\r
799 HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi);
\r
800 HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi);
\r
801 /* Transfer Abort functions */
\r
802 HAL_StatusTypeDef HAL_SPI_Abort(SPI_HandleTypeDef *hspi);
\r
803 HAL_StatusTypeDef HAL_SPI_Abort_IT(SPI_HandleTypeDef *hspi);
\r
805 void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi);
\r
806 void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi);
\r
807 void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi);
\r
808 void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi);
\r
809 void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi);
\r
810 void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi);
\r
811 void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi);
\r
812 void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi);
\r
813 void HAL_SPI_AbortCpltCallback(SPI_HandleTypeDef *hspi);
\r
818 /** @addtogroup SPI_Exported_Functions_Group3
\r
821 /* Peripheral State and Error functions ***************************************/
\r
822 HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi);
\r
823 uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi);
\r
844 #endif /* STM32L4xx_HAL_SPI_H */
\r
846 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r