STM32L4xx_HAL_Driver  1.14.0
stm32l4xx_hal_smartcard.c
Go to the documentation of this file.
1 
182 /* Includes ------------------------------------------------------------------*/
183 #include "stm32l4xx_hal.h"
184 
194 #ifdef HAL_SMARTCARD_MODULE_ENABLED
195 
196 /* Private typedef -----------------------------------------------------------*/
197 /* Private define ------------------------------------------------------------*/
201 #define SMARTCARD_TEACK_REACK_TIMEOUT 1000U
203 #if defined(USART_CR1_FIFOEN)
204 #define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \
205  USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8| \
206  USART_CR1_FIFOEN ))
207 #else
208 #define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \
209  USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8))
210 #endif /* USART_CR1_FIFOEN */
211 
212 #define USART_CR2_CLK_FIELDS ((uint32_t)(USART_CR2_CLKEN | USART_CR2_CPOL | USART_CR2_CPHA | \
213  USART_CR2_LBCL))
215 #define USART_CR2_FIELDS ((uint32_t)(USART_CR2_RTOEN | USART_CR2_CLK_FIELDS | USART_CR2_STOP))
217 #if defined(USART_CR1_FIFOEN)
218 #define USART_CR3_FIELDS ((uint32_t)(USART_CR3_ONEBIT | USART_CR3_NACK | USART_CR3_SCARCNT | \
219  USART_CR3_TXFTCFG | USART_CR3_RXFTCFG ))
220 #else
221 #define USART_CR3_FIELDS ((uint32_t)(USART_CR3_ONEBIT | USART_CR3_NACK | USART_CR3_SCARCNT))
222 #endif /* USART_CR1_FIFOEN */
223 
224 #define USART_BRR_MIN 0x10U
226 #define USART_BRR_MAX 0x0000FFFFU
231 /* Private macros ------------------------------------------------------------*/
232 /* Private variables ---------------------------------------------------------*/
233 /* Private function prototypes -----------------------------------------------*/
237 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
239 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
240 static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard);
241 static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard);
242 static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard);
243 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag,
244  FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
245 static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsmartcard);
246 static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsmartcard);
249 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma);
255 static void SMARTCARD_TxISR(SMARTCARD_HandleTypeDef *hsmartcard);
256 #if defined(USART_CR1_FIFOEN)
257 static void SMARTCARD_TxISR_FIFOEN(SMARTCARD_HandleTypeDef *hsmartcard);
258 #endif /* USART_CR1_FIFOEN */
259 static void SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
260 static void SMARTCARD_RxISR(SMARTCARD_HandleTypeDef *hsmartcard);
261 #if defined(USART_CR1_FIFOEN)
262 static void SMARTCARD_RxISR_FIFOEN(SMARTCARD_HandleTypeDef *hsmartcard);
263 #endif /* USART_CR1_FIFOEN */
264 
268 /* Exported functions --------------------------------------------------------*/
269 
329 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsmartcard)
330 {
331  /* Check the SMARTCARD handle allocation */
332  if (hsmartcard == NULL)
333  {
334  return HAL_ERROR;
335  }
336 
337  /* Check the USART associated to the SMARTCARD handle */
338  assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
339 
340  if (hsmartcard->gState == HAL_SMARTCARD_STATE_RESET)
341  {
342  /* Allocate lock resource and initialize it */
343  hsmartcard->Lock = HAL_UNLOCKED;
344 
345 #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1
347 
348  if (hsmartcard->MspInitCallback == NULL)
349  {
351  }
352 
353  /* Init the low level hardware */
354  hsmartcard->MspInitCallback(hsmartcard);
355 #else
356  /* Init the low level hardware : GPIO, CLOCK */
357  HAL_SMARTCARD_MspInit(hsmartcard);
358 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
359  }
360 
361  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
362 
363  /* Disable the Peripheral to set smartcard mode */
364  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
365 
366  /* In SmartCard mode, the following bits must be kept cleared:
367  - LINEN in the USART_CR2 register,
368  - HDSEL and IREN bits in the USART_CR3 register.*/
369  CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_LINEN);
370  CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN));
371 
372  /* set the USART in SMARTCARD mode */
373  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_SCEN);
374 
375  /* Set the SMARTCARD Communication parameters */
376  if (SMARTCARD_SetConfig(hsmartcard) == HAL_ERROR)
377  {
378  return HAL_ERROR;
379  }
380 
381  /* Set the SMARTCARD transmission completion indication */
382  SMARTCARD_TRANSMISSION_COMPLETION_SETTING(hsmartcard);
383 
384  if (hsmartcard->AdvancedInit.AdvFeatureInit != SMARTCARD_ADVFEATURE_NO_INIT)
385  {
386  SMARTCARD_AdvFeatureConfig(hsmartcard);
387  }
388 
389  /* Enable the Peripheral */
390  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
391 
392  /* TEACK and/or REACK to check before moving hsmartcard->gState and hsmartcard->RxState to Ready */
393  return (SMARTCARD_CheckIdleState(hsmartcard));
394 }
395 
402 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard)
403 {
404  /* Check the SMARTCARD handle allocation */
405  if (hsmartcard == NULL)
406  {
407  return HAL_ERROR;
408  }
409 
410  /* Check the USART/UART associated to the SMARTCARD handle */
411  assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
412 
413  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
414 
415  /* Disable the Peripheral */
416  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
417 
418  WRITE_REG(hsmartcard->Instance->CR1, 0x0U);
419  WRITE_REG(hsmartcard->Instance->CR2, 0x0U);
420  WRITE_REG(hsmartcard->Instance->CR3, 0x0U);
421  WRITE_REG(hsmartcard->Instance->RTOR, 0x0U);
422  WRITE_REG(hsmartcard->Instance->GTPR, 0x0U);
423 
424  /* DeInit the low level hardware */
425 #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1
426  if (hsmartcard->MspDeInitCallback == NULL)
427  {
429  }
430  /* DeInit the low level hardware */
431  hsmartcard->MspDeInitCallback(hsmartcard);
432 #else
433  HAL_SMARTCARD_MspDeInit(hsmartcard);
434 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
435 
436  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
437  hsmartcard->gState = HAL_SMARTCARD_STATE_RESET;
438  hsmartcard->RxState = HAL_SMARTCARD_STATE_RESET;
439 
440  /* Process Unlock */
441  __HAL_UNLOCK(hsmartcard);
442 
443  return HAL_OK;
444 }
445 
453 {
454  /* Prevent unused argument(s) compilation warning */
455  UNUSED(hsmartcard);
456 
457  /* NOTE : This function should not be modified, when the callback is needed,
458  the HAL_SMARTCARD_MspInit can be implemented in the user file
459  */
460 }
461 
469 {
470  /* Prevent unused argument(s) compilation warning */
471  UNUSED(hsmartcard);
472 
473  /* NOTE : This function should not be modified, when the callback is needed,
474  the HAL_SMARTCARD_MspDeInit can be implemented in the user file
475  */
476 }
477 
478 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
479 
500 {
501  HAL_StatusTypeDef status = HAL_OK;
502 
503  if (pCallback == NULL)
504  {
505  /* Update the error code */
506  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
507 
508  return HAL_ERROR;
509  }
510  /* Process locked */
511  __HAL_LOCK(hsmartcard);
512 
513  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
514  {
515  switch (CallbackID)
516  {
517 
519  hsmartcard->TxCpltCallback = pCallback;
520  break;
521 
523  hsmartcard->RxCpltCallback = pCallback;
524  break;
525 
527  hsmartcard->ErrorCallback = pCallback;
528  break;
529 
531  hsmartcard->AbortCpltCallback = pCallback;
532  break;
533 
535  hsmartcard->AbortTransmitCpltCallback = pCallback;
536  break;
537 
539  hsmartcard->AbortReceiveCpltCallback = pCallback;
540  break;
541 
542 #if defined(USART_CR1_FIFOEN)
544  hsmartcard->RxFifoFullCallback = pCallback;
545  break;
546 
548  hsmartcard->TxFifoEmptyCallback = pCallback;
549  break;
550 #endif /* USART_CR1_FIFOEN */
551 
553  hsmartcard->MspInitCallback = pCallback;
554  break;
555 
557  hsmartcard->MspDeInitCallback = pCallback;
558  break;
559 
560  default :
561  /* Update the error code */
562  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
563 
564  /* Return error status */
565  status = HAL_ERROR;
566  break;
567  }
568  }
569  else if (hsmartcard->gState == HAL_SMARTCARD_STATE_RESET)
570  {
571  switch (CallbackID)
572  {
574  hsmartcard->MspInitCallback = pCallback;
575  break;
576 
578  hsmartcard->MspDeInitCallback = pCallback;
579  break;
580 
581  default :
582  /* Update the error code */
583  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
584 
585  /* Return error status */
586  status = HAL_ERROR;
587  break;
588  }
589  }
590  else
591  {
592  /* Update the error code */
593  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
594 
595  /* Return error status */
596  status = HAL_ERROR;
597  }
598 
599  /* Release Lock */
600  __HAL_UNLOCK(hsmartcard);
601 
602  return status;
603 }
604 
625 {
626  HAL_StatusTypeDef status = HAL_OK;
627 
628  /* Process locked */
629  __HAL_LOCK(hsmartcard);
630 
631  if (HAL_SMARTCARD_STATE_READY == hsmartcard->gState)
632  {
633  switch (CallbackID)
634  {
636  hsmartcard->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback; /* Legacy weak TxCpltCallback */
637  break;
638 
640  hsmartcard->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback; /* Legacy weak RxCpltCallback */
641  break;
642 
644  hsmartcard->ErrorCallback = HAL_SMARTCARD_ErrorCallback; /* Legacy weak ErrorCallback */
645  break;
646 
648  hsmartcard->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
649  break;
650 
652  hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
653  break;
654 
656  hsmartcard->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
657  break;
658 
659 #if defined(USART_CR1_FIFOEN)
661  hsmartcard->RxFifoFullCallback = HAL_SMARTCARDEx_RxFifoFullCallback; /* Legacy weak RxFifoFullCallback */
662  break;
663 
665  hsmartcard->TxFifoEmptyCallback = HAL_SMARTCARDEx_TxFifoEmptyCallback; /* Legacy weak TxFifoEmptyCallback */
666  break;
667 #endif /* USART_CR1_FIFOEN */
668 
670  hsmartcard->MspInitCallback = HAL_SMARTCARD_MspInit; /* Legacy weak MspInitCallback */
671  break;
672 
674  hsmartcard->MspDeInitCallback = HAL_SMARTCARD_MspDeInit; /* Legacy weak MspDeInitCallback */
675  break;
676 
677  default :
678  /* Update the error code */
679  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
680 
681  /* Return error status */
682  status = HAL_ERROR;
683  break;
684  }
685  }
686  else if (HAL_SMARTCARD_STATE_RESET == hsmartcard->gState)
687  {
688  switch (CallbackID)
689  {
692  break;
693 
696  break;
697 
698  default :
699  /* Update the error code */
700  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
701 
702  /* Return error status */
703  status = HAL_ERROR;
704  break;
705  }
706  }
707  else
708  {
709  /* Update the error code */
710  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_INVALID_CALLBACK;
711 
712  /* Return error status */
713  status = HAL_ERROR;
714  }
715 
716  /* Release Lock */
717  __HAL_UNLOCK(hsmartcard);
718 
719  return status;
720 }
721 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
722 
818 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size,
819  uint32_t Timeout)
820 {
821  uint32_t tickstart;
822  uint8_t *ptmpdata = pData;
823 
824  /* Check that a Tx process is not already ongoing */
825  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
826  {
827  if ((ptmpdata == NULL) || (Size == 0U))
828  {
829  return HAL_ERROR;
830  }
831 
832  /* Process Locked */
833  __HAL_LOCK(hsmartcard);
834 
835  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX;
836 
837  /* Init tickstart for timeout management */
838  tickstart = HAL_GetTick();
839 
840  /* Disable the Peripheral first to update mode for TX master */
841  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
842 
843  /* Disable Rx, enable Tx */
844  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
845  SET_BIT(hsmartcard->Instance->RQR, (uint16_t)SMARTCARD_RXDATA_FLUSH_REQUEST);
846  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
847 
848  /* Enable the Peripheral */
849  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
850 
851  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
852  hsmartcard->TxXferSize = Size;
853  hsmartcard->TxXferCount = Size;
854 
855  while (hsmartcard->TxXferCount > 0U)
856  {
857  hsmartcard->TxXferCount--;
858  if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
859  {
860  return HAL_TIMEOUT;
861  }
862  hsmartcard->Instance->TDR = (uint8_t)(*ptmpdata & 0xFFU);
863  ptmpdata++;
864  }
865  if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_TRANSMISSION_COMPLETION_FLAG(hsmartcard), RESET, tickstart,
866  Timeout) != HAL_OK)
867  {
868  return HAL_TIMEOUT;
869  }
870  /* Re-enable Rx at end of transmission if initial mode is Rx/Tx */
871  if (hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
872  {
873  /* Disable the Peripheral first to update modes */
874  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
875  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
876  /* Enable the Peripheral */
877  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
878  }
879 
880  /* At end of Tx process, restore hsmartcard->gState to Ready */
881  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
882 
883  /* Process Unlocked */
884  __HAL_UNLOCK(hsmartcard);
885 
886  return HAL_OK;
887  }
888  else
889  {
890  return HAL_BUSY;
891  }
892 }
893 
907 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size,
908  uint32_t Timeout)
909 {
910  uint32_t tickstart;
911  uint8_t *ptmpdata = pData;
912 
913  /* Check that a Rx process is not already ongoing */
914  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
915  {
916  if ((ptmpdata == NULL) || (Size == 0U))
917  {
918  return HAL_ERROR;
919  }
920 
921  /* Process Locked */
922  __HAL_LOCK(hsmartcard);
923 
924  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
925  hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
926 
927  /* Init tickstart for timeout management */
928  tickstart = HAL_GetTick();
929 
930  hsmartcard->RxXferSize = Size;
931  hsmartcard->RxXferCount = Size;
932 
933  /* Check the remain data to be received */
934  while (hsmartcard->RxXferCount > 0U)
935  {
936  hsmartcard->RxXferCount--;
937 
938  if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
939  {
940  return HAL_TIMEOUT;
941  }
942  *ptmpdata = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0x00FF);
943  ptmpdata++;
944  }
945 
946  /* At end of Rx process, restore hsmartcard->RxState to Ready */
947  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
948 
949  /* Process Unlocked */
950  __HAL_UNLOCK(hsmartcard);
951 
952  return HAL_OK;
953  }
954  else
955  {
956  return HAL_BUSY;
957  }
958 }
959 
975 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
976 {
977  /* Check that a Tx process is not already ongoing */
978  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
979  {
980  if ((pData == NULL) || (Size == 0U))
981  {
982  return HAL_ERROR;
983  }
984 
985  /* Process Locked */
986  __HAL_LOCK(hsmartcard);
987 
988  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
989  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX;
990 
991  hsmartcard->pTxBuffPtr = pData;
992  hsmartcard->TxXferSize = Size;
993  hsmartcard->TxXferCount = Size;
994  hsmartcard->TxISR = NULL;
995 
996  /* Disable the Peripheral first to update mode for TX master */
997  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
998 
999  /* Disable Rx, enable Tx */
1000  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
1001  SET_BIT(hsmartcard->Instance->RQR, (uint16_t)SMARTCARD_RXDATA_FLUSH_REQUEST);
1002  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
1003 
1004  /* Enable the Peripheral */
1005  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
1006 
1007  /* Configure Tx interrupt processing */
1008 #if defined(USART_CR1_FIFOEN)
1009  if (hsmartcard->FifoMode == SMARTCARD_FIFOMODE_ENABLE)
1010  {
1011  /* Set the Tx ISR function pointer */
1012  hsmartcard->TxISR = SMARTCARD_TxISR_FIFOEN;
1013 
1014  /* Process Unlocked */
1015  __HAL_UNLOCK(hsmartcard);
1016 
1017  /* Enable the SMARTCARD Error Interrupt: (Frame error) */
1018  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1019 
1020  /* Enable the TX FIFO threshold interrupt */
1021  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_TXFTIE);
1022  }
1023  else
1024  {
1025  /* Set the Tx ISR function pointer */
1026  hsmartcard->TxISR = SMARTCARD_TxISR;
1027 
1028  /* Process Unlocked */
1029  __HAL_UNLOCK(hsmartcard);
1030 
1031  /* Enable the SMARTCARD Error Interrupt: (Frame error) */
1032  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1033 
1034  /* Enable the SMARTCARD Transmit Data Register Empty Interrupt */
1035  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
1036  }
1037 #else
1038  /* Set the Tx ISR function pointer */
1039  hsmartcard->TxISR = SMARTCARD_TxISR;
1040 
1041  /* Process Unlocked */
1042  __HAL_UNLOCK(hsmartcard);
1043 
1044  /* Enable the SMARTCARD Error Interrupt: (Frame error) */
1045  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1046 
1047  /* Enable the SMARTCARD Transmit Data Register Empty Interrupt */
1048  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE);
1049 #endif /* USART_CR1_FIFOEN */
1050 
1051  return HAL_OK;
1052  }
1053  else
1054  {
1055  return HAL_BUSY;
1056  }
1057 }
1058 
1074 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
1075 {
1076  /* Check that a Rx process is not already ongoing */
1077  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
1078  {
1079  if ((pData == NULL) || (Size == 0U))
1080  {
1081  return HAL_ERROR;
1082  }
1083 
1084  /* Process Locked */
1085  __HAL_LOCK(hsmartcard);
1086 
1087  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
1088  hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
1089 
1090  hsmartcard->pRxBuffPtr = pData;
1091  hsmartcard->RxXferSize = Size;
1092  hsmartcard->RxXferCount = Size;
1093 
1094  /* Configure Rx interrupt processing */
1095 #if defined(USART_CR1_FIFOEN)
1096  if ((hsmartcard->FifoMode == SMARTCARD_FIFOMODE_ENABLE) && (Size >= hsmartcard->NbRxDataToProcess))
1097  {
1098  /* Set the Rx ISR function pointer */
1099  hsmartcard->RxISR = SMARTCARD_RxISR_FIFOEN;
1100 
1101  /* Process Unlocked */
1102  __HAL_UNLOCK(hsmartcard);
1103 
1104  /* Enable the SMARTCART Parity Error interrupt and RX FIFO Threshold interrupt */
1105  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
1106  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_RXFTIE);
1107  }
1108  else
1109  {
1110  /* Set the Rx ISR function pointer */
1111  hsmartcard->RxISR = SMARTCARD_RxISR;
1112 
1113  /* Process Unlocked */
1114  __HAL_UNLOCK(hsmartcard);
1115 
1116  /* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */
1117  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE_RXFNEIE);
1118  }
1119 #else
1120  /* Set the Rx ISR function pointer */
1121  hsmartcard->RxISR = SMARTCARD_RxISR;
1122 
1123  /* Process Unlocked */
1124  __HAL_UNLOCK(hsmartcard);
1125 
1126  /* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */
1127  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE | USART_CR1_RXNEIE);
1128 #endif /* USART_CR1_FIFOEN */
1129 
1130  /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
1131  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1132 
1133  return HAL_OK;
1134  }
1135  else
1136  {
1137  return HAL_BUSY;
1138  }
1139 }
1140 
1149 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
1150 {
1151  /* Check that a Tx process is not already ongoing */
1152  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
1153  {
1154  if ((pData == NULL) || (Size == 0U))
1155  {
1156  return HAL_ERROR;
1157  }
1158 
1159  /* Process Locked */
1160  __HAL_LOCK(hsmartcard);
1161 
1162  hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX;
1163 
1164  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
1165  hsmartcard->pTxBuffPtr = pData;
1166  hsmartcard->TxXferSize = Size;
1167  hsmartcard->TxXferCount = Size;
1168 
1169  /* Disable the Peripheral first to update mode for TX master */
1170  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
1171 
1172  /* Disable Rx, enable Tx */
1173  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
1174  SET_BIT(hsmartcard->Instance->RQR, (uint16_t)SMARTCARD_RXDATA_FLUSH_REQUEST);
1175  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
1176 
1177  /* Enable the Peripheral */
1178  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
1179 
1180  /* Set the SMARTCARD DMA transfer complete callback */
1182 
1183  /* Set the SMARTCARD error callback */
1185 
1186  /* Set the DMA abort callback */
1187  hsmartcard->hdmatx->XferAbortCallback = NULL;
1188 
1189  /* Enable the SMARTCARD transmit DMA channel */
1190  if (HAL_DMA_Start_IT(hsmartcard->hdmatx, (uint32_t)hsmartcard->pTxBuffPtr, (uint32_t)&hsmartcard->Instance->TDR,
1191  Size) == HAL_OK)
1192  {
1193  /* Clear the TC flag in the ICR register */
1194  CLEAR_BIT(hsmartcard->Instance->ICR, USART_ICR_TCCF);
1195 
1196  /* Process Unlocked */
1197  __HAL_UNLOCK(hsmartcard);
1198 
1199  /* Enable the UART Error Interrupt: (Frame error) */
1200  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1201 
1202  /* Enable the DMA transfer for transmit request by setting the DMAT bit
1203  in the SMARTCARD associated USART CR3 register */
1204  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
1205 
1206  return HAL_OK;
1207  }
1208  else
1209  {
1210  /* Set error code to DMA */
1211  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1212 
1213  /* Process Unlocked */
1214  __HAL_UNLOCK(hsmartcard);
1215 
1216  /* Restore hsmartcard->State to ready */
1217  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
1218 
1219  return HAL_ERROR;
1220  }
1221  }
1222  else
1223  {
1224  return HAL_BUSY;
1225  }
1226 }
1227 
1238 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
1239 {
1240  /* Check that a Rx process is not already ongoing */
1241  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
1242  {
1243  if ((pData == NULL) || (Size == 0U))
1244  {
1245  return HAL_ERROR;
1246  }
1247 
1248  /* Process Locked */
1249  __HAL_LOCK(hsmartcard);
1250 
1251  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
1252  hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
1253 
1254  hsmartcard->pRxBuffPtr = pData;
1255  hsmartcard->RxXferSize = Size;
1256 
1257  /* Set the SMARTCARD DMA transfer complete callback */
1259 
1260  /* Set the SMARTCARD DMA error callback */
1262 
1263  /* Set the DMA abort callback */
1264  hsmartcard->hdmarx->XferAbortCallback = NULL;
1265 
1266  /* Enable the DMA channel */
1267  if (HAL_DMA_Start_IT(hsmartcard->hdmarx, (uint32_t)&hsmartcard->Instance->RDR, (uint32_t)hsmartcard->pRxBuffPtr,
1268  Size) == HAL_OK)
1269  {
1270  /* Process Unlocked */
1271  __HAL_UNLOCK(hsmartcard);
1272 
1273  /* Enable the SMARTCARD Parity Error Interrupt */
1274  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
1275 
1276  /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
1277  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1278 
1279  /* Enable the DMA transfer for the receiver request by setting the DMAR bit
1280  in the SMARTCARD associated USART CR3 register */
1281  SET_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
1282 
1283  return HAL_OK;
1284  }
1285  else
1286  {
1287  /* Set error code to DMA */
1288  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1289 
1290  /* Process Unlocked */
1291  __HAL_UNLOCK(hsmartcard);
1292 
1293  /* Restore hsmartcard->State to ready */
1294  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1295 
1296  return HAL_ERROR;
1297  }
1298  }
1299  else
1300  {
1301  return HAL_BUSY;
1302  }
1303 }
1304 
1318 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard)
1319 {
1320 #if defined(USART_CR1_FIFOEN)
1321  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE, RXFT, TXFT and ERR (Frame error, noise error, overrun error) interrupts */
1322  CLEAR_BIT(hsmartcard->Instance->CR1,
1323  (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE | USART_CR1_RTOIE |
1324  USART_CR1_EOBIE));
1325  CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_EIE | USART_CR3_RXFTIE | USART_CR3_TXFTIE));
1326 #else
1327  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1328  CLEAR_BIT(hsmartcard->Instance->CR1,
1329  (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1330  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1331 #endif /* USART_CR1_FIFOEN */
1332 
1333  /* Disable the SMARTCARD DMA Tx request if enabled */
1334  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
1335  {
1336  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
1337 
1338  /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */
1339  if (hsmartcard->hdmatx != NULL)
1340  {
1341  /* Set the SMARTCARD DMA Abort callback to Null.
1342  No call back execution at end of DMA abort procedure */
1343  hsmartcard->hdmatx->XferAbortCallback = NULL;
1344 
1345  if (HAL_DMA_Abort(hsmartcard->hdmatx) != HAL_OK)
1346  {
1347  if (HAL_DMA_GetError(hsmartcard->hdmatx) == HAL_DMA_ERROR_TIMEOUT)
1348  {
1349  /* Set error code to DMA */
1350  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1351 
1352  return HAL_TIMEOUT;
1353  }
1354  }
1355  }
1356  }
1357 
1358  /* Disable the SMARTCARD DMA Rx request if enabled */
1359  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
1360  {
1361  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
1362 
1363  /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */
1364  if (hsmartcard->hdmarx != NULL)
1365  {
1366  /* Set the SMARTCARD DMA Abort callback to Null.
1367  No call back execution at end of DMA abort procedure */
1368  hsmartcard->hdmarx->XferAbortCallback = NULL;
1369 
1370  if (HAL_DMA_Abort(hsmartcard->hdmarx) != HAL_OK)
1371  {
1372  if (HAL_DMA_GetError(hsmartcard->hdmarx) == HAL_DMA_ERROR_TIMEOUT)
1373  {
1374  /* Set error code to DMA */
1375  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1376 
1377  return HAL_TIMEOUT;
1378  }
1379  }
1380  }
1381  }
1382 
1383  /* Reset Tx and Rx transfer counters */
1384  hsmartcard->TxXferCount = 0U;
1385  hsmartcard->RxXferCount = 0U;
1386 
1387  /* Clear the Error flags in the ICR register */
1388  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1389  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1390  SMARTCARD_CLEAR_EOBF);
1391 
1392  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
1393  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
1394  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1395 
1396  /* Reset Handle ErrorCode to No Error */
1397  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
1398 
1399  return HAL_OK;
1400 }
1401 
1416 {
1417 #if defined(USART_CR1_FIFOEN)
1418  /* Disable TCIE, TXEIE and TXFTIE interrupts */
1419  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
1420  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_TXFTIE);
1421 #else
1422  /* Disable TXEIE and TCIE interrupts */
1423  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
1424 #endif /* USART_CR1_FIFOEN */
1425 
1426  /* Check if a receive process is ongoing or not. If not disable ERR IT */
1427  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
1428  {
1429  /* Disable the SMARTCARD Error Interrupt: (Frame error) */
1430  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1431  }
1432 
1433  /* Disable the SMARTCARD DMA Tx request if enabled */
1434  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
1435  {
1436  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
1437 
1438  /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */
1439  if (hsmartcard->hdmatx != NULL)
1440  {
1441  /* Set the SMARTCARD DMA Abort callback to Null.
1442  No call back execution at end of DMA abort procedure */
1443  hsmartcard->hdmatx->XferAbortCallback = NULL;
1444 
1445  if (HAL_DMA_Abort(hsmartcard->hdmatx) != HAL_OK)
1446  {
1447  if (HAL_DMA_GetError(hsmartcard->hdmatx) == HAL_DMA_ERROR_TIMEOUT)
1448  {
1449  /* Set error code to DMA */
1450  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1451 
1452  return HAL_TIMEOUT;
1453  }
1454  }
1455  }
1456  }
1457 
1458  /* Reset Tx transfer counter */
1459  hsmartcard->TxXferCount = 0U;
1460 
1461  /* Clear the Error flags in the ICR register */
1462  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF);
1463 
1464  /* Restore hsmartcard->gState to Ready */
1465  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
1466 
1467  return HAL_OK;
1468 }
1469 
1484 {
1485 #if defined(USART_CR1_FIFOEN)
1486  /* Disable RTOIE, EOBIE, RXNE, PE, RXFT, TXFT and ERR (Frame error, noise error, overrun error) interrupts */
1487  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1488  CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_EIE | USART_CR3_RXFTIE));
1489 #else
1490  /* Disable RTOIE, EOBIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1491  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1492  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1493 #endif /* USART_CR1_FIFOEN */
1494 
1495  /* Check if a Transmit process is ongoing or not. If not disable ERR IT */
1496  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
1497  {
1498  /* Disable the SMARTCARD Error Interrupt: (Frame error) */
1499  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1500  }
1501 
1502  /* Disable the SMARTCARD DMA Rx request if enabled */
1503  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
1504  {
1505  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
1506 
1507  /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */
1508  if (hsmartcard->hdmarx != NULL)
1509  {
1510  /* Set the SMARTCARD DMA Abort callback to Null.
1511  No call back execution at end of DMA abort procedure */
1512  hsmartcard->hdmarx->XferAbortCallback = NULL;
1513 
1514  if (HAL_DMA_Abort(hsmartcard->hdmarx) != HAL_OK)
1515  {
1516  if (HAL_DMA_GetError(hsmartcard->hdmarx) == HAL_DMA_ERROR_TIMEOUT)
1517  {
1518  /* Set error code to DMA */
1519  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1520 
1521  return HAL_TIMEOUT;
1522  }
1523  }
1524  }
1525  }
1526 
1527  /* Reset Rx transfer counter */
1528  hsmartcard->RxXferCount = 0U;
1529 
1530  /* Clear the Error flags in the ICR register */
1531  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1532  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1533  SMARTCARD_CLEAR_EOBF);
1534 
1535  /* Restore hsmartcard->RxState to Ready */
1536  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1537 
1538  return HAL_OK;
1539 }
1540 
1556 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsmartcard)
1557 {
1558  uint32_t abortcplt = 1U;
1559 
1560 #if defined(USART_CR1_FIFOEN)
1561  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE, RXFT, TXFT and ERR (Frame error, noise error, overrun error) interrupts */
1562  CLEAR_BIT(hsmartcard->Instance->CR1,
1563  (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE | USART_CR1_RTOIE |
1564  USART_CR1_EOBIE));
1565  CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_EIE | USART_CR3_RXFTIE | USART_CR3_TXFTIE));
1566 #else
1567  /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1568  CLEAR_BIT(hsmartcard->Instance->CR1,
1569  (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1570  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1571 #endif /* USART_CR1_FIFOEN */
1572 
1573  /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised
1574  before any call to DMA Abort functions */
1575  /* DMA Tx Handle is valid */
1576  if (hsmartcard->hdmatx != NULL)
1577  {
1578  /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled.
1579  Otherwise, set it to NULL */
1580  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
1581  {
1583  }
1584  else
1585  {
1586  hsmartcard->hdmatx->XferAbortCallback = NULL;
1587  }
1588  }
1589  /* DMA Rx Handle is valid */
1590  if (hsmartcard->hdmarx != NULL)
1591  {
1592  /* Set DMA Abort Complete callback if SMARTCARD DMA Rx request if enabled.
1593  Otherwise, set it to NULL */
1594  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
1595  {
1597  }
1598  else
1599  {
1600  hsmartcard->hdmarx->XferAbortCallback = NULL;
1601  }
1602  }
1603 
1604  /* Disable the SMARTCARD DMA Tx request if enabled */
1605  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
1606  {
1607  /* Disable DMA Tx at UART level */
1608  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
1609 
1610  /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */
1611  if (hsmartcard->hdmatx != NULL)
1612  {
1613  /* SMARTCARD Tx DMA Abort callback has already been initialised :
1614  will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
1615 
1616  /* Abort DMA TX */
1617  if (HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK)
1618  {
1619  hsmartcard->hdmatx->XferAbortCallback = NULL;
1620  }
1621  else
1622  {
1623  abortcplt = 0U;
1624  }
1625  }
1626  }
1627 
1628  /* Disable the SMARTCARD DMA Rx request if enabled */
1629  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
1630  {
1631  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
1632 
1633  /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */
1634  if (hsmartcard->hdmarx != NULL)
1635  {
1636  /* SMARTCARD Rx DMA Abort callback has already been initialised :
1637  will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
1638 
1639  /* Abort DMA RX */
1640  if (HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK)
1641  {
1642  hsmartcard->hdmarx->XferAbortCallback = NULL;
1643  abortcplt = 1U;
1644  }
1645  else
1646  {
1647  abortcplt = 0U;
1648  }
1649  }
1650  }
1651 
1652  /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
1653  if (abortcplt == 1U)
1654  {
1655  /* Reset Tx and Rx transfer counters */
1656  hsmartcard->TxXferCount = 0U;
1657  hsmartcard->RxXferCount = 0U;
1658 
1659  /* Clear ISR function pointers */
1660  hsmartcard->RxISR = NULL;
1661  hsmartcard->TxISR = NULL;
1662 
1663  /* Reset errorCode */
1664  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
1665 
1666  /* Clear the Error flags in the ICR register */
1667  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1668  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1669  SMARTCARD_CLEAR_EOBF);
1670 
1671  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
1672  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
1673  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1674 
1675  /* As no DMA to be aborted, call directly user Abort complete callback */
1676 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
1677  /* Call registered Abort complete callback */
1678  hsmartcard->AbortCpltCallback(hsmartcard);
1679 #else
1680  /* Call legacy weak Abort complete callback */
1681  HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
1682 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
1683  }
1684 
1685  return HAL_OK;
1686 }
1687 
1704 {
1705 #if defined(USART_CR1_FIFOEN)
1706  /* Disable TCIE, TXEIE and TXFTIE interrupts */
1707  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
1708  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_TXFTIE);
1709 #else
1710  /* Disable TXEIE and TCIE interrupts */
1711  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
1712 #endif /* USART_CR1_FIFOEN */
1713 
1714  /* Check if a receive process is ongoing or not. If not disable ERR IT */
1715  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
1716  {
1717  /* Disable the SMARTCARD Error Interrupt: (Frame error) */
1718  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1719  }
1720 
1721  /* Disable the SMARTCARD DMA Tx request if enabled */
1722  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
1723  {
1724  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
1725 
1726  /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */
1727  if (hsmartcard->hdmatx != NULL)
1728  {
1729  /* Set the SMARTCARD DMA Abort callback :
1730  will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
1732 
1733  /* Abort DMA TX */
1734  if (HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK)
1735  {
1736  /* Call Directly hsmartcard->hdmatx->XferAbortCallback function in case of error */
1737  hsmartcard->hdmatx->XferAbortCallback(hsmartcard->hdmatx);
1738  }
1739  }
1740  else
1741  {
1742  /* Reset Tx transfer counter */
1743  hsmartcard->TxXferCount = 0U;
1744 
1745  /* Clear TxISR function pointers */
1746  hsmartcard->TxISR = NULL;
1747 
1748  /* Restore hsmartcard->gState to Ready */
1749  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
1750 
1751  /* As no DMA to be aborted, call directly user Abort complete callback */
1752 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
1753  /* Call registered Abort Transmit Complete Callback */
1754  hsmartcard->AbortTransmitCpltCallback(hsmartcard);
1755 #else
1756  /* Call legacy weak Abort Transmit Complete Callback */
1758 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
1759  }
1760  }
1761  else
1762  {
1763  /* Reset Tx transfer counter */
1764  hsmartcard->TxXferCount = 0U;
1765 
1766  /* Clear TxISR function pointers */
1767  hsmartcard->TxISR = NULL;
1768 
1769  /* Clear the Error flags in the ICR register */
1770  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF);
1771 
1772  /* Restore hsmartcard->gState to Ready */
1773  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
1774 
1775  /* As no DMA to be aborted, call directly user Abort complete callback */
1776 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
1777  /* Call registered Abort Transmit Complete Callback */
1778  hsmartcard->AbortTransmitCpltCallback(hsmartcard);
1779 #else
1780  /* Call legacy weak Abort Transmit Complete Callback */
1782 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
1783  }
1784 
1785  return HAL_OK;
1786 }
1787 
1804 {
1805 #if defined(USART_CR1_FIFOEN)
1806  /* Disable RTOIE, EOBIE, RXNE, PE, RXFT and ERR (Frame error, noise error, overrun error) interrupts */
1807  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1808  CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_EIE | USART_CR3_RXFTIE));
1809 #else
1810  /* Disable RTOIE, EOBIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
1811  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
1812  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1813 #endif /* USART_CR1_FIFOEN */
1814 
1815  /* Check if a Transmit process is ongoing or not. If not disable ERR IT */
1816  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
1817  {
1818  /* Disable the SMARTCARD Error Interrupt: (Frame error) */
1819  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
1820  }
1821 
1822  /* Disable the SMARTCARD DMA Rx request if enabled */
1823  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
1824  {
1825  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
1826 
1827  /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */
1828  if (hsmartcard->hdmarx != NULL)
1829  {
1830  /* Set the SMARTCARD DMA Abort callback :
1831  will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
1833 
1834  /* Abort DMA RX */
1835  if (HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK)
1836  {
1837  /* Call Directly hsmartcard->hdmarx->XferAbortCallback function in case of error */
1838  hsmartcard->hdmarx->XferAbortCallback(hsmartcard->hdmarx);
1839  }
1840  }
1841  else
1842  {
1843  /* Reset Rx transfer counter */
1844  hsmartcard->RxXferCount = 0U;
1845 
1846  /* Clear RxISR function pointer */
1847  hsmartcard->RxISR = NULL;
1848 
1849  /* Clear the Error flags in the ICR register */
1850  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1851  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1852  SMARTCARD_CLEAR_EOBF);
1853 
1854  /* Restore hsmartcard->RxState to Ready */
1855  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1856 
1857  /* As no DMA to be aborted, call directly user Abort complete callback */
1858 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
1859  /* Call registered Abort Receive Complete Callback */
1860  hsmartcard->AbortReceiveCpltCallback(hsmartcard);
1861 #else
1862  /* Call legacy weak Abort Receive Complete Callback */
1864 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
1865  }
1866  }
1867  else
1868  {
1869  /* Reset Rx transfer counter */
1870  hsmartcard->RxXferCount = 0U;
1871 
1872  /* Clear RxISR function pointer */
1873  hsmartcard->RxISR = NULL;
1874 
1875  /* Clear the Error flags in the ICR register */
1876  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
1877  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
1878  SMARTCARD_CLEAR_EOBF);
1879 
1880  /* Restore hsmartcard->RxState to Ready */
1881  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
1882 
1883  /* As no DMA to be aborted, call directly user Abort complete callback */
1884 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
1885  /* Call registered Abort Receive Complete Callback */
1886  hsmartcard->AbortReceiveCpltCallback(hsmartcard);
1887 #else
1888  /* Call legacy weak Abort Receive Complete Callback */
1890 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
1891  }
1892 
1893  return HAL_OK;
1894 }
1895 
1903 {
1904  uint32_t isrflags = READ_REG(hsmartcard->Instance->ISR);
1905  uint32_t cr1its = READ_REG(hsmartcard->Instance->CR1);
1906  uint32_t cr3its = READ_REG(hsmartcard->Instance->CR3);
1907  uint32_t errorflags;
1908  uint32_t errorcode;
1909 
1910  /* If no error occurs */
1911  errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE | USART_ISR_RTOF));
1912  if (errorflags == 0U)
1913  {
1914  /* SMARTCARD in mode Receiver ---------------------------------------------------*/
1915 #if defined(USART_CR1_FIFOEN)
1916  if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U)
1917  && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U)
1918  || ((cr3its & USART_CR3_RXFTIE) != 0U)))
1919 #else
1920  if (((isrflags & USART_ISR_RXNE) != 0U)
1921  && ((cr1its & USART_CR1_RXNEIE) != 0U))
1922 #endif /* USART_CR1_FIFOEN */
1923  {
1924  if (hsmartcard->RxISR != NULL)
1925  {
1926  hsmartcard->RxISR(hsmartcard);
1927  }
1928  return;
1929  }
1930  }
1931 
1932  /* If some errors occur */
1933 #if defined(USART_CR1_FIFOEN)
1934  if ((errorflags != 0U)
1935  && ((((cr3its & (USART_CR3_RXFTIE | USART_CR3_EIE)) != 0U)
1936  || ((cr1its & (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE)) != 0U))))
1937 #else
1938  if ((errorflags != 0U)
1939  && (((cr3its & USART_CR3_EIE) != 0U)
1940  || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != 0U)))
1941 #endif /* USART_CR1_FIFOEN */
1942  {
1943  /* SMARTCARD parity error interrupt occurred -------------------------------------*/
1944  if (((isrflags & USART_ISR_PE) != 0U) && ((cr1its & USART_CR1_PEIE) != 0U))
1945  {
1946  __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_PEF);
1947 
1948  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_PE;
1949  }
1950 
1951  /* SMARTCARD frame error interrupt occurred --------------------------------------*/
1952  if (((isrflags & USART_ISR_FE) != 0U) && ((cr3its & USART_CR3_EIE) != 0U))
1953  {
1954  __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_FEF);
1955 
1956  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_FE;
1957  }
1958 
1959  /* SMARTCARD noise error interrupt occurred --------------------------------------*/
1960  if (((isrflags & USART_ISR_NE) != 0U) && ((cr3its & USART_CR3_EIE) != 0U))
1961  {
1962  __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_NEF);
1963 
1964  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_NE;
1965  }
1966 
1967  /* SMARTCARD Over-Run interrupt occurred -----------------------------------------*/
1968 #if defined(USART_CR1_FIFOEN)
1969  if (((isrflags & USART_ISR_ORE) != 0U)
1970  && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U)
1971  || ((cr3its & USART_CR3_RXFTIE) != 0U)
1972  || ((cr3its & USART_CR3_EIE) != 0U)))
1973 #else
1974  if (((isrflags & USART_ISR_ORE) != 0U)
1975  && (((cr1its & USART_CR1_RXNEIE) != 0U)
1976  || ((cr3its & USART_CR3_EIE) != 0U)))
1977 #endif /* USART_CR1_FIFOEN */
1978  {
1979  __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_OREF);
1980 
1981  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_ORE;
1982  }
1983 
1984  /* SMARTCARD receiver timeout interrupt occurred -----------------------------------------*/
1985  if (((isrflags & USART_ISR_RTOF) != 0U) && ((cr1its & USART_CR1_RTOIE) != 0U))
1986  {
1987  __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_RTOF);
1988 
1989  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_RTO;
1990  }
1991 
1992  /* Call SMARTCARD Error Call back function if need be --------------------------*/
1993  if (hsmartcard->ErrorCode != HAL_SMARTCARD_ERROR_NONE)
1994  {
1995  /* SMARTCARD in mode Receiver ---------------------------------------------------*/
1996 #if defined(USART_CR1_FIFOEN)
1997  if (((isrflags & USART_ISR_RXNE_RXFNE) != 0U)
1998  && (((cr1its & USART_CR1_RXNEIE_RXFNEIE) != 0U)
1999  || ((cr3its & USART_CR3_RXFTIE) != 0U)))
2000 #else
2001  if (((isrflags & USART_ISR_RXNE) != 0U)
2002  && ((cr1its & USART_CR1_RXNEIE) != 0U))
2003 #endif /* USART_CR1_FIFOEN */
2004  {
2005  if (hsmartcard->RxISR != NULL)
2006  {
2007  hsmartcard->RxISR(hsmartcard);
2008  }
2009  }
2010 
2011  /* If Error is to be considered as blocking :
2012  - Receiver Timeout error in Reception
2013  - Overrun error in Reception
2014  - any error occurs in DMA mode reception
2015  */
2016  errorcode = hsmartcard->ErrorCode;
2017  if ((HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
2018  || ((errorcode & (HAL_SMARTCARD_ERROR_RTO | HAL_SMARTCARD_ERROR_ORE)) != 0U))
2019  {
2020  /* Blocking error : transfer is aborted
2021  Set the SMARTCARD state ready to be able to start again the process,
2022  Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
2023  SMARTCARD_EndRxTransfer(hsmartcard);
2024 
2025  /* Disable the SMARTCARD DMA Rx request if enabled */
2026  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
2027  {
2028  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
2029 
2030  /* Abort the SMARTCARD DMA Rx channel */
2031  if (hsmartcard->hdmarx != NULL)
2032  {
2033  /* Set the SMARTCARD DMA Abort callback :
2034  will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */
2036 
2037  /* Abort DMA RX */
2038  if (HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK)
2039  {
2040  /* Call Directly hsmartcard->hdmarx->XferAbortCallback function in case of error */
2041  hsmartcard->hdmarx->XferAbortCallback(hsmartcard->hdmarx);
2042  }
2043  }
2044  else
2045  {
2046 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2047  /* Call registered user error callback */
2048  hsmartcard->ErrorCallback(hsmartcard);
2049 #else
2050  /* Call legacy weak user error callback */
2051  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2052 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2053  }
2054  }
2055  else
2056  {
2057 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2058  /* Call registered user error callback */
2059  hsmartcard->ErrorCallback(hsmartcard);
2060 #else
2061  /* Call legacy weak user error callback */
2062  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2063 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2064  }
2065  }
2066  /* other error type to be considered as blocking :
2067  - Frame error in Transmission
2068  */
2069  else if ((hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
2070  && ((errorcode & HAL_SMARTCARD_ERROR_FE) != 0U))
2071  {
2072  /* Blocking error : transfer is aborted
2073  Set the SMARTCARD state ready to be able to start again the process,
2074  Disable Tx Interrupts, and disable Tx DMA request, if ongoing */
2075  SMARTCARD_EndTxTransfer(hsmartcard);
2076 
2077  /* Disable the SMARTCARD DMA Tx request if enabled */
2078  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
2079  {
2080  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
2081 
2082  /* Abort the SMARTCARD DMA Tx channel */
2083  if (hsmartcard->hdmatx != NULL)
2084  {
2085  /* Set the SMARTCARD DMA Abort callback :
2086  will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */
2088 
2089  /* Abort DMA TX */
2090  if (HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK)
2091  {
2092  /* Call Directly hsmartcard->hdmatx->XferAbortCallback function in case of error */
2093  hsmartcard->hdmatx->XferAbortCallback(hsmartcard->hdmatx);
2094  }
2095  }
2096  else
2097  {
2098 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2099  /* Call registered user error callback */
2100  hsmartcard->ErrorCallback(hsmartcard);
2101 #else
2102  /* Call legacy weak user error callback */
2103  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2104 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2105  }
2106  }
2107  else
2108  {
2109 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2110  /* Call registered user error callback */
2111  hsmartcard->ErrorCallback(hsmartcard);
2112 #else
2113  /* Call legacy weak user error callback */
2114  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2115 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2116  }
2117  }
2118  else
2119  {
2120  /* Non Blocking error : transfer could go on.
2121  Error is notified to user through user error callback */
2122 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2123  /* Call registered user error callback */
2124  hsmartcard->ErrorCallback(hsmartcard);
2125 #else
2126  /* Call legacy weak user error callback */
2127  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2128 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2129  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2130  }
2131  }
2132  return;
2133 
2134  } /* End if some error occurs */
2135 
2136  /* SMARTCARD in mode Receiver, end of block interruption ------------------------*/
2137  if (((isrflags & USART_ISR_EOBF) != 0U) && ((cr1its & USART_CR1_EOBIE) != 0U))
2138  {
2139  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2140  __HAL_UNLOCK(hsmartcard);
2141 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2142  /* Call registered Rx complete callback */
2143  hsmartcard->RxCpltCallback(hsmartcard);
2144 #else
2145  /* Call legacy weak Rx complete callback */
2146  HAL_SMARTCARD_RxCpltCallback(hsmartcard);
2147 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2148  /* Clear EOBF interrupt after HAL_SMARTCARD_RxCpltCallback() call for the End of Block information
2149  to be available during HAL_SMARTCARD_RxCpltCallback() processing */
2150  __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_EOBF);
2151  return;
2152  }
2153 
2154  /* SMARTCARD in mode Transmitter ------------------------------------------------*/
2155 #if defined(USART_CR1_FIFOEN)
2156  if (((isrflags & USART_ISR_TXE_TXFNF) != 0U)
2157  && (((cr1its & USART_CR1_TXEIE_TXFNFIE) != 0U)
2158  || ((cr3its & USART_CR3_TXFTIE) != 0U)))
2159 #else
2160  if (((isrflags & USART_ISR_TXE) != 0U)
2161  && ((cr1its & USART_CR1_TXEIE) != 0U))
2162 #endif /* USART_CR1_FIFOEN */
2163  {
2164  if (hsmartcard->TxISR != NULL)
2165  {
2166  hsmartcard->TxISR(hsmartcard);
2167  }
2168  return;
2169  }
2170 
2171  /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/
2172  if (__HAL_SMARTCARD_GET_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication) != RESET)
2173  {
2174  if (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication) != RESET)
2175  {
2176  SMARTCARD_EndTransmit_IT(hsmartcard);
2177  return;
2178  }
2179  }
2180 
2181 #if defined(USART_CR1_FIFOEN)
2182  /* SMARTCARD TX Fifo Empty occurred ----------------------------------------------*/
2183  if (((isrflags & USART_ISR_TXFE) != 0U) && ((cr1its & USART_CR1_TXFEIE) != 0U))
2184  {
2185 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2186  /* Call registered Tx Fifo Empty Callback */
2187  hsmartcard->TxFifoEmptyCallback(hsmartcard);
2188 #else
2189  /* Call legacy weak Tx Fifo Empty Callback */
2191 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2192  return;
2193  }
2194 
2195  /* SMARTCARD RX Fifo Full occurred ----------------------------------------------*/
2196  if (((isrflags & USART_ISR_RXFF) != 0U) && ((cr1its & USART_CR1_RXFFIE) != 0U))
2197  {
2198 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2199  /* Call registered Rx Fifo Full Callback */
2200  hsmartcard->RxFifoFullCallback(hsmartcard);
2201 #else
2202  /* Call legacy weak Rx Fifo Full Callback */
2204 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2205  return;
2206  }
2207 #endif /* USART_CR1_FIFOEN */
2208 }
2209 
2217 {
2218  /* Prevent unused argument(s) compilation warning */
2219  UNUSED(hsmartcard);
2220 
2221  /* NOTE : This function should not be modified, when the callback is needed,
2222  the HAL_SMARTCARD_TxCpltCallback can be implemented in the user file.
2223  */
2224 }
2225 
2233 {
2234  /* Prevent unused argument(s) compilation warning */
2235  UNUSED(hsmartcard);
2236 
2237  /* NOTE : This function should not be modified, when the callback is needed,
2238  the HAL_SMARTCARD_RxCpltCallback can be implemented in the user file.
2239  */
2240 }
2241 
2249 {
2250  /* Prevent unused argument(s) compilation warning */
2251  UNUSED(hsmartcard);
2252 
2253  /* NOTE : This function should not be modified, when the callback is needed,
2254  the HAL_SMARTCARD_ErrorCallback can be implemented in the user file.
2255  */
2256 }
2257 
2265 {
2266  /* Prevent unused argument(s) compilation warning */
2267  UNUSED(hsmartcard);
2268 
2269  /* NOTE : This function should not be modified, when the callback is needed,
2270  the HAL_SMARTCARD_AbortCpltCallback can be implemented in the user file.
2271  */
2272 }
2273 
2281 {
2282  /* Prevent unused argument(s) compilation warning */
2283  UNUSED(hsmartcard);
2284 
2285  /* NOTE : This function should not be modified, when the callback is needed,
2286  the HAL_SMARTCARD_AbortTransmitCpltCallback can be implemented in the user file.
2287  */
2288 }
2289 
2297 {
2298  /* Prevent unused argument(s) compilation warning */
2299  UNUSED(hsmartcard);
2300 
2301  /* NOTE : This function should not be modified, when the callback is needed,
2302  the HAL_SMARTCARD_AbortReceiveCpltCallback can be implemented in the user file.
2303  */
2304 }
2305 
2336 {
2337  /* Return SMARTCARD handle state */
2338  uint32_t temp1;
2339  uint32_t temp2;
2340  temp1 = (uint32_t)hsmartcard->gState;
2341  temp2 = (uint32_t)hsmartcard->RxState;
2342 
2343  return (HAL_SMARTCARD_StateTypeDef)(temp1 | temp2);
2344 }
2345 
2353 {
2354  return hsmartcard->ErrorCode;
2355 }
2356 
2369 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2370 
2376 {
2377  /* Init the SMARTCARD Callback settings */
2378  hsmartcard->TxCpltCallback = HAL_SMARTCARD_TxCpltCallback; /* Legacy weak TxCpltCallback */
2379  hsmartcard->RxCpltCallback = HAL_SMARTCARD_RxCpltCallback; /* Legacy weak RxCpltCallback */
2380  hsmartcard->ErrorCallback = HAL_SMARTCARD_ErrorCallback; /* Legacy weak ErrorCallback */
2381  hsmartcard->AbortCpltCallback = HAL_SMARTCARD_AbortCpltCallback; /* Legacy weak AbortCpltCallback */
2382  hsmartcard->AbortTransmitCpltCallback = HAL_SMARTCARD_AbortTransmitCpltCallback; /* Legacy weak AbortTransmitCpltCallback */
2383  hsmartcard->AbortReceiveCpltCallback = HAL_SMARTCARD_AbortReceiveCpltCallback; /* Legacy weak AbortReceiveCpltCallback */
2384 #if defined(USART_CR1_FIFOEN)
2385  hsmartcard->RxFifoFullCallback = HAL_SMARTCARDEx_RxFifoFullCallback; /* Legacy weak RxFifoFullCallback */
2386  hsmartcard->TxFifoEmptyCallback = HAL_SMARTCARDEx_TxFifoEmptyCallback; /* Legacy weak TxFifoEmptyCallback */
2387 #endif /* USART_CR1_FIFOEN */
2388 
2389 }
2390 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */
2391 
2398 static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard)
2399 {
2400  uint32_t tmpreg;
2401  SMARTCARD_ClockSourceTypeDef clocksource;
2402  HAL_StatusTypeDef ret = HAL_OK;
2403 #if defined(USART_PRESC_PRESCALER)
2404  const uint16_t SMARTCARDPrescTable[12] = {1U, 2U, 4U, 6U, 8U, 10U, 12U, 16U, 32U, 64U, 128U, 256U};
2405 #endif /* USART_PRESC_PRESCALER */
2406 
2407  /* Check the parameters */
2408  assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
2409  assert_param(IS_SMARTCARD_BAUDRATE(hsmartcard->Init.BaudRate));
2410  assert_param(IS_SMARTCARD_WORD_LENGTH(hsmartcard->Init.WordLength));
2411  assert_param(IS_SMARTCARD_STOPBITS(hsmartcard->Init.StopBits));
2412  assert_param(IS_SMARTCARD_PARITY(hsmartcard->Init.Parity));
2413  assert_param(IS_SMARTCARD_MODE(hsmartcard->Init.Mode));
2414  assert_param(IS_SMARTCARD_POLARITY(hsmartcard->Init.CLKPolarity));
2415  assert_param(IS_SMARTCARD_PHASE(hsmartcard->Init.CLKPhase));
2416  assert_param(IS_SMARTCARD_LASTBIT(hsmartcard->Init.CLKLastBit));
2417  assert_param(IS_SMARTCARD_ONE_BIT_SAMPLE(hsmartcard->Init.OneBitSampling));
2418  assert_param(IS_SMARTCARD_NACK(hsmartcard->Init.NACKEnable));
2419  assert_param(IS_SMARTCARD_TIMEOUT(hsmartcard->Init.TimeOutEnable));
2420  assert_param(IS_SMARTCARD_AUTORETRY_COUNT(hsmartcard->Init.AutoRetryCount));
2421 #if defined(USART_PRESC_PRESCALER)
2422  assert_param(IS_SMARTCARD_CLOCKPRESCALER(hsmartcard->Init.ClockPrescaler));
2423 #endif /* USART_PRESC_PRESCALER */
2424 
2425  /*-------------------------- USART CR1 Configuration -----------------------*/
2426  /* In SmartCard mode, M and PCE are forced to 1 (8 bits + parity).
2427  * Oversampling is forced to 16 (OVER8 = 0).
2428  * Configure the Parity and Mode:
2429  * set PS bit according to hsmartcard->Init.Parity value
2430  * set TE and RE bits according to hsmartcard->Init.Mode value */
2431 #if defined(USART_CR1_FIFOEN)
2432  tmpreg = (uint32_t) hsmartcard->Init.Parity | hsmartcard->Init.Mode;
2433  tmpreg |= (uint32_t) hsmartcard->Init.WordLength | hsmartcard->FifoMode;
2434 #else
2435  tmpreg = (uint32_t)(hsmartcard->Init.Parity | hsmartcard->Init.Mode | hsmartcard->Init.WordLength);
2436 #endif /* USART_CR1_FIFOEN */
2437  MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_FIELDS, tmpreg);
2438 
2439  /*-------------------------- USART CR2 Configuration -----------------------*/
2440  tmpreg = hsmartcard->Init.StopBits;
2441  /* Synchronous mode is activated by default */
2442  tmpreg |= (uint32_t) USART_CR2_CLKEN | hsmartcard->Init.CLKPolarity;
2443  tmpreg |= (uint32_t) hsmartcard->Init.CLKPhase | hsmartcard->Init.CLKLastBit;
2444  tmpreg |= (uint32_t) hsmartcard->Init.TimeOutEnable;
2445  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_FIELDS, tmpreg);
2446 
2447  /*-------------------------- USART CR3 Configuration -----------------------*/
2448  /* Configure
2449  * - one-bit sampling method versus three samples' majority rule
2450  * according to hsmartcard->Init.OneBitSampling
2451  * - NACK transmission in case of parity error according
2452  * to hsmartcard->Init.NACKEnable
2453  * - autoretry counter according to hsmartcard->Init.AutoRetryCount */
2454 
2455  tmpreg = (uint32_t) hsmartcard->Init.OneBitSampling | hsmartcard->Init.NACKEnable;
2456  tmpreg |= ((uint32_t)hsmartcard->Init.AutoRetryCount << USART_CR3_SCARCNT_Pos);
2457  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_FIELDS, tmpreg);
2458 
2459 #if defined(USART_PRESC_PRESCALER)
2460  /*--------------------- SMARTCARD clock PRESC Configuration ----------------*/
2461  /* Configure
2462  * - SMARTCARD Clock Prescaler: set PRESCALER according to hsmartcard->Init.ClockPrescaler value */
2463  MODIFY_REG(hsmartcard->Instance->PRESC, USART_PRESC_PRESCALER, hsmartcard->Init.ClockPrescaler);
2464 #endif /* USART_PRESC_PRESCALER */
2465 
2466  /*-------------------------- USART GTPR Configuration ----------------------*/
2467  tmpreg = (hsmartcard->Init.Prescaler | ((uint32_t)hsmartcard->Init.GuardTime << USART_GTPR_GT_Pos));
2468  MODIFY_REG(hsmartcard->Instance->GTPR, (uint16_t)(USART_GTPR_GT | USART_GTPR_PSC), (uint16_t)tmpreg);
2469 
2470  /*-------------------------- USART RTOR Configuration ----------------------*/
2471  tmpreg = ((uint32_t)hsmartcard->Init.BlockLength << USART_RTOR_BLEN_Pos);
2472  if (hsmartcard->Init.TimeOutEnable == SMARTCARD_TIMEOUT_ENABLE)
2473  {
2474  assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
2475  tmpreg |= (uint32_t) hsmartcard->Init.TimeOutValue;
2476  }
2477  MODIFY_REG(hsmartcard->Instance->RTOR, (USART_RTOR_RTO | USART_RTOR_BLEN), tmpreg);
2478 
2479  /*-------------------------- USART BRR Configuration -----------------------*/
2480  SMARTCARD_GETCLOCKSOURCE(hsmartcard, clocksource);
2481  tmpreg = 0U;
2482  switch (clocksource)
2483  {
2485 #if defined(USART_PRESC_PRESCALER)
2486  tmpreg = (uint16_t)(((HAL_RCC_GetPCLK1Freq() / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2487 #else
2488  tmpreg = (uint16_t)((HAL_RCC_GetPCLK1Freq() + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2489 #endif /* USART_PRESC_PRESCALER */
2490  break;
2492 #if defined(USART_PRESC_PRESCALER)
2493  tmpreg = (uint16_t)(((HAL_RCC_GetPCLK2Freq() / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2494 #else
2495  tmpreg = (uint16_t)((HAL_RCC_GetPCLK2Freq() + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2496 #endif /* USART_PRESC_PRESCALER */
2497  break;
2499 #if defined(USART_PRESC_PRESCALER)
2500  tmpreg = (uint16_t)(((HSI_VALUE / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2501 #else
2502  tmpreg = (uint16_t)((HSI_VALUE + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2503 #endif /* USART_PRESC_PRESCALER */
2504  break;
2506 #if defined(USART_PRESC_PRESCALER)
2507  tmpreg = (uint16_t)(((HAL_RCC_GetSysClockFreq() / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2508 #else
2509  tmpreg = (uint16_t)((HAL_RCC_GetSysClockFreq() + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2510 #endif /* USART_PRESC_PRESCALER */
2511  break;
2513 #if defined(USART_PRESC_PRESCALER)
2514  tmpreg = (uint16_t)(((uint16_t)(LSE_VALUE / SMARTCARDPrescTable[hsmartcard->Init.ClockPrescaler]) + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2515 #else
2516  tmpreg = (uint16_t)((LSE_VALUE + (hsmartcard->Init.BaudRate / 2U)) / hsmartcard->Init.BaudRate);
2517 #endif /* USART_PRESC_PRESCALER */
2518  break;
2519  default:
2520  ret = HAL_ERROR;
2521  break;
2522  }
2523 
2524  /* USARTDIV must be greater than or equal to 0d16 */
2525  if ((tmpreg >= USART_BRR_MIN) && (tmpreg <= USART_BRR_MAX))
2526  {
2527  hsmartcard->Instance->BRR = tmpreg;
2528  }
2529  else
2530  {
2531  ret = HAL_ERROR;
2532  }
2533 
2534 #if defined(USART_CR1_FIFOEN)
2535  /* Initialize the number of data to process during RX/TX ISR execution */
2536  hsmartcard->NbTxDataToProcess = 1U;
2537  hsmartcard->NbRxDataToProcess = 1U;
2538 #endif /* USART_CR1_FIFOEN */
2539 
2540  /* Clear ISR function pointers */
2541  hsmartcard->RxISR = NULL;
2542  hsmartcard->TxISR = NULL;
2543 
2544  return ret;
2545 }
2546 
2547 
2555 {
2556  /* Check whether the set of advanced features to configure is properly set */
2557  assert_param(IS_SMARTCARD_ADVFEATURE_INIT(hsmartcard->AdvancedInit.AdvFeatureInit));
2558 
2559  /* if required, configure TX pin active level inversion */
2560  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXINVERT_INIT))
2561  {
2562  assert_param(IS_SMARTCARD_ADVFEATURE_TXINV(hsmartcard->AdvancedInit.TxPinLevelInvert));
2563  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_TXINV, hsmartcard->AdvancedInit.TxPinLevelInvert);
2564  }
2565 
2566  /* if required, configure RX pin active level inversion */
2567  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXINVERT_INIT))
2568  {
2569  assert_param(IS_SMARTCARD_ADVFEATURE_RXINV(hsmartcard->AdvancedInit.RxPinLevelInvert));
2570  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_RXINV, hsmartcard->AdvancedInit.RxPinLevelInvert);
2571  }
2572 
2573  /* if required, configure data inversion */
2574  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DATAINVERT_INIT))
2575  {
2576  assert_param(IS_SMARTCARD_ADVFEATURE_DATAINV(hsmartcard->AdvancedInit.DataInvert));
2577  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_DATAINV, hsmartcard->AdvancedInit.DataInvert);
2578  }
2579 
2580  /* if required, configure RX/TX pins swap */
2581  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_SWAP_INIT))
2582  {
2583  assert_param(IS_SMARTCARD_ADVFEATURE_SWAP(hsmartcard->AdvancedInit.Swap));
2584  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_SWAP, hsmartcard->AdvancedInit.Swap);
2585  }
2586 
2587  /* if required, configure RX overrun detection disabling */
2588  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT))
2589  {
2590  assert_param(IS_SMARTCARD_OVERRUN(hsmartcard->AdvancedInit.OverrunDisable));
2591  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_OVRDIS, hsmartcard->AdvancedInit.OverrunDisable);
2592  }
2593 
2594  /* if required, configure DMA disabling on reception error */
2595  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT))
2596  {
2597  assert_param(IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(hsmartcard->AdvancedInit.DMADisableonRxError));
2598  MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_DDRE, hsmartcard->AdvancedInit.DMADisableonRxError);
2599  }
2600 
2601  /* if required, configure MSB first on communication line */
2602  if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
2603  {
2604  assert_param(IS_SMARTCARD_ADVFEATURE_MSBFIRST(hsmartcard->AdvancedInit.MSBFirst));
2605  MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_MSBFIRST, hsmartcard->AdvancedInit.MSBFirst);
2606  }
2607 
2608 }
2609 
2616 static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard)
2617 {
2618  uint32_t tickstart;
2619 
2620  /* Initialize the SMARTCARD ErrorCode */
2621  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2622 
2623  /* Init tickstart for timeout management */
2624  tickstart = HAL_GetTick();
2625 
2626  /* Check if the Transmitter is enabled */
2627  if ((hsmartcard->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
2628  {
2629  /* Wait until TEACK flag is set */
2630  if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_TEACK, RESET, tickstart,
2631  SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK)
2632  {
2633  /* Timeout occurred */
2634  return HAL_TIMEOUT;
2635  }
2636  }
2637  /* Check if the Receiver is enabled */
2638  if ((hsmartcard->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
2639  {
2640  /* Wait until REACK flag is set */
2641  if (SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_REACK, RESET, tickstart,
2642  SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK)
2643  {
2644  /* Timeout occurred */
2645  return HAL_TIMEOUT;
2646  }
2647  }
2648 
2649  /* Initialize the SMARTCARD states */
2650  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2651  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2652 
2653  /* Process Unlocked */
2654  __HAL_UNLOCK(hsmartcard);
2655 
2656  return HAL_OK;
2657 }
2658 
2669 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag,
2670  FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
2671 {
2672  /* Wait until flag is set */
2673  while ((__HAL_SMARTCARD_GET_FLAG(hsmartcard, Flag) ? SET : RESET) == Status)
2674  {
2675  /* Check for the Timeout */
2676  if (Timeout != HAL_MAX_DELAY)
2677  {
2678  if (((HAL_GetTick() - Tickstart) > Timeout) || (Timeout == 0U))
2679  {
2680  /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
2681 #if defined(USART_CR1_FIFOEN)
2682  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE | USART_CR1_TXEIE_TXFNFIE));
2683 #else
2684  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
2685 #endif /* USART_CR1_FIFOEN */
2686  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2687 
2688  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2689  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2690 
2691  /* Process Unlocked */
2692  __HAL_UNLOCK(hsmartcard);
2693  return HAL_TIMEOUT;
2694  }
2695  }
2696  }
2697  return HAL_OK;
2698 }
2699 
2700 
2708 {
2709  /* Disable TXEIE, TCIE and ERR (Frame error, noise error, overrun error) interrupts */
2710 #if defined(USART_CR1_FIFOEN)
2711  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE_TXFNFIE | USART_CR1_TCIE));
2712 #else
2713  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
2714 #endif /* USART_CR1_FIFOEN */
2715  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2716 
2717  /* At end of Tx process, restore hsmartcard->gState to Ready */
2718  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2719 }
2720 
2721 
2729 {
2730  /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
2731 #if defined(USART_CR1_FIFOEN)
2732  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE_RXFNEIE | USART_CR1_PEIE));
2733 #else
2734  CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
2735 #endif /* USART_CR1_FIFOEN */
2736  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2737 
2738  /* At end of Rx process, restore hsmartcard->RxState to Ready */
2739  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2740 }
2741 
2742 
2750 {
2751  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2752  hsmartcard->TxXferCount = 0U;
2753 
2754  /* Disable the DMA transfer for transmit request by resetting the DMAT bit
2755  in the SMARTCARD associated USART CR3 register */
2756  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
2757 
2758  /* Enable the SMARTCARD Transmit Complete Interrupt */
2759  __HAL_SMARTCARD_ENABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
2760 }
2761 
2769 {
2770  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2771  hsmartcard->RxXferCount = 0U;
2772 
2773  /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
2774  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
2775  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
2776 
2777  /* Disable the DMA transfer for the receiver request by resetting the DMAR bit
2778  in the SMARTCARD associated USART CR3 register */
2779  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
2780 
2781  /* At end of Rx process, restore hsmartcard->RxState to Ready */
2782  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2783 
2784 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2785  /* Call registered Rx complete callback */
2786  hsmartcard->RxCpltCallback(hsmartcard);
2787 #else
2788  /* Call legacy weak Rx complete callback */
2789  HAL_SMARTCARD_RxCpltCallback(hsmartcard);
2790 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2791 }
2792 
2800 {
2801  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2802 
2803  /* Stop SMARTCARD DMA Tx request if ongoing */
2804  if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
2805  {
2806  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
2807  {
2808  hsmartcard->TxXferCount = 0U;
2809  SMARTCARD_EndTxTransfer(hsmartcard);
2810  }
2811  }
2812 
2813  /* Stop SMARTCARD DMA Rx request if ongoing */
2814  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
2815  {
2816  if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
2817  {
2818  hsmartcard->RxXferCount = 0U;
2819  SMARTCARD_EndRxTransfer(hsmartcard);
2820  }
2821  }
2822 
2823  hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_DMA;
2824 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2825  /* Call registered user error callback */
2826  hsmartcard->ErrorCallback(hsmartcard);
2827 #else
2828  /* Call legacy weak user error callback */
2829  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2830 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2831 }
2832 
2840 {
2841  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2842  hsmartcard->RxXferCount = 0U;
2843  hsmartcard->TxXferCount = 0U;
2844 
2845 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2846  /* Call registered user error callback */
2847  hsmartcard->ErrorCallback(hsmartcard);
2848 #else
2849  /* Call legacy weak user error callback */
2850  HAL_SMARTCARD_ErrorCallback(hsmartcard);
2851 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2852 }
2853 
2863 {
2864  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2865 
2866  hsmartcard->hdmatx->XferAbortCallback = NULL;
2867 
2868  /* Check if an Abort process is still ongoing */
2869  if (hsmartcard->hdmarx != NULL)
2870  {
2871  if (hsmartcard->hdmarx->XferAbortCallback != NULL)
2872  {
2873  return;
2874  }
2875  }
2876 
2877  /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2878  hsmartcard->TxXferCount = 0U;
2879  hsmartcard->RxXferCount = 0U;
2880 
2881  /* Reset errorCode */
2882  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2883 
2884  /* Clear the Error flags in the ICR register */
2885  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2886  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2887  SMARTCARD_CLEAR_EOBF);
2888 
2889  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2890  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2891  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2892 
2893 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2894  /* Call registered Abort complete callback */
2895  hsmartcard->AbortCpltCallback(hsmartcard);
2896 #else
2897  /* Call legacy weak Abort complete callback */
2898  HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
2899 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2900 }
2901 
2902 
2912 {
2913  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2914 
2915  hsmartcard->hdmarx->XferAbortCallback = NULL;
2916 
2917  /* Check if an Abort process is still ongoing */
2918  if (hsmartcard->hdmatx != NULL)
2919  {
2920  if (hsmartcard->hdmatx->XferAbortCallback != NULL)
2921  {
2922  return;
2923  }
2924  }
2925 
2926  /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
2927  hsmartcard->TxXferCount = 0U;
2928  hsmartcard->RxXferCount = 0U;
2929 
2930  /* Reset errorCode */
2931  hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
2932 
2933  /* Clear the Error flags in the ICR register */
2934  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2935  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2936  SMARTCARD_CLEAR_EOBF);
2937 
2938  /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
2939  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2940  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
2941 
2942 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2943  /* Call registered Abort complete callback */
2944  hsmartcard->AbortCpltCallback(hsmartcard);
2945 #else
2946  /* Call legacy weak Abort complete callback */
2947  HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
2948 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2949 }
2950 
2951 
2961 {
2962  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2963 
2964  hsmartcard->TxXferCount = 0U;
2965 
2966  /* Clear the Error flags in the ICR register */
2967  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF);
2968 
2969  /* Restore hsmartcard->gState to Ready */
2970  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
2971 
2972 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
2973  /* Call registered Abort Transmit Complete Callback */
2974  hsmartcard->AbortTransmitCpltCallback(hsmartcard);
2975 #else
2976  /* Call legacy weak Abort Transmit Complete Callback */
2978 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
2979 }
2980 
2990 {
2991  SMARTCARD_HandleTypeDef *hsmartcard = (SMARTCARD_HandleTypeDef *)(hdma->Parent);
2992 
2993  hsmartcard->RxXferCount = 0U;
2994 
2995  /* Clear the Error flags in the ICR register */
2996  __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard,
2997  SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF |
2998  SMARTCARD_CLEAR_EOBF);
2999 
3000  /* Restore hsmartcard->RxState to Ready */
3001  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
3002 
3003 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3004  /* Call registered Abort Receive Complete Callback */
3005  hsmartcard->AbortReceiveCpltCallback(hsmartcard);
3006 #else
3007  /* Call legacy weak Abort Receive Complete Callback */
3009 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3010 }
3011 
3022 {
3023  /* Check that a Tx process is ongoing */
3024  if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
3025  {
3026  if (hsmartcard->TxXferCount == 0U)
3027  {
3028  /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */
3029 #if defined(USART_CR1_FIFOEN)
3030  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
3031 #else
3032  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE);
3033 #endif /* USART_CR1_FIFOEN */
3034 
3035  /* Enable the SMARTCARD Transmit Complete Interrupt */
3036  __HAL_SMARTCARD_ENABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
3037  }
3038  else
3039  {
3040  hsmartcard->Instance->TDR = (uint8_t)(*hsmartcard->pTxBuffPtr & 0xFFU);
3041  hsmartcard->pTxBuffPtr++;
3042  hsmartcard->TxXferCount--;
3043  }
3044  }
3045 }
3046 
3047 #if defined(USART_CR1_FIFOEN)
3048 
3058 {
3059  uint16_t nb_tx_data;
3060 
3061  /* Check that a Tx process is ongoing */
3062  if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
3063  {
3064  for (nb_tx_data = hsmartcard->NbTxDataToProcess ; nb_tx_data > 0U ; nb_tx_data--)
3065  {
3066  if (hsmartcard->TxXferCount == 0U)
3067  {
3068  /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */
3069  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE_TXFNFIE);
3070 
3071  /* Enable the SMARTCARD Transmit Complete Interrupt */
3072  __HAL_SMARTCARD_ENABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
3073  }
3074  else if (READ_BIT(hsmartcard->Instance->ISR, USART_ISR_TXE_TXFNF) != 0U)
3075  {
3076  hsmartcard->Instance->TDR = (uint8_t)(*hsmartcard->pTxBuffPtr & 0xFFU);
3077  hsmartcard->pTxBuffPtr++;
3078  hsmartcard->TxXferCount--;
3079  }
3080  else
3081  {
3082  /* Nothing to do */
3083  }
3084  }
3085  }
3086 }
3087 
3088 #endif /* USART_CR1_FIFOEN */
3089 
3096 {
3097  /* Disable the SMARTCARD Transmit Complete Interrupt */
3098  __HAL_SMARTCARD_DISABLE_IT(hsmartcard, hsmartcard->AdvancedInit.TxCompletionIndication);
3099 
3100  /* Check if a receive process is ongoing or not. If not disable ERR IT */
3101  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
3102  {
3103  /* Disable the SMARTCARD Error Interrupt: (Frame error) */
3104  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
3105  }
3106 
3107  /* Re-enable Rx at end of transmission if initial mode is Rx/Tx */
3108  if (hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
3109  {
3110  /* Disable the Peripheral first to update modes */
3111  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
3112  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
3113  /* Enable the Peripheral */
3114  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
3115  }
3116 
3117  /* Tx process is ended, restore hsmartcard->gState to Ready */
3118  hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
3119 
3120  /* Clear TxISR function pointer */
3121  hsmartcard->TxISR = NULL;
3122 
3123 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3124  /* Call registered Tx complete callback */
3125  hsmartcard->TxCpltCallback(hsmartcard);
3126 #else
3127  /* Call legacy weak Tx complete callback */
3128  HAL_SMARTCARD_TxCpltCallback(hsmartcard);
3129 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3130 }
3131 
3142 {
3143  /* Check that a Rx process is ongoing */
3144  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
3145  {
3146  *hsmartcard->pRxBuffPtr = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0xFF);
3147  hsmartcard->pRxBuffPtr++;
3148 
3149  hsmartcard->RxXferCount--;
3150  if (hsmartcard->RxXferCount == 0U)
3151  {
3152 #if defined(USART_CR1_FIFOEN)
3153  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE_RXFNEIE);
3154 #else
3155  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE);
3156 #endif /* USART_CR1_FIFOEN */
3157 
3158  /* Check if a transmit process is ongoing or not. If not disable ERR IT */
3159  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
3160  {
3161  /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
3162  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
3163  }
3164 
3165  /* Disable the SMARTCARD Parity Error Interrupt */
3166  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
3167 
3168  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
3169 
3170  /* Clear RxISR function pointer */
3171  hsmartcard->RxISR = NULL;
3172 
3173 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3174  /* Call registered Rx complete callback */
3175  hsmartcard->RxCpltCallback(hsmartcard);
3176 #else
3177  /* Call legacy weak Rx complete callback */
3178  HAL_SMARTCARD_RxCpltCallback(hsmartcard);
3179 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3180  }
3181  }
3182  else
3183  {
3184  /* Clear RXNE interrupt flag */
3185  __HAL_SMARTCARD_SEND_REQ(hsmartcard, SMARTCARD_RXDATA_FLUSH_REQUEST);
3186  }
3187 }
3188 
3189 #if defined(USART_CR1_FIFOEN)
3190 
3200 {
3201  uint16_t nb_rx_data;
3202  uint16_t rxdatacount;
3203 
3204  /* Check that a Rx process is ongoing */
3205  if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
3206  {
3207  for (nb_rx_data = hsmartcard->NbRxDataToProcess ; nb_rx_data > 0U ; nb_rx_data--)
3208  {
3209  *hsmartcard->pRxBuffPtr = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0xFF);
3210  hsmartcard->pRxBuffPtr++;
3211 
3212  hsmartcard->RxXferCount--;
3213  if (hsmartcard->RxXferCount == 0U)
3214  {
3215  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE_RXFNEIE);
3216 
3217  /* Check if a transmit process is ongoing or not. If not disable ERR IT */
3218  if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
3219  {
3220  /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
3221  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
3222  }
3223 
3224  /* Disable the SMARTCARD Parity Error Interrupt */
3225  CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
3226 
3227  hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
3228 
3229  /* Clear RxISR function pointer */
3230  hsmartcard->RxISR = NULL;
3231 
3232 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1)
3233  /* Call registered Rx complete callback */
3234  hsmartcard->RxCpltCallback(hsmartcard);
3235 #else
3236  /* Call legacy weak Rx complete callback */
3237  HAL_SMARTCARD_RxCpltCallback(hsmartcard);
3238 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACK */
3239  }
3240  }
3241 
3242  /* When remaining number of bytes to receive is less than the RX FIFO
3243  threshold, next incoming frames are processed as if FIFO mode was
3244  disabled (i.e. one interrupt per received frame).
3245  */
3246  rxdatacount = hsmartcard->RxXferCount;
3247  if (((rxdatacount != 0U)) && (rxdatacount < hsmartcard->NbRxDataToProcess))
3248  {
3249  /* Disable the UART RXFT interrupt*/
3250  CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_RXFTIE);
3251 
3252  /* Update the RxISR function pointer */
3253  hsmartcard->RxISR = SMARTCARD_RxISR;
3254 
3255  /* Enable the UART Data Register Not Empty interrupt */
3256  SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE_RXFNEIE);
3257  }
3258  }
3259  else
3260  {
3261  /* Clear RXNE interrupt flag */
3262  __HAL_SMARTCARD_SEND_REQ(hsmartcard, SMARTCARD_RXDATA_FLUSH_REQUEST);
3263  }
3264 }
3265 
3266 #endif /* USART_CR1_FIFOEN */
3267 
3271 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
3272 
3280 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* TxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsmartcard)
End ongoing Rx transfer on UART peripheral (following error detection or Reception completion)...
void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard)
DeInitialize the SMARTCARD MSP.
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
void(* TxISR)(struct __SMARTCARD_HandleTypeDef *huart)
static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard)
Configure the SMARTCARD associated USART peripheral advanced features.
DMA handle Structure definition.
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard)
Configure the SMARTCARD associated USART peripheral.
void(* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard)
Abort ongoing transfers (blocking mode).
__IO HAL_SMARTCARD_StateTypeDef gState
void(* TxFifoEmptyCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
static void SMARTCARD_RxISR_FIFOEN(SMARTCARD_HandleTypeDef *hsmartcard)
Receive an amount of data in non-blocking mode.
HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsmartcard)
Return the SMARTCARD handle state.
HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
Receive an amount of data in interrupt mode.
void HAL_SMARTCARDEx_TxFifoEmptyCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD TX Fifo empty callback.
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsmartcard)
Abort ongoing Receive transfer (Interrupt mode).
This file contains all the functions prototypes for the HAL module driver.
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
Abort ongoing Transmit transfer (Interrupt mode).
static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsmartcard)
End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion)...
static void SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
Wrap up transmission in non-blocking mode.
HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsmartcard)
Initialize the SMARTCARD mode according to the specified parameters in the SMARTCARD_HandleTypeDef an...
uint32_t HAL_SMARTCARD_StateTypeDef
HAL SMARTCARD State definition.
void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Rx Transfer completed callback.
uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsmartcard)
Return the SMARTCARD handle error code.
static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma)
DMA SMARTCARD transmit process complete callback.
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
HAL_StatusTypeDef HAL_SMARTCARD_UnRegisterCallback(SMARTCARD_HandleTypeDef *hsmartcard, HAL_SMARTCARD_CallbackIDTypeDef CallbackID)
Unregister an SMARTCARD callback SMARTCARD callback is redirected to the weak predefined callback...
void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD error callback.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
__HAL_UNLOCK(hrtc)
static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
DMA SMARTCARD receive process complete callback.
uint32_t HAL_RCC_GetPCLK2Freq(void)
Return the PCLK2 frequency.
HAL_StatusTypeDef HAL_DMA_Start_IT(DMA_HandleTypeDef *hdma, uint32_t SrcAddress, uint32_t DstAddress, uint32_t DataLength)
Start the DMA Transfer with interrupt enabled.
static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
DMA SMARTCARD Rx communication abort callback, when initiated by user (To be called at end of DMA Rx ...
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard)
Handle SMARTCARD interrupt requests.
void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard)
Initialize the SMARTCARD MSP.
__HAL_LOCK(hrtc)
static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma)
DMA SMARTCARD communication abort callback, when initiated by HAL services on Error (To be called at ...
void SMARTCARD_InitCallbacksToDefault(SMARTCARD_HandleTypeDef *hsmartcard)
Initialize the callbacks to their default values.
static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to HAL_SMARTCARD_Abor...
static void SMARTCARD_TxISR(SMARTCARD_HandleTypeDef *hsmartcard)
Send an amount of data in non-blocking mode.
return HAL_OK
static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
DMA SMARTCARD communication error callback.
void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
Handle SMARTCARD Communication Timeout.
void(* AbortReceiveCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to HAL_SMARTCARD_Abor...
void(* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout)
Send an amount of data in blocking mode.
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Receive Complete callback.
HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout)
Receive an amount of data in blocking mode.
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsmartcard)
Abort ongoing Transmit transfer (blocking mode).
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsmartcard)
Abort ongoing Receive transfer (blocking mode).
SMARTCARD_ClockSourceTypeDef
SMARTCARD clock sources.
HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsmartcard)
Abort ongoing transfers (Interrupt mode).
void(* pSMARTCARD_CallbackTypeDef)(SMARTCARD_HandleTypeDef *hsmartcard)
HAL SMARTCARD Callback pointer definition.
HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard)
DeInitialize the SMARTCARD peripheral.
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
Send an amount of data in DMA mode.
void(* MspInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
DMA SMARTCARD Tx communication abort callback, when initiated by user (To be called at end of DMA Tx ...
void HAL_SMARTCARDEx_RxFifoFullCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD RX Fifo full callback.
static void SMARTCARD_RxISR(SMARTCARD_HandleTypeDef *hsmartcard)
Receive an amount of data in non-blocking mode.
HAL_SMARTCARD_CallbackIDTypeDef
HAL SMARTCARD Callback ID enumeration definition.
void(* MspDeInitCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
uint32_t HAL_RCC_GetSysClockFreq(void)
Return the SYSCLK frequency.
void(* RxFifoFullCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
MODIFY_REG(hrtc->Instance->CR, RTC_CR_WUCKSEL,(uint32_t) WakeUpClock)
HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback(SMARTCARD_HandleTypeDef *hsmartcard, HAL_SMARTCARD_CallbackIDTypeDef CallbackID, pSMARTCARD_CallbackTypeDef pCallback)
Register a User SMARTCARD Callback To be used instead of the weak predefined callback.
__IO HAL_SMARTCARD_StateTypeDef RxState
HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
Receive an amount of data in DMA mode.
uint32_t HAL_RCC_GetPCLK1Freq(void)
Return the PCLK1 frequency.
void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Tx Transfer completed callback.
void(* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
assert_param(IS_RTC_WAKEUP_CLOCK(WakeUpClock))
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
Send an amount of data in interrupt mode.
static void SMARTCARD_TxISR_FIFOEN(SMARTCARD_HandleTypeDef *hsmartcard)
Send an amount of data in non-blocking mode.
SMARTCARD handle Structure definition.
static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard)
Check the SMARTCARD Idle State.
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
Return the DMA error code.