stm32f7xx_hal_smartcard_ex.c 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. /**
  2. ******************************************************************************
  3. * @file stm32f7xx_hal_smartcard_ex.c
  4. * @author MCD Application Team
  5. * @brief SMARTCARD HAL module driver.
  6. *
  7. * This file provides extended firmware functions to manage the following
  8. * functionalities of the SmartCard.
  9. * + Initialization and de-initialization functions
  10. * + Peripheral Control functions
  11. @verbatim
  12. ===============================================================================
  13. ##### How to use this driver #####
  14. ===============================================================================
  15. [..]
  16. The Extended SMARTCARD HAL driver can be used as follow:
  17. (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
  18. then if required, program SMARTCARD advanced features (TX/RX pins swap, TimeOut,
  19. auto-retry counter,...) in the hsc AdvancedInit structure.
  20. @endverbatim
  21. ******************************************************************************
  22. * @attention
  23. *
  24. * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
  25. *
  26. * Redistribution and use in source and binary forms, with or without modification,
  27. * are permitted provided that the following conditions are met:
  28. * 1. Redistributions of source code must retain the above copyright notice,
  29. * this list of conditions and the following disclaimer.
  30. * 2. Redistributions in binary form must reproduce the above copyright notice,
  31. * this list of conditions and the following disclaimer in the documentation
  32. * and/or other materials provided with the distribution.
  33. * 3. Neither the name of STMicroelectronics nor the names of its contributors
  34. * may be used to endorse or promote products derived from this software
  35. * without specific prior written permission.
  36. *
  37. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  38. * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  39. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  40. * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
  41. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  42. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  43. * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  44. * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  45. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  46. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  47. *
  48. ******************************************************************************
  49. */
  50. /* Includes ------------------------------------------------------------------*/
  51. #include "stm32f7xx_hal.h"
  52. /** @addtogroup STM32F7xx_HAL_Driver
  53. * @{
  54. */
  55. /** @defgroup SMARTCARDEx SMARTCARDEx
  56. * @brief SMARTCARD Extended HAL module driver
  57. * @{
  58. */
  59. #ifdef HAL_SMARTCARD_MODULE_ENABLED
  60. /* Private typedef -----------------------------------------------------------*/
  61. /* Private define ------------------------------------------------------------*/
  62. /* Private macro -------------------------------------------------------------*/
  63. /* Private variables ---------------------------------------------------------*/
  64. /* Private function prototypes -----------------------------------------------*/
  65. /* Private functions ---------------------------------------------------------*/
  66. /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARDEx Exported Functions
  67. * @{
  68. */
  69. /** @defgroup SMARTCARDEx_Group1 Extended Peripheral Control functions
  70. * @brief Extended control functions
  71. *
  72. @verbatim
  73. ===============================================================================
  74. ##### Peripheral Control functions #####
  75. ===============================================================================
  76. [..]
  77. This subsection provides a set of functions allowing to initialize the SMARTCARD.
  78. (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
  79. (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
  80. (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
  81. (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
  82. @endverbatim
  83. * @{
  84. */
  85. /**
  86. * @brief Update on the fly the SMARTCARD block length in RTOR register
  87. * @param hsc SMARTCARD handle
  88. * @param BlockLength SMARTCARD block length (8-bit long at most)
  89. * @retval None
  90. */
  91. void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsc, uint8_t BlockLength)
  92. {
  93. MODIFY_REG(hsc->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS));
  94. }
  95. /**
  96. * @brief Update on the fly the receiver timeout value in RTOR register
  97. * @param hsc SMARTCARD handle
  98. * @param TimeOutValue receiver timeout value in number of baud blocks. The timeout
  99. * value must be less or equal to 0x0FFFFFFFF.
  100. * @retval None
  101. */
  102. void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsc, uint32_t TimeOutValue)
  103. {
  104. assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsc->Init.TimeOutValue));
  105. MODIFY_REG(hsc->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
  106. }
  107. /**
  108. * @brief Enable the SMARTCARD receiver timeout feature
  109. * @param hsc SMARTCARD handle
  110. * @retval HAL status
  111. */
  112. HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsc)
  113. {
  114. /* Process Locked */
  115. __HAL_LOCK(hsc);
  116. hsc->gState = HAL_SMARTCARD_STATE_BUSY;
  117. /* Set the USART RTOEN bit */
  118. hsc->Instance->CR2 |= USART_CR2_RTOEN;
  119. hsc->gState = HAL_SMARTCARD_STATE_READY;
  120. /* Process Unlocked */
  121. __HAL_UNLOCK(hsc);
  122. return HAL_OK;
  123. }
  124. /**
  125. * @brief Disable the SMARTCARD receiver timeout feature
  126. * @param hsc SMARTCARD handle
  127. * @retval HAL status
  128. */
  129. HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsc)
  130. {
  131. /* Process Locked */
  132. __HAL_LOCK(hsc);
  133. hsc->gState = HAL_SMARTCARD_STATE_BUSY;
  134. /* Clear the USART RTOEN bit */
  135. hsc->Instance->CR2 &= ~(USART_CR2_RTOEN);
  136. hsc->gState = HAL_SMARTCARD_STATE_READY;
  137. /* Process Unlocked */
  138. __HAL_UNLOCK(hsc);
  139. return HAL_OK;
  140. }
  141. /**
  142. * @}
  143. */
  144. /**
  145. * @}
  146. */
  147. #endif /* HAL_SMARTCARD_MODULE_ENABLED */
  148. /**
  149. * @}
  150. */
  151. /**
  152. * @}
  153. */
  154. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/