2 ******************************************************************************
3 * @file stm32f4xx_hal_smartcard.c
4 * @author MCD Application Team
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
15 ==============================================================================
16 ##### How to use this driver #####
17 ==============================================================================
19 The SMARTCARD HAL driver can be used as follows:
21 (#) Declare a SMARTCARD_HandleTypeDef handle structure.
22 (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API:
23 (##) Enable the USARTx interface clock.
24 (##) SMARTCARD pins configuration:
25 (+++) Enable the clock for the SMARTCARD GPIOs.
26 (+++) Configure these SMARTCARD pins as alternate function pull-up.
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 stream.
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 Stream.
37 (+++) Associate the initilalized 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 Stream.
40 (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware
41 flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure.
43 (#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API:
44 (++) These APIs configure also the low level Hardware GPIO, CLOCK, CORTEX...etc)
45 by calling the customed HAL_SMARTCARD_MspInit() API.
47 (@) The specific SMARTCARD interrupts (Transmission complete interrupt,
48 RXNE interrupt and Error Interrupts) will be managed using the macros
49 __SMARTCARD_ENABLE_IT() and __SMARTCARD_DISABLE_IT() inside the transmit and receive process.
52 Three operation modes are available within this driver :
54 *** Polling mode IO operation ***
55 =================================
57 (+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit()
58 (+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive()
60 *** Interrupt mode IO operation ***
61 ===================================
63 (+) Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT()
64 (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can
65 add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback
66 (+) Receive an amount of data in non blocking mode using HAL_SMARTCARD_Receive_IT()
67 (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can
68 add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback
69 (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
70 add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback
72 *** DMA mode IO operation ***
73 ==============================
75 (+) Send an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA()
76 (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can
77 add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback
78 (+) Receive an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Receive_DMA()
79 (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can
80 add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback
81 (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
82 add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback
84 *** SMARTCARD HAL driver macros list ***
85 =============================================
87 Below the list of most used macros in SMARTCARD HAL driver.
89 (+) __HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral
90 (+) __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral
91 (+) __HAL_SMARTCARD_GET_FLAG : Check whether the specified SMARTCARD flag is set or not
92 (+) __HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag
93 (+) __HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt
94 (+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt
97 (@) You can refer to the SMARTCARD HAL driver header file for more useful macros
100 ******************************************************************************
103 * <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
105 * Redistribution and use in source and binary forms, with or without modification,
106 * are permitted provided that the following conditions are met:
107 * 1. Redistributions of source code must retain the above copyright notice,
108 * this list of conditions and the following disclaimer.
109 * 2. Redistributions in binary form must reproduce the above copyright notice,
110 * this list of conditions and the following disclaimer in the documentation
111 * and/or other materials provided with the distribution.
112 * 3. Neither the name of STMicroelectronics nor the names of its contributors
113 * may be used to endorse or promote products derived from this software
114 * without specific prior written permission.
116 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
117 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
118 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
119 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
120 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
121 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
122 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
123 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
124 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
125 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
127 ******************************************************************************
130 /* Includes ------------------------------------------------------------------*/
131 #include "stm32f4xx_hal.h"
133 /** @addtogroup STM32F4xx_HAL_Driver
137 /** @defgroup SMARTCARD
138 * @brief HAL USART SMARTCARD module driver
141 #ifdef HAL_SMARTCARD_MODULE_ENABLED
142 /* Private typedef -----------------------------------------------------------*/
143 /* Private define ------------------------------------------------------------*/
144 #define SMARTCARD_TIMEOUT_VALUE 22000
145 /* Private macro -------------------------------------------------------------*/
146 /* Private variables ---------------------------------------------------------*/
147 /* Private function prototypes -----------------------------------------------*/
148 static void SMARTCARD_SetConfig (SMARTCARD_HandleTypeDef *hsc);
149 static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc);
150 static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc);
151 static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma);
152 static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
153 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma);
154 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout);
155 /* Private functions ---------------------------------------------------------*/
157 /** @defgroup SMARTCARD_Private_Functions
161 /** @defgroup SMARTCARD_Group1 SmartCard Initialization and de-initialization functions
162 * @brief Initialization and Configuration functions
165 ===============================================================================
166 ##### Initialization and Configuration functions #####
167 ===============================================================================
169 This subsection provides a set of functions allowing to initialize the USART
172 The Smartcard interface is designed to support asynchronous protocol Smartcards as
173 defined in the ISO 7816-3 standard.
175 The USART can provide a clock to the smartcard through the SCLK output.
176 In smartcard mode, SCLK is not associated to the communication but is simply derived
177 from the internal peripheral input clock through a 5-bit prescaler.
179 (+) For the asynchronous mode only these parameters can be configured:
183 (++) Parity: If the parity is enabled, then the MSB bit of the data written
184 in the data register is transmitted but is changed by the parity bit.
185 Depending on the frame length defined by the M bit (8-bits or 9-bits),
186 please refer to Reference manual for possible SMARTDARD frame formats.
190 (++) Receiver/transmitter modes
193 (++) NACKState: The Smartcard NACK state
195 (+) Recommended SmartCard interface configuration to get the Answer to Reset from the Card:
196 (++) Word Length = 9 Bits
199 (++) BaudRate = 12096 baud
200 (++) Tx and Rx enabled
202 Please refer to the ISO 7816-3 specification for more details.
204 -@- It is also possible to choose 0.5 stop bit for receiving but it is recommended
205 to use 1.5 stop bits for both transmitting and receiving to avoid switching
206 between the two configurations.
208 The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration
209 procedure (details for the procedure are available in reference manual (RM0329)).
216 * @brief Initializes the SmartCard mode according to the specified
217 * parameters in the SMARTCARD_InitTypeDef and create the associated handle .
218 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
219 * the configuration information for SMARTCARD module.
222 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc)
224 /* Check the SMARTCARD handle allocation */
230 /* Check the parameters */
231 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
232 assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState));
234 if(hsc->State == HAL_SMARTCARD_STATE_RESET)
236 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
237 HAL_SMARTCARD_MspInit(hsc);
240 hsc->State = HAL_SMARTCARD_STATE_BUSY;
242 /* Set the Prescaler */
243 MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_PSC, hsc->Init.Prescaler);
245 /* Set the Guard Time */
246 MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_GT, ((hsc->Init.GuardTime)<<8));
248 /* Set the Smartcard Communication parameters */
249 SMARTCARD_SetConfig(hsc);
251 /* In SmartCard mode, the following bits must be kept cleared:
252 - LINEN bit in the USART_CR2 register
253 - HDSEL and IREN bits in the USART_CR3 register.*/
254 hsc->Instance->CR2 &= ~USART_CR2_LINEN;
255 hsc->Instance->CR3 &= ~(USART_CR3_IREN | USART_CR3_HDSEL);
257 /* Enable the SMARTCARD Parity Error Interrupt */
258 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_PE);
260 /* Enable the SMARTCARD Framing Error Interrupt */
261 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR);
263 /* Enable the Peripharal */
264 __SMARTCARD_ENABLE(hsc);
266 /* Configure the Smartcard NACK state */
267 MODIFY_REG(hsc->Instance->CR3, USART_CR3_NACK, hsc->Init.NACKState);
269 /* Enable the SC mode by setting the SCEN bit in the CR3 register */
270 hsc->Instance->CR3 |= (USART_CR3_SCEN);
272 /* Initialize the SMARTCARD state*/
273 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
274 hsc->State= HAL_SMARTCARD_STATE_READY;
280 * @brief DeInitializes the USART SmartCard peripheral
281 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
282 * the configuration information for SMARTCARD module.
285 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc)
287 /* Check the SMARTCARD handle allocation */
293 /* Check the parameters */
294 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
296 hsc->State = HAL_SMARTCARD_STATE_BUSY;
298 /* DeInit the low level hardware */
299 HAL_SMARTCARD_MspDeInit(hsc);
301 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
302 hsc->State = HAL_SMARTCARD_STATE_RESET;
311 * @brief SMARTCARD MSP Init
312 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
313 * the configuration information for SMARTCARD module.
316 __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc)
318 /* NOTE : This function Should not be modified, when the callback is needed,
319 the HAL_SMARTCARD_MspInit could be implenetd in the user file
324 * @brief SMARTCARD MSP DeInit
325 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
326 * the configuration information for SMARTCARD module.
329 __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc)
331 /* NOTE : This function Should not be modified, when the callback is needed,
332 the HAL_SMARTCARD_MspDeInit could be implenetd in the user file
340 /** @defgroup SMARTCARD_Group2 IO operation functions
341 * @brief SMARTCARD Transmit and Receive functions
344 ===============================================================================
345 ##### IO operation functions #####
346 ===============================================================================
347 This subsection provides a set of functions allowing to manage the SMARTCARD data transfers.
349 IrDA is a half duplex communication protocol. If the Transmitter is busy, any data
350 on the IrDA receive line will be ignored by the IrDA decoder and if the Receiver
351 is busy, data on the TX from the USART to IrDA will not be encoded by IrDA.
352 While receiving data, transmission should be avoided as the data to be transmitted
355 (#) There are two modes of transfer:
356 (++) Blocking mode: The communication is performed in polling mode.
357 The HAL status of all data processing is returned by the same function
358 after finishing transfer.
359 (++) Non Blocking mode: The communication is performed using Interrupts
360 or DMA, These APIs return the HAL status.
361 The end of the data processing will be indicated through the
362 dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when
364 The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks
365 will be executed respectivelly at the end of the Transmit or Receive process
366 The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication error is detected
368 (#) Blocking mode APIs are :
369 (++) HAL_SMARTCARD_Transmit()
370 (++) HAL_SMARTCARD_Receive()
372 (#) Non Blocking mode APIs with Interrupt are :
373 (++) HAL_SMARTCARD_Transmit_IT()
374 (++) HAL_SMARTCARD_Receive_IT()
375 (++) HAL_SMARTCARD_IRQHandler()
377 (#) Non Blocking mode functions with DMA are :
378 (++) HAL_SMARTCARD_Transmit_DMA()
379 (++) HAL_SMARTCARD_Receive_DMA()
381 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
382 (++) HAL_SMARTCARD_TxCpltCallback()
383 (++) HAL_SMARTCARD_RxCpltCallback()
384 (++) HAL_SMARTCARD_ErrorCallback()
391 * @brief Send an amount of data in blocking mode
392 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
393 * the configuration information for SMARTCARD module.
394 * @param pData: pointer to data buffer
395 * @param Size: amount of data to be sent
396 * @param Timeout: Timeout duration
399 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
405 if((tmp1 == HAL_SMARTCARD_STATE_READY) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_RX))
407 if((pData == HAL_NULL) || (Size == 0))
415 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
416 /* Check if a non-blocking receive process is ongoing or not */
417 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)
419 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
423 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
426 hsc->TxXferSize = Size;
427 hsc->TxXferCount = Size;
428 while(hsc->TxXferCount > 0)
431 if(hsc->Init.WordLength == SMARTCARD_WORDLENGTH_9B)
433 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, Timeout) != HAL_OK)
437 tmp = (uint16_t*) pData;
438 hsc->Instance->DR = (*tmp & (uint16_t)0x01FF);
439 if(hsc->Init.Parity == SMARTCARD_PARITY_NONE)
450 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, Timeout) != HAL_OK)
454 hsc->Instance->DR = (*pData++ & (uint8_t)0xFF);
458 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, Timeout) != HAL_OK)
463 /* Check if a non-blocking receive process is ongoing or not */
464 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
466 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
470 hsc->State = HAL_SMARTCARD_STATE_READY;
472 /* Process Unlocked */
484 * @brief Receive an amount of data in blocking mode
485 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
486 * the configuration information for SMARTCARD module.
487 * @param pData: pointer to data buffer
488 * @param Size: amount of data to be received
489 * @param Timeout: Timeout duration
492 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
498 if((tmp1 == HAL_SMARTCARD_STATE_READY) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_TX))
500 if((pData == HAL_NULL) || (Size == 0))
508 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
510 /* Check if a non-blocking transmit process is ongoing or not */
511 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)
513 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
517 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
520 hsc->RxXferSize = Size;
521 hsc->RxXferCount = Size;
522 /* Check the remain data to be received */
523 while(hsc->RxXferCount > 0)
526 if(hsc->Init.WordLength == SMARTCARD_WORDLENGTH_9B)
528 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, Timeout) != HAL_OK)
532 tmp = (uint16_t*) pData;
533 if(hsc->Init.Parity == SMARTCARD_PARITY_NONE)
535 *tmp = (uint16_t)(hsc->Instance->DR & (uint16_t)0x01FF);
540 *tmp = (uint16_t)(hsc->Instance->DR & (uint16_t)0x00FF);
546 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, Timeout) != HAL_OK)
550 if(hsc->Init.Parity == SMARTCARD_PARITY_NONE)
552 *pData++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0x00FF);
556 *pData++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0x007F);
561 /* Check if a non-blocking transmit process is ongoing or not */
562 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
564 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
568 hsc->State = HAL_SMARTCARD_STATE_READY;
571 /* Process Unlocked */
583 * @brief Send an amount of data in non blocking mode
584 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
585 * the configuration information for SMARTCARD module.
586 * @param pData: pointer to data buffer
587 * @param Size: amount of data to be sent
590 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
595 if((tmp1 == HAL_SMARTCARD_STATE_READY) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_RX))
597 if((pData == HAL_NULL) || (Size == 0))
605 hsc->pTxBuffPtr = pData;
606 hsc->TxXferSize = Size;
607 hsc->TxXferCount = Size;
609 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
610 /* Check if a non-blocking receive process is ongoing or not */
611 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)
613 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
617 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
620 /* Enable the SMARTCARD Parity Error Interrupt */
621 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_PE);
623 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
624 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR);
626 /* Process Unlocked */
629 /* Enable the SMARTCARD Transmit data register empty Interrupt */
630 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TXE);
641 * @brief Receive an amount of data in non blocking mode
642 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
643 * the configuration information for SMARTCARD module.
644 * @param pData: pointer to data buffer
645 * @param Size: amount of data to be received
648 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
653 if((tmp1 == HAL_SMARTCARD_STATE_READY) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_TX))
655 if((pData == HAL_NULL) || (Size == 0))
663 hsc->pRxBuffPtr = pData;
664 hsc->RxXferSize = Size;
665 hsc->RxXferCount = Size;
667 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
668 /* Check if a non-blocking transmit process is ongoing or not */
669 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)
671 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
675 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
678 /* Enable the SMARTCARD Data Register not empty Interrupt */
679 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_RXNE);
681 /* Enable the SMARTCARD Parity Error Interrupt */
682 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_PE);
684 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
685 __SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR);
687 /* Process Unlocked */
699 * @brief Send an amount of data in non blocking mode
700 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
701 * the configuration information for SMARTCARD module.
702 * @param pData: pointer to data buffer
703 * @param Size: amount of data to be sent
706 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
712 if((tmp1 == HAL_SMARTCARD_STATE_READY) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_RX))
714 if((pData == HAL_NULL) || (Size == 0))
722 hsc->pTxBuffPtr = pData;
723 hsc->TxXferSize = Size;
724 hsc->TxXferCount = Size;
726 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
727 /* Check if a non-blocking receive process is ongoing or not */
728 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX)
730 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
734 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
737 /* Set the SMARTCARD DMA transfert complete callback */
738 hsc->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt;
740 /* Set the DMA error callback */
741 hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError;
743 /* Enable the SMARTCARD transmit DMA Stream */
744 tmp = (uint32_t*)&pData;
745 HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsc->Instance->DR, Size);
747 /* Enable the DMA transfer for transmit request by setting the DMAT bit
748 in the SMARTCARD CR3 register */
749 hsc->Instance->CR3 |= USART_CR3_DMAT;
751 /* Process Unlocked */
763 * @brief Receive an amount of data in non blocking mode
764 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
765 * the configuration information for SMARTCARD module.
766 * @param pData: pointer to data buffer
767 * @param Size: amount of data to be received
768 * @note When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit.s
771 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
777 if((tmp1 == HAL_SMARTCARD_STATE_READY) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_TX))
779 if((pData == HAL_NULL) || (Size == 0))
787 hsc->pRxBuffPtr = pData;
788 hsc->RxXferSize = Size;
790 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
791 /* Check if a non-blocking transmit process is ongoing or not */
792 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX)
794 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX;
798 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
801 /* Set the SMARTCARD DMA transfert complete callback */
802 hsc->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt;
804 /* Set the DMA error callback */
805 hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError;
807 /* Enable the DMA Stream */
808 tmp = (uint32_t*)&pData;
809 HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->DR, *(uint32_t*)tmp, Size);
811 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
812 in the SMARTCARD CR3 register */
813 hsc->Instance->CR3 |= USART_CR3_DMAR;
815 /* Process Unlocked */
827 * @brief This function handles SMARTCARD interrupt request.
828 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
829 * the configuration information for SMARTCARD module.
832 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc)
834 uint32_t tmp1 = 0, tmp2 = 0;
836 tmp1 = hsc->Instance->SR;
837 tmp2 = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_PE);
839 /* SMARTCARD parity error interrupt occured --------------------------------*/
840 if(((tmp1 & SMARTCARD_FLAG_PE) != RESET) && (tmp2 != RESET))
842 __HAL_SMARTCARD_CLEAR_PEFLAG(hsc);
843 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE;
846 tmp2 = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR);
847 /* SMARTCARD frame error interrupt occured ---------------------------------*/
848 if(((tmp1 & SMARTCARD_FLAG_FE) != RESET) && (tmp2 != RESET))
850 __HAL_SMARTCARD_CLEAR_FEFLAG(hsc);
851 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE;
854 tmp2 = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR);
855 /* SMARTCARD noise error interrupt occured ---------------------------------*/
856 if(((tmp1 & SMARTCARD_FLAG_NE) != RESET) && (tmp2 != RESET))
858 __HAL_SMARTCARD_CLEAR_NEFLAG(hsc);
859 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE;
862 tmp2 = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR);
863 /* SMARTCARD Over-Run interrupt occured ------------------------------------*/
864 if(((tmp1 & SMARTCARD_FLAG_ORE) != RESET) && (tmp2 != RESET))
866 __HAL_SMARTCARD_CLEAR_OREFLAG(hsc);
867 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE;
870 tmp2 = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_RXNE);
871 /* SMARTCARD in mode Receiver ----------------------------------------------*/
872 if(((tmp1 & SMARTCARD_FLAG_RXNE) != RESET) && (tmp2 != RESET))
874 SMARTCARD_Receive_IT(hsc);
877 tmp2 = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_TXE);
878 /* SMARTCARD in mode Transmitter -------------------------------------------*/
879 if(((tmp1 & SMARTCARD_FLAG_TXE) != RESET) && (tmp2 != RESET))
881 SMARTCARD_Transmit_IT(hsc);
884 /* Call the Error call Back in case of Errors */
885 if(hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE)
887 /* Set the SMARTCARD state ready to be able to start again the process */
888 hsc->State= HAL_SMARTCARD_STATE_READY;
889 HAL_SMARTCARD_ErrorCallback(hsc);
894 * @brief Tx Transfer completed callbacks
895 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
896 * the configuration information for SMARTCARD module.
899 __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
901 /* NOTE : This function Should not be modified, when the callback is needed,
902 the HAL_SMARTCARD_TxCpltCallback could be implemented in the user file
907 * @brief Rx Transfer completed callbacks
908 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
909 * the configuration information for SMARTCARD module.
912 __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
914 /* NOTE : This function Should not be modified, when the callback is needed,
915 the HAL_SMARTCARD_TxCpltCallback could be implemented in the user file
920 * @brief SMARTCARD error callbacks
921 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
922 * the configuration information for SMARTCARD module.
925 __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc)
927 /* NOTE : This function Should not be modified, when the callback is needed,
928 the HAL_SMARTCARD_ErrorCallback could be implemented in the user file
936 /** @defgroup SMARTCARD_Group3 Peripheral State and Errors functions
937 * @brief SMARTCARD State and Errors functions
940 ===============================================================================
941 ##### Peripheral State and Errors functions #####
942 ===============================================================================
944 This subsection provides a set of functions allowing to control the SmartCard.
945 (+) HAL_SMARTCARD_GetState() API can be helpful to check in run-time the state of the SmartCard peripheral.
946 (+) HAL_SMARTCARD_GetError() check in run-time errors that could be occured durung communication.
952 * @brief return the SMARTCARD state
953 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
954 * the configuration information for SMARTCARD module.
957 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc)
963 * @brief Return the SMARTCARD error code
964 * @param hsc : pointer to a SMARTCARD_HandleTypeDef structure that contains
965 * the configuration information for the specified SMARTCARD.
966 * @retval SMARTCARD Error Code
968 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc)
970 return hsc->ErrorCode;
978 * @brief DMA SMARTCARD transmit process complete callback
979 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
980 * the configuration information for the specified DMA module.
983 static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma)
985 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
987 hsc->TxXferCount = 0;
989 /* Disable the DMA transfer for transmit request by setting the DMAT bit
990 in the USART CR3 register */
991 hsc->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAT);
993 /* Wait for SMARTCARD TC Flag */
994 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, SMARTCARD_TIMEOUT_VALUE) != HAL_OK)
996 /* Timeout Occured */
997 hsc->State = HAL_SMARTCARD_STATE_TIMEOUT;
998 HAL_SMARTCARD_ErrorCallback(hsc);
1003 /* Check if a non-blocking receive process is ongoing or not */
1004 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
1006 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
1010 hsc->State = HAL_SMARTCARD_STATE_READY;
1012 HAL_SMARTCARD_TxCpltCallback(hsc);
1017 * @brief DMA SMARTCARD receive process complete callback
1018 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1019 * the configuration information for the specified DMA module.
1022 static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
1024 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1026 hsc->RxXferCount = 0;
1028 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
1029 in the USART CR3 register */
1030 hsc->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_DMAR);
1032 /* Check if a non-blocking transmit process is ongoing or not */
1033 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
1035 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
1039 hsc->State = HAL_SMARTCARD_STATE_READY;
1042 HAL_SMARTCARD_RxCpltCallback(hsc);
1046 * @brief DMA SMARTCARD communication error callback
1047 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
1048 * the configuration information for the specified DMA module.
1051 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
1053 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
1055 hsc->RxXferCount = 0;
1056 hsc->TxXferCount = 0;
1057 hsc->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
1058 hsc->State= HAL_SMARTCARD_STATE_READY;
1060 HAL_SMARTCARD_ErrorCallback(hsc);
1064 * @brief This function handles SMARTCARD Communication Timeout.
1065 * @param hsc: SMARTCARD handle
1066 * @param Flag: specifies the SMARTCARD flag to check.
1067 * @param Status: The new Flag status (SET or RESET).
1068 * @param Timeout: Timeout duration
1069 * @retval HAL status
1071 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout)
1073 uint32_t tickstart = 0;
1076 tickstart = HAL_GetTick();
1078 /* Wait until flag is set */
1081 while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) == RESET)
1083 /* Check for the Timeout */
1084 if(Timeout != HAL_MAX_DELAY)
1086 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1088 /* Disable TXE and RXNE interrupts for the interrupt process */
1089 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE);
1090 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE);
1092 hsc->State= HAL_SMARTCARD_STATE_READY;
1094 /* Process Unlocked */
1104 while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) != RESET)
1106 /* Check for the Timeout */
1107 if(Timeout != HAL_MAX_DELAY)
1109 if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout))
1111 /* Disable TXE and RXNE interrupts for the interrupt process */
1112 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE);
1113 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE);
1115 hsc->State= HAL_SMARTCARD_STATE_READY;
1117 /* Process Unlocked */
1129 * @brief Send an amount of data in non blocking mode
1130 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
1131 * the configuration information for SMARTCARD module.
1132 * @retval HAL status
1134 static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc)
1140 if((tmp1 == HAL_SMARTCARD_STATE_BUSY_TX) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_TX_RX))
1142 if(hsc->Init.WordLength == SMARTCARD_WORDLENGTH_9B)
1144 tmp = (uint16_t*) hsc->pTxBuffPtr;
1145 hsc->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
1146 if(hsc->Init.Parity == SMARTCARD_PARITY_NONE)
1148 hsc->pTxBuffPtr += 2;
1152 hsc->pTxBuffPtr += 1;
1157 hsc->Instance->DR = (uint8_t)(*hsc->pTxBuffPtr++ & (uint8_t)0x00FF);
1160 if(--hsc->TxXferCount == 0)
1162 /* Disable the SMARTCARD Transmit data register empty Interrupt */
1163 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE);
1165 /* Disable the SMARTCARD Parity Error Interrupt */
1166 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_PE);
1168 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
1169 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR);
1171 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, SMARTCARD_TIMEOUT_VALUE) != HAL_OK)
1176 /* Check if a non-blocking receive process is ongoing or not */
1177 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
1179 hsc->State = HAL_SMARTCARD_STATE_BUSY_RX;
1183 hsc->State = HAL_SMARTCARD_STATE_READY;
1186 HAL_SMARTCARD_TxCpltCallback(hsc);
1200 * @brief Receive an amount of data in non blocking mode
1201 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
1202 * the configuration information for SMARTCARD module.
1203 * @retval HAL status
1205 static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc)
1211 if((tmp1 == HAL_SMARTCARD_STATE_BUSY_RX) || (tmp1 == HAL_SMARTCARD_STATE_BUSY_TX_RX))
1213 if(hsc->Init.WordLength == SMARTCARD_WORDLENGTH_9B)
1215 tmp = (uint16_t*) hsc->pRxBuffPtr;
1216 if(hsc->Init.Parity == SMARTCARD_PARITY_NONE)
1218 *tmp = (uint16_t)(hsc->Instance->DR & (uint16_t)0x01FF);
1219 hsc->pRxBuffPtr += 2;
1223 *tmp = (uint16_t)(hsc->Instance->DR & (uint16_t)0x00FF);
1224 hsc->pRxBuffPtr += 1;
1229 if(hsc->Init.Parity == SMARTCARD_PARITY_NONE)
1231 *hsc->pRxBuffPtr++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0x00FF);
1235 *hsc->pRxBuffPtr++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0x007F);
1239 if(--hsc->RxXferCount == 0)
1241 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE);
1243 /* Disable the SMARTCARD Parity Error Interrupt */
1244 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_PE);
1246 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
1247 __SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR);
1249 /* Check if a non-blocking transmit process is ongoing or not */
1250 if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX)
1252 hsc->State = HAL_SMARTCARD_STATE_BUSY_TX;
1256 hsc->State = HAL_SMARTCARD_STATE_READY;
1259 HAL_SMARTCARD_RxCpltCallback(hsc);
1272 * @brief Configure the SMARTCARD peripheral
1273 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
1274 * the configuration information for SMARTCARD module.
1277 static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc)
1279 uint32_t tmpreg = 0x00;
1281 /* Check the parameters */
1282 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
1283 assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity));
1284 assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase));
1285 assert_param(IS_SMARTCARD_LASTBIT(hsc->Init.CLKLastBit));
1286 assert_param(IS_SMARTCARD_BAUDRATE(hsc->Init.BaudRate));
1287 assert_param(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength));
1288 assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits));
1289 assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity));
1290 assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode));
1291 assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState));
1293 /* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the
1294 receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */
1295 hsc->Instance->CR1 &= (uint32_t)~((uint32_t)(USART_CR1_TE | USART_CR1_RE));
1297 /*---------------------------- USART CR2 Configuration ---------------------*/
1298 tmpreg = hsc->Instance->CR2;
1299 /* Clear CLKEN, CPOL, CPHA and LBCL bits */
1300 tmpreg &= (uint32_t)~((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_LBCL));
1301 /* Configure the SMARTCARD Clock, CPOL, CPHA and LastBit -----------------------*/
1302 /* Set CPOL bit according to hsc->Init.CLKPolarity value */
1303 /* Set CPHA bit according to hsc->Init.CLKPhase value */
1304 /* Set LBCL bit according to hsc->Init.CLKLastBit value */
1305 /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
1306 tmpreg |= (uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity |
1307 hsc->Init.CLKPhase| hsc->Init.CLKLastBit | hsc->Init.StopBits);
1308 /* Write to USART CR2 */
1309 hsc->Instance->CR2 = (uint32_t)tmpreg;
1311 tmpreg = hsc->Instance->CR2;
1313 /* Clear STOP[13:12] bits */
1314 tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
1316 /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
1317 tmpreg |= (uint32_t)(hsc->Init.StopBits);
1319 /* Write to USART CR2 */
1320 hsc->Instance->CR2 = (uint32_t)tmpreg;
1322 /*-------------------------- USART CR1 Configuration -----------------------*/
1323 tmpreg = hsc->Instance->CR1;
1325 /* Clear M, PCE, PS, TE and RE bits */
1326 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
1329 /* Configure the SMARTCARD Word Length, Parity and mode:
1330 Set the M bits according to hsc->Init.WordLength value
1331 Set PCE and PS bits according to hsc->Init.Parity value
1332 Set TE and RE bits according to hsc->Init.Mode value */
1333 tmpreg |= (uint32_t)hsc->Init.WordLength | hsc->Init.Parity | hsc->Init.Mode;
1335 /* Write to USART CR1 */
1336 hsc->Instance->CR1 = (uint32_t)tmpreg;
1338 /*-------------------------- USART CR3 Configuration -----------------------*/
1339 /* Clear CTSE and RTSE bits */
1340 hsc->Instance->CR3 &= (uint32_t)~((uint32_t)(USART_CR3_RTSE | USART_CR3_CTSE));
1342 /*-------------------------- USART BRR Configuration -----------------------*/
1343 if((hsc->Instance == USART1) || (hsc->Instance == USART6))
1345 hsc->Instance->BRR = __SMARTCARD_BRR(HAL_RCC_GetPCLK2Freq(), hsc->Init.BaudRate);
1349 hsc->Instance->BRR = __SMARTCARD_BRR(HAL_RCC_GetPCLK1Freq(), hsc->Init.BaudRate);
1357 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
1366 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/