stm32f0xx_hal_smartcard_ex.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. /**
  2. ******************************************************************************
  3. * @file stm32f0xx_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. #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) \
  35. && !defined(STM32F070xB) && !defined(STM32F030xC)
  36. /* Includes ------------------------------------------------------------------*/
  37. #include "stm32f0xx_hal.h"
  38. /** @addtogroup STM32F0xx_HAL_Driver
  39. * @{
  40. */
  41. /** @defgroup SMARTCARDEx SMARTCARDEx
  42. * @brief SMARTCARD Extended HAL module driver
  43. * @{
  44. */
  45. #ifdef HAL_SMARTCARD_MODULE_ENABLED
  46. /* Private typedef -----------------------------------------------------------*/
  47. /* Private define ------------------------------------------------------------*/
  48. /* Private macros ------------------------------------------------------------*/
  49. /* Private variables ---------------------------------------------------------*/
  50. /* Private function prototypes -----------------------------------------------*/
  51. /* Exported functions --------------------------------------------------------*/
  52. /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions
  53. * @{
  54. */
  55. /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
  56. * @brief Extended control functions
  57. *
  58. @verbatim
  59. ===============================================================================
  60. ##### Peripheral Control functions #####
  61. ===============================================================================
  62. [..]
  63. This subsection provides a set of functions allowing to initialize the SMARTCARD.
  64. (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
  65. (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
  66. (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
  67. (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
  68. @endverbatim
  69. * @{
  70. */
  71. /** @brief Update on the fly the SMARTCARD block length in RTOR register.
  72. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  73. * the configuration information for the specified SMARTCARD module.
  74. * @param BlockLength SMARTCARD block length (8-bit long at most)
  75. * @retval None
  76. */
  77. void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
  78. {
  79. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << USART_RTOR_BLEN_Pos));
  80. }
  81. /** @brief Update on the fly the receiver timeout value in RTOR register.
  82. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  83. * the configuration information for the specified SMARTCARD module.
  84. * @param TimeOutValue receiver timeout value in number of baud blocks. The timeout
  85. * value must be less or equal to 0x0FFFFFFFF.
  86. * @retval None
  87. */
  88. void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
  89. {
  90. assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
  91. MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
  92. }
  93. /** @brief Enable the SMARTCARD receiver timeout feature.
  94. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  95. * the configuration information for the specified SMARTCARD module.
  96. * @retval HAL status
  97. */
  98. HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  99. {
  100. if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  101. {
  102. /* Process Locked */
  103. __HAL_LOCK(hsmartcard);
  104. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  105. /* Set the USART RTOEN bit */
  106. SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  107. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  108. /* Process Unlocked */
  109. __HAL_UNLOCK(hsmartcard);
  110. return HAL_OK;
  111. }
  112. else
  113. {
  114. return HAL_BUSY;
  115. }
  116. }
  117. /** @brief Disable the SMARTCARD receiver timeout feature.
  118. * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
  119. * the configuration information for the specified SMARTCARD module.
  120. * @retval HAL status
  121. */
  122. HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
  123. {
  124. if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
  125. {
  126. /* Process Locked */
  127. __HAL_LOCK(hsmartcard);
  128. hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
  129. /* Clear the USART RTOEN bit */
  130. CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
  131. hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
  132. /* Process Unlocked */
  133. __HAL_UNLOCK(hsmartcard);
  134. return HAL_OK;
  135. }
  136. else
  137. {
  138. return HAL_BUSY;
  139. }
  140. }
  141. /**
  142. * @}
  143. */
  144. /** @defgroup SMARTCARDEx_Exported_Functions_Group2 Extended Peripheral IO operation functions
  145. * @brief SMARTCARD Transmit and Receive functions
  146. *
  147. * @{
  148. */
  149. /**
  150. * @}
  151. */
  152. /**
  153. * @}
  154. */
  155. /** @defgroup SMARTCARDEx_Private_Functions SMARTCARD Extended Private Functions
  156. * @{
  157. */
  158. /**
  159. * @}
  160. */
  161. #endif /* HAL_SMARTCARD_MODULE_ENABLED */
  162. /**
  163. * @}
  164. */
  165. /**
  166. * @}
  167. */
  168. #endif /* !STM32F030x6 && !STM32F030x8 && !STM32F070x6 && !STM32F070xB && !STM32F030xC */