2 ******************************************************************************
3 * @file stm32f1xx_hal_smartcard.c
4 * @author MCD Application Team
6 * @date 15-December-2014
7 * @brief SMARTCARD HAL module driver.
8 * This file provides firmware functions to manage the following
9 * functionalities of the SMARTCARD peripheral:
10 * + Initialization and de-initialization functions
11 * + IO operation functions
12 * + Peripheral State and Errors functions
13 * + Peripheral Control functions
16 ==============================================================================
17 ##### How to use this driver #####
18 ==============================================================================
20 The SMARTCARD HAL driver can be used as follows:
22 (#) Declare a SMARTCARD_HandleTypeDef handle structure.
23 (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API:
24 (##) Enable the interface clock of the USARTx associated to the SMARTCARD.
25 (##) SMARTCARD pins configuration:
26 (+++) Enable the clock for the SMARTCARD GPIOs.
27 (+++) Configure the USART pins (TX as alternate function pull-up, RX as alternate function Input).
28 (##) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT()
29 and HAL_SMARTCARD_Receive_IT() APIs):
30 (+++) Configure the USARTx interrupt priority.
31 (+++) Enable the NVIC USART IRQ handle.
32 (##) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA()
33 and HAL_SMARTCARD_Receive_DMA() APIs):
34 (+++) Declare a DMA handle structure for the Tx/Rx channel.
35 (+++) Enable the DMAx interface clock.
36 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
37 (+++) Configure the DMA Tx/Rx channel.
38 (+++) Associate the initilalized DMA handle to the SMARTCARD DMA Tx/Rx handle.
39 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.
40 (+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle
41 (used for last byte sending completion detection in DMA non circular mode)
43 (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware
44 flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure.
46 (#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API:
47 (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc)
48 by calling the customed HAL_SMARTCARD_MspInit(&hsc) API.
50 -@@- The specific SMARTCARD interrupts (Transmission complete interrupt,
51 RXNE interrupt and Error Interrupts) will be managed using the macros
52 __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process.
54 (#) Three operation modes are available within this driver :
56 *** Polling mode IO operation ***
57 =================================
59 (+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit()
60 (+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive()
62 *** Interrupt mode IO operation ***
63 ===================================
65 (+) Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT()
66 (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can
67 add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback
68 (+) Receive an amount of data in non blocking mode using HAL_SMARTCARD_Receive_IT()
69 (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can
70 add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback
71 (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
72 add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback
74 *** DMA mode IO operation ***
75 ==============================
77 (+) Send an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA()
78 (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can
79 add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback
80 (+) Receive an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Receive_DMA()
81 (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can
82 add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback
83 (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
84 add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback
86 *** SMARTCARD HAL driver macros list ***
87 ========================================
89 Below the list of most used macros in SMARTCARD HAL driver.
91 (+) __HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral
92 (+) __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral
93 (+) __HAL_SMARTCARD_GET_FLAG : Check whether the specified SMARTCARD flag is set or not
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 the specified SMARTCARD interrupt has occurred or not
100 (@) You can refer to the SMARTCARD HAL driver header file for more useful macros
103 ******************************************************************************
106 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
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.
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.
130 ******************************************************************************
133 /* Includes ------------------------------------------------------------------*/
134 #include "stm32f1xx_hal.h"
136 /** @addtogroup STM32F1xx_HAL_Driver
140 /** @defgroup SMARTCARD SMARTCARD
141 * @brief HAL SMARTCARD module driver
145 #ifdef HAL_SMARTCARD_MODULE_ENABLED
147 /* Private typedef -----------------------------------------------------------*/
148 /* Private define ------------------------------------------------------------*/
149 /* Private macros --------------------------------------------------------*/
150 /* Private variables ---------------------------------------------------------*/
151 /* Private function prototypes -----------------------------------------------*/
152 /** @addtogroup SMARTCARD_Private_Functions SMARTCARD Private Functions
155 static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc);
156 static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
157 static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc);
158 static void SMARTCARD_SetConfig (SMARTCARD_HandleTypeDef *hsc);
159 static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma);
160 static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
161 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma);
162 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
167 /* Exported functions ---------------------------------------------------------*/
169 /** @defgroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions
173 /** @defgroup SMARTCARD_Exported_Functions_Group1 Initialization and de-initialization functions
174 * @brief Initialization and Configuration functions
178 ==============================================================================
179 ##### Initialization and Configuration functions #####
180 ==============================================================================
182 This subsection provides a set of functions allowing to initialize the USART
185 The Smartcard interface is designed to support asynchronous protocol Smartcards as
186 defined in the ISO 7816-3 standard.
188 The USART can provide a clock to the smartcard through the SCLK output.
189 In smartcard mode, SCLK is not associated to the communication but is simply derived
190 from the internal peripheral input clock through a 5-bit prescaler.
192 (+) For the Smartcard mode only these parameters can be configured:
194 (++) Word Length => Should be 9 bits (8 bits + parity)
196 (++) Parity: => Should be enabled
197 +-------------------------------------------------------------+
198 | M bit | PCE bit | SMARTCARD frame |
199 |---------------------|---------------------------------------|
200 | 1 | 1 | | SB | 8 bit data | PB | STB | |
201 +-------------------------------------------------------------+
205 (++) Receiver/transmitter modes
208 (++) NACKState: The Smartcard NACK state
210 (+) Recommended SmartCard interface configuration to get the Answer to Reset from the Card:
211 (++) Word Length = 9 Bits
214 (++) BaudRate = 12096 baud
215 (++) Tx and Rx enabled
217 Please refer to the ISO 7816-3 specification for more details.
219 -@- It is also possible to choose 0.5 stop bit for receiving but it is recommended
220 to use 1.5 stop bits for both transmitting and receiving to avoid switching
221 between the two configurations.
223 The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration
224 procedure (details for the procedure are available in reference manuals
225 (RM0008 for STM32F10Xxx MCUs and RM0041 for STM32F100xx MCUs)).
232 * @brief Initializes the SmartCard mode according to the specified
233 * parameters in the SMARTCARD_HandleTypeDef and create the associated handle.
234 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
235 * the configuration information for the specified SMARTCARD module.
238 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc)
240 /* Check the SMARTCARD handle allocation */
246 /* Check Wordlength, Parity and Stop bits parameters */
247 if ( (!(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength)))
248 ||(!(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits)))
249 ||(!(IS_SMARTCARD_PARITY(hsc->Init.Parity))) )
254 /* Check the parameters */
255 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
256 assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState));
257 assert_param(IS_SMARTCARD_PRESCALER(hsc->Init.Prescaler));
259 if(hsc->State == HAL_SMARTCARD_STATE_RESET)
261 /* Allocate lock resource and initialize it */
262 hsc-> Lock = HAL_UNLOCKED;
264 /* Init the low level hardware */
265 HAL_SMARTCARD_MspInit(hsc);
268 hsc->State = HAL_SMARTCARD_STATE_BUSY;
270 /* Disable the Peripheral */
271 __HAL_SMARTCARD_DISABLE(hsc);
273 /* Set the Prescaler */
274 MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_PSC, hsc->Init.Prescaler);
276 /* Set the Guard Time */
277 MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_GT, ((hsc->Init.GuardTime)<<8));
279 /* Set the Smartcard Communication parameters */
280 SMARTCARD_SetConfig(hsc);
282 /* In SmartCard mode, the following bits must be kept cleared:
283 - LINEN bit in the USART_CR2 register
284 - HDSEL and IREN bits in the USART_CR3 register.*/
285 CLEAR_BIT(hsc->Instance->CR2, USART_CR2_LINEN);
286 CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
288 /* Enable the Peripharal */
289 __HAL_SMARTCARD_ENABLE(hsc);
291 /* Configure the Smartcard NACK state */
292 MODIFY_REG(hsc->Instance->CR3, USART_CR3_NACK, hsc->Init.NACKState);
294 /* Enable the SC mode by setting the SCEN bit in the CR3 register */
295 SET_BIT(hsc->Instance->CR3, USART_CR3_SCEN);
297 /* Initialize the SMARTCARD state*/
298 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
299 hsc->State= HAL_SMARTCARD_STATE_READY;
305 * @brief DeInitializes the SMARTCARD peripheral
306 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
307 * the configuration information for the specified SMARTCARD module.
310 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc)
312 /* Check the SMARTCARD handle allocation */
318 /* Check the parameters */
319 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
321 hsc->State = HAL_SMARTCARD_STATE_BUSY;
323 /* Disable the Peripheral */
324 __HAL_SMARTCARD_DISABLE(hsc);
326 hsc->Instance->CR1 = 0x0;
327 hsc->Instance->CR2 = 0x0;
328 hsc->Instance->CR3 = 0x0;
329 hsc->Instance->BRR = 0x0;
330 hsc->Instance->GTPR = 0x0;
332 /* DeInit the low level hardware */
333 HAL_SMARTCARD_MspDeInit(hsc);
335 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
336 hsc->State = HAL_SMARTCARD_STATE_RESET;
345 * @brief SMARTCARD MSP Init.
346 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
347 * the configuration information for the specified SMARTCARD module.
350 __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc)
352 /* NOTE: This function should not be modified, when the callback is needed,
353 the HAL_SMARTCARD_MspInit can be implemented in the user file
358 * @brief SMARTCARD MSP DeInit.
359 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
360 * the configuration information for the specified SMARTCARD module.
363 __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc)
365 /* NOTE: This function should not be modified, when the callback is needed,
366 the HAL_SMARTCARD_MspDeInit can be implemented in the user file
374 /** @defgroup SMARTCARD_Exported_Functions_Group2 IO operation functions
375 * @brief SMARTCARD Transmit and Receive functions
378 ==============================================================================
379 ##### IO operation functions #####
380 ==============================================================================
382 This subsection provides a set of functions allowing to manage the SMARTCARD data transfers.
385 Smartcard is a single wire half duplex communication protocol.
386 The Smartcard interface is designed to support asynchronous protocol Smartcards as
387 defined in the ISO 7816-3 standard. The USART should be configured as:
388 (+) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
389 (+) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register.
391 (#) There are two modes of transfer:
392 (++) Blocking mode: The communication is performed in polling mode.
393 The HAL status of all data processing is returned by the same function
394 after finishing transfer.
395 (++) No-Blocking mode: The communication is performed using Interrupts
396 or DMA, the relevant API's return the HAL status.
397 The end of the data processing will be indicated through the
398 dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when
400 The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks
401 will be executed respectively at the end of the Transmit or Receive process
402 The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication
405 (#) Blocking mode APIs are :
406 (++) HAL_SMARTCARD_Transmit()
407 (++) HAL_SMARTCARD_Receive()
409 (#) Non Blocking mode APIs with Interrupt are :
410 (++) HAL_SMARTCARD_Transmit_IT()
411 (++) HAL_SMARTCARD_Receive_IT()
412 (++) HAL_SMARTCARD_IRQHandler()
414 (#) Non Blocking mode functions with DMA are :
415 (++) HAL_SMARTCARD_Transmit_DMA()
416 (++) HAL_SMARTCARD_Receive_DMA()
418 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
419 (++) HAL_SMARTCARD_TxCpltCallback()
420 (++) HAL_SMARTCARD_RxCpltCallback()
421 (++) HAL_SMARTCARD_ErrorCallback()
428 * @brief Sends an amount of data in blocking mode.
429 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
430 * the configuration information for the specified SMARTCARD module.
431 * @param pData: Pointer to data buffer
432 * @param Size: Amount of data to be sent
433 * @param Timeout: Specify timeout value
436 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
438 uint32_t tmp_state = 0;
440 tmp_state = hsc->State;
441 if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_RX))
443 if((pData == NULL) || (Size == 0))
451 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
452 /* Check if a non-blocking receive process is ongoing or not */
453 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)
455 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
459 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
462 hsc->TxXferSize = Size;
463 hsc->TxXferCount = Size;
464 while(hsc->TxXferCount > 0)
466 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, Timeout) != HAL_OK)
470 WRITE_REG(hsc->Instance->DR, (*pData++ & (uint8_t)0xFF));
474 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, Timeout) != HAL_OK)
479 /* Check if a non-blocking receive process is ongoing or not */
480 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
482 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
486 hsc->State = HAL_SMARTCARD_STATE_READY;
488 /* Process Unlocked */
500 * @brief Receive an amount of data in blocking mode.
501 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
502 * the configuration information for the specified SMARTCARD module.
503 * @param pData: Pointer to data buffer
504 * @param Size: Amount of data to be received
505 * @param Timeout: Specify timeout value
508 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
510 uint32_t tmp_state = 0;
512 tmp_state = hsc->State;
513 if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX))
515 if((pData == NULL) || (Size == 0))
523 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
525 /* Check if a non-blocking transmit process is ongoing or not */
526 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)
528 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
532 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
535 hsc->RxXferSize = Size;
536 hsc->RxXferCount = Size;
537 /* Check the remain data to be received */
538 while(hsc->RxXferCount > 0)
540 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, Timeout) != HAL_OK)
544 *pData++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0x00FF);
548 /* Check if a non-blocking transmit process is ongoing or not */
549 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
551 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
555 hsc->State = HAL_SMARTCARD_STATE_READY;
558 /* Process Unlocked */
570 * @brief Sends an amount of data in non-blocking mode.
571 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
572 * the configuration information for the specified SMARTCARD module.
573 * @param pData: Pointer to data buffer
574 * @param Size: Amount of data to be sent
577 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
579 uint32_t tmp_state = 0;
581 tmp_state = hsc->State;
582 if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_RX))
584 if((pData == NULL) || (Size == 0))
592 hsc->pTxBuffPtr = pData;
593 hsc->TxXferSize = Size;
594 hsc->TxXferCount = Size;
596 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
597 /* Check if a non-blocking receive process is ongoing or not */
598 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)
600 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
604 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
607 /* Process Unlocked */
610 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
611 __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR);
613 /* Enable the SMARTCARD Transmit data register empty Interrupt */
614 __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TXE);
625 * @brief Receives an amount of data in non-blocking mode.
626 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
627 * the configuration information for the specified SMARTCARD module.
628 * @param pData: Pointer to data buffer
629 * @param Size: Amount of data to be received
632 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
634 uint32_t tmp_state = 0;
636 tmp_state = hsc->State;
637 if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX))
639 if((pData == NULL) || (Size == 0))
647 hsc->pRxBuffPtr = pData;
648 hsc->RxXferSize = Size;
649 hsc->RxXferCount = Size;
651 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
652 /* Check if a non-blocking transmit process is ongoing or not */
653 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)
655 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
659 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
662 /* Process Unlocked */
665 /* Enable the SMARTCARD Data Register not empty Interrupt */
666 __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_RXNE);
668 /* Enable the SMARTCARD Parity Error Interrupt */
669 __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_PE);
671 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
672 __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR);
683 * @brief Sends an amount of data in non-blocking mode.
684 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
685 * the configuration information for the specified SMARTCARD module.
686 * @param pData: Pointer to data buffer
687 * @param Size: Amount of data to be sent
690 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
693 uint32_t tmp_state = 0;
695 tmp_state = hsc->State;
696 if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_RX))
698 if((pData == NULL) || (Size == 0))
706 hsc->pTxBuffPtr = pData;
707 hsc->TxXferSize = Size;
708 hsc->TxXferCount = Size;
710 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
711 /* Check if a non-blocking receive process is ongoing or not */
712 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)
714 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
718 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
721 /* Set the SMARTCARD DMA transfer complete callback */
722 hsc->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt;
724 /* Set the DMA error callback */
725 hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError;
727 /* Enable the SMARTCARD transmit DMA channel */
728 tmp = (uint32_t*)&pData;
729 HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsc->Instance->DR, Size);
731 /* Clear the TC flag in the SR register by writing 0 to it */
732 __HAL_SMARTCARD_CLEAR_FLAG(hsc, SMARTCARD_FLAG_TC);
734 /* Enable the DMA transfer for transmit request by setting the DMAT bit
735 in the SMARTCARD CR3 register */
736 SET_BIT(hsc->Instance->CR3,USART_CR3_DMAT);
738 /* Process Unlocked */
750 * @brief Receive an amount of data in non-blocking mode.
751 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
752 * the configuration information for the specified SMARTCARD module.
753 * @param pData: Pointer to data buffer
754 * @param Size: Amount of data to be received
755 * @note When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit.
758 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
761 uint32_t tmp_state = 0;
763 tmp_state = hsc->State;
764 if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX))
766 if((pData == NULL) || (Size == 0))
774 hsc->pRxBuffPtr = pData;
775 hsc->RxXferSize = Size;
777 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
778 /* Check if a non-blocking transmit process is ongoing or not */
779 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)
781 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
785 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
788 /* Set the SMARTCARD DMA transfer complete callback */
789 hsc->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt;
791 /* Set the DMA error callback */
792 hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError;
794 /* Enable the DMA channel */
795 tmp = (uint32_t*)&pData;
796 HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->DR, *(uint32_t*)tmp, Size);
798 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
799 in the SMARTCARD CR3 register */
800 SET_BIT(hsc->Instance->CR3,USART_CR3_DMAR);
802 /* Process Unlocked */
814 * @brief This function handles SMARTCARD interrupt request.
815 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
816 * the configuration information for the specified SMARTCARD module.
819 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc)
821 uint32_t tmp_flag = 0, tmp_it_source = 0;
823 tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_PE);
824 tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_PE);
825 /* SMARTCARD parity error interrupt occurred -----------------------------------*/
826 if((tmp_flag != RESET) && (tmp_it_source != RESET))
828 __HAL_SMARTCARD_CLEAR_PEFLAG(hsc);
829 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE;
832 tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_FE);
833 tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR);
834 /* SMARTCARD frame error interrupt occurred ------------------------------------*/
835 if((tmp_flag != RESET) && (tmp_it_source != RESET))
837 __HAL_SMARTCARD_CLEAR_FEFLAG(hsc);
838 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE;
841 tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_NE);
842 /* SMARTCARD noise error interrupt occurred ------------------------------------*/
843 if((tmp_flag != RESET) && (tmp_it_source != RESET))
845 __HAL_SMARTCARD_CLEAR_NEFLAG(hsc);
846 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE;
849 tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_ORE);
850 /* SMARTCARD Over-Run interrupt occurred ---------------------------------------*/
851 if((tmp_flag != RESET) && (tmp_it_source != RESET))
853 __HAL_SMARTCARD_CLEAR_OREFLAG(hsc);
854 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE;
857 tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_RXNE);
858 tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_RXNE);
859 /* SMARTCARD in mode Receiver --------------------------------------------------*/
860 if((tmp_flag != RESET) && (tmp_it_source != RESET))
862 SMARTCARD_Receive_IT(hsc);
865 tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_TXE);
866 tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_TXE);
867 /* SMARTCARD in mode Transmitter -----------------------------------------------*/
868 if((tmp_flag != RESET) && (tmp_it_source != RESET))
870 SMARTCARD_Transmit_IT(hsc);
873 tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_TC);
874 tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_TC);
875 /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/
876 if((tmp_flag != RESET) && (tmp_it_source != RESET))
878 SMARTCARD_EndTransmit_IT(hsc);
881 /* Call the Error call Back in case of Errors */
882 if(hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE)
884 /* Set the SMARTCARD state ready to be able to start again the process */
885 hsc->State= HAL_SMARTCARD_STATE_READY;
886 HAL_SMARTCARD_ErrorCallback(hsc);
891 * @brief Tx Transfer completed callback.
892 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
893 * the configuration information for the specified SMARTCARD module.
896 __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
898 /* NOTE: This function should not be modified, when the callback is needed,
899 the HAL_SMARTCARD_TxCpltCallback can be implemented in the user file
904 * @brief Rx Transfer completed callback.
905 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
906 * the configuration information for the specified SMARTCARD module.
909 __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
911 /* NOTE: This function should not be modified, when the callback is needed,
912 the HAL_SMARTCARD_RxCpltCallback can be implemented in the user file
917 * @brief SMARTCARD error callback.
918 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
919 * the configuration information for the specified SMARTCARD module.
922 __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc)
924 /* NOTE: This function should not be modified, when the callback is needed,
925 the HAL_SMARTCARD_ErrorCallback can be implemented in the user file
933 /** @defgroup SMARTCARD_Exported_Functions_Group3 Peripheral State and Errors functions
934 * @brief SMARTCARD State and Errors functions
937 ==============================================================================
938 ##### Peripheral State and Errors functions #####
939 ==============================================================================
941 This subsection provides a set of functions allowing to return the State of SmartCard
942 communication process and also return Peripheral Errors occurred during communication process
943 (+) HAL_SMARTCARD_GetState() API can be helpful to check in run-time the state
944 of the SMARTCARD peripheral.
945 (+) HAL_SMARTCARD_GetError() check in run-time errors that could be occurred during
953 * @brief Returns the SMARTCARD state.
954 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
955 * the configuration information for the specified SMARTCARD module.
958 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc)
964 * @brief Return the SMARTCARD error code
965 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
966 * the configuration information for the specified SMARTCARD module.
967 * @retval SMARTCARD Error Code
969 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc)
971 return hsc->ErrorCode;
982 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
983 * @brief SMARTCARD Private functions
987 * @brief DMA SMARTCARD transmit process complete callback.
988 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
989 * the configuration information for the specified DMA module.
992 static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma)
994 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
996 hsc->TxXferCount = 0;
998 /* Disable the DMA transfer for transmit request by setting the DMAT bit
999 in the SMARTCARD CR3 register */
1000 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
1002 /* Enable the SMARTCARD Transmit Complete Interrupt */
1003 __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TC);
1007 * @brief DMA SMARTCARD receive process complete callback.
1008 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
1009 * the configuration information for the specified DMA module.
1012 static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1014 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1016 hsc->RxXferCount = 0;
1018 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
1019 in the USART CR3 register */
1020 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
1022 /* Check if a non-blocking transmit process is ongoing or not */
1023 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
1025 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
1029 hsc->State = HAL_SMARTCARD_STATE_READY;
1032 HAL_SMARTCARD_RxCpltCallback(hsc);
1036 * @brief DMA SMARTCARD communication error callback.
1037 * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains
1038 * the configuration information for the specified DMA module.
1041 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
1043 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1045 hsc->RxXferCount = 0;
1046 hsc->TxXferCount = 0;
1047 hsc->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1048 hsc->State= HAL_SMARTCARD_STATE_READY;
1050 HAL_SMARTCARD_ErrorCallback(hsc);
1054 * @brief This function handles SMARTCARD Communication Timeout.
1055 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
1056 * the configuration information for the specified SMARTCARD module.
1057 * @param Flag: specifies the SMARTCARD flag to check.
1058 * @param Status: The new Flag status (SET or RESET).
1059 * @param Timeout: Timeout duration
1060 * @retval HAL status
1062 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
1064 uint32_t tickstart = 0;
1067 tickstart = HAL_GetTick();
1069 /* Wait until flag is set */
1072 while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) == RESET)
1074 /* Check for the Timeout */
1075 if(Timeout != HAL_MAX_DELAY)
1077 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1079 /* Disable TXE and RXNE interrupts for the interrupt process */
1080 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE);
1081 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE);
1083 hsc->State= HAL_SMARTCARD_STATE_READY;
1085 /* Process Unlocked */
1095 while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) != RESET)
1097 /* Check for the Timeout */
1098 if(Timeout != HAL_MAX_DELAY)
1100 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1102 /* Disable TXE and RXNE interrupts for the interrupt process */
1103 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE);
1104 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE);
1106 hsc->State= HAL_SMARTCARD_STATE_READY;
1108 /* Process Unlocked */
1120 * @brief Send an amount of data in non-blocking mode.
1121 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
1122 * the configuration information for the specified SMARTCARD module.
1123 * Function called under interruption only, once
1124 * interruptions have been enabled by HAL_SMARTCARD_Transmit_IT()
1125 * @retval HAL status
1127 static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc)
1129 uint32_t tmp_state = 0;
1131 tmp_state = hsc->State;
1132 if((tmp_state == HAL_SMARTCARD_STATE_BUSY_TX) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX_RX))
1134 WRITE_REG(hsc->Instance->DR, (*hsc->pTxBuffPtr++ & (uint8_t)0xFF));
1136 if(--hsc->TxXferCount == 0)
1138 /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */
1139 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE);
1141 /* Enable the SMARTCARD Transmit Complete Interrupt */
1142 __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TC);
1155 * @brief Wraps up transmission in non blocking mode.
1156 * @param hsmartcard: pointer to a SMARTCARD_HandleTypeDef structure that contains
1157 * the configuration information for the specified SMARTCARD module.
1158 * @retval HAL status
1160 static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
1162 /* Disable the SMARTCARD Transmit Complete Interrupt */
1163 __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TC);
1165 /* Check if a receive process is ongoing or not */
1166 if(hsmartcard->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
1168 hsmartcard->State = HAL_SMARTCARD_STATE_BUSY_RX;
1172 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
1173 __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_ERR);
1175 hsmartcard->State = HAL_SMARTCARD_STATE_READY;
1178 HAL_SMARTCARD_TxCpltCallback(hsmartcard);
1185 * @brief Receive an amount of data in non-blocking mode.
1186 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
1187 * the configuration information for the specified SMARTCARD module.
1188 * @retval HAL status
1190 static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc)
1192 uint32_t tmp_state = 0;
1194 tmp_state = hsc->State;
1195 if((tmp_state == HAL_SMARTCARD_STATE_BUSY_RX) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX_RX))
1197 *hsc->pRxBuffPtr++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0xFF);
1199 if(--hsc->RxXferCount == 0)
1201 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE);
1203 /* Disable the SMARTCARD Parity Error Interrupt */
1204 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_PE);
1206 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
1207 __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR);
1209 /* Check if a non-blocking transmit process is ongoing or not */
1210 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
1212 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
1216 hsc->State = HAL_SMARTCARD_STATE_READY;
1219 HAL_SMARTCARD_RxCpltCallback(hsc);
1232 * @brief Configures the SMARTCARD peripheral.
1233 * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains
1234 * the configuration information for the specified SMARTCARD module.
1237 static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc)
1239 /* Check the parameters */
1240 assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity));
1241 assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase));
1242 assert_param(IS_SMARTCARD_LASTBIT(hsc->Init.CLKLastBit));
1243 assert_param(IS_SMARTCARD_BAUDRATE(hsc->Init.BaudRate));
1244 assert_param(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength));
1245 assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits));
1246 assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity));
1247 assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode));
1248 assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState));
1250 /* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the
1251 receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */
1252 CLEAR_BIT(hsc->Instance->CR1, (uint32_t)(USART_CR1_TE | USART_CR1_RE));
1254 /*------ SMARTCARD-associated USART registers setting : CR2 Configuration ------*/
1255 /* Clear CLKEN, CPOL, CPHA and LBCL bits */
1256 /* Configure the SMARTCARD Clock, CPOL, CPHA and LastBit -----------------------*/
1257 /* Set CPOL bit according to hsc->Init.CLKPolarity value */
1258 /* Set CPHA bit according to hsc->Init.CLKPhase value */
1259 /* Set LBCL bit according to hsc->Init.CLKLastBit value */
1260 MODIFY_REG(hsc->Instance->CR2,
1261 ((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_LBCL)),
1262 ((uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity | hsc->Init.CLKPhase| hsc->Init.CLKLastBit)) );
1264 /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
1265 MODIFY_REG(hsc->Instance->CR2, USART_CR2_STOP,(uint32_t)(hsc->Init.StopBits));
1267 /*------ SMARTCARD-associated USART registers setting : CR1 Configuration ------*/
1268 /* Clear M, PCE, PS, TE and RE bits */
1269 /* Configure the SMARTCARD Word Length, Parity and mode:
1270 Set the M according to hsc->Init.WordLength value (forced to 1 as 9B data frame should be selected)
1271 Set PCE and PS bits according to hsc->Init.Parity value (PCE bit forced to 1 as parity control should always be enabled)
1272 Set TE and RE bits according to hsc->Init.Mode value */
1273 MODIFY_REG(hsc->Instance->CR1,
1274 ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE)),
1275 ((uint32_t)(USART_CR1_M | USART_CR1_PCE | hsc->Init.Parity | hsc->Init.Mode)) );
1277 /*------ SMARTCARD-associated USART registers setting : CR3 Configuration ------*/
1278 /* Clear CTSE and RTSE bits */
1279 CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
1281 /*------ SMARTCARD-associated USART registers setting : BRR Configuration ------*/
1282 if(hsc->Instance == USART1)
1284 hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK2Freq(), hsc->Init.BaudRate);
1288 hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK1Freq(), hsc->Init.BaudRate);
1296 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
1305 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/