stm32f3xx_hal_smartcard_ex.c 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /**
  2. ******************************************************************************
  3. * @file stm32f3xx_hal_smartcard_ex.c
  4. * @author MCD Application Team
  5. * @brief SMARTCARD HAL module driver.
  6. * This file provides extended firmware functions to manage the following
  7. * functionalities of the SmartCard.
  8. * + Initialization and de-initialization functions
  9. * + Peripheral Control functions
  10. *
  11. ******************************************************************************
  12. * @attention
  13. *
  14. * Copyright (c) 2016 STMicroelectronics.
  15. * All rights reserved.
  16. *
  17. * This software is licensed under terms that can be found in the LICENSE file
  18. * in the root directory of this software component.
  19. * If no LICENSE file comes with this software, it is provided AS-IS.
  20. *
  21. ******************************************************************************
  22. @verbatim
  23. =============================================================================
  24. ##### SMARTCARD peripheral extended features #####
  25. =============================================================================
  26. [..]
  27. The Extended SMARTCARD HAL driver can be used as follows:
  28. (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
  29. then program SMARTCARD advanced features if required (TX/RX pins swap, TimeOut,
  30. auto-retry counter,...) in the hsmartcard AdvancedInit structure.
  31. @endverbatim
  32. ******************************************************************************
  33. */
  34. /* Includes ------------------------------------------------------------------*/
  35. #include "stm32f3xx_hal.h"
  36. /** @addtogroup STM32F3xx_HAL_Driver
  37. * @{
  38. */
  39. /** @defgroup SMARTCARDEx SMARTCARDEx
  40. * @brief SMARTCARD Extended HAL module driver
  41. * @{
  42. */
  43. #ifdef HAL_SMARTCARD_MODULE_ENABLED
  44. /* Private typedef -----------------------------------------------------------*/
  45. /* Private define ------------------------------------------------------------*/
  46. /* Private macros ------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private function prototypes -----------------------------------------------*/
  49. /* Exported functions --------------------------------------------------------*/
  50. /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions
  51. * @{
  52. */
  53. /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
  54. * @brief Extended control functions
  55. *
  56. @verbatim
  57. ===============================================================================
  58. ##### Peripheral Control functions #####
  59. ===============================================================================
  60. [..]
  61. This subsection provides a set of functions allowing to initialize the SMARTCARD.
  62. (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
  63. (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
  64. (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
  65. (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
  66. @endverbatim
  67. * @{
  68. */
  69. /** @brief Update on the fly the SMARTCARD block length in RTOR register.
  70. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  71. * the configuration information for the specified SMARTCARD module.
  72. * @param BlockLength SMARTCARD block length (8-bit long at most)
  73. * @retval None
  74. */
  75. void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
  76. {
  77. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << USART_RTOR_BLEN_Pos));
  78. }
  79. /** @brief Update on the fly the receiver timeout value in RTOR register.
  80. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  81. * the configuration information for the specified SMARTCARD module.
  82. * @param TimeOutValue receiver timeout value in number of baud blocks. The timeout
  83. * value must be less or equal to 0x0FFFFFFFF.
  84. * @retval None
  85. */
  86. void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
  87. {
  88. assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
  89. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
  90. }
  91. /** @brief Enable the SMARTCARD receiver timeout feature.
  92. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  93. * the configuration information for the specified SMARTCARD module.
  94. * @retval HAL status
  95. */
  96. HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  97. {
  98. if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  99. {
  100. /* Process Locked */
  101. __HAL_LOCK(hsmartcard);
  102. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  103. /* Set the USART RTOEN bit */
  104. SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  105. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  106. /* Process Unlocked */
  107. __HAL_UNLOCK(hsmartcard);
  108. return HAL_OK;
  109. }
  110. else
  111. {
  112. return HAL_BUSY;
  113. }
  114. }
  115. /** @brief Disable the SMARTCARD receiver timeout feature.
  116. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  117. * the configuration information for the specified SMARTCARD module.
  118. * @retval HAL status
  119. */
  120. HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  121. {
  122. if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  123. {
  124. /* Process Locked */
  125. __HAL_LOCK(hsmartcard);
  126. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  127. /* Clear the USART RTOEN bit */
  128. CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  129. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  130. /* Process Unlocked */
  131. __HAL_UNLOCK(hsmartcard);
  132. return HAL_OK;
  133. }
  134. else
  135. {
  136. return HAL_BUSY;
  137. }
  138. }
  139. /**
  140. * @}
  141. */
  142. /** @defgroup SMARTCARDEx_Exported_Functions_Group2 Extended Peripheral IO operation functions
  143. * @brief SMARTCARD Transmit and Receive functions
  144. *
  145. * @{
  146. */
  147. /**
  148. * @}
  149. */
  150. /**
  151. * @}
  152. */
  153. /** @defgroup SMARTCARDEx_Private_Functions SMARTCARD Extended Private Functions
  154. * @{
  155. */
  156. /**
  157. * @}
  158. */
  159. #endif /* HAL_SMARTCARD_MODULE_ENABLED */
  160. /**
  161. * @}
  162. */
  163. /**
  164. * @}
  165. */