STM32L4xx_HAL_Driver  1.14.0

SMARTCARD Transmit and Receive functions. More...

Functions

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. More...
 
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. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT (SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
 Send an amount of data in interrupt mode. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT (SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
 Receive an amount of data in interrupt mode. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA (SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
 Send an amount of data in DMA mode. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA (SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
 Receive an amount of data in DMA mode. More...
 
HAL_StatusTypeDef HAL_SMARTCARD_Abort (SMARTCARD_HandleTypeDef *hsmartcard)
 Abort ongoing transfers (blocking mode). More...
 
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit (SMARTCARD_HandleTypeDef *hsmartcard)
 Abort ongoing Transmit transfer (blocking mode). More...
 
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive (SMARTCARD_HandleTypeDef *hsmartcard)
 Abort ongoing Receive transfer (blocking mode). More...
 
HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT (SMARTCARD_HandleTypeDef *hsmartcard)
 Abort ongoing transfers (Interrupt mode). More...
 
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT (SMARTCARD_HandleTypeDef *hsmartcard)
 Abort ongoing Transmit transfer (Interrupt mode). More...
 
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT (SMARTCARD_HandleTypeDef *hsmartcard)
 Abort ongoing Receive transfer (Interrupt mode). More...
 
void HAL_SMARTCARD_IRQHandler (SMARTCARD_HandleTypeDef *hsmartcard)
 Handle SMARTCARD interrupt requests. More...
 
void HAL_SMARTCARD_TxCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
 Tx Transfer completed callback. More...
 
void HAL_SMARTCARD_RxCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
 Rx Transfer completed callback. More...
 
void HAL_SMARTCARD_ErrorCallback (SMARTCARD_HandleTypeDef *hsmartcard)
 SMARTCARD error callback. More...
 
void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
 SMARTCARD Abort Complete callback. More...
 
void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
 SMARTCARD Abort Complete callback. More...
 
void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
 SMARTCARD Abort Receive Complete callback. More...
 

Detailed Description

SMARTCARD Transmit and Receive functions.

  ==============================================================================
                         ##### IO operation functions #####
  ==============================================================================
  [..]
    This subsection provides a set of functions allowing to manage the SMARTCARD data transfers.

  [..]
    Smartcard is a single wire half duplex communication protocol.
    The Smartcard interface is designed to support asynchronous protocol Smartcards as
    defined in the ISO 7816-3 standard. The USART should be configured as:
    (+) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
    (+) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register.

  [..]
    (+) There are two modes of transfer:
        (++) Blocking mode: The communication is performed in polling mode.
             The HAL status of all data processing is returned by the same function
             after finishing transfer.
        (++) Non-Blocking mode: The communication is performed using Interrupts
             or DMA, the relevant API's return the HAL status.
             The end of the data processing will be indicated through the
             dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when
             using DMA mode.
        (++) The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks
             will be executed respectively at the end of the Transmit or Receive process
             The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication
             error is detected.

    (+) Blocking mode APIs are :
        (++) HAL_SMARTCARD_Transmit()
        (++) HAL_SMARTCARD_Receive()

    (+) Non Blocking mode APIs with Interrupt are :
        (++) HAL_SMARTCARD_Transmit_IT()
        (++) HAL_SMARTCARD_Receive_IT()
        (++) HAL_SMARTCARD_IRQHandler()

    (+) Non Blocking mode functions with DMA are :
        (++) HAL_SMARTCARD_Transmit_DMA()
        (++) HAL_SMARTCARD_Receive_DMA()

    (+) A set of Transfer Complete Callbacks are provided in non Blocking mode:
        (++) HAL_SMARTCARD_TxCpltCallback()
        (++) HAL_SMARTCARD_RxCpltCallback()
        (++) HAL_SMARTCARD_ErrorCallback()

    (#) Non-Blocking mode transfers could be aborted using Abort API's :
        (+) HAL_SMARTCARD_Abort()
        (+) HAL_SMARTCARD_AbortTransmit()
        (+) HAL_SMARTCARD_AbortReceive()
        (+) HAL_SMARTCARD_Abort_IT()
        (+) HAL_SMARTCARD_AbortTransmit_IT()
        (+) HAL_SMARTCARD_AbortReceive_IT()

    (#) For Abort services based on interrupts (HAL_SMARTCARD_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
        (+) HAL_SMARTCARD_AbortCpltCallback()
        (+) HAL_SMARTCARD_AbortTransmitCpltCallback()
        (+) HAL_SMARTCARD_AbortReceiveCpltCallback()

    (#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
        Errors are handled as follows :
       (+) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
           to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
           Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
           and HAL_SMARTCARD_ErrorCallback() user callback is executed. Transfer is kept ongoing on SMARTCARD side.
           If user wants to abort it, Abort services should be called by user.
       (+) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
           This concerns Frame Error in Interrupt mode tranmission, Overrun Error in Interrupt mode reception and all errors in DMA mode.
           Error code is set to allow user to identify error type, and HAL_SMARTCARD_ErrorCallback() user callback is executed.

Function Documentation

◆ HAL_SMARTCARD_Abort()

HAL_StatusTypeDef HAL_SMARTCARD_Abort ( SMARTCARD_HandleTypeDef hsmartcard)

Abort ongoing transfers (blocking mode).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Note
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SMARTCARD Interrupts (Tx and Rx)
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
  • Set handle State to READY
This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
Return values
HALstatus

Definition at line 1318 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
__IO HAL_SMARTCARD_StateTypeDef RxState
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
Return the DMA error code.

◆ HAL_SMARTCARD_Abort_IT()

HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT ( SMARTCARD_HandleTypeDef hsmartcard)

Abort ongoing transfers (Interrupt mode).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Note
This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SMARTCARD Interrupts (Tx and Rx)
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
  • Set handle State to READY
  • At abort completion, call user abort complete callback
This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function).
Return values
HALstatus

Definition at line 1556 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
void(* TxISR)(struct __SMARTCARD_HandleTypeDef *huart)
__IO HAL_SMARTCARD_StateTypeDef gState
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
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)
return HAL_OK
void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
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 ...
__IO HAL_SMARTCARD_StateTypeDef RxState
void(* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)

◆ HAL_SMARTCARD_AbortCpltCallback()

__weak void HAL_SMARTCARD_AbortCpltCallback ( SMARTCARD_HandleTypeDef hsmartcard)

SMARTCARD Abort Complete callback.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2264 of file stm32l4xx_hal_smartcard.c.

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 }

◆ HAL_SMARTCARD_AbortReceive()

HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive ( SMARTCARD_HandleTypeDef hsmartcard)

Abort ongoing Receive transfer (blocking mode).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Note
This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SMARTCARD Interrupts (Rx)
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
  • Set handle State to READY
This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
Return values
HALstatus

Definition at line 1483 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
__IO HAL_SMARTCARD_StateTypeDef RxState
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
Return the DMA error code.

◆ HAL_SMARTCARD_AbortReceive_IT()

HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT ( SMARTCARD_HandleTypeDef hsmartcard)

Abort ongoing Receive transfer (Interrupt mode).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Note
This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SMARTCARD Interrupts (Rx)
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
  • Set handle State to READY
  • At abort completion, call user abort complete callback
This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function).
Return values
HALstatus

Definition at line 1803 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
__IO HAL_SMARTCARD_StateTypeDef gState
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
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 HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Receive Complete callback.
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ HAL_SMARTCARD_AbortReceiveCpltCallback()

__weak void HAL_SMARTCARD_AbortReceiveCpltCallback ( SMARTCARD_HandleTypeDef hsmartcard)

SMARTCARD Abort Receive Complete callback.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2296 of file stm32l4xx_hal_smartcard.c.

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 }

◆ HAL_SMARTCARD_AbortTransmit()

HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit ( SMARTCARD_HandleTypeDef hsmartcard)

Abort ongoing Transmit transfer (blocking mode).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Note
This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SMARTCARD Interrupts (Tx)
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
  • Set handle State to READY
This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
Return values
HALstatus

Definition at line 1415 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_SMARTCARD_StateTypeDef gState
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
return HAL_OK
HAL_StatusTypeDef HAL_DMA_Abort(DMA_HandleTypeDef *hdma)
Abort the DMA Transfer.
__IO HAL_SMARTCARD_StateTypeDef RxState
uint32_t HAL_DMA_GetError(DMA_HandleTypeDef *hdma)
Return the DMA error code.

◆ HAL_SMARTCARD_AbortTransmit_IT()

HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT ( SMARTCARD_HandleTypeDef hsmartcard)

Abort ongoing Transmit transfer (Interrupt mode).

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Note
This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. This procedure performs following operations :
  • Disable SMARTCARD Interrupts (Tx)
  • Disable the DMA transfer in the peripheral register (if enabled)
  • Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
  • Set handle State to READY
  • At abort completion, call user abort complete callback
This procedure is executed in Interrupt mode, meaning that abort procedure could be considered as completed only when user abort complete callback is executed (not when exiting function).
Return values
HALstatus

Definition at line 1703 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* TxISR)(struct __SMARTCARD_HandleTypeDef *huart)
void(* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef gState
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to HAL_SMARTCARD_Abor...
return HAL_OK
void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD Abort Complete callback.
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ HAL_SMARTCARD_AbortTransmitCpltCallback()

__weak void HAL_SMARTCARD_AbortTransmitCpltCallback ( SMARTCARD_HandleTypeDef hsmartcard)

SMARTCARD Abort Complete callback.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2280 of file stm32l4xx_hal_smartcard.c.

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 }

◆ HAL_SMARTCARD_ErrorCallback()

__weak void HAL_SMARTCARD_ErrorCallback ( SMARTCARD_HandleTypeDef hsmartcard)

SMARTCARD error callback.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2248 of file stm32l4xx_hal_smartcard.c.

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 }

