提交 | 用户 | age
|
bfc108
|
1 |
/**
|
Q |
2 |
******************************************************************************
|
|
3 |
* @file stm32f0xx_hal_smartcard.c
|
|
4 |
* @author MCD Application Team
|
|
5 |
* @brief SMARTCARD HAL module driver.
|
|
6 |
* This file provides firmware functions to manage the following
|
|
7 |
* functionalities of the SMARTCARD peripheral:
|
|
8 |
* + Initialization and de-initialization functions
|
|
9 |
* + IO operation functions
|
|
10 |
* + Peripheral Control functions
|
|
11 |
* + Peripheral State and Error functions
|
|
12 |
*
|
|
13 |
@verbatim
|
|
14 |
==============================================================================
|
|
15 |
##### How to use this driver #####
|
|
16 |
==============================================================================
|
|
17 |
[..]
|
|
18 |
The SMARTCARD HAL driver can be used as follows:
|
|
19 |
|
|
20 |
(#) Declare a SMARTCARD_HandleTypeDef handle structure (eg. SMARTCARD_HandleTypeDef hsmartcard).
|
|
21 |
(#) Associate a USART to the SMARTCARD handle hsmartcard.
|
|
22 |
(#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API:
|
|
23 |
(++) Enable the USARTx interface clock.
|
|
24 |
(++) USART pins configuration:
|
|
25 |
(+++) Enable the clock for the USART GPIOs.
|
|
26 |
(+++) Configure the USART pins (TX as alternate function pull-up, RX as alternate function Input).
|
|
27 |
(++) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT()
|
|
28 |
and HAL_SMARTCARD_Receive_IT() APIs):
|
|
29 |
(+++) Configure the USARTx interrupt priority.
|
|
30 |
(+++) Enable the NVIC USART IRQ handle.
|
|
31 |
(++) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA()
|
|
32 |
and HAL_SMARTCARD_Receive_DMA() APIs):
|
|
33 |
(+++) Declare a DMA handle structure for the Tx/Rx channel.
|
|
34 |
(+++) Enable the DMAx interface clock.
|
|
35 |
(+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
|
|
36 |
(+++) Configure the DMA Tx/Rx channel.
|
|
37 |
(+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle.
|
|
38 |
(+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.
|
|
39 |
|
|
40 |
(#) Program the Baud Rate, Parity, Mode(Receiver/Transmitter), clock enabling/disabling and accordingly,
|
|
41 |
the clock parameters (parity, phase, last bit), prescaler value, guard time and NACK on transmission
|
|
42 |
error enabling or disabling in the hsmartcard handle Init structure.
|
|
43 |
|
|
44 |
(#) If required, program SMARTCARD advanced features (TX/RX pins swap, TimeOut, auto-retry counter,...)
|
|
45 |
in the hsmartcard handle AdvancedInit structure.
|
|
46 |
|
|
47 |
(#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API:
|
|
48 |
(++) This API configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc)
|
|
49 |
by calling the customized HAL_SMARTCARD_MspInit() API.
|
|
50 |
[..]
|
|
51 |
(@) The specific SMARTCARD interrupts (Transmission complete interrupt,
|
|
52 |
RXNE interrupt and Error Interrupts) will be managed using the macros
|
|
53 |
__HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process.
|
|
54 |
|
|
55 |
[..]
|
|
56 |
[..] Three operation modes are available within this driver :
|
|
57 |
|
|
58 |
*** Polling mode IO operation ***
|
|
59 |
=================================
|
|
60 |
[..]
|
|
61 |
(+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit()
|
|
62 |
(+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive()
|
|
63 |
|
|
64 |
*** Interrupt mode IO operation ***
|
|
65 |
===================================
|
|
66 |
[..]
|
|
67 |
(+) Send an amount of data in non-blocking mode using HAL_SMARTCARD_Transmit_IT()
|
|
68 |
(+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback() is executed and user can
|
|
69 |
add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback()
|
|
70 |
(+) Receive an amount of data in non-blocking mode using HAL_SMARTCARD_Receive_IT()
|
|
71 |
(+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback() is executed and user can
|
|
72 |
add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback()
|
|
73 |
(+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
|
|
74 |
add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback()
|
|
75 |
|
|
76 |
*** DMA mode IO operation ***
|
|
77 |
==============================
|
|
78 |
[..]
|
|
79 |
(+) Send an amount of data in non-blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA()
|
|
80 |
(+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback() is executed and user can
|
|
81 |
add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback()
|
|
82 |
(+) Receive an amount of data in non-blocking mode (DMA) using HAL_SMARTCARD_Receive_DMA()
|
|
83 |
(+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback() is executed and user can
|
|
84 |
add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback()
|
|
85 |
(+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
|
|
86 |
add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback()
|
|
87 |
|
|
88 |
*** SMARTCARD HAL driver macros list ***
|
|
89 |
========================================
|
|
90 |
[..]
|
|
91 |
Below the list of most used macros in SMARTCARD HAL driver.
|
|
92 |
|
|
93 |
(+) __HAL_SMARTCARD_GET_FLAG : Check whether or not the specified SMARTCARD flag is set
|
|
94 |
(+) __HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag
|
|
95 |
(+) __HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt
|
|
96 |
(+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt
|
|
97 |
(+) __HAL_SMARTCARD_GET_IT_SOURCE: Check whether or not the specified SMARTCARD interrupt is enabled
|
|
98 |
|
|
99 |
[..]
|
|
100 |
(@) You can refer to the SMARTCARD HAL driver header file for more useful macros
|
|
101 |
|
|
102 |
@endverbatim
|
|
103 |
******************************************************************************
|
|
104 |
* @attention
|
|
105 |
*
|
|
106 |
* <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
|
|
107 |
*
|
|
108 |
* Redistribution and use in source and binary forms, with or without modification,
|
|
109 |
* are permitted provided that the following conditions are met:
|
|
110 |
* 1. Redistributions of source code must retain the above copyright notice,
|
|
111 |
* this list of conditions and the following disclaimer.
|
|
112 |
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
113 |
* this list of conditions and the following disclaimer in the documentation
|
|
114 |
* and/or other materials provided with the distribution.
|
|
115 |
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
|
116 |
* may be used to endorse or promote products derived from this software
|
|
117 |
* without specific prior written permission.
|
|
118 |
*
|
|
119 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
120 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
121 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
122 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
123 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
124 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
125 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
126 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
127 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
128 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
129 |
*
|
|
130 |
******************************************************************************
|
|
131 |
*/
|
|
132 |
|
|
133 |
/* Includes ------------------------------------------------------------------*/
|
|
134 |
#include "stm32f0xx_hal.h"
|
|
135 |
|
|
136 |
#if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC)
|
|
137 |
|
|
138 |
/** @addtogroup STM32F0xx_HAL_Driver
|
|
139 |
* @{
|
|
140 |
*/
|
|
141 |
|
|
142 |
/** @defgroup SMARTCARD SMARTCARD
|
|
143 |
* @brief HAL SMARTCARD module driver
|
|
144 |
* @{
|
|
145 |
*/
|
|
146 |
|
|
147 |
#ifdef HAL_SMARTCARD_MODULE_ENABLED
|
|
148 |
|
|
149 |
/* Private typedef -----------------------------------------------------------*/
|
|
150 |
/* Private define ------------------------------------------------------------*/
|
|
151 |
/** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
|
|
152 |
* @{
|
|
153 |
*/
|
|
154 |
#define SMARTCARD_TEACK_REACK_TIMEOUT 1000U /*!< SMARTCARD TX or RX enable acknowledge time-out value */
|
|
155 |
|
|
156 |
#define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \
|
|
157 |
USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8)) /*!< USART CR1 fields of parameters set by SMARTCARD_SetConfig API */
|
|
158 |
#define USART_CR2_CLK_FIELDS ((uint32_t)(USART_CR2_CLKEN|USART_CR2_CPOL|USART_CR2_CPHA|USART_CR2_LBCL)) /*!< SMARTCARD clock-related USART CR2 fields of parameters */
|
|
159 |
#define USART_CR2_FIELDS ((uint32_t)(USART_CR2_RTOEN|USART_CR2_CLK_FIELDS|USART_CR2_STOP)) /*!< USART CR2 fields of parameters set by SMARTCARD_SetConfig API */
|
|
160 |
#define USART_CR3_FIELDS ((uint32_t)(USART_CR3_ONEBIT|USART_CR3_NACK|USART_CR3_SCARCNT)) /*!< USART CR3 fields of parameters set by SMARTCARD_SetConfig API */
|
|
161 |
/**
|
|
162 |
* @}
|
|
163 |
*/
|
|
164 |
|
|
165 |
/* Private macros ------------------------------------------------------------*/
|
|
166 |
/* Private variables ---------------------------------------------------------*/
|
|
167 |
/* Private function prototypes -----------------------------------------------*/
|
|
168 |
/** @addtogroup SMARTCARD_Private_Functions
|
|
169 |
* @{
|
|
170 |
*/
|
|
171 |
static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
172 |
static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
173 |
static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
174 |
static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
|
|
175 |
static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
176 |
static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
177 |
static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma);
|
|
178 |
static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
|
|
179 |
static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma);
|
|
180 |
static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma);
|
|
181 |
static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
|
|
182 |
static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
|
|
183 |
static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
|
|
184 |
static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
|
|
185 |
static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
186 |
static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
187 |
static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard);
|
|
188 |
/**
|
|
189 |
* @}
|
|
190 |
*/
|
|
191 |
|
|
192 |
/* Exported functions --------------------------------------------------------*/
|
|
193 |
|
|
194 |
/** @defgroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions
|
|
195 |
* @{
|
|
196 |
*/
|
|
197 |
|
|
198 |
/** @defgroup SMARTCARD_Exported_Functions_Group1 Initialization and de-initialization functions
|
|
199 |
* @brief Initialization and Configuration functions
|
|
200 |
*
|
|
201 |
@verbatim
|
|
202 |
==============================================================================
|
|
203 |
##### Initialization and Configuration functions #####
|
|
204 |
==============================================================================
|
|
205 |
[..]
|
|
206 |
This subsection provides a set of functions allowing to initialize the USARTx
|
|
207 |
associated to the SmartCard.
|
|
208 |
[..]
|
|
209 |
The Smartcard interface is designed to support asynchronous protocol Smartcards as
|
|
210 |
defined in the ISO 7816-3 standard.
|
|
211 |
[..]
|
|
212 |
The USART can provide a clock to the smartcard through the SCLK output.
|
|
213 |
In smartcard mode, SCLK is not associated to the communication but is simply derived
|
|
214 |
from the internal peripheral input clock through a 5-bit prescaler.
|
|
215 |
[..]
|
|
216 |
(+) These parameters can be configured:
|
|
217 |
(++) Baud Rate
|
|
218 |
(++) Parity: should be enabled
|
|
219 |
(++) Receiver/transmitter modes
|
|
220 |
(++) Synchronous mode (and if enabled, phase, polarity and last bit parameters)
|
|
221 |
(++) Prescaler value
|
|
222 |
(++) Guard bit time
|
|
223 |
(++) NACK enabling or disabling on transmission error
|
|
224 |
|
|
225 |
(+) The following advanced features can be configured as well:
|
|
226 |
(++) TX and/or RX pin level inversion
|
|
227 |
(++) data logical level inversion
|
|
228 |
(++) RX and TX pins swap
|
|
229 |
(++) RX overrun detection disabling
|
|
230 |
(++) DMA disabling on RX error
|
|
231 |
(++) MSB first on communication line
|
|
232 |
(++) Time out enabling (and if activated, timeout value)
|
|
233 |
(++) Block length
|
|
234 |
(++) Auto-retry counter
|
|
235 |
[..]
|
|
236 |
The HAL_SMARTCARD_Init() API follows the USART synchronous configuration procedures
|
|
237 |
(details for the procedures are available in reference manual).
|
|
238 |
|
|
239 |
@endverbatim
|
|
240 |
* @{
|
|
241 |
*/
|
|
242 |
|
|
243 |
/*
|
|
244 |
Additional Table:
|
|
245 |
Frame Length is fixed to 8 bits plus parity:
|
|
246 |
SMARTCARD frame format is given in the following table
|
|
247 |
+---------------------------------------------------------------+
|
|
248 |
| M1M0 bits | PCE bit | SMARTCARD frame |
|
|
249 |
|-----------------------|---------------------------------------|
|
|
250 |
| 01 | 1 | | SB | 8 bit data | PB | STB | |
|
|
251 |
+---------------------------------------------------------------+
|
|
252 |
|
|
253 |
*/
|
|
254 |
|
|
255 |
/**
|
|
256 |
* @brief Initialize the SMARTCARD mode according to the specified
|
|
257 |
* parameters in the SMARTCARD_HandleTypeDef and initialize the associated handle.
|
|
258 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
259 |
* the configuration information for the specified SMARTCARD module.
|
|
260 |
* @retval HAL status
|
|
261 |
*/
|
|
262 |
HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
263 |
{
|
|
264 |
/* Check the SMARTCARD handle allocation */
|
|
265 |
if(hsmartcard == NULL)
|
|
266 |
{
|
|
267 |
return HAL_ERROR;
|
|
268 |
}
|
|
269 |
|
|
270 |
/* Check the USART associated to the SMARTCARD handle */
|
|
271 |
assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
|
|
272 |
|
|
273 |
if(hsmartcard->gState == HAL_SMARTCARD_STATE_RESET)
|
|
274 |
{
|
|
275 |
/* Allocate lock resource and initialize it */
|
|
276 |
hsmartcard->Lock = HAL_UNLOCKED;
|
|
277 |
|
|
278 |
/* Init the low level hardware : GPIO, CLOCK */
|
|
279 |
HAL_SMARTCARD_MspInit(hsmartcard);
|
|
280 |
}
|
|
281 |
|
|
282 |
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
|
283 |
|
|
284 |
/* Disable the Peripheral to set smartcard mode */
|
|
285 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
286 |
|
|
287 |
/* In SmartCard mode, the following bits must be kept cleared:
|
|
288 |
- LINEN in the USART_CR2 register,
|
|
289 |
- HDSEL and IREN bits in the USART_CR3 register.*/
|
|
290 |
CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_LINEN);
|
|
291 |
CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN));
|
|
292 |
|
|
293 |
/* set the USART in SMARTCARD mode */
|
|
294 |
SET_BIT(hsmartcard->Instance->CR3, USART_CR3_SCEN);
|
|
295 |
|
|
296 |
/* Set the SMARTCARD Communication parameters */
|
|
297 |
if (SMARTCARD_SetConfig(hsmartcard) == HAL_ERROR)
|
|
298 |
{
|
|
299 |
return HAL_ERROR;
|
|
300 |
}
|
|
301 |
|
|
302 |
if (hsmartcard->AdvancedInit.AdvFeatureInit != SMARTCARD_ADVFEATURE_NO_INIT)
|
|
303 |
{
|
|
304 |
SMARTCARD_AdvFeatureConfig(hsmartcard);
|
|
305 |
}
|
|
306 |
|
|
307 |
/* Enable the Peripheral */
|
|
308 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
309 |
|
|
310 |
/* TEACK and/or REACK to check before moving hsmartcard->gState and hsmartcard->RxState to Ready */
|
|
311 |
return (SMARTCARD_CheckIdleState(hsmartcard));
|
|
312 |
}
|
|
313 |
|
|
314 |
/**
|
|
315 |
* @brief DeInitialize the SMARTCARD peripheral.
|
|
316 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
317 |
* the configuration information for the specified SMARTCARD module.
|
|
318 |
* @retval HAL status
|
|
319 |
*/
|
|
320 |
HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
321 |
{
|
|
322 |
/* Check the SMARTCARD handle allocation */
|
|
323 |
if(hsmartcard == NULL)
|
|
324 |
{
|
|
325 |
return HAL_ERROR;
|
|
326 |
}
|
|
327 |
|
|
328 |
/* Check the USART/UART associated to the SMARTCARD handle */
|
|
329 |
assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
|
|
330 |
|
|
331 |
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY;
|
|
332 |
|
|
333 |
/* Disable the Peripheral */
|
|
334 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
335 |
|
|
336 |
WRITE_REG(hsmartcard->Instance->CR1, 0x0U);
|
|
337 |
WRITE_REG(hsmartcard->Instance->CR2, 0x0U);
|
|
338 |
WRITE_REG(hsmartcard->Instance->CR3, 0x0U);
|
|
339 |
WRITE_REG(hsmartcard->Instance->RTOR, 0x0U);
|
|
340 |
WRITE_REG(hsmartcard->Instance->GTPR, 0x0U);
|
|
341 |
|
|
342 |
/* DeInit the low level hardware */
|
|
343 |
HAL_SMARTCARD_MspDeInit(hsmartcard);
|
|
344 |
|
|
345 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
346 |
hsmartcard->gState = HAL_SMARTCARD_STATE_RESET;
|
|
347 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_RESET;
|
|
348 |
|
|
349 |
/* Process Unlock */
|
|
350 |
__HAL_UNLOCK(hsmartcard);
|
|
351 |
|
|
352 |
return HAL_OK;
|
|
353 |
}
|
|
354 |
|
|
355 |
/**
|
|
356 |
* @brief Initialize the SMARTCARD MSP.
|
|
357 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
358 |
* the configuration information for the specified SMARTCARD module.
|
|
359 |
* @retval None
|
|
360 |
*/
|
|
361 |
__weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
362 |
{
|
|
363 |
/* Prevent unused argument(s) compilation warning */
|
|
364 |
UNUSED(hsmartcard);
|
|
365 |
|
|
366 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
367 |
the HAL_SMARTCARD_MspInit can be implemented in the user file
|
|
368 |
*/
|
|
369 |
}
|
|
370 |
|
|
371 |
/**
|
|
372 |
* @brief DeInitialize the SMARTCARD MSP.
|
|
373 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
374 |
* the configuration information for the specified SMARTCARD module.
|
|
375 |
* @retval None
|
|
376 |
*/
|
|
377 |
__weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
378 |
{
|
|
379 |
/* Prevent unused argument(s) compilation warning */
|
|
380 |
UNUSED(hsmartcard);
|
|
381 |
|
|
382 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
383 |
the HAL_SMARTCARD_MspDeInit can be implemented in the user file
|
|
384 |
*/
|
|
385 |
}
|
|
386 |
|
|
387 |
/**
|
|
388 |
* @}
|
|
389 |
*/
|
|
390 |
|
|
391 |
/** @defgroup SMARTCARD_Exported_Functions_Group2 IO operation functions
|
|
392 |
* @brief SMARTCARD Transmit and Receive functions
|
|
393 |
*
|
|
394 |
@verbatim
|
|
395 |
==============================================================================
|
|
396 |
##### IO operation functions #####
|
|
397 |
==============================================================================
|
|
398 |
[..]
|
|
399 |
This subsection provides a set of functions allowing to manage the SMARTCARD data transfers.
|
|
400 |
|
|
401 |
[..]
|
|
402 |
Smartcard is a single wire half duplex communication protocol.
|
|
403 |
The Smartcard interface is designed to support asynchronous protocol Smartcards as
|
|
404 |
defined in the ISO 7816-3 standard. The USART should be configured as:
|
|
405 |
(+) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
|
|
406 |
(+) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register.
|
|
407 |
|
|
408 |
[..]
|
|
409 |
(#) There are two modes of transfer:
|
|
410 |
(++) Blocking mode: The communication is performed in polling mode.
|
|
411 |
The HAL status of all data processing is returned by the same function
|
|
412 |
after finishing transfer.
|
|
413 |
(++) Non-Blocking mode: The communication is performed using Interrupts
|
|
414 |
or DMA, the relevant API's return the HAL status.
|
|
415 |
The end of the data processing will be indicated through the
|
|
416 |
dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when
|
|
417 |
using DMA mode.
|
|
418 |
(++) The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks
|
|
419 |
will be executed respectively at the end of the Transmit or Receive process
|
|
420 |
The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication
|
|
421 |
error is detected.
|
|
422 |
|
|
423 |
(#) Blocking mode APIs are :
|
|
424 |
(++) HAL_SMARTCARD_Transmit()
|
|
425 |
(++) HAL_SMARTCARD_Receive()
|
|
426 |
|
|
427 |
(#) Non Blocking mode APIs with Interrupt are :
|
|
428 |
(++) HAL_SMARTCARD_Transmit_IT()
|
|
429 |
(++) HAL_SMARTCARD_Receive_IT()
|
|
430 |
(++) HAL_SMARTCARD_IRQHandler()
|
|
431 |
|
|
432 |
(#) Non Blocking mode functions with DMA are :
|
|
433 |
(++) HAL_SMARTCARD_Transmit_DMA()
|
|
434 |
(++) HAL_SMARTCARD_Receive_DMA()
|
|
435 |
|
|
436 |
(#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
|
|
437 |
(++) HAL_SMARTCARD_TxCpltCallback()
|
|
438 |
(++) HAL_SMARTCARD_RxCpltCallback()
|
|
439 |
(++) HAL_SMARTCARD_ErrorCallback()
|
|
440 |
|
|
441 |
(#) Non-Blocking mode transfers could be aborted using Abort API's :
|
|
442 |
(++) HAL_SMARTCARD_Abort()
|
|
443 |
(++) HAL_SMARTCARD_AbortTransmit()
|
|
444 |
(++) HAL_SMARTCARD_AbortReceive()
|
|
445 |
(++) HAL_SMARTCARD_Abort_IT()
|
|
446 |
(++) HAL_SMARTCARD_AbortTransmit_IT()
|
|
447 |
(++) HAL_SMARTCARD_AbortReceive_IT()
|
|
448 |
|
|
449 |
(#) For Abort services based on interrupts (HAL_SMARTCARD_Abortxxx_IT), a set of Abort Complete Callbacks are provided:
|
|
450 |
(++) HAL_SMARTCARD_AbortCpltCallback()
|
|
451 |
(++) HAL_SMARTCARD_AbortTransmitCpltCallback()
|
|
452 |
(++) HAL_SMARTCARD_AbortReceiveCpltCallback()
|
|
453 |
|
|
454 |
(#) In Non-Blocking mode transfers, possible errors are split into 2 categories.
|
|
455 |
Errors are handled as follows :
|
|
456 |
(++) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is
|
|
457 |
to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception .
|
|
458 |
Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type,
|
|
459 |
and HAL_SMARTCARD_ErrorCallback() user callback is executed. Transfer is kept ongoing on SMARTCARD side.
|
|
460 |
If user wants to abort it, Abort services should be called by user.
|
|
461 |
(++) Error is considered as Blocking : Transfer could not be completed properly and is aborted.
|
|
462 |
This concerns Frame Error in Interrupt mode tranmission, Overrun Error in Interrupt mode reception and all errors in DMA mode.
|
|
463 |
Error code is set to allow user to identify error type, and HAL_SMARTCARD_ErrorCallback() user callback is executed.
|
|
464 |
|
|
465 |
@endverbatim
|
|
466 |
* @{
|
|
467 |
*/
|
|
468 |
|
|
469 |
/**
|
|
470 |
* @brief Send an amount of data in blocking mode.
|
|
471 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
472 |
* the configuration information for the specified SMARTCARD module.
|
|
473 |
* @param pData pointer to data buffer.
|
|
474 |
* @param Size amount of data to be sent.
|
|
475 |
* @param Timeout Timeout duration.
|
|
476 |
* @retval HAL status
|
|
477 |
*/
|
|
478 |
HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
|
479 |
{
|
|
480 |
uint32_t tickstart = 0U;
|
|
481 |
|
|
482 |
/* Check that a Tx process is not already ongoing */
|
|
483 |
if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
|
484 |
{
|
|
485 |
if((pData == NULL) || (Size == 0U))
|
|
486 |
{
|
|
487 |
return HAL_ERROR;
|
|
488 |
}
|
|
489 |
|
|
490 |
/* Process Locked */
|
|
491 |
__HAL_LOCK(hsmartcard);
|
|
492 |
|
|
493 |
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX;
|
|
494 |
|
|
495 |
/* Init tickstart for timeout managment*/
|
|
496 |
tickstart = HAL_GetTick();
|
|
497 |
|
|
498 |
/* Disable the Peripheral first to update mode for TX master */
|
|
499 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
500 |
|
|
501 |
/* Disable Rx, enable Tx */
|
|
502 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
|
|
503 |
SET_BIT(hsmartcard->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST);
|
|
504 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
|
|
505 |
|
|
506 |
/* Enable the Peripheral */
|
|
507 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
508 |
|
|
509 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
510 |
hsmartcard->TxXferSize = Size;
|
|
511 |
hsmartcard->TxXferCount = Size;
|
|
512 |
|
|
513 |
while(hsmartcard->TxXferCount > 0U)
|
|
514 |
{
|
|
515 |
hsmartcard->TxXferCount--;
|
|
516 |
if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
|
|
517 |
{
|
|
518 |
return HAL_TIMEOUT;
|
|
519 |
}
|
|
520 |
hsmartcard->Instance->TDR = (*pData++ & (uint8_t)0xFFU);
|
|
521 |
}
|
|
522 |
if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
|
|
523 |
{
|
|
524 |
return HAL_TIMEOUT;
|
|
525 |
}
|
|
526 |
/* Re-enable Rx at end of transmission if initial mode is Rx/Tx */
|
|
527 |
if(hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
|
|
528 |
{
|
|
529 |
/* Disable the Peripheral first to update modes */
|
|
530 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
531 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
|
|
532 |
/* Enable the Peripheral */
|
|
533 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
534 |
}
|
|
535 |
|
|
536 |
/* At end of Tx process, restore hsmartcard->gState to Ready */
|
|
537 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
538 |
|
|
539 |
/* Process Unlocked */
|
|
540 |
__HAL_UNLOCK(hsmartcard);
|
|
541 |
|
|
542 |
return HAL_OK;
|
|
543 |
}
|
|
544 |
else
|
|
545 |
{
|
|
546 |
return HAL_BUSY;
|
|
547 |
}
|
|
548 |
}
|
|
549 |
|
|
550 |
/**
|
|
551 |
* @brief Receive an amount of data in blocking mode.
|
|
552 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
553 |
* the configuration information for the specified SMARTCARD module.
|
|
554 |
* @param pData pointer to data buffer.
|
|
555 |
* @param Size amount of data to be received.
|
|
556 |
* @param Timeout Timeout duration.
|
|
557 |
* @retval HAL status
|
|
558 |
*/
|
|
559 |
HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout)
|
|
560 |
{
|
|
561 |
uint32_t tickstart = 0U;
|
|
562 |
|
|
563 |
/* Check that a Rx process is not already ongoing */
|
|
564 |
if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
|
|
565 |
{
|
|
566 |
if((pData == NULL) || (Size == 0U))
|
|
567 |
{
|
|
568 |
return HAL_ERROR;
|
|
569 |
}
|
|
570 |
|
|
571 |
/* Process Locked */
|
|
572 |
__HAL_LOCK(hsmartcard);
|
|
573 |
|
|
574 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
575 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
|
|
576 |
|
|
577 |
/* Init tickstart for timeout managment*/
|
|
578 |
tickstart = HAL_GetTick();
|
|
579 |
|
|
580 |
hsmartcard->RxXferSize = Size;
|
|
581 |
hsmartcard->RxXferCount = Size;
|
|
582 |
|
|
583 |
/* Check the remain data to be received */
|
|
584 |
while(hsmartcard->RxXferCount > 0U)
|
|
585 |
{
|
|
586 |
hsmartcard->RxXferCount--;
|
|
587 |
|
|
588 |
if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
|
|
589 |
{
|
|
590 |
return HAL_TIMEOUT;
|
|
591 |
}
|
|
592 |
*pData++ = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0x00FFU);
|
|
593 |
}
|
|
594 |
|
|
595 |
/* At end of Rx process, restore hsmartcard->RxState to Ready */
|
|
596 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
597 |
|
|
598 |
/* Process Unlocked */
|
|
599 |
__HAL_UNLOCK(hsmartcard);
|
|
600 |
|
|
601 |
return HAL_OK;
|
|
602 |
}
|
|
603 |
else
|
|
604 |
{
|
|
605 |
return HAL_BUSY;
|
|
606 |
}
|
|
607 |
}
|
|
608 |
|
|
609 |
/**
|
|
610 |
* @brief Send an amount of data in interrupt mode.
|
|
611 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
612 |
* the configuration information for the specified SMARTCARD module.
|
|
613 |
* @param pData pointer to data buffer.
|
|
614 |
* @param Size amount of data to be sent.
|
|
615 |
* @retval HAL status
|
|
616 |
*/
|
|
617 |
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
|
|
618 |
{
|
|
619 |
/* Check that a Tx process is not already ongoing */
|
|
620 |
if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
|
621 |
{
|
|
622 |
if((pData == NULL) || (Size == 0))
|
|
623 |
{
|
|
624 |
return HAL_ERROR;
|
|
625 |
}
|
|
626 |
|
|
627 |
/* Process Locked */
|
|
628 |
__HAL_LOCK(hsmartcard);
|
|
629 |
|
|
630 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
631 |
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX;
|
|
632 |
|
|
633 |
hsmartcard->pTxBuffPtr = pData;
|
|
634 |
hsmartcard->TxXferSize = Size;
|
|
635 |
hsmartcard->TxXferCount = Size;
|
|
636 |
|
|
637 |
/* Disable the Peripheral first to update mode for TX master */
|
|
638 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
639 |
|
|
640 |
/* Disable Rx, enable Tx */
|
|
641 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
|
|
642 |
SET_BIT(hsmartcard->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST);
|
|
643 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
|
|
644 |
|
|
645 |
/* Enable the Peripheral */
|
|
646 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
647 |
|
|
648 |
/* Process Unlocked */
|
|
649 |
__HAL_UNLOCK(hsmartcard);
|
|
650 |
|
|
651 |
/* Enable the SMARTCARD Error Interrupt: (Frame error) */
|
|
652 |
SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
653 |
|
|
654 |
/* Enable the SMARTCARD Transmit Data Register Empty Interrupt */
|
|
655 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE);
|
|
656 |
|
|
657 |
return HAL_OK;
|
|
658 |
}
|
|
659 |
else
|
|
660 |
{
|
|
661 |
return HAL_BUSY;
|
|
662 |
}
|
|
663 |
}
|
|
664 |
|
|
665 |
/**
|
|
666 |
* @brief Receive an amount of data in interrupt mode.
|
|
667 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
668 |
* the configuration information for the specified SMARTCARD module.
|
|
669 |
* @param pData pointer to data buffer.
|
|
670 |
* @param Size amount of data to be received.
|
|
671 |
* @retval HAL status
|
|
672 |
*/
|
|
673 |
HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
|
|
674 |
{
|
|
675 |
/* Check that a Rx process is not already ongoing */
|
|
676 |
if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
|
|
677 |
{
|
|
678 |
if((pData == NULL) || (Size == 0U))
|
|
679 |
{
|
|
680 |
return HAL_ERROR;
|
|
681 |
}
|
|
682 |
|
|
683 |
/* Process Locked */
|
|
684 |
__HAL_LOCK(hsmartcard);
|
|
685 |
|
|
686 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
687 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
|
|
688 |
|
|
689 |
hsmartcard->pRxBuffPtr = pData;
|
|
690 |
hsmartcard->RxXferSize = Size;
|
|
691 |
hsmartcard->RxXferCount = Size;
|
|
692 |
|
|
693 |
/* Process Unlocked */
|
|
694 |
__HAL_UNLOCK(hsmartcard);
|
|
695 |
|
|
696 |
/* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */
|
|
697 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE| USART_CR1_RXNEIE);
|
|
698 |
|
|
699 |
/* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
|
|
700 |
SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
701 |
|
|
702 |
return HAL_OK;
|
|
703 |
}
|
|
704 |
else
|
|
705 |
{
|
|
706 |
return HAL_BUSY;
|
|
707 |
}
|
|
708 |
}
|
|
709 |
|
|
710 |
/**
|
|
711 |
* @brief Send an amount of data in DMA mode.
|
|
712 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
713 |
* the configuration information for the specified SMARTCARD module.
|
|
714 |
* @param pData pointer to data buffer.
|
|
715 |
* @param Size amount of data to be sent.
|
|
716 |
* @retval HAL status
|
|
717 |
*/
|
|
718 |
HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
|
|
719 |
{
|
|
720 |
/* Check that a Tx process is not already ongoing */
|
|
721 |
if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
|
722 |
{
|
|
723 |
if((pData == NULL) || (Size == 0U))
|
|
724 |
{
|
|
725 |
return HAL_ERROR;
|
|
726 |
}
|
|
727 |
|
|
728 |
/* Process Locked */
|
|
729 |
__HAL_LOCK(hsmartcard);
|
|
730 |
|
|
731 |
hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX;
|
|
732 |
|
|
733 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
734 |
hsmartcard->pTxBuffPtr = pData;
|
|
735 |
hsmartcard->TxXferSize = Size;
|
|
736 |
hsmartcard->TxXferCount = Size;
|
|
737 |
|
|
738 |
/* Disable the Peripheral first to update mode for TX master */
|
|
739 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
740 |
|
|
741 |
/* Disable Rx, enable Tx */
|
|
742 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
|
|
743 |
SET_BIT(hsmartcard->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST);
|
|
744 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE);
|
|
745 |
|
|
746 |
/* Enable the Peripheral */
|
|
747 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
748 |
|
|
749 |
/* Set the SMARTCARD DMA transfer complete callback */
|
|
750 |
hsmartcard->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt;
|
|
751 |
|
|
752 |
/* Set the SMARTCARD error callback */
|
|
753 |
hsmartcard->hdmatx->XferErrorCallback = SMARTCARD_DMAError;
|
|
754 |
|
|
755 |
/* Set the DMA abort callback */
|
|
756 |
hsmartcard->hdmatx->XferAbortCallback = NULL;
|
|
757 |
|
|
758 |
/* Enable the SMARTCARD transmit DMA channel */
|
|
759 |
HAL_DMA_Start_IT(hsmartcard->hdmatx, (uint32_t)hsmartcard->pTxBuffPtr, (uint32_t)&hsmartcard->Instance->TDR, Size);
|
|
760 |
|
|
761 |
/* Clear the TC flag in the ICR register */
|
|
762 |
CLEAR_BIT(hsmartcard->Instance->ICR, USART_ICR_TCCF);
|
|
763 |
|
|
764 |
/* Process Unlocked */
|
|
765 |
__HAL_UNLOCK(hsmartcard);
|
|
766 |
|
|
767 |
/* Enable the UART Error Interrupt: (Frame error) */
|
|
768 |
SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
769 |
|
|
770 |
/* Enable the DMA transfer for transmit request by setting the DMAT bit
|
|
771 |
in the SMARTCARD associated USART CR3 register */
|
|
772 |
SET_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
|
|
773 |
|
|
774 |
return HAL_OK;
|
|
775 |
}
|
|
776 |
else
|
|
777 |
{
|
|
778 |
return HAL_BUSY;
|
|
779 |
}
|
|
780 |
}
|
|
781 |
|
|
782 |
/**
|
|
783 |
* @brief Receive an amount of data in DMA mode.
|
|
784 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
785 |
* the configuration information for the specified SMARTCARD module.
|
|
786 |
* @param pData pointer to data buffer.
|
|
787 |
* @param Size amount of data to be received.
|
|
788 |
* @note The SMARTCARD-associated USART parity is enabled (PCE = 1),
|
|
789 |
* the received data contain the parity bit (MSB position).
|
|
790 |
* @retval HAL status
|
|
791 |
*/
|
|
792 |
HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size)
|
|
793 |
{
|
|
794 |
/* Check that a Rx process is not already ongoing */
|
|
795 |
if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
|
|
796 |
{
|
|
797 |
if((pData == NULL) || (Size == 0U))
|
|
798 |
{
|
|
799 |
return HAL_ERROR;
|
|
800 |
}
|
|
801 |
|
|
802 |
/* Process Locked */
|
|
803 |
__HAL_LOCK(hsmartcard);
|
|
804 |
|
|
805 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
806 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
|
|
807 |
|
|
808 |
hsmartcard->pRxBuffPtr = pData;
|
|
809 |
hsmartcard->RxXferSize = Size;
|
|
810 |
|
|
811 |
/* Set the SMARTCARD DMA transfer complete callback */
|
|
812 |
hsmartcard->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt;
|
|
813 |
|
|
814 |
/* Set the SMARTCARD DMA error callback */
|
|
815 |
hsmartcard->hdmarx->XferErrorCallback = SMARTCARD_DMAError;
|
|
816 |
|
|
817 |
/* Set the DMA abort callback */
|
|
818 |
hsmartcard->hdmarx->XferAbortCallback = NULL;
|
|
819 |
|
|
820 |
/* Enable the DMA channel */
|
|
821 |
HAL_DMA_Start_IT(hsmartcard->hdmarx, (uint32_t)&hsmartcard->Instance->RDR, (uint32_t)hsmartcard->pRxBuffPtr, Size);
|
|
822 |
|
|
823 |
/* Process Unlocked */
|
|
824 |
__HAL_UNLOCK(hsmartcard);
|
|
825 |
|
|
826 |
/* Enable the UART Parity Error Interrupt */
|
|
827 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
|
|
828 |
|
|
829 |
/* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */
|
|
830 |
SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
831 |
|
|
832 |
/* Enable the DMA transfer for the receiver request by setting the DMAR bit
|
|
833 |
in the SMARTCARD associated USART CR3 register */
|
|
834 |
SET_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
|
|
835 |
|
|
836 |
return HAL_OK;
|
|
837 |
}
|
|
838 |
else
|
|
839 |
{
|
|
840 |
return HAL_BUSY;
|
|
841 |
}
|
|
842 |
}
|
|
843 |
|
|
844 |
/**
|
|
845 |
* @brief Abort ongoing transfers (blocking mode).
|
|
846 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
847 |
* the configuration information for the specified SMARTCARD module.
|
|
848 |
* @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
|
|
849 |
* This procedure performs following operations :
|
|
850 |
* - Disable SMARTCARD Interrupts (Tx and Rx)
|
|
851 |
* - Disable the DMA transfer in the peripheral register (if enabled)
|
|
852 |
* - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
|
|
853 |
* - Set handle State to READY
|
|
854 |
* @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
|
|
855 |
* @retval HAL status
|
|
856 |
*/
|
|
857 |
HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
858 |
{
|
|
859 |
/* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
|
|
860 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
|
|
861 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
862 |
|
|
863 |
/* Disable the SMARTCARD DMA Tx request if enabled */
|
|
864 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
|
|
865 |
{
|
|
866 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
|
|
867 |
|
|
868 |
/* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */
|
|
869 |
if(hsmartcard->hdmatx != NULL)
|
|
870 |
{
|
|
871 |
/* Set the SMARTCARD DMA Abort callback to Null.
|
|
872 |
No call back execution at end of DMA abort procedure */
|
|
873 |
hsmartcard->hdmatx->XferAbortCallback = NULL;
|
|
874 |
|
|
875 |
HAL_DMA_Abort(hsmartcard->hdmatx);
|
|
876 |
}
|
|
877 |
}
|
|
878 |
|
|
879 |
/* Disable the SMARTCARD DMA Rx request if enabled */
|
|
880 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
|
|
881 |
{
|
|
882 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
|
|
883 |
|
|
884 |
/* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */
|
|
885 |
if(hsmartcard->hdmarx != NULL)
|
|
886 |
{
|
|
887 |
/* Set the SMARTCARD DMA Abort callback to Null.
|
|
888 |
No call back execution at end of DMA abort procedure */
|
|
889 |
hsmartcard->hdmarx->XferAbortCallback = NULL;
|
|
890 |
|
|
891 |
HAL_DMA_Abort(hsmartcard->hdmarx);
|
|
892 |
}
|
|
893 |
}
|
|
894 |
|
|
895 |
/* Reset Tx and Rx transfer counters */
|
|
896 |
hsmartcard->TxXferCount = 0U;
|
|
897 |
hsmartcard->RxXferCount = 0U;
|
|
898 |
|
|
899 |
/* Clear the Error flags in the ICR register */
|
|
900 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
901 |
|
|
902 |
/* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
|
|
903 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
904 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
905 |
|
|
906 |
/* Reset Handle ErrorCode to No Error */
|
|
907 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
908 |
|
|
909 |
return HAL_OK;
|
|
910 |
}
|
|
911 |
|
|
912 |
/**
|
|
913 |
* @brief Abort ongoing Transmit transfer (blocking mode).
|
|
914 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
915 |
* the configuration information for the specified SMARTCARD module.
|
|
916 |
* @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode.
|
|
917 |
* This procedure performs following operations :
|
|
918 |
* - Disable SMARTCARD Interrupts (Tx)
|
|
919 |
* - Disable the DMA transfer in the peripheral register (if enabled)
|
|
920 |
* - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
|
|
921 |
* - Set handle State to READY
|
|
922 |
* @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
|
|
923 |
* @retval HAL status
|
|
924 |
*/
|
|
925 |
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
926 |
{
|
|
927 |
/* Disable TXEIE and TCIE interrupts */
|
|
928 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
|
|
929 |
|
|
930 |
/* Check if a receive process is ongoing or not. If not disable ERR IT */
|
|
931 |
if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
|
|
932 |
{
|
|
933 |
/* Disable the SMARTCARD Error Interrupt: (Frame error) */
|
|
934 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
935 |
}
|
|
936 |
|
|
937 |
/* Disable the SMARTCARD DMA Tx request if enabled */
|
|
938 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
|
|
939 |
{
|
|
940 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
|
|
941 |
|
|
942 |
/* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */
|
|
943 |
if(hsmartcard->hdmatx != NULL)
|
|
944 |
{
|
|
945 |
/* Set the SMARTCARD DMA Abort callback to Null.
|
|
946 |
No call back execution at end of DMA abort procedure */
|
|
947 |
hsmartcard->hdmatx->XferAbortCallback = NULL;
|
|
948 |
|
|
949 |
HAL_DMA_Abort(hsmartcard->hdmatx);
|
|
950 |
}
|
|
951 |
}
|
|
952 |
|
|
953 |
/* Reset Tx transfer counter */
|
|
954 |
hsmartcard->TxXferCount = 0U;
|
|
955 |
|
|
956 |
/* Clear the Error flags in the ICR register */
|
|
957 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF);
|
|
958 |
|
|
959 |
/* Restore hsmartcard->gState to Ready */
|
|
960 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
961 |
|
|
962 |
return HAL_OK;
|
|
963 |
}
|
|
964 |
|
|
965 |
/**
|
|
966 |
* @brief Abort ongoing Receive transfer (blocking mode).
|
|
967 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
968 |
* the configuration information for the specified SMARTCARD module.
|
|
969 |
* @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode.
|
|
970 |
* This procedure performs following operations :
|
|
971 |
* - Disable SMARTCARD Interrupts (Rx)
|
|
972 |
* - Disable the DMA transfer in the peripheral register (if enabled)
|
|
973 |
* - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
|
|
974 |
* - Set handle State to READY
|
|
975 |
* @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
|
|
976 |
* @retval HAL status
|
|
977 |
*/
|
|
978 |
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
979 |
{
|
|
980 |
/* Disable RTOIE, EOBIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
|
|
981 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
|
|
982 |
|
|
983 |
/* Check if a Transmit process is ongoing or not. If not disable ERR IT */
|
|
984 |
if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
|
985 |
{
|
|
986 |
/* Disable the SMARTCARD Error Interrupt: (Frame error) */
|
|
987 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
988 |
}
|
|
989 |
|
|
990 |
/* Disable the SMARTCARD DMA Rx request if enabled */
|
|
991 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
|
|
992 |
{
|
|
993 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
|
|
994 |
|
|
995 |
/* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */
|
|
996 |
if(hsmartcard->hdmarx != NULL)
|
|
997 |
{
|
|
998 |
/* Set the SMARTCARD DMA Abort callback to Null.
|
|
999 |
No call back execution at end of DMA abort procedure */
|
|
1000 |
hsmartcard->hdmarx->XferAbortCallback = NULL;
|
|
1001 |
|
|
1002 |
HAL_DMA_Abort(hsmartcard->hdmarx);
|
|
1003 |
}
|
|
1004 |
}
|
|
1005 |
|
|
1006 |
/* Reset Rx transfer counter */
|
|
1007 |
hsmartcard->RxXferCount = 0U;
|
|
1008 |
|
|
1009 |
/* Clear the Error flags in the ICR register */
|
|
1010 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
1011 |
|
|
1012 |
/* Restore hsmartcard->RxState to Ready */
|
|
1013 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1014 |
|
|
1015 |
return HAL_OK;
|
|
1016 |
}
|
|
1017 |
|
|
1018 |
/**
|
|
1019 |
* @brief Abort ongoing transfers (Interrupt mode).
|
|
1020 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1021 |
* the configuration information for the specified SMARTCARD module.
|
|
1022 |
* @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
|
|
1023 |
* This procedure performs following operations :
|
|
1024 |
* - Disable SMARTCARD Interrupts (Tx and Rx)
|
|
1025 |
* - Disable the DMA transfer in the peripheral register (if enabled)
|
|
1026 |
* - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
|
|
1027 |
* - Set handle State to READY
|
|
1028 |
* - At abort completion, call user abort complete callback
|
|
1029 |
* @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
|
|
1030 |
* considered as completed only when user abort complete callback is executed (not when exiting function).
|
|
1031 |
* @retval HAL status
|
|
1032 |
*/
|
|
1033 |
HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1034 |
{
|
|
1035 |
uint32_t abortcplt = 1U;
|
|
1036 |
|
|
1037 |
/* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
|
|
1038 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
|
|
1039 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
1040 |
|
|
1041 |
/* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised
|
|
1042 |
before any call to DMA Abort functions */
|
|
1043 |
/* DMA Tx Handle is valid */
|
|
1044 |
if(hsmartcard->hdmatx != NULL)
|
|
1045 |
{
|
|
1046 |
/* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled.
|
|
1047 |
Otherwise, set it to NULL */
|
|
1048 |
if(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
|
|
1049 |
{
|
|
1050 |
hsmartcard->hdmatx->XferAbortCallback = SMARTCARD_DMATxAbortCallback;
|
|
1051 |
}
|
|
1052 |
else
|
|
1053 |
{
|
|
1054 |
hsmartcard->hdmatx->XferAbortCallback = NULL;
|
|
1055 |
}
|
|
1056 |
}
|
|
1057 |
/* DMA Rx Handle is valid */
|
|
1058 |
if(hsmartcard->hdmarx != NULL)
|
|
1059 |
{
|
|
1060 |
/* Set DMA Abort Complete callback if SMARTCARD DMA Rx request if enabled.
|
|
1061 |
Otherwise, set it to NULL */
|
|
1062 |
if(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
|
|
1063 |
{
|
|
1064 |
hsmartcard->hdmarx->XferAbortCallback = SMARTCARD_DMARxAbortCallback;
|
|
1065 |
}
|
|
1066 |
else
|
|
1067 |
{
|
|
1068 |
hsmartcard->hdmarx->XferAbortCallback = NULL;
|
|
1069 |
}
|
|
1070 |
}
|
|
1071 |
|
|
1072 |
/* Disable the SMARTCARD DMA Tx request if enabled */
|
|
1073 |
if(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
|
|
1074 |
{
|
|
1075 |
/* Disable DMA Tx at UART level */
|
|
1076 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
|
|
1077 |
|
|
1078 |
/* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */
|
|
1079 |
if(hsmartcard->hdmatx != NULL)
|
|
1080 |
{
|
|
1081 |
/* SMARTCARD Tx DMA Abort callback has already been initialised :
|
|
1082 |
will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
|
|
1083 |
|
|
1084 |
/* Abort DMA TX */
|
|
1085 |
if(HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK)
|
|
1086 |
{
|
|
1087 |
hsmartcard->hdmatx->XferAbortCallback = NULL;
|
|
1088 |
}
|
|
1089 |
else
|
|
1090 |
{
|
|
1091 |
abortcplt = 0U;
|
|
1092 |
}
|
|
1093 |
}
|
|
1094 |
}
|
|
1095 |
|
|
1096 |
/* Disable the SMARTCARD DMA Rx request if enabled */
|
|
1097 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
|
|
1098 |
{
|
|
1099 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
|
|
1100 |
|
|
1101 |
/* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */
|
|
1102 |
if(hsmartcard->hdmarx != NULL)
|
|
1103 |
{
|
|
1104 |
/* SMARTCARD Rx DMA Abort callback has already been initialised :
|
|
1105 |
will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
|
|
1106 |
|
|
1107 |
/* Abort DMA RX */
|
|
1108 |
if(HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK)
|
|
1109 |
{
|
|
1110 |
hsmartcard->hdmarx->XferAbortCallback = NULL;
|
|
1111 |
abortcplt = 1U;
|
|
1112 |
}
|
|
1113 |
else
|
|
1114 |
{
|
|
1115 |
abortcplt = 0U;
|
|
1116 |
}
|
|
1117 |
}
|
|
1118 |
}
|
|
1119 |
|
|
1120 |
/* if no DMA abort complete callback execution is required => call user Abort Complete callback */
|
|
1121 |
if (abortcplt == 1U)
|
|
1122 |
{
|
|
1123 |
/* Reset Tx and Rx transfer counters */
|
|
1124 |
hsmartcard->TxXferCount = 0U;
|
|
1125 |
hsmartcard->RxXferCount = 0U;
|
|
1126 |
|
|
1127 |
/* Reset errorCode */
|
|
1128 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
1129 |
|
|
1130 |
/* Clear the Error flags in the ICR register */
|
|
1131 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
1132 |
|
|
1133 |
/* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
|
|
1134 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
1135 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1136 |
|
|
1137 |
/* As no DMA to be aborted, call directly user Abort complete callback */
|
|
1138 |
HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
|
|
1139 |
}
|
|
1140 |
|
|
1141 |
return HAL_OK;
|
|
1142 |
}
|
|
1143 |
|
|
1144 |
/**
|
|
1145 |
* @brief Abort ongoing Transmit transfer (Interrupt mode).
|
|
1146 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1147 |
* the configuration information for the specified SMARTCARD module.
|
|
1148 |
* @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode.
|
|
1149 |
* This procedure performs following operations :
|
|
1150 |
* - Disable SMARTCARD Interrupts (Tx)
|
|
1151 |
* - Disable the DMA transfer in the peripheral register (if enabled)
|
|
1152 |
* - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
|
|
1153 |
* - Set handle State to READY
|
|
1154 |
* - At abort completion, call user abort complete callback
|
|
1155 |
* @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
|
|
1156 |
* considered as completed only when user abort complete callback is executed (not when exiting function).
|
|
1157 |
* @retval HAL status
|
|
1158 |
*/
|
|
1159 |
HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1160 |
{
|
|
1161 |
/* Disable TXEIE and TCIE interrupts */
|
|
1162 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
|
|
1163 |
|
|
1164 |
/* Check if a receive process is ongoing or not. If not disable ERR IT */
|
|
1165 |
if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
|
|
1166 |
{
|
|
1167 |
/* Disable the SMARTCARD Error Interrupt: (Frame error) */
|
|
1168 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
1169 |
}
|
|
1170 |
|
|
1171 |
/* Disable the SMARTCARD DMA Tx request if enabled */
|
|
1172 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
|
|
1173 |
{
|
|
1174 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
|
|
1175 |
|
|
1176 |
/* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */
|
|
1177 |
if(hsmartcard->hdmatx != NULL)
|
|
1178 |
{
|
|
1179 |
/* Set the SMARTCARD DMA Abort callback :
|
|
1180 |
will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
|
|
1181 |
hsmartcard->hdmatx->XferAbortCallback = SMARTCARD_DMATxOnlyAbortCallback;
|
|
1182 |
|
|
1183 |
/* Abort DMA TX */
|
|
1184 |
if(HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK)
|
|
1185 |
{
|
|
1186 |
/* Call Directly hsmartcard->hdmatx->XferAbortCallback function in case of error */
|
|
1187 |
hsmartcard->hdmatx->XferAbortCallback(hsmartcard->hdmatx);
|
|
1188 |
}
|
|
1189 |
}
|
|
1190 |
else
|
|
1191 |
{
|
|
1192 |
/* Reset Tx transfer counter */
|
|
1193 |
hsmartcard->TxXferCount = 0U;
|
|
1194 |
|
|
1195 |
/* Restore hsmartcard->gState to Ready */
|
|
1196 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
1197 |
|
|
1198 |
/* As no DMA to be aborted, call directly user Abort complete callback */
|
|
1199 |
HAL_SMARTCARD_AbortTransmitCpltCallback(hsmartcard);
|
|
1200 |
}
|
|
1201 |
}
|
|
1202 |
else
|
|
1203 |
{
|
|
1204 |
/* Reset Tx transfer counter */
|
|
1205 |
hsmartcard->TxXferCount = 0U;
|
|
1206 |
|
|
1207 |
/* Clear the Error flags in the ICR register */
|
|
1208 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF);
|
|
1209 |
|
|
1210 |
/* Restore hsmartcard->gState to Ready */
|
|
1211 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
1212 |
|
|
1213 |
/* As no DMA to be aborted, call directly user Abort complete callback */
|
|
1214 |
HAL_SMARTCARD_AbortTransmitCpltCallback(hsmartcard);
|
|
1215 |
}
|
|
1216 |
|
|
1217 |
return HAL_OK;
|
|
1218 |
}
|
|
1219 |
|
|
1220 |
/**
|
|
1221 |
* @brief Abort ongoing Receive transfer (Interrupt mode).
|
|
1222 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1223 |
* the configuration information for the specified SMARTCARD module.
|
|
1224 |
* @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode.
|
|
1225 |
* This procedure performs following operations :
|
|
1226 |
* - Disable SMARTCARD Interrupts (Rx)
|
|
1227 |
* - Disable the DMA transfer in the peripheral register (if enabled)
|
|
1228 |
* - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
|
|
1229 |
* - Set handle State to READY
|
|
1230 |
* - At abort completion, call user abort complete callback
|
|
1231 |
* @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
|
|
1232 |
* considered as completed only when user abort complete callback is executed (not when exiting function).
|
|
1233 |
* @retval HAL status
|
|
1234 |
*/
|
|
1235 |
HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1236 |
{
|
|
1237 |
/* Disable RTOIE, EOBIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
|
|
1238 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE));
|
|
1239 |
|
|
1240 |
/* Check if a Transmit process is ongoing or not. If not disable ERR IT */
|
|
1241 |
if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
|
1242 |
{
|
|
1243 |
/* Disable the SMARTCARD Error Interrupt: (Frame error) */
|
|
1244 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
1245 |
}
|
|
1246 |
|
|
1247 |
/* Disable the SMARTCARD DMA Rx request if enabled */
|
|
1248 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
|
|
1249 |
{
|
|
1250 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
|
|
1251 |
|
|
1252 |
/* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */
|
|
1253 |
if(hsmartcard->hdmarx != NULL)
|
|
1254 |
{
|
|
1255 |
/* Set the SMARTCARD DMA Abort callback :
|
|
1256 |
will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
|
|
1257 |
hsmartcard->hdmarx->XferAbortCallback = SMARTCARD_DMARxOnlyAbortCallback;
|
|
1258 |
|
|
1259 |
/* Abort DMA RX */
|
|
1260 |
if(HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK)
|
|
1261 |
{
|
|
1262 |
/* Call Directly hsmartcard->hdmarx->XferAbortCallback function in case of error */
|
|
1263 |
hsmartcard->hdmarx->XferAbortCallback(hsmartcard->hdmarx);
|
|
1264 |
}
|
|
1265 |
}
|
|
1266 |
else
|
|
1267 |
{
|
|
1268 |
/* Reset Rx transfer counter */
|
|
1269 |
hsmartcard->RxXferCount = 0U;
|
|
1270 |
|
|
1271 |
/* Clear the Error flags in the ICR register */
|
|
1272 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
1273 |
|
|
1274 |
/* Restore hsmartcard->RxState to Ready */
|
|
1275 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1276 |
|
|
1277 |
/* As no DMA to be aborted, call directly user Abort complete callback */
|
|
1278 |
HAL_SMARTCARD_AbortReceiveCpltCallback(hsmartcard);
|
|
1279 |
}
|
|
1280 |
}
|
|
1281 |
else
|
|
1282 |
{
|
|
1283 |
/* Reset Rx transfer counter */
|
|
1284 |
hsmartcard->RxXferCount = 0U;
|
|
1285 |
|
|
1286 |
/* Clear the Error flags in the ICR register */
|
|
1287 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
1288 |
|
|
1289 |
/* Restore hsmartcard->RxState to Ready */
|
|
1290 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1291 |
|
|
1292 |
/* As no DMA to be aborted, call directly user Abort complete callback */
|
|
1293 |
HAL_SMARTCARD_AbortReceiveCpltCallback(hsmartcard);
|
|
1294 |
}
|
|
1295 |
|
|
1296 |
return HAL_OK;
|
|
1297 |
}
|
|
1298 |
|
|
1299 |
/**
|
|
1300 |
* @brief Handle SMARTCARD interrupt requests.
|
|
1301 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1302 |
* the configuration information for the specified SMARTCARD module.
|
|
1303 |
* @retval None
|
|
1304 |
*/
|
|
1305 |
void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1306 |
{
|
|
1307 |
uint32_t isrflags = READ_REG(hsmartcard->Instance->ISR);
|
|
1308 |
uint32_t cr1its = READ_REG(hsmartcard->Instance->CR1);
|
|
1309 |
uint32_t cr3its;
|
|
1310 |
uint32_t errorflags;
|
|
1311 |
|
|
1312 |
/* If no error occurs */
|
|
1313 |
errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE | USART_ISR_RTOF));
|
|
1314 |
if (errorflags == RESET)
|
|
1315 |
{
|
|
1316 |
/* SMARTCARD in mode Receiver ---------------------------------------------------*/
|
|
1317 |
if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
|
|
1318 |
{
|
|
1319 |
SMARTCARD_Receive_IT(hsmartcard);
|
|
1320 |
/* Clear RXNE interrupt flag done by reading RDR in SMARTCARD_Receive_IT() */
|
|
1321 |
return;
|
|
1322 |
}
|
|
1323 |
}
|
|
1324 |
|
|
1325 |
/* If some errors occur */
|
|
1326 |
cr3its = READ_REG(hsmartcard->Instance->CR3);
|
|
1327 |
if( (errorflags != RESET)
|
|
1328 |
&& ( ((cr3its & USART_CR3_EIE) != RESET)
|
|
1329 |
|| ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE)) != RESET)) )
|
|
1330 |
{
|
|
1331 |
/* SMARTCARD parity error interrupt occurred -------------------------------------*/
|
|
1332 |
if(((isrflags & USART_ISR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
|
|
1333 |
{
|
|
1334 |
__HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_PEF);
|
|
1335 |
|
|
1336 |
hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_PE;
|
|
1337 |
}
|
|
1338 |
|
|
1339 |
/* SMARTCARD frame error interrupt occurred --------------------------------------*/
|
|
1340 |
if(((isrflags & USART_ISR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
|
|
1341 |
{
|
|
1342 |
__HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_FEF);
|
|
1343 |
|
|
1344 |
hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_FE;
|
|
1345 |
}
|
|
1346 |
|
|
1347 |
/* SMARTCARD noise error interrupt occurred --------------------------------------*/
|
|
1348 |
if(((isrflags & USART_ISR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
|
|
1349 |
{
|
|
1350 |
__HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_NEF);
|
|
1351 |
|
|
1352 |
hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_NE;
|
|
1353 |
}
|
|
1354 |
|
|
1355 |
/* SMARTCARD Over-Run interrupt occurred -----------------------------------------*/
|
|
1356 |
if(((isrflags & USART_ISR_ORE) != RESET) &&
|
|
1357 |
(((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET)))
|
|
1358 |
{
|
|
1359 |
__HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_OREF);
|
|
1360 |
|
|
1361 |
hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_ORE;
|
|
1362 |
}
|
|
1363 |
|
|
1364 |
/* SMARTCARD receiver timeout interrupt occurred -----------------------------------------*/
|
|
1365 |
if(((isrflags & USART_ISR_RTOF) != RESET) && ((cr1its & USART_CR1_RTOIE) != RESET))
|
|
1366 |
{
|
|
1367 |
__HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_RTOF);
|
|
1368 |
|
|
1369 |
hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_RTO;
|
|
1370 |
}
|
|
1371 |
|
|
1372 |
/* Call SMARTCARD Error Call back function if need be --------------------------*/
|
|
1373 |
if(hsmartcard->ErrorCode != HAL_SMARTCARD_ERROR_NONE)
|
|
1374 |
{
|
|
1375 |
/* SMARTCARD in mode Receiver ---------------------------------------------------*/
|
|
1376 |
if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
|
|
1377 |
{
|
|
1378 |
SMARTCARD_Receive_IT(hsmartcard);
|
|
1379 |
}
|
|
1380 |
|
|
1381 |
/* If Error is to be considered as blocking :
|
|
1382 |
- Receiver Timeout error in Reception
|
|
1383 |
- Overrun error in Reception
|
|
1384 |
- any error occurs in DMA mode reception
|
|
1385 |
*/
|
|
1386 |
if ( ((hsmartcard->ErrorCode & (HAL_SMARTCARD_ERROR_RTO | HAL_SMARTCARD_ERROR_ORE)) != RESET)
|
|
1387 |
|| (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)))
|
|
1388 |
{
|
|
1389 |
/* Blocking error : transfer is aborted
|
|
1390 |
Set the SMARTCARD state ready to be able to start again the process,
|
|
1391 |
Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
|
|
1392 |
SMARTCARD_EndRxTransfer(hsmartcard);
|
|
1393 |
|
|
1394 |
/* Disable the SMARTCARD DMA Rx request if enabled */
|
|
1395 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))
|
|
1396 |
{
|
|
1397 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
|
|
1398 |
|
|
1399 |
/* Abort the SMARTCARD DMA Rx channel */
|
|
1400 |
if(hsmartcard->hdmarx != NULL)
|
|
1401 |
{
|
|
1402 |
/* Set the SMARTCARD DMA Abort callback :
|
|
1403 |
will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */
|
|
1404 |
hsmartcard->hdmarx->XferAbortCallback = SMARTCARD_DMAAbortOnError;
|
|
1405 |
|
|
1406 |
/* Abort DMA RX */
|
|
1407 |
if(HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK)
|
|
1408 |
{
|
|
1409 |
/* Call Directly hsmartcard->hdmarx->XferAbortCallback function in case of error */
|
|
1410 |
hsmartcard->hdmarx->XferAbortCallback(hsmartcard->hdmarx);
|
|
1411 |
}
|
|
1412 |
}
|
|
1413 |
else
|
|
1414 |
{
|
|
1415 |
/* Call user error callback */
|
|
1416 |
HAL_SMARTCARD_ErrorCallback(hsmartcard);
|
|
1417 |
}
|
|
1418 |
}
|
|
1419 |
else
|
|
1420 |
{
|
|
1421 |
/* Call user error callback */
|
|
1422 |
HAL_SMARTCARD_ErrorCallback(hsmartcard);
|
|
1423 |
}
|
|
1424 |
}
|
|
1425 |
/* other error type to be considered as blocking :
|
|
1426 |
- Frame error in Transmission
|
|
1427 |
*/
|
|
1428 |
else if ((hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX) && ((hsmartcard->ErrorCode & HAL_SMARTCARD_ERROR_FE) != RESET))
|
|
1429 |
{
|
|
1430 |
/* Blocking error : transfer is aborted
|
|
1431 |
Set the SMARTCARD state ready to be able to start again the process,
|
|
1432 |
Disable Tx Interrupts, and disable Tx DMA request, if ongoing */
|
|
1433 |
SMARTCARD_EndTxTransfer(hsmartcard);
|
|
1434 |
|
|
1435 |
/* Disable the SMARTCARD DMA Tx request if enabled */
|
|
1436 |
if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT))
|
|
1437 |
{
|
|
1438 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
|
|
1439 |
|
|
1440 |
/* Abort the SMARTCARD DMA Tx channel */
|
|
1441 |
if(hsmartcard->hdmatx != NULL)
|
|
1442 |
{
|
|
1443 |
/* Set the SMARTCARD DMA Abort callback :
|
|
1444 |
will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */
|
|
1445 |
hsmartcard->hdmatx->XferAbortCallback = SMARTCARD_DMAAbortOnError;
|
|
1446 |
|
|
1447 |
/* Abort DMA TX */
|
|
1448 |
if(HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK)
|
|
1449 |
{
|
|
1450 |
/* Call Directly hsmartcard->hdmatx->XferAbortCallback function in case of error */
|
|
1451 |
hsmartcard->hdmatx->XferAbortCallback(hsmartcard->hdmatx);
|
|
1452 |
}
|
|
1453 |
}
|
|
1454 |
else
|
|
1455 |
{
|
|
1456 |
/* Call user error callback */
|
|
1457 |
HAL_SMARTCARD_ErrorCallback(hsmartcard);
|
|
1458 |
}
|
|
1459 |
}
|
|
1460 |
else
|
|
1461 |
{
|
|
1462 |
/* Call user error callback */
|
|
1463 |
HAL_SMARTCARD_ErrorCallback(hsmartcard);
|
|
1464 |
}
|
|
1465 |
}
|
|
1466 |
else
|
|
1467 |
{
|
|
1468 |
/* Non Blocking error : transfer could go on.
|
|
1469 |
Error is notified to user through user error callback */
|
|
1470 |
HAL_SMARTCARD_ErrorCallback(hsmartcard);
|
|
1471 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
1472 |
}
|
|
1473 |
}
|
|
1474 |
return;
|
|
1475 |
|
|
1476 |
} /* End if some error occurs */
|
|
1477 |
|
|
1478 |
/* SMARTCARD in mode Receiver, end of block interruption ------------------------*/
|
|
1479 |
if(((isrflags & USART_ISR_EOBF) != RESET) && ((cr1its & USART_CR1_EOBIE) != RESET))
|
|
1480 |
{
|
|
1481 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1482 |
__HAL_UNLOCK(hsmartcard);
|
|
1483 |
HAL_SMARTCARD_RxCpltCallback(hsmartcard);
|
|
1484 |
/* Clear EOBF interrupt after HAL_SMARTCARD_RxCpltCallback() call for the End of Block information
|
|
1485 |
* to be available during HAL_SMARTCARD_RxCpltCallback() processing */
|
|
1486 |
__HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_EOBF);
|
|
1487 |
return;
|
|
1488 |
}
|
|
1489 |
|
|
1490 |
/* SMARTCARD in mode Transmitter ------------------------------------------------*/
|
|
1491 |
if(((isrflags & USART_ISR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
|
|
1492 |
{
|
|
1493 |
SMARTCARD_Transmit_IT(hsmartcard);
|
|
1494 |
return;
|
|
1495 |
}
|
|
1496 |
|
|
1497 |
/* SMARTCARD in mode Transmitter (transmission end) ------------------------*/
|
|
1498 |
if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_TC) != RESET) &&(__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_TC) != RESET))
|
|
1499 |
{
|
|
1500 |
SMARTCARD_EndTransmit_IT(hsmartcard);
|
|
1501 |
return;
|
|
1502 |
}
|
|
1503 |
}
|
|
1504 |
|
|
1505 |
/**
|
|
1506 |
* @brief Tx Transfer completed callback.
|
|
1507 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1508 |
* the configuration information for the specified SMARTCARD module.
|
|
1509 |
* @retval None
|
|
1510 |
*/
|
|
1511 |
__weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1512 |
{
|
|
1513 |
/* Prevent unused argument(s) compilation warning */
|
|
1514 |
UNUSED(hsmartcard);
|
|
1515 |
|
|
1516 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
1517 |
the HAL_SMARTCARD_TxCpltCallback can be implemented in the user file.
|
|
1518 |
*/
|
|
1519 |
}
|
|
1520 |
|
|
1521 |
/**
|
|
1522 |
* @brief Rx Transfer completed callback.
|
|
1523 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1524 |
* the configuration information for the specified SMARTCARD module.
|
|
1525 |
* @retval None
|
|
1526 |
*/
|
|
1527 |
__weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1528 |
{
|
|
1529 |
/* Prevent unused argument(s) compilation warning */
|
|
1530 |
UNUSED(hsmartcard);
|
|
1531 |
|
|
1532 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
1533 |
the HAL_SMARTCARD_RxCpltCallback can be implemented in the user file.
|
|
1534 |
*/
|
|
1535 |
}
|
|
1536 |
|
|
1537 |
/**
|
|
1538 |
* @brief SMARTCARD error callback.
|
|
1539 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1540 |
* the configuration information for the specified SMARTCARD module.
|
|
1541 |
* @retval None
|
|
1542 |
*/
|
|
1543 |
__weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1544 |
{
|
|
1545 |
/* Prevent unused argument(s) compilation warning */
|
|
1546 |
UNUSED(hsmartcard);
|
|
1547 |
|
|
1548 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
1549 |
the HAL_SMARTCARD_ErrorCallback can be implemented in the user file.
|
|
1550 |
*/
|
|
1551 |
}
|
|
1552 |
|
|
1553 |
/**
|
|
1554 |
* @brief SMARTCARD Abort Complete callback.
|
|
1555 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1556 |
* the configuration information for the specified SMARTCARD module.
|
|
1557 |
* @retval None
|
|
1558 |
*/
|
|
1559 |
__weak void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1560 |
{
|
|
1561 |
/* Prevent unused argument(s) compilation warning */
|
|
1562 |
UNUSED(hsmartcard);
|
|
1563 |
|
|
1564 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
1565 |
the HAL_SMARTCARD_AbortCpltCallback can be implemented in the user file.
|
|
1566 |
*/
|
|
1567 |
}
|
|
1568 |
|
|
1569 |
/**
|
|
1570 |
* @brief SMARTCARD Abort Complete callback.
|
|
1571 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1572 |
* the configuration information for the specified SMARTCARD module.
|
|
1573 |
* @retval None
|
|
1574 |
*/
|
|
1575 |
__weak void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1576 |
{
|
|
1577 |
/* Prevent unused argument(s) compilation warning */
|
|
1578 |
UNUSED(hsmartcard);
|
|
1579 |
|
|
1580 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
1581 |
the HAL_SMARTCARD_AbortTransmitCpltCallback can be implemented in the user file.
|
|
1582 |
*/
|
|
1583 |
}
|
|
1584 |
|
|
1585 |
/**
|
|
1586 |
* @brief SMARTCARD Abort Receive Complete callback.
|
|
1587 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1588 |
* the configuration information for the specified SMARTCARD module.
|
|
1589 |
* @retval None
|
|
1590 |
*/
|
|
1591 |
__weak void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1592 |
{
|
|
1593 |
/* Prevent unused argument(s) compilation warning */
|
|
1594 |
UNUSED(hsmartcard);
|
|
1595 |
|
|
1596 |
/* NOTE : This function should not be modified, when the callback is needed,
|
|
1597 |
the HAL_SMARTCARD_AbortReceiveCpltCallback can be implemented in the user file.
|
|
1598 |
*/
|
|
1599 |
}
|
|
1600 |
|
|
1601 |
/**
|
|
1602 |
* @}
|
|
1603 |
*/
|
|
1604 |
|
|
1605 |
/** @defgroup SMARTCARD_Exported_Functions_Group3 Peripheral State and Errors functions
|
|
1606 |
* @brief SMARTCARD State and Errors functions
|
|
1607 |
*
|
|
1608 |
@verbatim
|
|
1609 |
==============================================================================
|
|
1610 |
##### Peripheral State and Errors functions #####
|
|
1611 |
==============================================================================
|
|
1612 |
[..]
|
|
1613 |
This subsection provides a set of functions allowing to return the State of SmartCard
|
|
1614 |
handle and also return Peripheral Errors occurred during communication process
|
|
1615 |
(+) HAL_SMARTCARD_GetState() API can be helpful to check in run-time the state
|
|
1616 |
of the SMARTCARD peripheral.
|
|
1617 |
(+) HAL_SMARTCARD_GetError() checks in run-time errors that could occur during
|
|
1618 |
communication.
|
|
1619 |
|
|
1620 |
@endverbatim
|
|
1621 |
* @{
|
|
1622 |
*/
|
|
1623 |
|
|
1624 |
/**
|
|
1625 |
* @brief Return the SMARTCARD handle state.
|
|
1626 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1627 |
* the configuration information for the specified SMARTCARD module.
|
|
1628 |
* @retval SMARTCARD handle state
|
|
1629 |
*/
|
|
1630 |
HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1631 |
{
|
|
1632 |
/* Return SMARTCARD handle state */
|
|
1633 |
uint32_t temp1= 0x00U, temp2 = 0x00U;
|
|
1634 |
temp1 = hsmartcard->gState;
|
|
1635 |
temp2 = hsmartcard->RxState;
|
|
1636 |
|
|
1637 |
return (HAL_SMARTCARD_StateTypeDef)(temp1 | temp2);
|
|
1638 |
}
|
|
1639 |
|
|
1640 |
/**
|
|
1641 |
* @brief Return the SMARTCARD handle error code.
|
|
1642 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1643 |
* the configuration information for the specified SMARTCARD module.
|
|
1644 |
* @retval SMARTCARD handle Error Code
|
|
1645 |
*/
|
|
1646 |
uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1647 |
{
|
|
1648 |
return hsmartcard->ErrorCode;
|
|
1649 |
}
|
|
1650 |
|
|
1651 |
/**
|
|
1652 |
* @}
|
|
1653 |
*/
|
|
1654 |
|
|
1655 |
/**
|
|
1656 |
* @}
|
|
1657 |
*/
|
|
1658 |
|
|
1659 |
/** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
|
|
1660 |
* @{
|
|
1661 |
*/
|
|
1662 |
|
|
1663 |
/**
|
|
1664 |
* @brief Configure the SMARTCARD associated USART peripheral.
|
|
1665 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1666 |
* the configuration information for the specified SMARTCARD module.
|
|
1667 |
* @retval HAL status
|
|
1668 |
*/
|
|
1669 |
static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1670 |
{
|
|
1671 |
uint32_t tmpreg = 0x00000000U;
|
|
1672 |
SMARTCARD_ClockSourceTypeDef clocksource = SMARTCARD_CLOCKSOURCE_UNDEFINED;
|
|
1673 |
HAL_StatusTypeDef ret = HAL_OK;
|
|
1674 |
|
|
1675 |
/* Check the parameters */
|
|
1676 |
assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance));
|
|
1677 |
assert_param(IS_SMARTCARD_BAUDRATE(hsmartcard->Init.BaudRate));
|
|
1678 |
assert_param(IS_SMARTCARD_WORD_LENGTH(hsmartcard->Init.WordLength));
|
|
1679 |
assert_param(IS_SMARTCARD_STOPBITS(hsmartcard->Init.StopBits));
|
|
1680 |
assert_param(IS_SMARTCARD_PARITY(hsmartcard->Init.Parity));
|
|
1681 |
assert_param(IS_SMARTCARD_MODE(hsmartcard->Init.Mode));
|
|
1682 |
assert_param(IS_SMARTCARD_POLARITY(hsmartcard->Init.CLKPolarity));
|
|
1683 |
assert_param(IS_SMARTCARD_PHASE(hsmartcard->Init.CLKPhase));
|
|
1684 |
assert_param(IS_SMARTCARD_LASTBIT(hsmartcard->Init.CLKLastBit));
|
|
1685 |
assert_param(IS_SMARTCARD_ONE_BIT_SAMPLE(hsmartcard->Init.OneBitSampling));
|
|
1686 |
assert_param(IS_SMARTCARD_NACK(hsmartcard->Init.NACKEnable));
|
|
1687 |
assert_param(IS_SMARTCARD_TIMEOUT(hsmartcard->Init.TimeOutEnable));
|
|
1688 |
assert_param(IS_SMARTCARD_AUTORETRY_COUNT(hsmartcard->Init.AutoRetryCount));
|
|
1689 |
|
|
1690 |
/*-------------------------- USART CR1 Configuration -----------------------*/
|
|
1691 |
/* In SmartCard mode, M and PCE are forced to 1 (8 bits + parity).
|
|
1692 |
* Oversampling is forced to 16 (OVER8 = 0).
|
|
1693 |
* Configure the Parity and Mode:
|
|
1694 |
* set PS bit according to hsmartcard->Init.Parity value
|
|
1695 |
* set TE and RE bits according to hsmartcard->Init.Mode value */
|
|
1696 |
tmpreg = (uint32_t) hsmartcard->Init.Parity | hsmartcard->Init.Mode;
|
|
1697 |
tmpreg |= (uint32_t) hsmartcard->Init.WordLength;
|
|
1698 |
MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_FIELDS, tmpreg);
|
|
1699 |
|
|
1700 |
/*-------------------------- USART CR2 Configuration -----------------------*/
|
|
1701 |
tmpreg = hsmartcard->Init.StopBits;
|
|
1702 |
/* Synchronous mode is activated by default */
|
|
1703 |
tmpreg |= (uint32_t) USART_CR2_CLKEN | hsmartcard->Init.CLKPolarity;
|
|
1704 |
tmpreg |= (uint32_t) hsmartcard->Init.CLKPhase | hsmartcard->Init.CLKLastBit;
|
|
1705 |
tmpreg |= (uint32_t) hsmartcard->Init.TimeOutEnable;
|
|
1706 |
MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_FIELDS, tmpreg);
|
|
1707 |
|
|
1708 |
/*-------------------------- USART CR3 Configuration -----------------------*/
|
|
1709 |
/* Configure
|
|
1710 |
* - one-bit sampling method versus three samples' majority rule
|
|
1711 |
* according to hsmartcard->Init.OneBitSampling
|
|
1712 |
* - NACK transmission in case of parity error according
|
|
1713 |
* to hsmartcard->Init.NACKEnable
|
|
1714 |
* - autoretry counter according to hsmartcard->Init.AutoRetryCount */
|
|
1715 |
tmpreg = (uint32_t) hsmartcard->Init.OneBitSampling | hsmartcard->Init.NACKEnable;
|
|
1716 |
tmpreg |= ((uint32_t)hsmartcard->Init.AutoRetryCount << SMARTCARD_CR3_SCARCNT_LSB_POS);
|
|
1717 |
MODIFY_REG(hsmartcard->Instance-> CR3,USART_CR3_FIELDS, tmpreg);
|
|
1718 |
|
|
1719 |
/*-------------------------- USART GTPR Configuration ----------------------*/
|
|
1720 |
tmpreg = (hsmartcard->Init.Prescaler | ((uint32_t)hsmartcard->Init.GuardTime << SMARTCARD_GTPR_GT_LSB_POS));
|
|
1721 |
MODIFY_REG(hsmartcard->Instance->GTPR, (USART_GTPR_GT|USART_GTPR_PSC), tmpreg);
|
|
1722 |
|
|
1723 |
/*-------------------------- USART RTOR Configuration ----------------------*/
|
|
1724 |
tmpreg = ((uint32_t)hsmartcard->Init.BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS);
|
|
1725 |
if (hsmartcard->Init.TimeOutEnable == SMARTCARD_TIMEOUT_ENABLE)
|
|
1726 |
{
|
|
1727 |
assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue));
|
|
1728 |
tmpreg |= (uint32_t) hsmartcard->Init.TimeOutValue;
|
|
1729 |
}
|
|
1730 |
MODIFY_REG(hsmartcard->Instance->RTOR, (USART_RTOR_RTO|USART_RTOR_BLEN), tmpreg);
|
|
1731 |
|
|
1732 |
/*-------------------------- USART BRR Configuration -----------------------*/
|
|
1733 |
SMARTCARD_GETCLOCKSOURCE(hsmartcard, clocksource);
|
|
1734 |
switch (clocksource)
|
|
1735 |
{
|
|
1736 |
case SMARTCARD_CLOCKSOURCE_PCLK1:
|
|
1737 |
hsmartcard->Instance->BRR = (uint16_t)((HAL_RCC_GetPCLK1Freq() + (hsmartcard->Init.BaudRate/2U)) / hsmartcard->Init.BaudRate);
|
|
1738 |
break;
|
|
1739 |
case SMARTCARD_CLOCKSOURCE_HSI:
|
|
1740 |
hsmartcard->Instance->BRR = (uint16_t)((HSI_VALUE + (hsmartcard->Init.BaudRate/2U)) / hsmartcard->Init.BaudRate);
|
|
1741 |
break;
|
|
1742 |
case SMARTCARD_CLOCKSOURCE_SYSCLK:
|
|
1743 |
hsmartcard->Instance->BRR = (uint16_t)((HAL_RCC_GetSysClockFreq() + (hsmartcard->Init.BaudRate/2U)) / hsmartcard->Init.BaudRate);
|
|
1744 |
break;
|
|
1745 |
case SMARTCARD_CLOCKSOURCE_LSE:
|
|
1746 |
hsmartcard->Instance->BRR = (uint16_t)((LSE_VALUE + (hsmartcard->Init.BaudRate/2U)) / hsmartcard->Init.BaudRate);
|
|
1747 |
break;
|
|
1748 |
case SMARTCARD_CLOCKSOURCE_UNDEFINED:
|
|
1749 |
default:
|
|
1750 |
ret = HAL_ERROR;
|
|
1751 |
break;
|
|
1752 |
}
|
|
1753 |
|
|
1754 |
return ret;
|
|
1755 |
}
|
|
1756 |
|
|
1757 |
|
|
1758 |
/**
|
|
1759 |
* @brief Configure the SMARTCARD associated USART peripheral advanced features.
|
|
1760 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1761 |
* the configuration information for the specified SMARTCARD module.
|
|
1762 |
* @retval None
|
|
1763 |
*/
|
|
1764 |
static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1765 |
{
|
|
1766 |
/* Check whether the set of advanced features to configure is properly set */
|
|
1767 |
assert_param(IS_SMARTCARD_ADVFEATURE_INIT(hsmartcard->AdvancedInit.AdvFeatureInit));
|
|
1768 |
|
|
1769 |
/* if required, configure TX pin active level inversion */
|
|
1770 |
if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXINVERT_INIT))
|
|
1771 |
{
|
|
1772 |
assert_param(IS_SMARTCARD_ADVFEATURE_TXINV(hsmartcard->AdvancedInit.TxPinLevelInvert));
|
|
1773 |
MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_TXINV, hsmartcard->AdvancedInit.TxPinLevelInvert);
|
|
1774 |
}
|
|
1775 |
|
|
1776 |
/* if required, configure RX pin active level inversion */
|
|
1777 |
if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXINVERT_INIT))
|
|
1778 |
{
|
|
1779 |
assert_param(IS_SMARTCARD_ADVFEATURE_RXINV(hsmartcard->AdvancedInit.RxPinLevelInvert));
|
|
1780 |
MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_RXINV, hsmartcard->AdvancedInit.RxPinLevelInvert);
|
|
1781 |
}
|
|
1782 |
|
|
1783 |
/* if required, configure data inversion */
|
|
1784 |
if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DATAINVERT_INIT))
|
|
1785 |
{
|
|
1786 |
assert_param(IS_SMARTCARD_ADVFEATURE_DATAINV(hsmartcard->AdvancedInit.DataInvert));
|
|
1787 |
MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_DATAINV, hsmartcard->AdvancedInit.DataInvert);
|
|
1788 |
}
|
|
1789 |
|
|
1790 |
/* if required, configure RX/TX pins swap */
|
|
1791 |
if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_SWAP_INIT))
|
|
1792 |
{
|
|
1793 |
assert_param(IS_SMARTCARD_ADVFEATURE_SWAP(hsmartcard->AdvancedInit.Swap));
|
|
1794 |
MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_SWAP, hsmartcard->AdvancedInit.Swap);
|
|
1795 |
}
|
|
1796 |
|
|
1797 |
/* if required, configure RX overrun detection disabling */
|
|
1798 |
if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT))
|
|
1799 |
{
|
|
1800 |
assert_param(IS_SMARTCARD_OVERRUN(hsmartcard->AdvancedInit.OverrunDisable));
|
|
1801 |
MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_OVRDIS, hsmartcard->AdvancedInit.OverrunDisable);
|
|
1802 |
}
|
|
1803 |
|
|
1804 |
/* if required, configure DMA disabling on reception error */
|
|
1805 |
if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT))
|
|
1806 |
{
|
|
1807 |
assert_param(IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(hsmartcard->AdvancedInit.DMADisableonRxError));
|
|
1808 |
MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_DDRE, hsmartcard->AdvancedInit.DMADisableonRxError);
|
|
1809 |
}
|
|
1810 |
|
|
1811 |
/* if required, configure MSB first on communication line */
|
|
1812 |
if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
|
|
1813 |
{
|
|
1814 |
assert_param(IS_SMARTCARD_ADVFEATURE_MSBFIRST(hsmartcard->AdvancedInit.MSBFirst));
|
|
1815 |
MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_MSBFIRST, hsmartcard->AdvancedInit.MSBFirst);
|
|
1816 |
}
|
|
1817 |
|
|
1818 |
}
|
|
1819 |
|
|
1820 |
/**
|
|
1821 |
* @brief Check the SMARTCARD Idle State.
|
|
1822 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1823 |
* the configuration information for the specified SMARTCARD module.
|
|
1824 |
* @retval HAL status
|
|
1825 |
*/
|
|
1826 |
static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1827 |
{
|
|
1828 |
uint32_t tickstart = 0U;
|
|
1829 |
|
|
1830 |
/* Initialize the SMARTCARD ErrorCode */
|
|
1831 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
1832 |
|
|
1833 |
/* Init tickstart for timeout managment*/
|
|
1834 |
tickstart = HAL_GetTick();
|
|
1835 |
|
|
1836 |
/* TEACK and REACK bits in ISR are checked only when available (not available on all F0 devices).
|
|
1837 |
Bits are defined for some specific devices, and are available only for UART instances supporting WakeUp from Stop Mode feature.
|
|
1838 |
*/
|
|
1839 |
#if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC)
|
|
1840 |
if (IS_UART_WAKEUP_FROMSTOP_INSTANCE(hsmartcard->Instance))
|
|
1841 |
{
|
|
1842 |
/* Check if the Transmitter is enabled */
|
|
1843 |
if((hsmartcard->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE)
|
|
1844 |
{
|
|
1845 |
/* Wait until TEACK flag is set */
|
|
1846 |
if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_TEACK, RESET, tickstart, SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK)
|
|
1847 |
{
|
|
1848 |
/* Timeout occurred */
|
|
1849 |
return HAL_TIMEOUT;
|
|
1850 |
}
|
|
1851 |
}
|
|
1852 |
|
|
1853 |
/* Check if the Receiver is enabled */
|
|
1854 |
if((hsmartcard->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE)
|
|
1855 |
{
|
|
1856 |
/* Wait until REACK flag is set */
|
|
1857 |
if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_REACK, RESET, tickstart, SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK)
|
|
1858 |
{
|
|
1859 |
/* Timeout occurred */
|
|
1860 |
return HAL_TIMEOUT;
|
|
1861 |
}
|
|
1862 |
}
|
|
1863 |
}
|
|
1864 |
#endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */
|
|
1865 |
|
|
1866 |
/* Initialize the SMARTCARD states */
|
|
1867 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
1868 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1869 |
|
|
1870 |
/* Process Unlocked */
|
|
1871 |
__HAL_UNLOCK(hsmartcard);
|
|
1872 |
|
|
1873 |
return HAL_OK;
|
|
1874 |
}
|
|
1875 |
|
|
1876 |
/**
|
|
1877 |
* @brief Handle SMARTCARD Communication Timeout.
|
|
1878 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1879 |
* the configuration information for the specified SMARTCARD module.
|
|
1880 |
* @param Flag Specifies the SMARTCARD flag to check.
|
|
1881 |
* @param Status The new Flag status (SET or RESET).
|
|
1882 |
* @param Tickstart Tick start value
|
|
1883 |
* @param Timeout Timeout duration.
|
|
1884 |
* @retval HAL status
|
|
1885 |
*/
|
|
1886 |
static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
|
|
1887 |
{
|
|
1888 |
/* Wait until flag is set */
|
|
1889 |
while((__HAL_SMARTCARD_GET_FLAG(hsmartcard, Flag) ? SET : RESET) == Status)
|
|
1890 |
{
|
|
1891 |
/* Check for the Timeout */
|
|
1892 |
if(Timeout != HAL_MAX_DELAY)
|
|
1893 |
{
|
|
1894 |
if((Timeout == 0U) || ((HAL_GetTick()-Tickstart) > Timeout))
|
|
1895 |
{
|
|
1896 |
/* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */
|
|
1897 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE));
|
|
1898 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
1899 |
|
|
1900 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
1901 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1902 |
|
|
1903 |
/* Process Unlocked */
|
|
1904 |
__HAL_UNLOCK(hsmartcard);
|
|
1905 |
return HAL_TIMEOUT;
|
|
1906 |
}
|
|
1907 |
}
|
|
1908 |
}
|
|
1909 |
return HAL_OK;
|
|
1910 |
}
|
|
1911 |
|
|
1912 |
|
|
1913 |
/**
|
|
1914 |
* @brief End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion).
|
|
1915 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1916 |
* the configuration information for the specified SMARTCARD module.
|
|
1917 |
* @retval None
|
|
1918 |
*/
|
|
1919 |
static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1920 |
{
|
|
1921 |
/* Disable TXEIE, TCIE and ERR (Frame error, noise error, overrun error) interrupts */
|
|
1922 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
|
|
1923 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
1924 |
|
|
1925 |
/* At end of Tx process, restore hsmartcard->gState to Ready */
|
|
1926 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
1927 |
}
|
|
1928 |
|
|
1929 |
|
|
1930 |
/**
|
|
1931 |
* @brief End ongoing Rx transfer on UART peripheral (following error detection or Reception completion).
|
|
1932 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
1933 |
* the configuration information for the specified SMARTCARD module.
|
|
1934 |
* @retval None
|
|
1935 |
*/
|
|
1936 |
static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
1937 |
{
|
|
1938 |
/* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
|
|
1939 |
CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
|
|
1940 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
1941 |
|
|
1942 |
/* At end of Rx process, restore hsmartcard->RxState to Ready */
|
|
1943 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1944 |
}
|
|
1945 |
|
|
1946 |
|
|
1947 |
/**
|
|
1948 |
* @brief DMA SMARTCARD transmit process complete callback.
|
|
1949 |
* @param hdma Pointer to a DMA_HandleTypeDef structure that contains
|
|
1950 |
* the configuration information for the specified DMA module.
|
|
1951 |
* @retval None
|
|
1952 |
*/
|
|
1953 |
static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma)
|
|
1954 |
{
|
|
1955 |
SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent);
|
|
1956 |
hsmartcard->TxXferCount = 0U;
|
|
1957 |
|
|
1958 |
/* Disable the DMA transfer for transmit request by resetting the DMAT bit
|
|
1959 |
in the SMARTCARD associated USART CR3 register */
|
|
1960 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT);
|
|
1961 |
|
|
1962 |
/* Enable the SMARTCARD Transmit Complete Interrupt */
|
|
1963 |
__HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_TC);
|
|
1964 |
}
|
|
1965 |
|
|
1966 |
/**
|
|
1967 |
* @brief DMA SMARTCARD receive process complete callback.
|
|
1968 |
* @param hdma Pointer to a DMA_HandleTypeDef structure that contains
|
|
1969 |
* the configuration information for the specified DMA module.
|
|
1970 |
* @retval None
|
|
1971 |
*/
|
|
1972 |
static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
|
|
1973 |
{
|
|
1974 |
SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent);
|
|
1975 |
hsmartcard->RxXferCount = 0U;
|
|
1976 |
|
|
1977 |
/* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */
|
|
1978 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
|
|
1979 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
1980 |
|
|
1981 |
/* Disable the DMA transfer for the receiver request by resetting the DMAR bit
|
|
1982 |
in the SMARTCARD associated USART CR3 register */
|
|
1983 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR);
|
|
1984 |
|
|
1985 |
/* At end of Rx process, restore hsmartcard->RxState to Ready */
|
|
1986 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
1987 |
|
|
1988 |
HAL_SMARTCARD_RxCpltCallback(hsmartcard);
|
|
1989 |
}
|
|
1990 |
|
|
1991 |
/**
|
|
1992 |
* @brief DMA SMARTCARD communication error callback.
|
|
1993 |
* @param hdma Pointer to a DMA_HandleTypeDef structure that contains
|
|
1994 |
* the configuration information for the specified DMA module.
|
|
1995 |
* @retval None
|
|
1996 |
*/
|
|
1997 |
static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
|
|
1998 |
{
|
|
1999 |
SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent);
|
|
2000 |
|
|
2001 |
/* Stop SMARTCARD DMA Tx request if ongoing */
|
|
2002 |
if ( (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
|
|
2003 |
&&(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) )
|
|
2004 |
{
|
|
2005 |
hsmartcard->TxXferCount = 0U;
|
|
2006 |
SMARTCARD_EndTxTransfer(hsmartcard);
|
|
2007 |
}
|
|
2008 |
|
|
2009 |
/* Stop SMARTCARD DMA Rx request if ongoing */
|
|
2010 |
if ( (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
|
|
2011 |
&&(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) )
|
|
2012 |
{
|
|
2013 |
hsmartcard->RxXferCount = 0U;
|
|
2014 |
SMARTCARD_EndRxTransfer(hsmartcard);
|
|
2015 |
}
|
|
2016 |
|
|
2017 |
hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_DMA;
|
|
2018 |
HAL_SMARTCARD_ErrorCallback(hsmartcard);
|
|
2019 |
}
|
|
2020 |
|
|
2021 |
/**
|
|
2022 |
* @brief DMA SMARTCARD communication abort callback, when initiated by HAL services on Error
|
|
2023 |
* (To be called at end of DMA Abort procedure following error occurrence).
|
|
2024 |
* @param hdma DMA handle.
|
|
2025 |
* @retval None
|
|
2026 |
*/
|
|
2027 |
static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma)
|
|
2028 |
{
|
|
2029 |
SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent);
|
|
2030 |
hsmartcard->RxXferCount = 0U;
|
|
2031 |
hsmartcard->TxXferCount = 0U;
|
|
2032 |
|
|
2033 |
HAL_SMARTCARD_ErrorCallback(hsmartcard);
|
|
2034 |
}
|
|
2035 |
|
|
2036 |
/**
|
|
2037 |
* @brief DMA SMARTCARD Tx communication abort callback, when initiated by user
|
|
2038 |
* (To be called at end of DMA Tx Abort procedure following user abort request).
|
|
2039 |
* @note When this callback is executed, User Abort complete call back is called only if no
|
|
2040 |
* Abort still ongoing for Rx DMA Handle.
|
|
2041 |
* @param hdma DMA handle.
|
|
2042 |
* @retval None
|
|
2043 |
*/
|
|
2044 |
static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
|
|
2045 |
{
|
|
2046 |
SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef* )(hdma->Parent);
|
|
2047 |
|
|
2048 |
hsmartcard->hdmatx->XferAbortCallback = NULL;
|
|
2049 |
|
|
2050 |
/* Check if an Abort process is still ongoing */
|
|
2051 |
if(hsmartcard->hdmarx != NULL)
|
|
2052 |
{
|
|
2053 |
if(hsmartcard->hdmarx->XferAbortCallback != NULL)
|
|
2054 |
{
|
|
2055 |
return;
|
|
2056 |
}
|
|
2057 |
}
|
|
2058 |
|
|
2059 |
/* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
|
|
2060 |
hsmartcard->TxXferCount = 0U;
|
|
2061 |
hsmartcard->RxXferCount = 0U;
|
|
2062 |
|
|
2063 |
/* Reset errorCode */
|
|
2064 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
2065 |
|
|
2066 |
/* Clear the Error flags in the ICR register */
|
|
2067 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
2068 |
|
|
2069 |
/* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
|
|
2070 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
2071 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
2072 |
|
|
2073 |
/* Call user Abort complete callback */
|
|
2074 |
HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
|
|
2075 |
}
|
|
2076 |
|
|
2077 |
|
|
2078 |
/**
|
|
2079 |
* @brief DMA SMARTCARD Rx communication abort callback, when initiated by user
|
|
2080 |
* (To be called at end of DMA Rx Abort procedure following user abort request).
|
|
2081 |
* @note When this callback is executed, User Abort complete call back is called only if no
|
|
2082 |
* Abort still ongoing for Tx DMA Handle.
|
|
2083 |
* @param hdma DMA handle.
|
|
2084 |
* @retval None
|
|
2085 |
*/
|
|
2086 |
static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
|
|
2087 |
{
|
|
2088 |
SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef* )(hdma->Parent);
|
|
2089 |
|
|
2090 |
hsmartcard->hdmarx->XferAbortCallback = NULL;
|
|
2091 |
|
|
2092 |
/* Check if an Abort process is still ongoing */
|
|
2093 |
if(hsmartcard->hdmatx != NULL)
|
|
2094 |
{
|
|
2095 |
if(hsmartcard->hdmatx->XferAbortCallback != NULL)
|
|
2096 |
{
|
|
2097 |
return;
|
|
2098 |
}
|
|
2099 |
}
|
|
2100 |
|
|
2101 |
/* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
|
|
2102 |
hsmartcard->TxXferCount = 0U;
|
|
2103 |
hsmartcard->RxXferCount = 0U;
|
|
2104 |
|
|
2105 |
/* Reset errorCode */
|
|
2106 |
hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
|
|
2107 |
|
|
2108 |
/* Clear the Error flags in the ICR register */
|
|
2109 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
2110 |
|
|
2111 |
/* Restore hsmartcard->gState and hsmartcard->RxState to Ready */
|
|
2112 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
2113 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
2114 |
|
|
2115 |
/* Call user Abort complete callback */
|
|
2116 |
HAL_SMARTCARD_AbortCpltCallback(hsmartcard);
|
|
2117 |
}
|
|
2118 |
|
|
2119 |
|
|
2120 |
/**
|
|
2121 |
* @brief DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to
|
|
2122 |
* HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer)
|
|
2123 |
* (This callback is executed at end of DMA Tx Abort procedure following user abort request,
|
|
2124 |
* and leads to user Tx Abort Complete callback execution).
|
|
2125 |
* @param hdma DMA handle.
|
|
2126 |
* @retval None
|
|
2127 |
*/
|
|
2128 |
static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
|
|
2129 |
{
|
|
2130 |
SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent);
|
|
2131 |
|
|
2132 |
hsmartcard->TxXferCount = 0U;
|
|
2133 |
|
|
2134 |
/* Clear the Error flags in the ICR register */
|
|
2135 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF);
|
|
2136 |
|
|
2137 |
/* Restore hsmartcard->gState to Ready */
|
|
2138 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
2139 |
|
|
2140 |
/* Call user Abort complete callback */
|
|
2141 |
HAL_SMARTCARD_AbortTransmitCpltCallback(hsmartcard);
|
|
2142 |
}
|
|
2143 |
|
|
2144 |
/**
|
|
2145 |
* @brief DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to
|
|
2146 |
* HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer)
|
|
2147 |
* (This callback is executed at end of DMA Rx Abort procedure following user abort request,
|
|
2148 |
* and leads to user Rx Abort Complete callback execution).
|
|
2149 |
* @param hdma DMA handle.
|
|
2150 |
* @retval None
|
|
2151 |
*/
|
|
2152 |
static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
|
|
2153 |
{
|
|
2154 |
SMARTCARD_HandleTypeDef* hsmartcard = ( SMARTCARD_HandleTypeDef* )(hdma->Parent);
|
|
2155 |
|
|
2156 |
hsmartcard->RxXferCount = 0U;
|
|
2157 |
|
|
2158 |
/* Clear the Error flags in the ICR register */
|
|
2159 |
__HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF);
|
|
2160 |
|
|
2161 |
/* Restore hsmartcard->RxState to Ready */
|
|
2162 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
2163 |
|
|
2164 |
/* Call user Abort complete callback */
|
|
2165 |
HAL_SMARTCARD_AbortReceiveCpltCallback(hsmartcard);
|
|
2166 |
}
|
|
2167 |
|
|
2168 |
/**
|
|
2169 |
* @brief Send an amount of data in non-blocking mode.
|
|
2170 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
2171 |
* the configuration information for the specified SMARTCARD module.
|
|
2172 |
* Function called under interruption only, once
|
|
2173 |
* interruptions have been enabled by HAL_SMARTCARD_Transmit_IT()
|
|
2174 |
* @retval HAL status
|
|
2175 |
*/
|
|
2176 |
static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
2177 |
{
|
|
2178 |
/* Check that a Tx process is ongoing */
|
|
2179 |
if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX)
|
|
2180 |
{
|
|
2181 |
if(hsmartcard->TxXferCount == 0U)
|
|
2182 |
{
|
|
2183 |
/* Disable the SMARTCARD Transmit Data Register Empty Interrupt */
|
|
2184 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE);
|
|
2185 |
|
|
2186 |
/* Enable the SMARTCARD Transmit Complete Interrupt */
|
|
2187 |
__HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_TC);
|
|
2188 |
|
|
2189 |
return HAL_OK;
|
|
2190 |
}
|
|
2191 |
else
|
|
2192 |
{
|
|
2193 |
hsmartcard->Instance->TDR = (*hsmartcard->pTxBuffPtr++ & (uint8_t)0xFFU);
|
|
2194 |
hsmartcard->TxXferCount--;
|
|
2195 |
|
|
2196 |
return HAL_OK;
|
|
2197 |
}
|
|
2198 |
}
|
|
2199 |
else
|
|
2200 |
{
|
|
2201 |
return HAL_BUSY;
|
|
2202 |
}
|
|
2203 |
}
|
|
2204 |
|
|
2205 |
/**
|
|
2206 |
* @brief Wrap up transmission in non-blocking mode.
|
|
2207 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
2208 |
* the configuration information for the specified SMARTCARD module.
|
|
2209 |
* @retval HAL status
|
|
2210 |
*/
|
|
2211 |
static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
2212 |
{
|
|
2213 |
/* Disable the SMARTCARD Transmit Complete Interrupt */
|
|
2214 |
__HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TC);
|
|
2215 |
|
|
2216 |
/* Check if a receive process is ongoing or not. If not disable ERR IT */
|
|
2217 |
if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY)
|
|
2218 |
{
|
|
2219 |
/* Disable the SMARTCARD Error Interrupt: (Frame error) */
|
|
2220 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
2221 |
}
|
|
2222 |
|
|
2223 |
/* Re-enable Rx at end of transmission if initial mode is Rx/Tx */
|
|
2224 |
if(hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX)
|
|
2225 |
{
|
|
2226 |
/* Disable the Peripheral first to update modes */
|
|
2227 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
2228 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE);
|
|
2229 |
/* Enable the Peripheral */
|
|
2230 |
SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE);
|
|
2231 |
}
|
|
2232 |
|
|
2233 |
/* Tx process is ended, restore hsmartcard->gState to Ready */
|
|
2234 |
hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
|
|
2235 |
|
|
2236 |
HAL_SMARTCARD_TxCpltCallback(hsmartcard);
|
|
2237 |
|
|
2238 |
return HAL_OK;
|
|
2239 |
}
|
|
2240 |
|
|
2241 |
/**
|
|
2242 |
* @brief Receive an amount of data in non-blocking mode.
|
|
2243 |
* @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains
|
|
2244 |
* the configuration information for the specified SMARTCARD module.
|
|
2245 |
* Function called under interruption only, once
|
|
2246 |
* interruptions have been enabled by HAL_SMARTCARD_Receive_IT().
|
|
2247 |
* @retval HAL status
|
|
2248 |
*/
|
|
2249 |
static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard)
|
|
2250 |
{
|
|
2251 |
/* Check that a Rx process is ongoing */
|
|
2252 |
if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
|
|
2253 |
{
|
|
2254 |
*hsmartcard->pRxBuffPtr++ = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0xFFU);
|
|
2255 |
|
|
2256 |
if(--hsmartcard->RxXferCount == 0U)
|
|
2257 |
{
|
|
2258 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE);
|
|
2259 |
|
|
2260 |
/* Check if a transmit process is ongoing or not. If not disable ERR IT */
|
|
2261 |
if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY)
|
|
2262 |
{
|
|
2263 |
/* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
|
|
2264 |
CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
|
|
2265 |
}
|
|
2266 |
|
|
2267 |
/* Disable the SMARTCARD Parity Error Interrupt */
|
|
2268 |
CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE);
|
|
2269 |
|
|
2270 |
hsmartcard->RxState = HAL_SMARTCARD_STATE_READY;
|
|
2271 |
|
|
2272 |
HAL_SMARTCARD_RxCpltCallback(hsmartcard);
|
|
2273 |
|
|
2274 |
return HAL_OK;
|
|
2275 |
}
|
|
2276 |
|
|
2277 |
return HAL_OK;
|
|
2278 |
}
|
|
2279 |
else
|
|
2280 |
{
|
|
2281 |
/* Clear RXNE interrupt flag */
|
|
2282 |
__HAL_SMARTCARD_SEND_REQ(hsmartcard, SMARTCARD_RXDATA_FLUSH_REQUEST);
|
|
2283 |
|
|
2284 |
return HAL_BUSY;
|
|
2285 |
}
|
|
2286 |
}
|
|
2287 |
|
|
2288 |
/**
|
|
2289 |
* @}
|
|
2290 |
*/
|
|
2291 |
|
|
2292 |
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
|
|
2293 |
/**
|
|
2294 |
* @}
|
|
2295 |
*/
|
|
2296 |
|
|
2297 |
/**
|
|
2298 |
* @}
|
|
2299 |
*/
|
|
2300 |
|
|
2301 |
#endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */
|
|
2302 |
|
|
2303 |
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|