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
29 (#) After having configured the SMARTCARD basic features with HAL_SMARTCARD_Init(),
30 then program SMARTCARD advanced features if required (TX/RX pins swap, TimeOut,
31 auto-retry counter,...) in the hsmartcard AdvancedInit structure.
32 @endverbatim
33 ******************************************************************************
34 */
35
36 /* Includes ------------------------------------------------------------------*/
37 #include "stm32f3xx_hal.h"
38
39 /** @addtogroup STM32F3xx_HAL_Driver
40 * @{
41 */
42
43 /** @defgroup SMARTCARDEx SMARTCARDEx
44 * @brief SMARTCARD Extended HAL module driver
45 * @{
46 */
47 #ifdef HAL_SMARTCARD_MODULE_ENABLED
48
49 /* Private typedef -----------------------------------------------------------*/
50 /* Private define ------------------------------------------------------------*/
51 /* Private macros ------------------------------------------------------------*/
52 /* Private variables ---------------------------------------------------------*/
53 /* Private function prototypes -----------------------------------------------*/
54 /* Exported functions --------------------------------------------------------*/
55 /** @defgroup SMARTCARDEx_Exported_Functions SMARTCARD Extended Exported Functions
56 * @{
57 */
58
59 /** @defgroup SMARTCARDEx_Exported_Functions_Group1 Extended Peripheral Control functions
60 * @brief Extended control functions
61 *
62 @verbatim
63 ===============================================================================
64 ##### Peripheral Control functions #####
65 ===============================================================================
66 [..]
67 This subsection provides a set of functions allowing to initialize the SMARTCARD.
68 (+) HAL_SMARTCARDEx_BlockLength_Config() API allows to configure the Block Length on the fly
69 (+) HAL_SMARTCARDEx_TimeOut_Config() API allows to configure the receiver timeout value on the fly
70 (+) HAL_SMARTCARDEx_EnableReceiverTimeOut() API enables the receiver timeout feature
71 (+) HAL_SMARTCARDEx_DisableReceiverTimeOut() API disables the receiver timeout feature
72
73 @endverbatim
74 * @{
75 */
76
77 /** @brief Update on the fly the SMARTCARD block length in RTOR register.
78 * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
79 * the configuration information for the specified SMARTCARD module.
80 * @param BlockLength SMARTCARD block length (8-bit long at most)
81 * @retval None
82 */
HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef * hsmartcard,uint8_t BlockLength)83 void HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength)
84 {
85 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_BLEN, ((uint32_t)BlockLength << USART_RTOR_BLEN_Pos));
86 }
87
88 /** @brief Update on the fly the receiver timeout value in RTOR register.
89 * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
90 * the configuration information for the specified SMARTCARD module.
91 * @param TimeOutValue receiver timeout value in number of baud blocks. The timeout
92 * value must be less or equal to 0x0FFFFFFFF.
93 * @retval None
94 */
HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef * hsmartcard,uint32_t TimeOutValue)95 void HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue)
96 {
97 assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
98 MODIFY_REG(hsmartcard->Instance->RTOR, USART_RTOR_RTO, TimeOutValue);
99 }
100
101 /** @brief Enable the SMARTCARD receiver timeout feature.
102 * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
103 * the configuration information for the specified SMARTCARD module.
104 * @retval HAL status
105 */
HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef * hsmartcard)106 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
107 {
108 if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
109 {
110 /* Process Locked */
111 __HAL_LOCK(hsmartcard);
112
113 hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
114
115 /* Set the USART RTOEN bit */
116 SET_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
117
118 hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
119
120 /* Process Unlocked */
121 __HAL_UNLOCK(hsmartcard);
122
123 return HAL_OK;
124 }
125 else
126 {
127 return HAL_BUSY;
128 }
129 }
130
131 /** @brief Disable the SMARTCARD receiver timeout feature.
132 * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
133 * the configuration information for the specified SMARTCARD module.
134 * @retval HAL status
135 */
HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef * hsmartcard)136 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard)
137 {
138 if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
139 {
140 /* Process Locked */
141 __HAL_LOCK(hsmartcard);
142
143 hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
144
145 /* Clear the USART RTOEN bit */
146 CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_RTOEN);
147
148 hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
149
150 /* Process Unlocked */
151 __HAL_UNLOCK(hsmartcard);
152
153 return HAL_OK;
154 }
155 else
156 {
157 return HAL_BUSY;
158 }
159 }
160
161 /**
162 * @}
163 */
164
165 /** @defgroup SMARTCARDEx_Exported_Functions_Group2 Extended Peripheral IO operation functions
166 * @brief SMARTCARD Transmit and Receive functions
167 *
168 * @{
169 */
170
171 /**
172 * @}
173 */
174
175
176 /**
177 * @}
178 */
179
180 /** @defgroup SMARTCARDEx_Private_Functions SMARTCARD Extended Private Functions
181 * @{
182 */
183
184 /**
185 * @}
186 */
187
188 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
189
190 /**
191 * @}
192 */
193
194 /**
195 * @}
196 */
197
198