◆ HAL_SMARTCARD_IRQHandler()

void HAL_SMARTCARD_IRQHandler ( SMARTCARD_HandleTypeDef hsmartcard)

Handle SMARTCARD interrupt requests.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 1902 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsmartcard)
End ongoing Rx transfer on UART peripheral (following error detection or Reception completion)...
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
void(* TxISR)(struct __SMARTCARD_HandleTypeDef *huart)
__IO HAL_SMARTCARD_StateTypeDef gState
void(* TxFifoEmptyCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void HAL_SMARTCARDEx_TxFifoEmptyCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD TX Fifo empty callback.
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.
void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
Rx Transfer completed callback.
void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD error callback.
HAL_StatusTypeDef HAL_DMA_Abort_IT(DMA_HandleTypeDef *hdma)
Aborts the DMA Transfer in Interrupt mode.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma)
DMA SMARTCARD communication abort callback, when initiated by HAL services on Error (To be called at ...
return HAL_OK
void(* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD_AdvFeatureInitTypeDef AdvancedInit
void HAL_SMARTCARDEx_RxFifoFullCallback(SMARTCARD_HandleTypeDef *hsmartcard)
SMARTCARD RX Fifo full callback.
void(* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
void(* RxFifoFullCallback)(struct __SMARTCARD_HandleTypeDef *hsmartcard)
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ HAL_SMARTCARD_Receive()

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.

Note
When FIFO mode is enabled, the RXFNE flag is set as long as the RXFIFO is not empty. Read operations from the RDR register are performed when RXFNE flag is set. From hardware perspective, RXFNE flag and RXNE are mapped on the same bit-field.
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
pDatapointer to data buffer.
Sizeamount of data to be received.
TimeoutTimeout duration.
Return values
HALstatus

Definition at line 907 of file stm32l4xx_hal_smartcard.c.

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 }
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
Handle SMARTCARD Communication Timeout.
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ HAL_SMARTCARD_Receive_DMA()

HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA ( SMARTCARD_HandleTypeDef hsmartcard,
uint8_t *  pData,
uint16_t  Size 
)

Receive an amount of data in DMA mode.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
pDatapointer to data buffer.
Sizeamount of data to be received.
Note
The SMARTCARD-associated USART parity is enabled (PCE = 1), the received data contain the parity bit (MSB position).
Return values
HALstatus

Definition at line 1238 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__HAL_UNLOCK(hrtc)
static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
DMA SMARTCARD receive process complete callback.
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.
__HAL_LOCK(hrtc)
return HAL_OK
static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
DMA SMARTCARD communication error callback.
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ HAL_SMARTCARD_Receive_IT()

HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT ( SMARTCARD_HandleTypeDef hsmartcard,
uint8_t *  pData,
uint16_t  Size 
)

Receive an amount of data in interrupt mode.

Note
When FIFO mode is disabled, USART interrupt is generated whenever USART_RDR register can be read, i.e one interrupt per data to receive.
When FIFO mode is enabled, USART interrupt is generated whenever RXFIFO threshold reached. In that case the interrupt rate depends on RXFIFO threshold configuration.
This function sets the hsmartcard->RxIsr function pointer according to the FIFO mode (data reception processing depends on FIFO mode).
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
pDatapointer to data buffer.
Sizeamount of data to be received.
Return values
HALstatus

Definition at line 1074 of file stm32l4xx_hal_smartcard.c.

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 }
void(* RxISR)(struct __SMARTCARD_HandleTypeDef *huart)
static void SMARTCARD_RxISR_FIFOEN(SMARTCARD_HandleTypeDef *hsmartcard)
Receive an amount of data in non-blocking mode.
__HAL_UNLOCK(hrtc)
__HAL_LOCK(hrtc)
return HAL_OK
static void SMARTCARD_RxISR(SMARTCARD_HandleTypeDef *hsmartcard)
Receive an amount of data in non-blocking mode.
__IO HAL_SMARTCARD_StateTypeDef RxState

◆ HAL_SMARTCARD_RxCpltCallback()

__weak void HAL_SMARTCARD_RxCpltCallback ( SMARTCARD_HandleTypeDef hsmartcard)

Rx Transfer completed callback.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2232 of file stm32l4xx_hal_smartcard.c.

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 }

◆ HAL_SMARTCARD_Transmit()

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.

Note
When FIFO mode is enabled, writing a data in the TDR register adds one data to the TXFIFO. Write operations to the TDR register are performed when TXFNF flag is set. From hardware perspective, TXFNF flag and TXE are mapped on the same bit-field.
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
pDatapointer to data buffer.
Sizeamount of data to be sent.
TimeoutTimeout duration.
Return values
HALstatus

Definition at line 818 of file stm32l4xx_hal_smartcard.c.

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 }
__IO HAL_SMARTCARD_StateTypeDef gState
uint32_t HAL_GetTick(void)
Provide a tick value in millisecond.
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
Handle SMARTCARD Communication Timeout.

◆ HAL_SMARTCARD_Transmit_DMA()

HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA ( SMARTCARD_HandleTypeDef hsmartcard,
uint8_t *  pData,
uint16_t  Size 
)

Send an amount of data in DMA mode.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
pDatapointer to data buffer.
Sizeamount of data to be sent.
Return values
HALstatus

Definition at line 1149 of file stm32l4xx_hal_smartcard.c.

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 }
void(* XferAbortCallback)(struct __DMA_HandleTypeDef *hdma)
void(* XferCpltCallback)(struct __DMA_HandleTypeDef *hdma)
__IO HAL_SMARTCARD_StateTypeDef gState
static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma)
DMA SMARTCARD transmit process complete callback.
void(* XferErrorCallback)(struct __DMA_HandleTypeDef *hdma)
__HAL_UNLOCK(hrtc)
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.
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
return HAL_OK
static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
DMA SMARTCARD communication error callback.

