Go to the documentation of this file.
21 #ifndef STM32F7xx_HAL_SPI_H
22 #define STM32F7xx_HAL_SPI_H
68 uint32_t BaudRatePrescaler;
80 uint32_t CRCCalculation;
83 uint32_t CRCPolynomial;
150 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
165 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
171 HAL_SPI_TX_COMPLETE_CB_ID = 0x00U,
172 HAL_SPI_RX_COMPLETE_CB_ID = 0x01U,
173 HAL_SPI_TX_RX_COMPLETE_CB_ID = 0x02U,
174 HAL_SPI_TX_HALF_COMPLETE_CB_ID = 0x03U,
175 HAL_SPI_RX_HALF_COMPLETE_CB_ID = 0x04U,
176 HAL_SPI_TX_RX_HALF_COMPLETE_CB_ID = 0x05U,
177 HAL_SPI_ERROR_CB_ID = 0x06U,
178 HAL_SPI_ABORT_CB_ID = 0x07U,
179 HAL_SPI_MSPINIT_CB_ID = 0x08U,
180 HAL_SPI_MSPDEINIT_CB_ID = 0x09U
182 } HAL_SPI_CallbackIDTypeDef;
202 #define HAL_SPI_ERROR_NONE (0x00000000U)
203 #define HAL_SPI_ERROR_MODF (0x00000001U)
204 #define HAL_SPI_ERROR_CRC (0x00000002U)
205 #define HAL_SPI_ERROR_OVR (0x00000004U)
206 #define HAL_SPI_ERROR_FRE (0x00000008U)
207 #define HAL_SPI_ERROR_DMA (0x00000010U)
208 #define HAL_SPI_ERROR_FLAG (0x00000020U)
209 #define HAL_SPI_ERROR_ABORT (0x00000040U)
210 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
211 #define HAL_SPI_ERROR_INVALID_CALLBACK (0x00000080U)
220 #define SPI_MODE_SLAVE (0x00000000U)
221 #define SPI_MODE_MASTER (SPI_CR1_MSTR | SPI_CR1_SSI)
229 #define SPI_DIRECTION_2LINES (0x00000000U)
230 #define SPI_DIRECTION_2LINES_RXONLY SPI_CR1_RXONLY
231 #define SPI_DIRECTION_1LINE SPI_CR1_BIDIMODE
239 #define SPI_DATASIZE_4BIT (0x00000300U)
240 #define SPI_DATASIZE_5BIT (0x00000400U)
241 #define SPI_DATASIZE_6BIT (0x00000500U)
242 #define SPI_DATASIZE_7BIT (0x00000600U)
243 #define SPI_DATASIZE_8BIT (0x00000700U)
244 #define SPI_DATASIZE_9BIT (0x00000800U)
245 #define SPI_DATASIZE_10BIT (0x00000900U)
246 #define SPI_DATASIZE_11BIT (0x00000A00U)
247 #define SPI_DATASIZE_12BIT (0x00000B00U)
248 #define SPI_DATASIZE_13BIT (0x00000C00U)
249 #define SPI_DATASIZE_14BIT (0x00000D00U)
250 #define SPI_DATASIZE_15BIT (0x00000E00U)
251 #define SPI_DATASIZE_16BIT (0x00000F00U)
259 #define SPI_POLARITY_LOW (0x00000000U)
260 #define SPI_POLARITY_HIGH SPI_CR1_CPOL
268 #define SPI_PHASE_1EDGE (0x00000000U)
269 #define SPI_PHASE_2EDGE SPI_CR1_CPHA
277 #define SPI_NSS_SOFT SPI_CR1_SSM
278 #define SPI_NSS_HARD_INPUT (0x00000000U)
279 #define SPI_NSS_HARD_OUTPUT (SPI_CR2_SSOE << 16U)
287 #define SPI_NSS_PULSE_ENABLE SPI_CR2_NSSP
288 #define SPI_NSS_PULSE_DISABLE (0x00000000U)
296 #define SPI_BAUDRATEPRESCALER_2 (0x00000000U)
297 #define SPI_BAUDRATEPRESCALER_4 (SPI_CR1_BR_0)
298 #define SPI_BAUDRATEPRESCALER_8 (SPI_CR1_BR_1)
299 #define SPI_BAUDRATEPRESCALER_16 (SPI_CR1_BR_1 | SPI_CR1_BR_0)
300 #define SPI_BAUDRATEPRESCALER_32 (SPI_CR1_BR_2)
301 #define SPI_BAUDRATEPRESCALER_64 (SPI_CR1_BR_2 | SPI_CR1_BR_0)
302 #define SPI_BAUDRATEPRESCALER_128 (SPI_CR1_BR_2 | SPI_CR1_BR_1)
303 #define SPI_BAUDRATEPRESCALER_256 (SPI_CR1_BR_2 | SPI_CR1_BR_1 | SPI_CR1_BR_0)
311 #define SPI_FIRSTBIT_MSB (0x00000000U)
312 #define SPI_FIRSTBIT_LSB SPI_CR1_LSBFIRST
320 #define SPI_TIMODE_DISABLE (0x00000000U)
321 #define SPI_TIMODE_ENABLE SPI_CR2_FRF
329 #define SPI_CRCCALCULATION_DISABLE (0x00000000U)
330 #define SPI_CRCCALCULATION_ENABLE SPI_CR1_CRCEN
342 #define SPI_CRC_LENGTH_DATASIZE (0x00000000U)
343 #define SPI_CRC_LENGTH_8BIT (0x00000001U)
344 #define SPI_CRC_LENGTH_16BIT (0x00000002U)
357 #define SPI_RXFIFO_THRESHOLD SPI_CR2_FRXTH
358 #define SPI_RXFIFO_THRESHOLD_QF SPI_CR2_FRXTH
359 #define SPI_RXFIFO_THRESHOLD_HF (0x00000000U)
367 #define SPI_IT_TXE SPI_CR2_TXEIE
368 #define SPI_IT_RXNE SPI_CR2_RXNEIE
369 #define SPI_IT_ERR SPI_CR2_ERRIE
377 #define SPI_FLAG_RXNE SPI_SR_RXNE
378 #define SPI_FLAG_TXE SPI_SR_TXE
379 #define SPI_FLAG_BSY SPI_SR_BSY
380 #define SPI_FLAG_CRCERR SPI_SR_CRCERR
381 #define SPI_FLAG_MODF SPI_SR_MODF
382 #define SPI_FLAG_OVR SPI_SR_OVR
383 #define SPI_FLAG_FRE SPI_SR_FRE
384 #define SPI_FLAG_FTLVL SPI_SR_FTLVL
385 #define SPI_FLAG_FRLVL SPI_SR_FRLVL
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)
394 #define SPI_FTLVL_EMPTY (0x00000000U)
395 #define SPI_FTLVL_QUARTER_FULL (0x00000800U)
396 #define SPI_FTLVL_HALF_FULL (0x00001000U)
397 #define SPI_FTLVL_FULL (0x00001800U)
406 #define SPI_FRLVL_EMPTY (0x00000000U)
407 #define SPI_FRLVL_QUARTER_FULL (0x00000200U)
408 #define SPI_FRLVL_HALF_FULL (0x00000400U)
409 #define SPI_FRLVL_FULL (0x00000600U)
428 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
429 #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) do{ \
430 (__HANDLE__)->State = HAL_SPI_STATE_RESET; \
431 (__HANDLE__)->MspInitCallback = NULL; \
432 (__HANDLE__)->MspDeInitCallback = NULL; \
435 #define __HAL_SPI_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SPI_STATE_RESET)
448 #define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__) SET_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))
460 #define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__) CLEAR_BIT((__HANDLE__)->Instance->CR2, (__INTERRUPT__))
472 #define __HAL_SPI_GET_IT_SOURCE(__HANDLE__, __INTERRUPT__) ((((__HANDLE__)->Instance->CR2 & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
490 #define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__) ((((__HANDLE__)->Instance->SR) & (__FLAG__)) == (__FLAG__))
497 #define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__) ((__HANDLE__)->Instance->SR = (uint16_t)(~SPI_FLAG_CRCERR))
504 #define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__) \
506 __IO uint32_t tmpreg_modf = 0x00U; \
507 tmpreg_modf = (__HANDLE__)->Instance->SR; \
508 CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE); \
509 UNUSED(tmpreg_modf); \
517 #define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__) \
519 __IO uint32_t tmpreg_ovr = 0x00U; \
520 tmpreg_ovr = (__HANDLE__)->Instance->DR; \
521 tmpreg_ovr = (__HANDLE__)->Instance->SR; \
522 UNUSED(tmpreg_ovr); \
530 #define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__) \
532 __IO uint32_t tmpreg_fre = 0x00U; \
533 tmpreg_fre = (__HANDLE__)->Instance->SR; \
534 UNUSED(tmpreg_fre); \
542 #define __HAL_SPI_ENABLE(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE)
549 #define __HAL_SPI_DISABLE(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_SPE)
565 #define SPI_1LINE_TX(__HANDLE__) SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE)
572 #define SPI_1LINE_RX(__HANDLE__) CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_BIDIOE)
579 #define SPI_RESET_CRC(__HANDLE__) do{CLEAR_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN);\
580 SET_BIT((__HANDLE__)->Instance->CR1, SPI_CR1_CRCEN);}while(0U)
597 #define SPI_CHECK_FLAG(__SR__, __FLAG__) ((((__SR__) & ((__FLAG__) & SPI_FLAG_MASK)) == ((__FLAG__) & SPI_FLAG_MASK)) ? SET : RESET)
608 #define SPI_CHECK_IT_SOURCE(__CR2__, __INTERRUPT__) ((((__CR2__) & (__INTERRUPT__)) == (__INTERRUPT__)) ? SET : RESET)
615 #define IS_SPI_MODE(__MODE__) (((__MODE__) == SPI_MODE_SLAVE) || \
616 ((__MODE__) == SPI_MODE_MASTER))
623 #define IS_SPI_DIRECTION(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \
624 ((__MODE__) == SPI_DIRECTION_2LINES_RXONLY) || \
625 ((__MODE__) == SPI_DIRECTION_1LINE))
631 #define IS_SPI_DIRECTION_2LINES(__MODE__) ((__MODE__) == SPI_DIRECTION_2LINES)
637 #define IS_SPI_DIRECTION_2LINES_OR_1LINE(__MODE__) (((__MODE__) == SPI_DIRECTION_2LINES) || \
638 ((__MODE__) == SPI_DIRECTION_1LINE))
645 #define IS_SPI_DATASIZE(__DATASIZE__) (((__DATASIZE__) == SPI_DATASIZE_16BIT) || \
646 ((__DATASIZE__) == SPI_DATASIZE_15BIT) || \
647 ((__DATASIZE__) == SPI_DATASIZE_14BIT) || \
648 ((__DATASIZE__) == SPI_DATASIZE_13BIT) || \
649 ((__DATASIZE__) == SPI_DATASIZE_12BIT) || \
650 ((__DATASIZE__) == SPI_DATASIZE_11BIT) || \
651 ((__DATASIZE__) == SPI_DATASIZE_10BIT) || \
652 ((__DATASIZE__) == SPI_DATASIZE_9BIT) || \
653 ((__DATASIZE__) == SPI_DATASIZE_8BIT) || \
654 ((__DATASIZE__) == SPI_DATASIZE_7BIT) || \
655 ((__DATASIZE__) == SPI_DATASIZE_6BIT) || \
656 ((__DATASIZE__) == SPI_DATASIZE_5BIT) || \
657 ((__DATASIZE__) == SPI_DATASIZE_4BIT))
664 #define IS_SPI_CPOL(__CPOL__) (((__CPOL__) == SPI_POLARITY_LOW) || \
665 ((__CPOL__) == SPI_POLARITY_HIGH))
672 #define IS_SPI_CPHA(__CPHA__) (((__CPHA__) == SPI_PHASE_1EDGE) || \
673 ((__CPHA__) == SPI_PHASE_2EDGE))
680 #define IS_SPI_NSS(__NSS__) (((__NSS__) == SPI_NSS_SOFT) || \
681 ((__NSS__) == SPI_NSS_HARD_INPUT) || \
682 ((__NSS__) == SPI_NSS_HARD_OUTPUT))
689 #define IS_SPI_NSSP(__NSSP__) (((__NSSP__) == SPI_NSS_PULSE_ENABLE) || \
690 ((__NSSP__) == SPI_NSS_PULSE_DISABLE))
697 #define IS_SPI_BAUDRATE_PRESCALER(__PRESCALER__) (((__PRESCALER__) == SPI_BAUDRATEPRESCALER_2) || \
698 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_4) || \
699 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_8) || \
700 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_16) || \
701 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_32) || \
702 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_64) || \
703 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_128) || \
704 ((__PRESCALER__) == SPI_BAUDRATEPRESCALER_256))
711 #define IS_SPI_FIRST_BIT(__BIT__) (((__BIT__) == SPI_FIRSTBIT_MSB) || \
712 ((__BIT__) == SPI_FIRSTBIT_LSB))
719 #define IS_SPI_TIMODE(__MODE__) (((__MODE__) == SPI_TIMODE_DISABLE) || \
720 ((__MODE__) == SPI_TIMODE_ENABLE))
727 #define IS_SPI_CRC_CALCULATION(__CALCULATION__) (((__CALCULATION__) == SPI_CRCCALCULATION_DISABLE) || \
728 ((__CALCULATION__) == SPI_CRCCALCULATION_ENABLE))
735 #define IS_SPI_CRC_LENGTH(__LENGTH__) (((__LENGTH__) == SPI_CRC_LENGTH_DATASIZE) ||\
736 ((__LENGTH__) == SPI_CRC_LENGTH_8BIT) || \
737 ((__LENGTH__) == SPI_CRC_LENGTH_16BIT))
744 #define IS_SPI_CRC_POLYNOMIAL(__POLYNOMIAL__) (((__POLYNOMIAL__) >= 0x1U) && ((__POLYNOMIAL__) <= 0xFFFFU) && (((__POLYNOMIAL__)&0x1U) != 0U))
750 #define IS_SPI_DMA_HANDLE(__HANDLE__) ((__HANDLE__) != NULL)
774 #if (USE_HAL_SPI_REGISTER_CALLBACKS == 1U)
void HAL_SPI_AbortCpltCallback(SPI_HandleTypeDef *hspi)
HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi)
Serial Peripheral Interface.
HAL_StatusTypeDef
HAL Status structures definition
HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
DMA handle Structure definition.
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)
struct __SPI_HandleTypeDef SPI_HandleTypeDef
SPI handle Structure definition.
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
void(* TxISR)(struct __SPI_HandleTypeDef *hspi)
SPI handle Structure definition.
HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi)
Header file of SPI HAL Extended module.
void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi)
HAL_LockTypeDef
HAL Lock structures definition
HAL_StatusTypeDef HAL_SPI_Abort(SPI_HandleTypeDef *hspi)
SPI Configuration Structure definition.
DMA_HandleTypeDef * hdmatx
HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
__IO uint16_t RxXferCount
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
void(* RxISR)(struct __SPI_HandleTypeDef *hspi)
void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi)
@ HAL_SPI_STATE_BUSY_TX_RX
__IO uint16_t TxXferCount
HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi)
uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi)
__IO HAL_SPI_StateTypeDef State
HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi)
This file contains HAL common defines, enumeration, macros and structures definitions.
HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi)
HAL_SPI_StateTypeDef
HAL SPI State structure definition.
HAL_StatusTypeDef HAL_SPI_Abort_IT(SPI_HandleTypeDef *hspi)
void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi)
DMA_HandleTypeDef * hdmarx
HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
HAL_StatusTypeDef HAL_SPI_DeInit(SPI_HandleTypeDef *hspi)
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi)