STM32F769IDiscovery  1.00
uDANTE Audio Networking with STM32F7 DISCO board
stm32f7xx_hal_spi.c
Go to the documentation of this file.
1 
87 /* Includes ------------------------------------------------------------------*/
88 #include "stm32f7xx_hal.h"
89 
98 #ifdef HAL_SPI_MODULE_ENABLED
99 
100 /* Private typedef -----------------------------------------------------------*/
101 /* Private defines -----------------------------------------------------------*/
105 #define SPI_DEFAULT_TIMEOUT 50
106 
110 /* Private macros ------------------------------------------------------------*/
111 /* Private variables ---------------------------------------------------------*/
112 /* Private function prototypes -----------------------------------------------*/
116 static void SPI_DMATransmitCplt(DMA_HandleTypeDef *hdma);
117 static void SPI_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
118 static void SPI_DMATransmitReceiveCplt(DMA_HandleTypeDef *hdma);
119 static void SPI_DMAHalfTransmitCplt(DMA_HandleTypeDef *hdma);
120 static void SPI_DMAHalfReceiveCplt(DMA_HandleTypeDef *hdma);
121 static void SPI_DMAHalfTransmitReceiveCplt(DMA_HandleTypeDef *hdma);
122 static void SPI_DMAError(DMA_HandleTypeDef *hdma);
123 static void SPI_DMAAbortOnError(DMA_HandleTypeDef *hdma);
124 static HAL_StatusTypeDef SPI_WaitFlagStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Flag, uint32_t State, uint32_t Timeout);
125 static HAL_StatusTypeDef SPI_WaitFifoStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Fifo, uint32_t State, uint32_t Timeout);
126 static void SPI_TxISR_8BIT(struct __SPI_HandleTypeDef *hspi);
127 static void SPI_TxISR_16BIT(struct __SPI_HandleTypeDef *hspi);
128 static void SPI_RxISR_8BIT(struct __SPI_HandleTypeDef *hspi);
129 #if (USE_SPI_CRC != 0U)
130 static void SPI_RxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi);
131 static void SPI_RxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi);
132 static void SPI_2linesRxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi);
133 static void SPI_2linesRxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi);
134 #endif
135 static void SPI_RxISR_16BIT(struct __SPI_HandleTypeDef *hspi);
136 static void SPI_2linesRxISR_8BIT(struct __SPI_HandleTypeDef *hspi);
137 static void SPI_2linesTxISR_8BIT(struct __SPI_HandleTypeDef *hspi);
138 static void SPI_2linesTxISR_16BIT(struct __SPI_HandleTypeDef *hspi);
139 static void SPI_2linesRxISR_16BIT(struct __SPI_HandleTypeDef *hspi);
140 static void SPI_CloseRxTx_ISR(SPI_HandleTypeDef *hspi);
141 static void SPI_CloseRx_ISR(SPI_HandleTypeDef *hspi);
142 static void SPI_CloseTx_ISR(SPI_HandleTypeDef *hspi);
143 static HAL_StatusTypeDef SPI_EndRxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout);
144 static HAL_StatusTypeDef SPI_EndRxTxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout);
149 /* Exported functions ---------------------------------------------------------*/
150 
198 {
199  uint32_t frxth;
200 
201  /* Check the SPI handle allocation */
202  if(hspi == NULL)
203  {
204  return HAL_ERROR;
205  }
206 
207  /* Check the parameters */
219 #if (USE_SPI_CRC != 0U)
222  {
225  }
226  /* Align the CRC Length on the data size */
228  {
229  /* CRC Length aligned on the data size : value set by default */
230  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
231  {
233  }
234  else
235  {
237  }
238  }
239 #endif
240 
241  if(hspi->State == HAL_SPI_STATE_RESET)
242  {
243  /* Allocate lock resource and initialize it */
244  hspi->Lock = HAL_UNLOCKED;
245 
246  /* Init the low level hardware : GPIO, CLOCK, NVIC... */
247  HAL_SPI_MspInit(hspi);
248  }
249 
250  hspi->State = HAL_SPI_STATE_BUSY;
251 
252  /* Disable the selected SPI peripheral */
253  __HAL_SPI_DISABLE(hspi);
254 
255  /* Align by default the rs fifo threshold on the data size */
256  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
257  {
258  frxth = SPI_RXFIFO_THRESHOLD_HF;
259  }
260  else
261  {
262  frxth = SPI_RXFIFO_THRESHOLD_QF;
263  }
264 
265  /* CRC calculation is valid only for 16Bit and 8 Bit */
266  if(( hspi->Init.DataSize != SPI_DATASIZE_16BIT ) && ( hspi->Init.DataSize != SPI_DATASIZE_8BIT ))
267  {
268  /* CRC must be disabled */
270  }
271 
272  /*---------------------------- SPIx CR1 & CR2 Configuration ------------------------*/
273  /* Configure : SPI Mode, Communication Mode, Clock polarity and phase, NSS management,
274  Communication speed, First bit, CRC calculation state, CRC Length */
275  hspi->Instance->CR1 = (hspi->Init.Mode | hspi->Init.Direction |
276  hspi->Init.CLKPolarity | hspi->Init.CLKPhase | (hspi->Init.NSS & SPI_CR1_SSM) |
277  hspi->Init.BaudRatePrescaler | hspi->Init.FirstBit | hspi->Init.CRCCalculation);
278 
279  if( hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT)
280  {
281  hspi->Instance->CR1|= SPI_CR1_CRCL;
282  }
283 
284  /* Configure : NSS management */
285  /* Configure : Rx Fifo Threshold */
286  hspi->Instance->CR2 = (((hspi->Init.NSS >> 16) & SPI_CR2_SSOE) | hspi->Init.TIMode | hspi->Init.NSSPMode |
287  hspi->Init.DataSize ) | frxth;
288 
289 #if (USE_SPI_CRC != 0U)
290  /*---------------------------- SPIx CRCPOLY Configuration --------------------*/
291  /* Configure : CRC Polynomial */
292  WRITE_REG(hspi->Instance->CRCPR, hspi->Init.CRCPolynomial);
293 #endif
294 
296  hspi->State= HAL_SPI_STATE_READY;
297 
298  return HAL_OK;
299 }
300 
308 {
309  /* Check the SPI handle allocation */
310  if(hspi == NULL)
311  {
312  return HAL_ERROR;
313  }
314 
315  /* Check the parameters */
317 
318  hspi->State = HAL_SPI_STATE_BUSY;
319 
320  /* Disable the SPI Peripheral Clock */
321  __HAL_SPI_DISABLE(hspi);
322 
323  /* DeInit the low level hardware: GPIO, CLOCK, NVIC... */
324  HAL_SPI_MspDeInit(hspi);
325 
327  hspi->State = HAL_SPI_STATE_RESET;
328 
329  __HAL_UNLOCK(hspi);
330 
331  return HAL_OK;
332 }
333 
340 __weak void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
341 {
342  /* Prevent unused argument(s) compilation warning */
343  UNUSED(hspi);
344 
345  /* NOTE : This function should not be modified, when the callback is needed,
346  the HAL_SPI_MspInit should be implemented in the user file
347  */
348 }
349 
356 __weak void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)
357 {
358  /* Prevent unused argument(s) compilation warning */
359  UNUSED(hspi);
360 
361  /* NOTE : This function should not be modified, when the callback is needed,
362  the HAL_SPI_MspDeInit should be implemented in the user file
363  */
364 }
365 
412 HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
413 {
414  uint32_t tickstart = HAL_GetTick();
415  HAL_StatusTypeDef errorcode = HAL_OK;
416 
418 
419  /* Process Locked */
420  __HAL_LOCK(hspi);
421 
422  if(hspi->State != HAL_SPI_STATE_READY)
423  {
424  errorcode = HAL_BUSY;
425  goto error;
426  }
427 
428  if((pData == NULL ) || (Size == 0))
429  {
430  errorcode = HAL_ERROR;
431  goto error;
432  }
433 
434  /* Set the transaction information */
437  hspi->pTxBuffPtr = pData;
438  hspi->TxXferSize = Size;
439  hspi->TxXferCount = Size;
440  hspi->pRxBuffPtr = (uint8_t *)NULL;
441  hspi->RxXferSize = 0;
442  hspi->RxXferCount = 0;
443 
444  /* Configure communication direction : 1Line */
445  if(hspi->Init.Direction == SPI_DIRECTION_1LINE)
446  {
447  SPI_1LINE_TX(hspi);
448  }
449 
450 #if (USE_SPI_CRC != 0U)
451  /* Reset CRC Calculation */
453  {
454  SPI_RESET_CRC(hspi);
455  }
456 #endif
457 
458  /* Check if the SPI is already enabled */
459  if((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
460  {
461  /* Enable SPI peripheral */
462  __HAL_SPI_ENABLE(hspi);
463  }
464 
465  /* Transmit data in 16 Bit mode */
466  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
467  {
468  /* Transmit data in 16 Bit mode */
469  while (hspi->TxXferCount > 0)
470  {
471  /* Wait until TXE flag is set to send data */
472  if((hspi->Instance->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE)
473  {
474  hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr);
475  hspi->pTxBuffPtr += sizeof(uint16_t);
476  hspi->TxXferCount--;
477  }
478  else
479  {
480  /* Timeout management */
481  if((Timeout == 0) || ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout)))
482  {
483  errorcode = HAL_TIMEOUT;
484  goto error;
485  }
486  }
487  }
488  }
489  /* Transmit data in 8 Bit mode */
490  else
491  {
492  while (hspi->TxXferCount > 0)
493  {
494  /* Wait until TXE flag is set to send data */
495  if((hspi->Instance->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE)
496  {
497  if(hspi->TxXferCount > 1)
498  {
499  /* write on the data register in packing mode */
500  hspi->Instance->DR = *((uint16_t*)hspi->pTxBuffPtr);
501  hspi->pTxBuffPtr += sizeof(uint16_t);
502  hspi->TxXferCount -= 2;
503  }
504  else
505  {
506  *((__IO uint8_t*)&hspi->Instance->DR) = (*hspi->pTxBuffPtr++);
507  hspi->TxXferCount--;
508  }
509  }
510  else
511  {
512  /* Timeout management */
513  if((Timeout == 0) || ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout)))
514  {
515  errorcode = HAL_TIMEOUT;
516  goto error;
517  }
518  }
519  }
520  }
521 
522 #if (USE_SPI_CRC != 0U)
523  /* Enable CRC Transmission */
525  {
526  hspi->Instance->CR1|= SPI_CR1_CRCNEXT;
527  }
528 #endif
529 
530  /* Check the end of the transaction */
531  if(SPI_EndRxTxTransaction(hspi,Timeout) != HAL_OK)
532  {
534  }
535 
536  /* Clear overrun flag in 2 Lines communication mode because received is not read */
537  if(hspi->Init.Direction == SPI_DIRECTION_2LINES)
538  {
540  }
541 
542  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
543  {
544  errorcode = HAL_ERROR;
545  }
546 
547 error:
548  hspi->State = HAL_SPI_STATE_READY;
549  /* Process Unlocked */
550  __HAL_UNLOCK(hspi);
551  return errorcode;
552 }
553 
563 HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
564 {
565 #if (USE_SPI_CRC != 0U)
566  __IO uint16_t tmpreg;
567 #endif
568  uint32_t tickstart = HAL_GetTick();
569  HAL_StatusTypeDef errorcode = HAL_OK;
570 
571  if((hspi->Init.Mode == SPI_MODE_MASTER) && (hspi->Init.Direction == SPI_DIRECTION_2LINES))
572  {
573  /* the receive process is not supported in 2Lines direction master mode */
574  /* in this case we call the TransmitReceive process */
575  /* Process Locked */
576  return HAL_SPI_TransmitReceive(hspi,pData,pData,Size,Timeout);
577  }
578 
579  /* Process Locked */
580  __HAL_LOCK(hspi);
581 
582  if(hspi->State != HAL_SPI_STATE_READY)
583  {
584  errorcode = HAL_BUSY;
585  goto error;
586  }
587 
588  if((pData == NULL ) || (Size == 0))
589  {
590  errorcode = HAL_ERROR;
591  goto error;
592  }
593 
596  hspi->pRxBuffPtr = pData;
597  hspi->RxXferSize = Size;
598  hspi->RxXferCount = Size;
599  hspi->pTxBuffPtr = (uint8_t *)NULL;
600  hspi->TxXferSize = 0;
601  hspi->TxXferCount = 0;
602 
603 #if (USE_SPI_CRC != 0U)
604  /* Reset CRC Calculation */
606  {
607  SPI_RESET_CRC(hspi);
608  /* this is done to handle the CRCNEXT before the latest data */
609  hspi->RxXferCount--;
610  }
611 #endif
612 
613  /* Set the Rx Fido threshold */
614  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
615  {
616  /* set fiforxthreshold according the reception data length: 16bit */
618  }
619  else
620  {
621  /* set fiforxthreshold according the reception data length: 8bit */
623  }
624 
625  /* Configure communication direction 1Line and enabled SPI if needed */
626  if(hspi->Init.Direction == SPI_DIRECTION_1LINE)
627  {
628  SPI_1LINE_RX(hspi);
629  }
630 
631  /* Check if the SPI is already enabled */
632  if((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
633  {
634  /* Enable SPI peripheral */
635  __HAL_SPI_ENABLE(hspi);
636  }
637 
638  /* Receive data in 8 Bit mode */
639  if(hspi->Init.DataSize <= SPI_DATASIZE_8BIT)
640  {
641  /* Transfer loop */
642  while(hspi->RxXferCount > 0)
643  {
644  /* Check the RXNE flag */
645  if((hspi->Instance->SR & SPI_FLAG_RXNE) == SPI_FLAG_RXNE)
646  {
647  /* read the received data */
648  (*hspi->pRxBuffPtr++)= *(__IO uint8_t *)&hspi->Instance->DR;
649  hspi->RxXferCount--;
650  }
651  else
652  {
653  /* Timeout management */
654  if((Timeout == 0) || ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout)))
655  {
656  errorcode = HAL_TIMEOUT;
657  goto error;
658  }
659  }
660  }
661  }
662  else
663  {
664  /* Transfer loop */
665  while(hspi->RxXferCount > 0)
666  {
667  /* Check the RXNE flag */
668  if((hspi->Instance->SR & SPI_FLAG_RXNE) == SPI_FLAG_RXNE)
669  {
670  *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;
671  hspi->pRxBuffPtr += sizeof(uint16_t);
672  hspi->RxXferCount--;
673  }
674  else
675  {
676  /* Timeout management */
677  if((Timeout == 0) || ((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout)))
678  {
679  errorcode = HAL_TIMEOUT;
680  goto error;
681  }
682  }
683  }
684  }
685 
686 #if (USE_SPI_CRC != 0U)
687  /* Handle the CRC Transmission */
689  {
690  /* freeze the CRC before the latest data */
691  hspi->Instance->CR1|= SPI_CR1_CRCNEXT;
692 
693  /* Read the latest data */
694  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SPI_FLAG_RXNE, Timeout) != HAL_OK)
695  {
696  /* the latest data has not been received */
697  errorcode = HAL_TIMEOUT;
698  goto error;
699  }
700 
701  /* Receive last data in 16 Bit mode */
702  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
703  {
704  *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;
705  }
706  /* Receive last data in 8 Bit mode */
707  else
708  {
709  *hspi->pRxBuffPtr = *(__IO uint8_t *)&hspi->Instance->DR;
710  }
711 
712  /* Wait until TXE flag */
713  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SPI_FLAG_RXNE, Timeout) != HAL_OK)
714  {
715  /* Flag Error*/
717  errorcode = HAL_TIMEOUT;
718  goto error;
719  }
720 
721  if(hspi->Init.DataSize == SPI_DATASIZE_16BIT)
722  {
723  tmpreg = hspi->Instance->DR;
724  UNUSED(tmpreg); /* To avoid GCC warning */
725  }
726  else
727  {
728  tmpreg = *(__IO uint8_t *)&hspi->Instance->DR;
729  UNUSED(tmpreg); /* To avoid GCC warning */
730 
732  {
733  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SPI_FLAG_RXNE, Timeout) != HAL_OK)
734  {
735  /* Error on the CRC reception */
737  errorcode = HAL_TIMEOUT;
738  goto error;
739  }
740  tmpreg = *(__IO uint8_t *)&hspi->Instance->DR;
741  UNUSED(tmpreg); /* To avoid GCC warning */
742  }
743  }
744  }
745 #endif
746 
747  /* Check the end of the transaction */
748  if(SPI_EndRxTransaction(hspi,Timeout) != HAL_OK)
749  {
751  }
752 
753 #if (USE_SPI_CRC != 0U)
754  /* Check if CRC error occurred */
756  {
759  }
760 #endif
761 
762  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
763  {
764  errorcode = HAL_ERROR;
765  }
766 
767 error :
768  hspi->State = HAL_SPI_STATE_READY;
769  __HAL_UNLOCK(hspi);
770  return errorcode;
771 }
772 
783 HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
784 {
785 #if (USE_SPI_CRC != 0U)
786  __IO uint16_t tmpreg;
787 #endif
788  uint32_t tickstart = HAL_GetTick();
789  /* Variable used to alternate Rx and Tx during transfer */
790  uint32_t txallowed = 1U;
791 
792  HAL_StatusTypeDef errorcode = HAL_OK;
793 
795 
796  /* Process Locked */
797  __HAL_LOCK(hspi);
798 
799  if(hspi->State != HAL_SPI_STATE_READY)
800  {
801  errorcode = HAL_BUSY;
802  goto error;
803  }
804 
805  if((pTxData == NULL) || (pRxData == NULL) || (Size == 0))
806  {
807  errorcode = HAL_ERROR;
808  goto error;
809  }
810 
813  hspi->pRxBuffPtr = pRxData;
814  hspi->RxXferCount = Size;
815  hspi->RxXferSize = Size;
816  hspi->pTxBuffPtr = pTxData;
817  hspi->TxXferCount = Size;
818  hspi->TxXferSize = Size;
819 
820 #if (USE_SPI_CRC != 0U)
821  /* Reset CRC Calculation */
823  {
824  SPI_RESET_CRC(hspi);
825  }
826 #endif
827 
828  /* Set the Rx Fifo threshold */
829  if((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || (hspi->RxXferCount > 1))
830  {
831  /* set fiforxthreshold according the reception data length: 16bit */
833  }
834  else
835  {
836  /* set fiforxthreshold according the reception data length: 8bit */
838  }
839 
840  /* Check if the SPI is already enabled */
841  if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
842  {
843  /* Enable SPI peripheral */
844  __HAL_SPI_ENABLE(hspi);
845  }
846 
847  /* Transmit and Receive data in 16 Bit mode */
848  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
849  {
850  while ((hspi->TxXferCount > 0 ) || (hspi->RxXferCount > 0))
851  {
852  /* Check TXE flag */
853  if(txallowed && ((hspi->TxXferCount > 0) && ((hspi->Instance->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE)))
854  {
855  hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr);
856  hspi->pTxBuffPtr += sizeof(uint16_t);
857  hspi->TxXferCount--;
858  /* Next Data is a reception (Rx). Tx not allowed */
859  txallowed = 0U;
860 
861 #if (USE_SPI_CRC != 0U)
862  /* Enable CRC Transmission */
863  if((hspi->TxXferCount == 0) && (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE))
864  {
865  /* Set NSS Soft to received correctly the CRC on slave mode with NSS pulse activated */
866  if(((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) && ((hspi->Instance->CR2 & SPI_CR2_NSSP) == SPI_CR2_NSSP))
867  {
868  SET_BIT(hspi->Instance->CR1, SPI_CR1_SSM);
869  }
871  }
872 #endif
873  }
874  /* Check RXNE flag */
875  if((hspi->RxXferCount > 0) && ((hspi->Instance->SR & SPI_FLAG_RXNE) == SPI_FLAG_RXNE))
876  {
877  *((uint16_t *)hspi->pRxBuffPtr) = hspi->Instance->DR;
878  hspi->pRxBuffPtr += sizeof(uint16_t);
879  hspi->RxXferCount--;
880  /* Next Data is a reception (Rx). Tx not allowed */
881  txallowed = 1U;
882  }
883  if((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout))
884  {
885  errorcode = HAL_TIMEOUT;
886  goto error;
887  }
888  }
889  }
890  /* Transmit and Receive data in 8 Bit mode */
891  else
892  {
893  while((hspi->TxXferCount > 0) || (hspi->RxXferCount > 0))
894  {
895  /* check TXE flag */
896  if(txallowed && ((hspi->TxXferCount > 0) && ((hspi->Instance->SR & SPI_FLAG_TXE) == SPI_FLAG_TXE)))
897  {
898  if(hspi->TxXferCount > 1)
899  {
900  hspi->Instance->DR = *((uint16_t*)hspi->pTxBuffPtr);
901  hspi->pTxBuffPtr += sizeof(uint16_t);
902  hspi->TxXferCount -= 2;
903  }
904  else
905  {
906  *(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr++);
907  hspi->TxXferCount--;
908  /* Next Data is a reception (Rx). Tx not allowed */
909  txallowed = 0U;
910  }
911 
912 #if (USE_SPI_CRC != 0U)
913  /* Enable CRC Transmission */
914  if((hspi->TxXferCount == 0) && (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE))
915  {
916  /* Set NSS Soft to received correctly the CRC on slave mode with NSS pulse activated */
917  if(((hspi->Instance->CR1 & SPI_CR1_MSTR) == 0) && ((hspi->Instance->CR2 & SPI_CR2_NSSP) == SPI_CR2_NSSP))
918  {
919  SET_BIT(hspi->Instance->CR1, SPI_CR1_SSM);
920  }
922  }
923 #endif
924  }
925 
926  /* Wait until RXNE flag is reset */
927  if((hspi->RxXferCount > 0) && ((hspi->Instance->SR & SPI_FLAG_RXNE) == SPI_FLAG_RXNE))
928  {
929  if(hspi->RxXferCount > 1)
930  {
931  *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;
932  hspi->pRxBuffPtr += sizeof(uint16_t);
933  hspi->RxXferCount -= 2;
934  if(hspi->RxXferCount <= 1)
935  {
936  /* set fiforxthreshold before to switch on 8 bit data size */
938  }
939  }
940  else
941  {
942  (*hspi->pRxBuffPtr++) = *(__IO uint8_t *)&hspi->Instance->DR;
943  hspi->RxXferCount--;
944  /* Next Data is a Transmission (Tx). Tx is allowed */
945  txallowed = 1U;
946  }
947  }
948  if((Timeout != HAL_MAX_DELAY) && ((HAL_GetTick()-tickstart) >= Timeout))
949  {
950  errorcode = HAL_TIMEOUT;
951  goto error;
952  }
953  }
954  }
955 
956 #if (USE_SPI_CRC != 0U)
957  /* Read CRC from DR to close CRC calculation process */
959  {
960  /* Wait until TXE flag */
961  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SPI_FLAG_RXNE, Timeout) != HAL_OK)
962  {
963  /* Error on the CRC reception */
965  errorcode = HAL_TIMEOUT;
966  goto error;
967  }
968 
969  if(hspi->Init.DataSize == SPI_DATASIZE_16BIT)
970  {
971  tmpreg = hspi->Instance->DR;
972  UNUSED(tmpreg); /* To avoid GCC warning */
973  }
974  else
975  {
976  tmpreg = *(__IO uint8_t *)&hspi->Instance->DR;
977  UNUSED(tmpreg); /* To avoid GCC warning */
978 
979  if(hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT)
980  {
981  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SPI_FLAG_RXNE, Timeout) != HAL_OK)
982  {
983  /* Error on the CRC reception */
985  errorcode = HAL_TIMEOUT;
986  goto error;
987  }
988  tmpreg = *(__IO uint8_t *)&hspi->Instance->DR;
989  UNUSED(tmpreg); /* To avoid GCC warning */
990  }
991  }
992  }
993 
994  /* Check if CRC error occurred */
996  {
998  /* Clear CRC Flag */
1000 
1001  errorcode = HAL_ERROR;
1002  }
1003 #endif
1004 
1005  /* Check the end of the transaction */
1006  if(SPI_EndRxTxTransaction(hspi,Timeout) != HAL_OK)
1007  {
1008  hspi->ErrorCode = HAL_SPI_ERROR_FLAG;
1009  }
1010 
1011  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
1012  {
1013  errorcode = HAL_ERROR;
1014  }
1015 
1016 error :
1017  hspi->State = HAL_SPI_STATE_READY;
1018  __HAL_UNLOCK(hspi);
1019  return errorcode;
1020 }
1021 
1030 HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
1031 {
1032  HAL_StatusTypeDef errorcode = HAL_OK;
1034 
1035  /* Process Locked */
1036  __HAL_LOCK(hspi);
1037 
1038  if((pData == NULL) || (Size == 0))
1039  {
1040  errorcode = HAL_ERROR;
1041  goto error;
1042  }
1043 
1044  if(hspi->State != HAL_SPI_STATE_READY)
1045  {
1046  errorcode = HAL_BUSY;
1047  goto error;
1048  }
1049 
1050  /* prepare the transfer */
1051  hspi->State = HAL_SPI_STATE_BUSY_TX;
1052  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
1053  hspi->pTxBuffPtr = pData;
1054  hspi->TxXferSize = Size;
1055  hspi->TxXferCount = Size;
1056  hspi->pRxBuffPtr = (uint8_t *)NULL;
1057  hspi->RxXferSize = 0;
1058  hspi->RxXferCount = 0;
1059  hspi->RxISR = NULL;
1060 
1061  /* Set the function for IT treatment */
1062  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT )
1063  {
1064  hspi->TxISR = SPI_TxISR_16BIT;
1065  }
1066  else
1067  {
1068  hspi->TxISR = SPI_TxISR_8BIT;
1069  }
1070 
1071  /* Configure communication direction : 1Line */
1072  if(hspi->Init.Direction == SPI_DIRECTION_1LINE)
1073  {
1074  SPI_1LINE_TX(hspi);
1075  }
1076 
1077 #if (USE_SPI_CRC != 0U)
1078  /* Reset CRC Calculation */
1080  {
1081  SPI_RESET_CRC(hspi);
1082  }
1083 #endif
1084 
1085  /* Enable TXE and ERR interrupt */
1087 
1088  /* Check if the SPI is already enabled */
1089  if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
1090  {
1091  /* Enable SPI peripheral */
1092  __HAL_SPI_ENABLE(hspi);
1093  }
1094 
1095 error :
1096  __HAL_UNLOCK(hspi);
1097  return errorcode;
1098 }
1099 
1108 HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
1109 {
1110  HAL_StatusTypeDef errorcode = HAL_OK;
1111 
1112  /* Process Locked */
1113  __HAL_LOCK(hspi);
1114 
1115  if(hspi->State != HAL_SPI_STATE_READY)
1116  {
1117  errorcode = HAL_BUSY;
1118  goto error;
1119  }
1120  if((pData == NULL) || (Size == 0))
1121  {
1122  errorcode = HAL_ERROR;
1123  goto error;
1124  }
1125 
1126  /* Configure communication */
1127  hspi->State = HAL_SPI_STATE_BUSY_RX;
1128  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
1129  hspi->pRxBuffPtr = pData;
1130  hspi->RxXferSize = Size;
1131  hspi->RxXferCount = Size;
1132  hspi->pTxBuffPtr = (uint8_t *)NULL;
1133  hspi->TxXferSize = 0;
1134  hspi->TxXferCount = 0;
1135 
1136  if((hspi->Init.Mode == SPI_MODE_MASTER) && (hspi->Init.Direction == SPI_DIRECTION_2LINES))
1137  {
1138  /* Process Unlocked */
1139  __HAL_UNLOCK(hspi);
1140  /* the receive process is not supported in 2Lines direction master mode */
1141  /* in this we call the TransmitReceive process */
1142  return HAL_SPI_TransmitReceive_IT(hspi,pData,pData,Size);
1143  }
1144 
1146  {
1147  hspi->CRCSize = 1;
1148  if((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT))
1149  {
1150  hspi->CRCSize = 2;
1151  }
1152  }
1153  else
1154  {
1155  hspi->CRCSize = 0;
1156  }
1157 
1158  hspi->TxISR = NULL;
1159  /* check the data size to adapt Rx threshold and the set the function for IT treatment */
1160  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT )
1161  {
1162  /* set fiforxthresold according the reception data length: 16 bit */
1164  hspi->RxISR = SPI_RxISR_16BIT;
1165  }
1166  else
1167  {
1168  /* set fiforxthresold according the reception data length: 8 bit */
1170  hspi->RxISR = SPI_RxISR_8BIT;
1171  }
1172 
1173  /* Configure communication direction : 1Line */
1174  if(hspi->Init.Direction == SPI_DIRECTION_1LINE)
1175  {
1176  SPI_1LINE_RX(hspi);
1177  }
1178 
1179 #if (USE_SPI_CRC != 0U)
1180  /* Reset CRC Calculation */
1182  {
1183  SPI_RESET_CRC(hspi);
1184  }
1185 #endif
1186 
1187  /* Enable TXE and ERR interrupt */
1189 
1190  /* Check if the SPI is already enabled */
1191  if((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
1192  {
1193  /* Enable SPI peripheral */
1194  __HAL_SPI_ENABLE(hspi);
1195  }
1196 
1197 error :
1198  /* Process Unlocked */
1199  __HAL_UNLOCK(hspi);
1200  return errorcode;
1201 }
1202 
1212 HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
1213 {
1214  HAL_StatusTypeDef errorcode = HAL_OK;
1216 
1217  /* Process locked */
1218  __HAL_LOCK(hspi);
1219 
1220  if(!((hspi->State == HAL_SPI_STATE_READY) || \
1221  ((hspi->Init.Mode == SPI_MODE_MASTER) && (hspi->Init.Direction == SPI_DIRECTION_2LINES) && (hspi->State == HAL_SPI_STATE_BUSY_RX))))
1222  {
1223  errorcode = HAL_BUSY;
1224  goto error;
1225  }
1226 
1227  if((pTxData == NULL ) || (pRxData == NULL ) || (Size == 0))
1228  {
1229  errorcode = HAL_ERROR;
1230  goto error;
1231  }
1232 
1233  hspi->CRCSize = 0;
1235  {
1236  hspi->CRCSize = 1;
1237  if((hspi->Init.DataSize <= SPI_DATASIZE_8BIT) && (hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT))
1238  {
1239  hspi->CRCSize = 2;
1240  }
1241  }
1242 
1243  if(hspi->State != HAL_SPI_STATE_BUSY_RX)
1244  {
1246  }
1247 
1248  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
1249  hspi->pTxBuffPtr = pTxData;
1250  hspi->TxXferSize = Size;
1251  hspi->TxXferCount = Size;
1252  hspi->pRxBuffPtr = pRxData;
1253  hspi->RxXferSize = Size;
1254  hspi->RxXferCount = Size;
1255 
1256  /* Set the function for IT treatment */
1257  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT )
1258  {
1259  hspi->RxISR = SPI_2linesRxISR_16BIT;
1260  hspi->TxISR = SPI_2linesTxISR_16BIT;
1261  }
1262  else
1263  {
1264  hspi->RxISR = SPI_2linesRxISR_8BIT;
1265  hspi->TxISR = SPI_2linesTxISR_8BIT;
1266  }
1267 
1268 #if (USE_SPI_CRC != 0U)
1269  /* Reset CRC Calculation */
1271  {
1272  SPI_RESET_CRC(hspi);
1273  }
1274 #endif
1275 
1276  /* check if packing mode is enabled and if there is more than 2 data to receive */
1277  if((hspi->Init.DataSize > SPI_DATASIZE_8BIT) || (hspi->RxXferCount >= 2))
1278  {
1279  /* set fiforxthresold according the reception data length: 16 bit */
1281  }
1282  else
1283  {
1284  /* set fiforxthresold according the reception data length: 8 bit */
1286  }
1287 
1288  /* Enable TXE, RXNE and ERR interrupt */
1290 
1291  /* Check if the SPI is already enabled */
1292  if((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
1293  {
1294  /* Enable SPI peripheral */
1295  __HAL_SPI_ENABLE(hspi);
1296  }
1297 
1298 error :
1299  /* Process Unlocked */
1300  __HAL_UNLOCK(hspi);
1301  return errorcode;
1302 }
1303 
1312 HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
1313 {
1314  HAL_StatusTypeDef errorcode = HAL_OK;
1316 
1317  /* Process Locked */
1318  __HAL_LOCK(hspi);
1319 
1320  if(hspi->State != HAL_SPI_STATE_READY)
1321  {
1322  errorcode = HAL_BUSY;
1323  goto error;
1324  }
1325 
1326  if((pData == NULL) || (Size == 0))
1327  {
1328  errorcode = HAL_ERROR;
1329  goto error;
1330  }
1331 
1332  hspi->State = HAL_SPI_STATE_BUSY_TX;
1333  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
1334  hspi->pTxBuffPtr = pData;
1335  hspi->TxXferSize = Size;
1336  hspi->TxXferCount = Size;
1337  hspi->pRxBuffPtr = (uint8_t *)NULL;
1338  hspi->RxXferSize = 0;
1339  hspi->RxXferCount = 0;
1340 
1341  /* Configure communication direction : 1Line */
1342  if(hspi->Init.Direction == SPI_DIRECTION_1LINE)
1343  {
1344  SPI_1LINE_TX(hspi);
1345  }
1346 
1347 #if (USE_SPI_CRC != 0U)
1348  /* Reset CRC Calculation */
1350  {
1351  SPI_RESET_CRC(hspi);
1352  }
1353 #endif
1354 
1355  /* Set the SPI TxDMA Half transfer complete callback */
1356  hspi->hdmatx->XferHalfCpltCallback = SPI_DMAHalfTransmitCplt;
1357 
1358  /* Set the SPI TxDMA transfer complete callback */
1359  hspi->hdmatx->XferCpltCallback = SPI_DMATransmitCplt;
1360 
1361  /* Set the DMA error callback */
1362  hspi->hdmatx->XferErrorCallback = SPI_DMAError;
1363 
1364  /* Set the DMA abort callback */
1365  hspi->hdmatx->XferAbortCallback = SPI_DMAAbortOnError;
1366 
1368  /* packing mode is enabled only if the DMA setting is HALWORD */
1370  {
1371  /* Check the even/odd of the data size + crc if enabled */
1372  if((hspi->TxXferCount & 0x1) == 0)
1373  {
1375  hspi->TxXferCount = (hspi->TxXferCount >> 1);
1376  }
1377  else
1378  {
1380  hspi->TxXferCount = (hspi->TxXferCount >> 1) + 1;
1381  }
1382  }
1383 
1384  /* Enable SPI Error interrupts, EIE: MODF, OVR, FE, FRE, CEC(depends on family) */
1385  SET_BIT(hspi->Instance->CR2, (SPI_CR2_ERRIE));
1387 
1388  /* Enable the Tx DMA channel */
1389  HAL_DMA_Start_IT(hspi->hdmatx, (uint32_t)hspi->pTxBuffPtr, (uint32_t)&hspi->Instance->DR, hspi->TxXferCount);
1390 
1391  /* Check if the SPI is already enabled */
1392  if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
1393  {
1394  /* Enable SPI peripheral */
1395  __HAL_SPI_ENABLE(hspi);
1396  }
1397 
1398  /* Enable Tx DMA Request */
1400 
1401 error :
1402  /* Process Unlocked */
1403  __HAL_UNLOCK(hspi);
1404  return errorcode;
1405 }
1406 
1416 HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
1417 {
1418  HAL_StatusTypeDef errorcode = HAL_OK;
1419 
1420  /* Process Locked */
1421  __HAL_LOCK(hspi);
1422 
1423  if(hspi->State != HAL_SPI_STATE_READY)
1424  {
1425  errorcode = HAL_BUSY;
1426  goto error;
1427  }
1428 
1429  if((pData == NULL) || (Size == 0))
1430  {
1431  errorcode = HAL_ERROR;
1432  goto error;
1433  }
1434 
1435  hspi->State = HAL_SPI_STATE_BUSY_RX;
1436  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
1437  hspi->pRxBuffPtr = pData;
1438  hspi->RxXferSize = Size;
1439  hspi->RxXferCount = Size;
1440  hspi->pTxBuffPtr = (uint8_t *)NULL;
1441  hspi->TxXferSize = 0;
1442  hspi->TxXferCount = 0;
1443 
1444  if((hspi->Init.Mode == SPI_MODE_MASTER) && (hspi->Init.Direction == SPI_DIRECTION_2LINES))
1445  {
1446  /* Process Unlocked */
1447  __HAL_UNLOCK(hspi);
1448  /* the receive process is not supported in 2Lines direction master mode */
1449  /* in this case we call the TransmitReceive process */
1450  return HAL_SPI_TransmitReceive_DMA(hspi,pData,pData,Size);
1451  }
1452 
1453  /* Configure communication direction : 1Line */
1454  if(hspi->Init.Direction == SPI_DIRECTION_1LINE)
1455  {
1456  SPI_1LINE_RX(hspi);
1457  }
1458 
1459 #if (USE_SPI_CRC != 0U)
1460  /* Reset CRC Calculation */
1462  {
1463  SPI_RESET_CRC(hspi);
1464  }
1465 #endif
1466 
1467  /* packing mode management is enabled by the DMA settings */
1469  {
1470  /* Restriction the DMA data received is not allowed in this mode */
1471  errorcode = HAL_ERROR;
1472  goto error;
1473  }
1474 
1476  if( hspi->Init.DataSize > SPI_DATASIZE_8BIT)
1477  {
1478  /* set fiforxthreshold according the reception data length: 16bit */
1480  }
1481  else
1482  {
1483  /* set fiforxthreshold according the reception data length: 8bit */
1485  }
1486 
1487  /* Set the SPI RxDMA Half transfer complete callback */
1488  hspi->hdmarx->XferHalfCpltCallback = SPI_DMAHalfReceiveCplt;
1489 
1490  /* Set the SPI Rx DMA transfer complete callback */
1491  hspi->hdmarx->XferCpltCallback = SPI_DMAReceiveCplt;
1492 
1493  /* Set the DMA error callback */
1494  hspi->hdmarx->XferErrorCallback = SPI_DMAError;
1495 
1496  /* Set the DMA abort callback */
1497  hspi->hdmatx->XferAbortCallback = SPI_DMAAbortOnError;
1498 
1499  /* Enable SPI Error interrupts, EIE: MODF, OVR, FE, FRE, CEC(depends on family) */
1500  SET_BIT(hspi->Instance->CR2, (SPI_CR2_ERRIE));
1502 
1503  /* Enable Rx DMA Request */
1505 
1506  /* Enable the Rx DMA channel */
1507  HAL_DMA_Start_IT(hspi->hdmarx, (uint32_t)&hspi->Instance->DR, (uint32_t)hspi->pRxBuffPtr, hspi->RxXferCount);
1508 
1509  /* Check if the SPI is already enabled */
1510  if((hspi->Instance->CR1 & SPI_CR1_SPE) != SPI_CR1_SPE)
1511  {
1512  /* Enable SPI peripheral */
1513  __HAL_SPI_ENABLE(hspi);
1514  }
1515 
1516 error:
1517  /* Process Unlocked */
1518  __HAL_UNLOCK(hspi);
1519  return errorcode;
1520 }
1521 
1532 HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
1533 {
1534  HAL_StatusTypeDef errorcode = HAL_OK;
1536 
1537  /* Process locked */
1538  __HAL_LOCK(hspi);
1539 
1540  if(!((hspi->State == HAL_SPI_STATE_READY) ||
1541  ((hspi->Init.Mode == SPI_MODE_MASTER) && (hspi->Init.Direction == SPI_DIRECTION_2LINES) && (hspi->State == HAL_SPI_STATE_BUSY_RX))))
1542  {
1543  errorcode = HAL_BUSY;
1544  goto error;
1545  }
1546 
1547  if((pTxData == NULL ) || (pRxData == NULL ) || (Size == 0))
1548  {
1549  errorcode = HAL_ERROR;
1550  goto error;
1551  }
1552 
1553  /* check if the transmit Receive function is not called by a receive master */
1554  if(hspi->State != HAL_SPI_STATE_BUSY_RX)
1555  {
1557  }
1558 
1559  hspi->ErrorCode = HAL_SPI_ERROR_NONE;
1560  hspi->pTxBuffPtr = (uint8_t *)pTxData;
1561  hspi->TxXferSize = Size;
1562  hspi->TxXferCount = Size;
1563  hspi->pRxBuffPtr = (uint8_t *)pRxData;
1564  hspi->RxXferSize = Size;
1565  hspi->RxXferCount = Size;
1566 
1567 #if (USE_SPI_CRC != 0U)
1568  /* Reset CRC Calculation + increase the rxsize */
1570  {
1571  SPI_RESET_CRC(hspi);
1572  }
1573 #endif
1574 
1575  /* Reset the threshold bit */
1577 
1578  /* the packing mode management is enabled by the DMA settings according the spi data size */
1579  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
1580  {
1581  /* set fiforxthreshold according the reception data length: 16bit */
1583  }
1584  else
1585  {
1586  /* set fiforxthresold according the reception data length: 8bit */
1588 
1590  {
1591  if((hspi->TxXferSize & 0x1) == 0x0)
1592  {
1594  hspi->TxXferCount = hspi->TxXferCount >> 1;
1595  }
1596  else
1597  {
1599  hspi->TxXferCount = (hspi->TxXferCount >> 1) + 1;
1600  }
1601  }
1602 
1604  {
1605  /* set fiforxthresold according the reception data length: 16bit */
1607 
1608  if((hspi->RxXferCount & 0x1) == 0x0 )
1609  {
1611  hspi->RxXferCount = hspi->RxXferCount >> 1;
1612  }
1613  else
1614  {
1616  hspi->RxXferCount = (hspi->RxXferCount >> 1) + 1;
1617  }
1618  }
1619  }
1620 
1621  /* Set the SPI Rx DMA transfer complete callback if the transfer request is a
1622  reception request (RXNE) */
1623  if(hspi->State == HAL_SPI_STATE_BUSY_RX)
1624  {
1625  /* Set the SPI Rx DMA Half transfer complete callback */
1626  hspi->hdmarx->XferHalfCpltCallback = SPI_DMAHalfReceiveCplt;
1627  hspi->hdmarx->XferCpltCallback = SPI_DMAReceiveCplt;
1628  }
1629  else
1630  {
1631  /* Set the SPI Rx DMA Half transfer complete callback */
1632  hspi->hdmarx->XferHalfCpltCallback = SPI_DMAHalfTransmitReceiveCplt;
1633  hspi->hdmarx->XferCpltCallback = SPI_DMATransmitReceiveCplt;
1634  }
1635 
1636  /* Set the DMA error callback */
1637  hspi->hdmarx->XferErrorCallback = SPI_DMAError;
1638 
1639  /* Set the DMA abort callback */
1640  hspi->hdmarx->XferAbortCallback = SPI_DMAAbortOnError;
1641 
1642  /* Enable SPI Error interrupts, EIE: MODF, OVR, FE, FRE, CEC(depends on family) */
1643  SET_BIT(hspi->Instance->CR2, (SPI_CR2_ERRIE));
1645 
1646  /* Enable Rx DMA Request */
1648 
1649  /* Enable the Rx DMA channel */
1650  HAL_DMA_Start_IT(hspi->hdmarx, (uint32_t)&hspi->Instance->DR, (uint32_t) hspi->pRxBuffPtr, hspi->RxXferCount);
1651 
1652  /* Set the SPI Tx DMA transfer complete callback as NULL because the communication closing
1653  is performed in DMA reception complete callback */
1654  hspi->hdmatx->XferHalfCpltCallback = NULL;
1655  hspi->hdmatx->XferCpltCallback = NULL;
1656 
1657  /* Set the DMA error callback */
1658  hspi->hdmatx->XferErrorCallback = SPI_DMAError;
1659 
1660  /* Set the DMA abort callback */
1661  hspi->hdmatx->XferAbortCallback = SPI_DMAAbortOnError;
1662 
1663  /* Enable the Tx DMA channel */
1664  HAL_DMA_Start_IT(hspi->hdmatx, (uint32_t)hspi->pTxBuffPtr, (uint32_t)&hspi->Instance->DR, hspi->TxXferCount);
1665 
1666  /* Check if the SPI is already enabled */
1667  if((hspi->Instance->CR1 &SPI_CR1_SPE) != SPI_CR1_SPE)
1668  {
1669  /* Enable SPI peripheral */
1670  __HAL_SPI_ENABLE(hspi);
1671  }
1672 
1673  /* Enable Tx DMA Request */
1675 
1676 error :
1677  /* Process Unlocked */
1678  __HAL_UNLOCK(hspi);
1679  return errorcode;
1680 }
1681 
1689 {
1690  /* Process Locked */
1691  __HAL_LOCK(hspi);
1692 
1693  /* Disable the SPI DMA Tx & Rx requests */
1695 
1696  /* Process Unlocked */
1697  __HAL_UNLOCK(hspi);
1698 
1699  return HAL_OK;
1700 }
1701 
1709 {
1710  /* Process Locked */
1711  __HAL_LOCK(hspi);
1712 
1713  /* Enable the SPI DMA Tx & Rx requests */
1715 
1716  /* Process Unlocked */
1717  __HAL_UNLOCK(hspi);
1718 
1719  return HAL_OK;
1720 }
1721 
1729 {
1730  /* The Lock is not implemented on this API to allow the user application
1731  to call the HAL SPI API under callbacks HAL_SPI_TxCpltCallback() or HAL_SPI_RxCpltCallback() or HAL_SPI_TxRxCpltCallback():
1732  when calling HAL_DMA_Abort() API the DMA TX/RX Transfer complete interrupt is generated
1733  and the correspond call back is executed HAL_SPI_TxCpltCallback() or HAL_SPI_RxCpltCallback() or HAL_SPI_TxRxCpltCallback()
1734  */
1735 
1736  /* Abort the SPI DMA tx Stream */
1737  if(hspi->hdmatx != NULL)
1738  {
1739  HAL_DMA_Abort(hspi->hdmatx);
1740  }
1741  /* Abort the SPI DMA rx Stream */
1742  if(hspi->hdmarx != NULL)
1743  {
1744  HAL_DMA_Abort(hspi->hdmarx);
1745  }
1746 
1747  /* Disable the SPI DMA Tx & Rx requests */
1749  hspi->State = HAL_SPI_STATE_READY;
1750  return HAL_OK;
1751 }
1752 
1760 {
1761  uint32_t itsource = hspi->Instance->CR2;
1762  uint32_t itflag = hspi->Instance->SR;
1763 
1764  /* SPI in mode Receiver ----------------------------------------------------*/
1765  if(((itflag & SPI_FLAG_OVR) == RESET) &&
1766  ((itflag & SPI_FLAG_RXNE) != RESET) && ((itsource & SPI_IT_RXNE) != RESET))
1767  {
1768  hspi->RxISR(hspi);
1769  return;
1770  }
1771 
1772  /* SPI in mode Transmitter ---------------------------------------------------*/
1773  if(((itflag & SPI_FLAG_TXE) != RESET) && ((itsource & SPI_IT_TXE) != RESET))
1774  {
1775  hspi->TxISR(hspi);
1776  return;
1777  }
1778 
1779  /* SPI in Error Treatment ---------------------------------------------------*/
1780  if((itflag & (SPI_FLAG_MODF | SPI_FLAG_OVR | SPI_FLAG_FRE)) != RESET)
1781  {
1782  /* SPI Overrun error interrupt occurred -------------------------------------*/
1783  if((itflag & SPI_FLAG_OVR) != RESET)
1784  {
1785  if(hspi->State != HAL_SPI_STATE_BUSY_TX)
1786  {
1787  hspi->ErrorCode |= HAL_SPI_ERROR_OVR;
1789  }
1790  else
1791  {
1792  return;
1793  }
1794  }
1795 
1796  /* SPI Mode Fault error interrupt occurred -------------------------------------*/
1797  if((itflag & SPI_FLAG_MODF) != RESET)
1798  {
1799  hspi->ErrorCode |= HAL_SPI_ERROR_MODF;
1801  }
1802 
1803  /* SPI Frame error interrupt occurred ----------------------------------------*/
1804  if((itflag & SPI_FLAG_FRE) != RESET)
1805  {
1806  hspi->ErrorCode |= HAL_SPI_ERROR_FRE;
1808  }
1809 
1810  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
1811  {
1812  /* All SPI errors are treated as Blocking errors : transfer is aborted.
1813  Set the SPI state to ready so as to be able to restart the process,
1814  Disable Rx/Tx Interrupts, and disable DMA Rx/Tx requests, if ongoing */
1815 
1816  /* Disable TXE, RXNE, MODF, OVR, FRE, and CRCERR (Master mode fault, Overrun error, TI frame format error, CRC protocol error) interrupts */
1819 
1820  /* Restore SPI State to Ready */
1821  hspi->State = HAL_SPI_STATE_READY;
1822 
1823  /* Disable the SPI DMA requests if enabled */
1825  {
1827 
1828  /* Abort the SPI DMA Rx channel */
1829  if(hspi->hdmarx != NULL)
1830  {
1831  /* Set the SPI DMA Abort callback :
1832  will lead to call HAL_SPI_ErrorCallback() at end of DMA abort procedure */
1833  hspi->hdmarx->XferAbortCallback = SPI_DMAAbortOnError;
1834 
1835  /* Abort DMA RX */
1836  if(HAL_DMA_Abort_IT(hspi->hdmarx) != HAL_OK)
1837  {
1838  /* Call Directly hspi->hdmarx->XferAbortCallback function in case of error */
1839  hspi->hdmarx->XferAbortCallback(hspi->hdmarx);
1840  }
1841  }
1842  /* Abort the SPI DMA Tx channel */
1843  if(hspi->hdmatx != NULL)
1844  {
1845  /* Set the SPI DMA Abort callback :
1846  will lead to call HAL_SPI_ErrorCallback() at end of DMA abort procedure */
1847  hspi->hdmatx->XferAbortCallback = SPI_DMAAbortOnError;
1848 
1849  /* Abort DMA TX */
1850  if(HAL_DMA_Abort_IT(hspi->hdmatx) != HAL_OK)
1851  {
1852  /* Call Directly hspi->hdmatx->XferAbortCallback function in case of error */
1853  hspi->hdmatx->XferAbortCallback(hspi->hdmatx);
1854  }
1855  }
1856  }
1857  else
1858  {
1859  /* Call user error callback */
1860  HAL_SPI_ErrorCallback(hspi);
1861  }
1862  }
1863  }
1864 }
1865 
1872 __weak void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
1873 {
1874  /* Prevent unused argument(s) compilation warning */
1875  UNUSED(hspi);
1876 
1877  /* NOTE : This function should not be modified, when the callback is needed,
1878  the HAL_SPI_TxCpltCallback should be implemented in the user file
1879  */
1880 }
1881 
1888 __weak void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
1889 {
1890  /* Prevent unused argument(s) compilation warning */
1891  UNUSED(hspi);
1892 
1893  /* NOTE : This function should not be modified, when the callback is needed,
1894  the HAL_SPI_RxCpltCallback should be implemented in the user file
1895  */
1896 }
1897 
1905 {
1906  /* Prevent unused argument(s) compilation warning */
1907  UNUSED(hspi);
1908 
1909  /* NOTE : This function should not be modified, when the callback is needed,
1910  the HAL_SPI_TxRxCpltCallback should be implemented in the user file
1911  */
1912 }
1913 
1921 {
1922  /* Prevent unused argument(s) compilation warning */
1923  UNUSED(hspi);
1924 
1925  /* NOTE : This function should not be modified, when the callback is needed,
1926  the HAL_SPI_TxHalfCpltCallback should be implemented in the user file
1927  */
1928 }
1929 
1937 {
1938  /* Prevent unused argument(s) compilation warning */
1939  UNUSED(hspi);
1940 
1941  /* NOTE : This function should not be modified, when the callback is needed,
1942  the HAL_SPI_RxHalfCpltCallback() should be implemented in the user file
1943  */
1944 }
1945 
1953 {
1954  /* Prevent unused argument(s) compilation warning */
1955  UNUSED(hspi);
1956 
1957  /* NOTE : This function should not be modified, when the callback is needed,
1958  the HAL_SPI_TxRxHalfCpltCallback() should be implemented in the user file
1959  */
1960 }
1961 
1968 __weak void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
1969 {
1970  /* Prevent unused argument(s) compilation warning */
1971  UNUSED(hspi);
1972 
1973  /* NOTE : This function should not be modified, when the callback is needed,
1974  the HAL_SPI_ErrorCallback should be implemented in the user file
1975  */
1976  /* NOTE : The ErrorCode parameter in the hspi handle is updated by the SPI processes
1977  and user can use HAL_SPI_GetError() API to check the latest error occurred
1978  */
1979 }
1980 
2007 {
2008  /* Return SPI handle state */
2009  return hspi->State;
2010 }
2011 
2018 uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi)
2019 {
2020  return hspi->ErrorCode;
2021 }
2022 
2043 static void SPI_DMATransmitCplt(DMA_HandleTypeDef *hdma)
2044 {
2045  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2046 
2047  /* DMA Normal Mode */
2048  if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
2049  {
2050  /* Disable Tx DMA Request */
2052 
2053  /* Check the end of the transaction */
2054  if(SPI_EndRxTxTransaction(hspi,SPI_DEFAULT_TIMEOUT) != HAL_OK)
2055  {
2056  hspi->ErrorCode = HAL_SPI_ERROR_FLAG;
2057  }
2058 
2059  /* Clear overrun flag in 2 Lines communication mode because received data is not read */
2060  if(hspi->Init.Direction == SPI_DIRECTION_2LINES)
2061  {
2063  }
2064 
2065  hspi->TxXferCount = 0;
2066  hspi->State = HAL_SPI_STATE_READY;
2067 
2068  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
2069  {
2070  HAL_SPI_ErrorCallback(hspi);
2071  return;
2072  }
2073  }
2074  HAL_SPI_TxCpltCallback(hspi);
2075 }
2076 
2083 static void SPI_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
2084 {
2085  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2086 
2087  /* DMA Normal mode */
2088  if((hdma->Instance->CR & DMA_SxCR_CIRC) == 0)
2089  {
2090 
2091 #if (USE_SPI_CRC != 0U)
2092  __IO uint16_t tmpreg;
2093  /* CRC handling */
2095  {
2096  /* Wait until TXE flag */
2097  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SPI_FLAG_RXNE, SPI_DEFAULT_TIMEOUT) != HAL_OK)
2098  {
2099  /* Error on the CRC reception */
2100  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2101  }
2102  if(hspi->Init.DataSize > SPI_DATASIZE_8BIT)
2103  {
2104  tmpreg = hspi->Instance->DR;
2105  UNUSED(tmpreg); /* To avoid GCC warning */
2106  }
2107  else
2108  {
2109  tmpreg = *(__IO uint8_t *)&hspi->Instance->DR;
2110  UNUSED(tmpreg); /* To avoid GCC warning */
2111 
2112  if(hspi->Init.CRCLength == SPI_CRC_LENGTH_16BIT)
2113  {
2114  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_RXNE, SPI_FLAG_RXNE, SPI_DEFAULT_TIMEOUT) != HAL_OK)
2115  {
2116  /* Error on the CRC reception */
2117  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2118  }
2119  tmpreg = *(__IO uint8_t *)&hspi->Instance->DR;
2120  UNUSED(tmpreg); /* To avoid GCC warning */
2121  }
2122  }
2123  }
2124 #endif
2125 
2126  /* Disable Rx/Tx DMA Request (done by default to handle the case master rx direction 2 lines) */
2128 
2129  /* Check the end of the transaction */
2130  if(SPI_EndRxTransaction(hspi,SPI_DEFAULT_TIMEOUT)!=HAL_OK)
2131  {
2132  hspi->ErrorCode|= HAL_SPI_ERROR_FLAG;
2133  }
2134 
2135  hspi->RxXferCount = 0;
2136  hspi->State = HAL_SPI_STATE_READY;
2137 
2138 #if (USE_SPI_CRC != 0U)
2139  /* Check if CRC error occurred */
2141  {
2142  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2144  }
2145 #endif
2146 
2147  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
2148  {
2149  HAL_SPI_ErrorCallback(hspi);
2150  return;
2151  }
2152  }
2153  HAL_SPI_RxCpltCallback(hspi);
2154 }
2155 
2162 static void SPI_DMATransmitReceiveCplt(DMA_HandleTypeDef *hdma)
2163 {
2164  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2165 #if (USE_SPI_CRC != 0U)
2166  __IO uint16_t tmpreg;
2167  /* CRC handling */
2169  {
2170  if((hspi->Init.DataSize == SPI_DATASIZE_8BIT) && (hspi->Init.CRCLength == SPI_CRC_LENGTH_8BIT))
2171  {
2172  if(SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_QUARTER_FULL, SPI_DEFAULT_TIMEOUT) != HAL_OK)
2173  {
2174  /* Error on the CRC reception */
2175  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2176  }
2177  tmpreg = *(__IO uint8_t *)&hspi->Instance->DR;
2178  UNUSED(tmpreg); /* To avoid GCC warning */
2179  }
2180  else
2181  {
2182  if(SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_HALF_FULL, SPI_DEFAULT_TIMEOUT) != HAL_OK)
2183  {
2184  /* Error on the CRC reception */
2185  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2186  }
2187  tmpreg = hspi->Instance->DR;
2188  UNUSED(tmpreg); /* To avoid GCC warning */
2189  }
2190  }
2191 #endif
2192 
2193  /* Check the end of the transaction */
2194  if(SPI_EndRxTxTransaction(hspi,SPI_DEFAULT_TIMEOUT) != HAL_OK)
2195  {
2196  hspi->ErrorCode = HAL_SPI_ERROR_FLAG;
2197  }
2198 
2199  /* Disable Rx/Tx DMA Request */
2201 
2202  hspi->TxXferCount = 0;
2203  hspi->RxXferCount = 0;
2204  hspi->State = HAL_SPI_STATE_READY;
2205 
2206 #if (USE_SPI_CRC != 0U)
2207  /* Check if CRC error occurred */
2209  {
2210  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2212  }
2213 #endif
2214 
2215  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
2216  {
2217  HAL_SPI_ErrorCallback(hspi);
2218  return;
2219  }
2221 }
2222 
2229 static void SPI_DMAHalfTransmitCplt(DMA_HandleTypeDef *hdma)
2230 {
2231  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2233 }
2234 
2241 static void SPI_DMAHalfReceiveCplt(DMA_HandleTypeDef *hdma)
2242 {
2243  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2245 }
2246 
2253 static void SPI_DMAHalfTransmitReceiveCplt(DMA_HandleTypeDef *hdma)
2254 {
2255  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2257 }
2258 
2265 static void SPI_DMAError(DMA_HandleTypeDef *hdma)
2266 {
2267  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2268 
2269  /* Stop the disable DMA transfer on SPI side */
2271 
2272  hspi->ErrorCode|= HAL_SPI_ERROR_DMA;
2273  hspi->State = HAL_SPI_STATE_READY;
2274  HAL_SPI_ErrorCallback(hspi);
2275 }
2276 
2283 static void SPI_DMAAbortOnError(DMA_HandleTypeDef *hdma)
2284 {
2285  SPI_HandleTypeDef* hspi = ( SPI_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
2286  hspi->RxXferCount = 0U;
2287  hspi->TxXferCount = 0U;
2288 
2289  HAL_SPI_ErrorCallback(hspi);
2290 }
2291 
2298 static void SPI_2linesRxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
2299 {
2300  /* Receive data in packing mode */
2301  if(hspi->RxXferCount > 1)
2302  {
2303  *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;
2304  hspi->pRxBuffPtr += sizeof(uint16_t);
2305  hspi->RxXferCount -= 2;
2306  if(hspi->RxXferCount == 1)
2307  {
2308  /* set fiforxthreshold according the reception data length: 8bit */
2310  }
2311  }
2312  /* Receive data in 8 Bit mode */
2313  else
2314  {
2315  *hspi->pRxBuffPtr++ = *((__IO uint8_t *)&hspi->Instance->DR);
2316  hspi->RxXferCount--;
2317  }
2318 
2319  /* check end of the reception */
2320  if(hspi->RxXferCount == 0)
2321  {
2322 #if (USE_SPI_CRC != 0U)
2324  {
2326  hspi->RxISR = SPI_2linesRxISR_8BITCRC;
2327  return;
2328  }
2329 #endif
2330 
2331  /* Disable RXNE interrupt */
2332  __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE);
2333 
2334  if(hspi->TxXferCount == 0)
2335  {
2336  SPI_CloseRxTx_ISR(hspi);
2337  }
2338  }
2339 }
2340 
2341 #if (USE_SPI_CRC != 0U)
2342 
2348 static void SPI_2linesRxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi)
2349 {
2350  __IO uint8_t tmpreg = *((__IO uint8_t *)&hspi->Instance->DR);
2351  UNUSED(tmpreg); /* To avoid GCC warning */
2352 
2353  hspi->CRCSize--;
2354 
2355  /* check end of the reception */
2356  if(hspi->CRCSize == 0)
2357  {
2358  /* Disable RXNE interrupt */
2359  __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE);
2360 
2361  if(hspi->TxXferCount == 0)
2362  {
2363  SPI_CloseRxTx_ISR(hspi);
2364  }
2365  }
2366 }
2367 #endif
2368 
2375 static void SPI_2linesTxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
2376 {
2377  /* Transmit data in packing Bit mode */
2378  if(hspi->TxXferCount >= 2)
2379  {
2380  hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr);
2381  hspi->pTxBuffPtr += sizeof(uint16_t);
2382  hspi->TxXferCount -= 2;
2383  }
2384  /* Transmit data in 8 Bit mode */
2385  else
2386  {
2387  *(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr++);
2388  hspi->TxXferCount--;
2389  }
2390 
2391  /* check the end of the transmission */
2392  if(hspi->TxXferCount == 0)
2393  {
2394 #if (USE_SPI_CRC != 0U)
2396  {
2397  hspi->Instance->CR1 |= SPI_CR1_CRCNEXT;
2398  }
2399 #endif
2400 
2401  /* Disable TXE interrupt */
2402  __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXE);
2403 
2404  if(hspi->RxXferCount == 0)
2405  {
2406  SPI_CloseRxTx_ISR(hspi);
2407  }
2408  }
2409 }
2410 
2417 static void SPI_2linesRxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
2418 {
2419  /* Receive data in 16 Bit mode */
2420  *((uint16_t*)hspi->pRxBuffPtr) = hspi->Instance->DR;
2421  hspi->pRxBuffPtr += sizeof(uint16_t);
2422  hspi->RxXferCount--;
2423 
2424  if(hspi->RxXferCount == 0)
2425  {
2426 #if (USE_SPI_CRC != 0U)
2428  {
2429  hspi->RxISR = SPI_2linesRxISR_16BITCRC;
2430  return;
2431  }
2432 #endif
2433 
2434  /* Disable RXNE interrupt */
2435  __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE);
2436 
2437  if(hspi->TxXferCount == 0)
2438  {
2439  SPI_CloseRxTx_ISR(hspi);
2440  }
2441  }
2442 }
2443 
2444 #if (USE_SPI_CRC != 0U)
2445 
2451 static void SPI_2linesRxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi)
2452 {
2453  /* Receive data in 16 Bit mode */
2454  __IO uint16_t tmpreg = hspi->Instance->DR;
2455  UNUSED(tmpreg); /* To avoid GCC warning */
2456 
2457  /* Disable RXNE interrupt */
2458  __HAL_SPI_DISABLE_IT(hspi, SPI_IT_RXNE);
2459 
2460  SPI_CloseRxTx_ISR(hspi);
2461 }
2462 #endif
2463 
2470 static void SPI_2linesTxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
2471 {
2472  /* Transmit data in 16 Bit mode */
2473  hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr);
2474  hspi->pTxBuffPtr += sizeof(uint16_t);
2475  hspi->TxXferCount--;
2476 
2477  /* Enable CRC Transmission */
2478  if(hspi->TxXferCount == 0)
2479  {
2480 #if (USE_SPI_CRC != 0U)
2482  {
2483  hspi->Instance->CR1 |= SPI_CR1_CRCNEXT;
2484  }
2485 #endif
2486 
2487  /* Disable TXE interrupt */
2488  __HAL_SPI_DISABLE_IT(hspi, SPI_IT_TXE);
2489 
2490  if(hspi->RxXferCount == 0)
2491  {
2492  SPI_CloseRxTx_ISR(hspi);
2493  }
2494  }
2495 }
2496 
2497 #if (USE_SPI_CRC != 0U)
2498 
2504 static void SPI_RxISR_8BITCRC(struct __SPI_HandleTypeDef *hspi)
2505 {
2506  __IO uint8_t tmpreg;
2507  tmpreg = *((__IO uint8_t*)&hspi->Instance->DR);
2508 
2509  UNUSED(tmpreg); /* To avoid GCC warning */
2510 
2511  hspi->CRCSize--;
2512 
2513  if(hspi->CRCSize == 0)
2514  {
2515  SPI_CloseRx_ISR(hspi);
2516  }
2517 }
2518 #endif
2519 
2526 static void SPI_RxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
2527 {
2528  *hspi->pRxBuffPtr++ = (*(__IO uint8_t *)&hspi->Instance->DR);
2529  hspi->RxXferCount--;
2530 
2531 #if (USE_SPI_CRC != 0U)
2532  /* Enable CRC Transmission */
2533  if((hspi->RxXferCount == 1) && (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE))
2534  {
2535  hspi->Instance->CR1 |= SPI_CR1_CRCNEXT;
2536  }
2537 #endif
2538 
2539  if(hspi->RxXferCount == 0)
2540  {
2541 #if (USE_SPI_CRC != 0U)
2543  {
2544  hspi->RxISR = SPI_RxISR_8BITCRC;
2545  return;
2546  }
2547 #endif
2548  SPI_CloseRx_ISR(hspi);
2549  }
2550 }
2551 
2552 #if (USE_SPI_CRC != 0U)
2553 
2559 static void SPI_RxISR_16BITCRC(struct __SPI_HandleTypeDef *hspi)
2560 {
2561  __IO uint16_t tmpreg;
2562 
2563  tmpreg = hspi->Instance->DR;
2564  UNUSED(tmpreg); /* To avoid GCC warning */
2565 
2566  /* Disable RXNE and ERR interrupt */
2567  __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_RXNE | SPI_IT_ERR));
2568 
2569  SPI_CloseRx_ISR(hspi);
2570 }
2571 #endif
2572 
2579 static void SPI_RxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
2580 {
2581  *((uint16_t *)hspi->pRxBuffPtr) = hspi->Instance->DR;
2582  hspi->pRxBuffPtr += sizeof(uint16_t);
2583  hspi->RxXferCount--;
2584 #if (USE_SPI_CRC != 0U)
2585  /* Enable CRC Transmission */
2586  if((hspi->RxXferCount == 1) && (hspi->Init.CRCCalculation == SPI_CRCCALCULATION_ENABLE))
2587  {
2588  hspi->Instance->CR1 |= SPI_CR1_CRCNEXT;
2589  }
2590 #endif
2591  if(hspi->RxXferCount == 0)
2592  {
2593 #if (USE_SPI_CRC != 0U)
2595  {
2596  hspi->RxISR = SPI_RxISR_16BITCRC;
2597  return;
2598  }
2599 #endif
2600  SPI_CloseRx_ISR(hspi);
2601  }
2602 }
2603 
2610 static void SPI_TxISR_8BIT(struct __SPI_HandleTypeDef *hspi)
2611 {
2612  *(__IO uint8_t *)&hspi->Instance->DR = (*hspi->pTxBuffPtr++);
2613  hspi->TxXferCount--;
2614 
2615  if(hspi->TxXferCount == 0)
2616  {
2617 #if (USE_SPI_CRC != 0U)
2619  {
2620  /* Enable CRC Transmission */
2621  hspi->Instance->CR1 |= SPI_CR1_CRCNEXT;
2622  }
2623 #endif
2624  SPI_CloseTx_ISR(hspi);
2625  }
2626 }
2627 
2634 static void SPI_TxISR_16BIT(struct __SPI_HandleTypeDef *hspi)
2635 {
2636  /* Transmit data in 16 Bit mode */
2637  hspi->Instance->DR = *((uint16_t *)hspi->pTxBuffPtr);
2638  hspi->pTxBuffPtr += sizeof(uint16_t);
2639  hspi->TxXferCount--;
2640 
2641  if(hspi->TxXferCount == 0)
2642  {
2643 #if (USE_SPI_CRC != 0U)
2645  {
2646  /* Enable CRC Transmission */
2647  hspi->Instance->CR1 |= SPI_CR1_CRCNEXT;
2648  }
2649 #endif
2650  SPI_CloseTx_ISR(hspi);
2651  }
2652 }
2653 
2663 static HAL_StatusTypeDef SPI_WaitFlagStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Flag, uint32_t State, uint32_t Timeout)
2664 {
2665  uint32_t tickstart = HAL_GetTick();
2666 
2667  while((hspi->Instance->SR & Flag) != State)
2668  {
2669  if(Timeout != HAL_MAX_DELAY)
2670  {
2671  if((Timeout == 0) || ((HAL_GetTick()-tickstart) >= Timeout))
2672  {
2673  /* Disable the SPI and reset the CRC: the CRC value should be cleared
2674  on both master and slave sides in order to resynchronize the master
2675  and slave for their respective CRC calculation */
2676 
2677  /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
2678  __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
2679 
2681  {
2682  /* Disable SPI peripheral */
2683  __HAL_SPI_DISABLE(hspi);
2684  }
2685 
2686  /* Reset CRC Calculation */
2688  {
2689  SPI_RESET_CRC(hspi);
2690  }
2691 
2692  hspi->State= HAL_SPI_STATE_READY;
2693 
2694  /* Process Unlocked */
2695  __HAL_UNLOCK(hspi);
2696 
2697  return HAL_TIMEOUT;
2698  }
2699  }
2700  }
2701  return HAL_OK;
2702 }
2703 
2713 static HAL_StatusTypeDef SPI_WaitFifoStateUntilTimeout(SPI_HandleTypeDef *hspi, uint32_t Fifo, uint32_t State, uint32_t Timeout)
2714 {
2715  __IO uint8_t tmpreg;
2716  uint32_t tickstart = HAL_GetTick();
2717 
2718  while((hspi->Instance->SR & Fifo) != State)
2719  {
2720  if((Fifo == SPI_SR_FRLVL) && (State == SPI_FRLVL_EMPTY))
2721  {
2722  tmpreg = *((__IO uint8_t*)&hspi->Instance->DR);
2723  UNUSED(tmpreg); /* To avoid GCC warning */
2724  }
2725 
2726  if(Timeout != HAL_MAX_DELAY)
2727  {
2728  if((Timeout == 0) || ((HAL_GetTick()-tickstart) >= Timeout))
2729  {
2730  /* Disable the SPI and reset the CRC: the CRC value should be cleared
2731  on both master and slave sides in order to resynchronize the master
2732  and slave for their respective CRC calculation */
2733 
2734  /* Disable TXE, RXNE and ERR interrupts for the interrupt process */
2735  __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_RXNE | SPI_IT_ERR));
2736 
2738  {
2739  /* Disable SPI peripheral */
2740  __HAL_SPI_DISABLE(hspi);
2741  }
2742 
2743  /* Reset CRC Calculation */
2745  {
2746  SPI_RESET_CRC(hspi);
2747  }
2748 
2749  hspi->State = HAL_SPI_STATE_READY;
2750 
2751  /* Process Unlocked */
2752  __HAL_UNLOCK(hspi);
2753 
2754  return HAL_TIMEOUT;
2755  }
2756  }
2757  }
2758  return HAL_OK;
2759 }
2760 
2768 static HAL_StatusTypeDef SPI_EndRxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout)
2769 {
2771  {
2772  /* Disable SPI peripheral */
2773  __HAL_SPI_DISABLE(hspi);
2774  }
2775 
2776  /* Control the BSY flag */
2777  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_BSY, RESET, Timeout) != HAL_OK)
2778  {
2779  hspi->ErrorCode |= HAL_SPI_ERROR_FLAG;
2780  return HAL_TIMEOUT;
2781  }
2782 
2784  {
2785  /* Empty the FRLVL fifo */
2786  if(SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_EMPTY, Timeout) != HAL_OK)
2787  {
2788  hspi->ErrorCode |= HAL_SPI_ERROR_FLAG;
2789  return HAL_TIMEOUT;
2790  }
2791  }
2792  return HAL_OK;
2793 }
2794 
2800 static HAL_StatusTypeDef SPI_EndRxTxTransaction(SPI_HandleTypeDef *hspi, uint32_t Timeout)
2801 {
2802  /* Procedure to check the transaction complete */
2803  if(SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FTLVL, SPI_FTLVL_EMPTY, Timeout) != HAL_OK)
2804  {
2805  hspi->ErrorCode |= HAL_SPI_ERROR_FLAG;
2806  return HAL_TIMEOUT;
2807  }
2808  if(SPI_WaitFifoStateUntilTimeout(hspi, SPI_FLAG_FRLVL, SPI_FRLVL_EMPTY, Timeout) != HAL_OK)
2809  {
2810  hspi->ErrorCode |= HAL_SPI_ERROR_FLAG;
2811  return HAL_TIMEOUT;
2812  }
2813  /* Control the BSY flag */
2814  if(SPI_WaitFlagStateUntilTimeout(hspi, SPI_FLAG_BSY, RESET, Timeout) != HAL_OK)
2815  {
2816  hspi->ErrorCode |= HAL_SPI_ERROR_FLAG;
2817  return HAL_TIMEOUT;
2818  }
2819  return HAL_OK;
2820 }
2821 
2828 static void SPI_CloseRxTx_ISR(SPI_HandleTypeDef *hspi)
2829 {
2830  /* Disable ERR interrupt */
2832 
2833  /* Check the end of the transaction */
2834  if(SPI_EndRxTxTransaction(hspi,SPI_DEFAULT_TIMEOUT)!=HAL_OK)
2835  {
2836  hspi->ErrorCode|= HAL_SPI_ERROR_FLAG;
2837  }
2838 
2839 #if (USE_SPI_CRC != 0U)
2840  /* Check if CRC error occurred */
2842  {
2843  hspi->State = HAL_SPI_STATE_READY;
2844  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2846  HAL_SPI_ErrorCallback(hspi);
2847  }
2848  else
2849  {
2850 #endif
2851  if(hspi->ErrorCode == HAL_SPI_ERROR_NONE)
2852  {
2853  if(hspi->State == HAL_SPI_STATE_BUSY_RX)
2854  {
2855  hspi->State = HAL_SPI_STATE_READY;
2856  HAL_SPI_RxCpltCallback(hspi);
2857  }
2858  else
2859  {
2860  hspi->State = HAL_SPI_STATE_READY;
2862  }
2863  }
2864  else
2865  {
2866  hspi->State = HAL_SPI_STATE_READY;
2867  HAL_SPI_ErrorCallback(hspi);
2868  }
2869 #if (USE_SPI_CRC != 0U)
2870  }
2871 #endif
2872 }
2873 
2880 static void SPI_CloseRx_ISR(SPI_HandleTypeDef *hspi)
2881 {
2882  /* Disable RXNE and ERR interrupt */
2883  __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_RXNE | SPI_IT_ERR));
2884 
2885  /* Check the end of the transaction */
2886  if(SPI_EndRxTransaction(hspi,SPI_DEFAULT_TIMEOUT)!=HAL_OK)
2887  {
2888  hspi->ErrorCode|= HAL_SPI_ERROR_FLAG;
2889  }
2890  hspi->State = HAL_SPI_STATE_READY;
2891 #if (USE_SPI_CRC != 0U)
2892  /* Check if CRC error occurred */
2894  {
2895  hspi->ErrorCode|= HAL_SPI_ERROR_CRC;
2897  HAL_SPI_ErrorCallback(hspi);
2898  }
2899  else
2900  {
2901 #endif
2902  if(hspi->ErrorCode == HAL_SPI_ERROR_NONE)
2903  {
2904  HAL_SPI_RxCpltCallback(hspi);
2905  }
2906  else
2907  {
2908  HAL_SPI_ErrorCallback(hspi);
2909  }
2910 #if (USE_SPI_CRC != 0U)
2911  }
2912 #endif
2913 }
2914 
2921 static void SPI_CloseTx_ISR(SPI_HandleTypeDef *hspi)
2922 {
2923  /* Disable TXE and ERR interrupt */
2924  __HAL_SPI_DISABLE_IT(hspi, (SPI_IT_TXE | SPI_IT_ERR));
2925 
2926  /* Check the end of the transaction */
2927  if(SPI_EndRxTxTransaction(hspi,SPI_DEFAULT_TIMEOUT)!=HAL_OK)
2928  {
2929  hspi->ErrorCode|= HAL_SPI_ERROR_FLAG;
2930  }
2931 
2932  /* Clear overrun flag in 2 Lines communication mode because received is not read */
2933  if(hspi->Init.Direction == SPI_DIRECTION_2LINES)
2934  {
2936  }
2937 
2938  hspi->State = HAL_SPI_STATE_READY;
2939  if(hspi->ErrorCode != HAL_SPI_ERROR_NONE)
2940  {
2941  HAL_SPI_ErrorCallback(hspi);
2942  }
2943  else
2944  {
2945  HAL_SPI_TxCpltCallback(hspi);
2946  }
2947 }
2948 
2953 #endif /* HAL_SPI_MODULE_ENABLED */
2954 
2963 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
HAL_StatusTypeDef HAL_SPI_Transmit(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
#define SPI_SR_FRE
Definition: stm32f745xx.h:6635
#define HAL_SPI_ERROR_FRE
void HAL_SPI_TxRxCpltCallback(SPI_HandleTypeDef *hspi)
#define CLEAR_BIT(REG, BIT)
Definition: stm32f7xx.h:180
#define IS_SPI_NSSP(NSSP)
__IO uint32_t DR
Definition: stm32f745xx.h:846
#define SPI_FLAG_RXNE
#define SPI_DIRECTION_2LINES_RXONLY
HAL_StatusTypeDef HAL_SPI_Transmit_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
HAL_LockTypeDef Lock
#define IS_SPI_CRC_POLYNOMIAL(POLYNOMIAL)
#define SPI_CR1_SPE
Definition: stm32f745xx.h:6597
#define SPI_CR2_TXEIE
Definition: stm32f745xx.h:6616
void HAL_SPI_ErrorCallback(SPI_HandleTypeDef *hspi)
void HAL_SPI_RxCpltCallback(SPI_HandleTypeDef *hspi)
#define assert_param(expr)
Include module&#39;s header file.
#define SPI_SR_FRLVL
Definition: stm32f745xx.h:6636
__IO uint32_t CR1
Definition: stm32f745xx.h:843
HAL_StatusTypeDef HAL_SPI_TransmitReceive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
#define __HAL_SPI_CLEAR_FREFLAG(__HANDLE__)
Clears the SPI FRE pending flag.
#define __HAL_SPI_ENABLE(__HANDLE__)
Enables the SPI.
__IO HAL_SPI_StateTypeDef State
#define SPI_CR2_ERRIE
Definition: stm32f745xx.h:6614
#define IS_SPI_CRC_LENGTH(LENGTH)
#define SPI_FRLVL_HALF_FULL
#define __HAL_UNLOCK(__HANDLE__)
#define SPI_CR2_RXDMAEN
Definition: stm32f745xx.h:6609
#define IS_SPI_NSS(NSS)
#define HAL_SPI_ERROR_MODF
#define IS_SPI_MODE(MODE)
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
#define SPI_IT_TXE
#define DMA_MDATAALIGN_HALFWORD
#define SPI_CR1_SSM
Definition: stm32f745xx.h:6600
#define SPI_FLAG_OVR
DMA_InitTypeDef Init
#define __HAL_SPI_CLEAR_OVRFLAG(__HANDLE__)
Clears the SPI OVR pending flag.
#define SPI_RXFIFO_THRESHOLD_QF
#define SPI_FLAG_TXE
#define HAL_SPI_ERROR_NONE
#define WRITE_REG(REG, VAL)
Definition: stm32f7xx.h:186
#define SPI_CRC_LENGTH_DATASIZE
__IO uint32_t SR
Definition: stm32f745xx.h:845
#define IS_SPI_TIMODE(MODE)
#define SPI_CR2_RXNEIE
Definition: stm32f745xx.h:6615
#define SPI_1LINE_TX(__HANDLE__)
Sets the SPI transmit-only mode.
void HAL_SPI_TxHalfCpltCallback(SPI_HandleTypeDef *hspi)
#define SPI_RXFIFO_THRESHOLD
#define IS_SPI_FIRST_BIT(BIT)
#define SPI_CR2_LDMARX
Definition: stm32f745xx.h:6623
SPI_InitTypeDef Init
#define SPI_SR_OVR
Definition: stm32f745xx.h:6633
#define SPI_CR2_NSSP
Definition: stm32f745xx.h:6612
HAL_StatusTypeDef HAL_SPI_Receive_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
#define SPI_CRC_LENGTH_8BIT
#define SPI_CR1_CRCL
Definition: stm32f745xx.h:6602
#define SPI_CRCCALCULATION_DISABLE
#define SPI_CR1_MSTR
Definition: stm32f745xx.h:6592
#define SPI_FLAG_MODF
#define HAL_SPI_ERROR_FLAG
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
#define __HAL_LOCK(__HANDLE__)
#define SPI_FRLVL_QUARTER_FULL
#define SPI_CR1_CRCNEXT
Definition: stm32f745xx.h:6603
#define SPI_DIRECTION_1LINE
#define SPI_IT_ERR
#define NULL
Definition: usbd_def.h:53
#define DMA_SxCR_CIRC
Definition: stm32f745xx.h:3313
void HAL_SPI_MspDeInit(SPI_HandleTypeDef *hspi)
#define HAL_MAX_DELAY
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
#define __HAL_SPI_GET_FLAG(__HANDLE__, __FLAG__)
Checks whether the specified SPI flag is set or not.
DMA_HandleTypeDef * hdmatx
#define HAL_SPI_ERROR_CRC
SPI handle Structure definition.
#define __IO
Definition: core_cm0.h:213
#define SPI_FRLVL_EMPTY
#define __HAL_SPI_DISABLE_IT(__HANDLE__, __INTERRUPT__)
uint32_t BaudRatePrescaler
#define HAL_SPI_ERROR_OVR
#define __HAL_SPI_DISABLE(__HANDLE__)
Disables the SPI.
HAL_SPI_StateTypeDef HAL_SPI_GetState(SPI_HandleTypeDef *hspi)
#define SPI_DIRECTION_2LINES
#define IS_SPI_ALL_INSTANCE(__INSTANCE__)
Definition: stm32f745xx.h:8890
HAL_StatusTypeDef HAL_SPI_DMAPause(SPI_HandleTypeDef *hspi)
#define SPI_FLAG_FRE
This file contains all the functions prototypes for the HAL module driver.
#define HAL_SPI_ERROR_DMA
HAL_StatusTypeDef HAL_SPI_DeInit(SPI_HandleTypeDef *hspi)
#define SPI_CRCCALCULATION_ENABLE
HAL_StatusTypeDef HAL_SPI_Init(SPI_HandleTypeDef *hspi)
#define IS_SPI_CRC_CALCULATION(CALCULATION)
DMA_Stream_TypeDef * Instance
#define SPI_CR2_LDMATX
Definition: stm32f745xx.h:6624
HAL_StatusTypeDef HAL_SPI_TransmitReceive_IT(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size)
#define SPI_IT_RXNE
HAL_StatusTypeDef HAL_SPI_DMAResume(SPI_HandleTypeDef *hspi)
#define SPI_FLAG_CRCERR
#define SPI_1LINE_RX(__HANDLE__)
Sets the SPI receive-only mode.
void(* XferHalfCpltCallback)(struct __DMA_HandleTypeDef *hdma)
#define SPI_FLAG_FRLVL
#define SPI_RXFIFO_THRESHOLD_HF
#define SPI_MODE_MASTER
__IO uint32_t CR
Definition: stm32f745xx.h:392
#define UNUSED(x)
void(* RxISR)(struct __SPI_HandleTypeDef *hspi)
#define IS_SPI_BAUDRATE_PRESCALER(PRESCALER)
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
#define SPI_DATASIZE_16BIT
void(* TxISR)(struct __SPI_HandleTypeDef *hspi)
#define SPI_CR2_TXDMAEN
Definition: stm32f745xx.h:6610
HAL_StatusTypeDef HAL_SPI_Receive_DMA(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
#define SET_BIT(REG, BIT)
Definition: stm32f7xx.h:178
uint32_t HAL_SPI_GetError(SPI_HandleTypeDef *hspi)
#define SPI_SR_CRCERR
Definition: stm32f745xx.h:6631
#define HAL_IS_BIT_SET(REG, BIT)
#define SPI_CR2_SSOE
Definition: stm32f745xx.h:6611
#define SPI_FLAG_BSY
#define IS_SPI_CPOL(CPOL)
#define IS_SPI_DIRECTION(MODE)
DMA handle Structure definition.
#define SPI_CRC_LENGTH_16BIT
void HAL_SPI_RxHalfCpltCallback(SPI_HandleTypeDef *hspi)
HAL_StatusTypeDef HAL_SPI_TransmitReceive(SPI_HandleTypeDef *hspi, uint8_t *pTxData, uint8_t *pRxData, uint16_t Size, uint32_t Timeout)
#define SPI_RESET_CRC(__HANDLE__)
Resets the CRC calculation of the SPI.
#define SPI_FTLVL_EMPTY
#define IS_SPI_CPHA(CPHA)
#define __HAL_SPI_CLEAR_CRCERRFLAG(__HANDLE__)
Clears the SPI CRCERR pending flag.
HAL_StatusTypeDef HAL_SPI_Transmit_IT(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size)
#define SPI_DATASIZE_8BIT
#define IS_SPI_DATASIZE(DATASIZE)
uint32_t MemDataAlignment
HAL_StatusTypeDef
HAL Status structures definition.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_SPI_DMAStop(SPI_HandleTypeDef *hspi)
void HAL_SPI_TxCpltCallback(SPI_HandleTypeDef *hspi)
void HAL_SPI_TxRxHalfCpltCallback(SPI_HandleTypeDef *hspi)
#define SPI_FLAG_FTLVL
__IO uint32_t CR2
Definition: stm32f745xx.h:844
uint32_t HAL_GetTick(void)
Provides a tick value in millisecond.
HAL_StatusTypeDef HAL_SPI_Receive(SPI_HandleTypeDef *hspi, uint8_t *pData, uint16_t Size, uint32_t Timeout)
#define __HAL_SPI_ENABLE_IT(__HANDLE__, __INTERRUPT__)
Enables or disables the specified SPI interrupts.
__IO uint32_t CRCPR
Definition: stm32f745xx.h:847
#define SPI_SR_MODF
Definition: stm32f745xx.h:6632
#define __HAL_SPI_CLEAR_MODFFLAG(__HANDLE__)
Clears the SPI MODF pending flag.
#define IS_SPI_DIRECTION_2LINES(MODE)
HAL_SPI_StateTypeDef
HAL State structures definition.
DMA_HandleTypeDef * hdmarx
void HAL_SPI_IRQHandler(SPI_HandleTypeDef *hspi)
void HAL_SPI_MspInit(SPI_HandleTypeDef *hspi)
#define IS_SPI_DIRECTION_2LINES_OR_1LINE(MODE)