◆ HAL_SMARTCARD_Transmit_IT()

HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT ( SMARTCARD_HandleTypeDef hsmartcard,
uint8_t *  pData,
uint16_t  Size 
)

Send an amount of data in interrupt mode.

Note
When FIFO mode is disabled, USART interrupt is generated whenever USART_TDR register is empty, i.e one interrupt per data to transmit.
When FIFO mode is enabled, USART interrupt is generated whenever TXFIFO threshold reached. In that case the interrupt rate depends on TXFIFO threshold configuration.
This function sets the hsmartcard->TxIsr function pointer according to the FIFO mode (data transmission processing depends on FIFO mode).
Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
pDatapointer to data buffer.
Sizeamount of data to be sent.
Return values
HALstatus

Definition at line 975 of file stm32l4xx_hal_smartcard.c.

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 }
void(* TxISR)(struct __SMARTCARD_HandleTypeDef *huart)
__IO HAL_SMARTCARD_StateTypeDef gState
__HAL_UNLOCK(hrtc)
CLEAR_BIT(hrtc->Instance->CR, RTC_CR_WUTE)
__HAL_LOCK(hrtc)
static void SMARTCARD_TxISR(SMARTCARD_HandleTypeDef *hsmartcard)
Send an amount of data in non-blocking mode.
return HAL_OK
static void SMARTCARD_TxISR_FIFOEN(SMARTCARD_HandleTypeDef *hsmartcard)
Send an amount of data in non-blocking mode.

◆ HAL_SMARTCARD_TxCpltCallback()

__weak void HAL_SMARTCARD_TxCpltCallback ( SMARTCARD_HandleTypeDef hsmartcard)

Tx Transfer completed callback.

Parameters
hsmartcardPointer to a SMARTCARD_HandleTypeDef structure that contains the configuration information for the specified SMARTCARD module.
Return values
None

Definition at line 2216 of file stm32l4xx_hal_smartcard.c.

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 }