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