You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

185 lines
6.5 KiB

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