John Karatka / mbed

Fork of mbed-dev by mbed official

Committer:
AnnaBridge
Date:
Thu Nov 23 11:57:25 2017 +0000
Revision:
179:79309dc6340a
Parent:
165:e614a9f1c9e2
mbed-dev library. Release version 156

Who changed what in which revision?

UserRevisionLine numberNew contents of line
<> 144:ef7eb2e8f9f7 1 /**
<> 144:ef7eb2e8f9f7 2 ******************************************************************************
<> 144:ef7eb2e8f9f7 3 * @file stm32f1xx_hal_smartcard.c
<> 144:ef7eb2e8f9f7 4 * @author MCD Application Team
AnnaBridge 165:e614a9f1c9e2 5 * @version V1.1.0
AnnaBridge 165:e614a9f1c9e2 6 * @date 14-April-2017
<> 144:ef7eb2e8f9f7 7 * @brief SMARTCARD HAL module driver.
<> 144:ef7eb2e8f9f7 8 * This file provides firmware functions to manage the following
<> 144:ef7eb2e8f9f7 9 * functionalities of the SMARTCARD peripheral:
<> 144:ef7eb2e8f9f7 10 * + Initialization and de-initialization functions
<> 144:ef7eb2e8f9f7 11 * + IO operation functions
AnnaBridge 165:e614a9f1c9e2 12 * + Peripheral Control functions
<> 144:ef7eb2e8f9f7 13 * + Peripheral State and Errors functions
<> 144:ef7eb2e8f9f7 14 @verbatim
<> 144:ef7eb2e8f9f7 15 ==============================================================================
<> 144:ef7eb2e8f9f7 16 ##### How to use this driver #####
<> 144:ef7eb2e8f9f7 17 ==============================================================================
<> 144:ef7eb2e8f9f7 18 [..]
<> 144:ef7eb2e8f9f7 19 The SMARTCARD HAL driver can be used as follows:
<> 144:ef7eb2e8f9f7 20
<> 144:ef7eb2e8f9f7 21 (#) Declare a SMARTCARD_HandleTypeDef handle structure.
<> 144:ef7eb2e8f9f7 22 (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API:
AnnaBridge 165:e614a9f1c9e2 23 (##) Enable the USARTx interface clock.
<> 144:ef7eb2e8f9f7 24 (##) SMARTCARD pins configuration:
<> 144:ef7eb2e8f9f7 25 (+++) Enable the clock for the SMARTCARD GPIOs.
AnnaBridge 165:e614a9f1c9e2 26 (+++) Configure the SMARTCARD pins as alternate function pull-up.
<> 144:ef7eb2e8f9f7 27 (##) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT()
<> 144:ef7eb2e8f9f7 28 and HAL_SMARTCARD_Receive_IT() APIs):
<> 144:ef7eb2e8f9f7 29 (+++) Configure the USARTx interrupt priority.
<> 144:ef7eb2e8f9f7 30 (+++) Enable the NVIC USART IRQ handle.
<> 144:ef7eb2e8f9f7 31 (##) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA()
<> 144:ef7eb2e8f9f7 32 and HAL_SMARTCARD_Receive_DMA() APIs):
<> 144:ef7eb2e8f9f7 33 (+++) Declare a DMA handle structure for the Tx/Rx channel.
<> 144:ef7eb2e8f9f7 34 (+++) Enable the DMAx interface clock.
<> 144:ef7eb2e8f9f7 35 (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters.
<> 144:ef7eb2e8f9f7 36 (+++) Configure the DMA Tx/Rx channel.
AnnaBridge 165:e614a9f1c9e2 37 (+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle.
<> 144:ef7eb2e8f9f7 38 (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel.
<> 144:ef7eb2e8f9f7 39 (+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle
<> 144:ef7eb2e8f9f7 40 (used for last byte sending completion detection in DMA non circular mode)
<> 144:ef7eb2e8f9f7 41
AnnaBridge 165:e614a9f1c9e2 42 (#) Program the Baud Rate, Word Length, Stop Bit, Parity, Hardware
<> 144:ef7eb2e8f9f7 43 flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure.
<> 144:ef7eb2e8f9f7 44
<> 144:ef7eb2e8f9f7 45 (#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API:
AnnaBridge 165:e614a9f1c9e2 46 (++) These APIs configure also the low level Hardware GPIO, CLOCK, CORTEX...etc)
AnnaBridge 165:e614a9f1c9e2 47 by calling the customized HAL_SMARTCARD_MspInit() API.
AnnaBridge 165:e614a9f1c9e2 48 [..]
AnnaBridge 165:e614a9f1c9e2 49 (@)The specific SMARTCARD interrupts (Transmission complete interrupt,
AnnaBridge 165:e614a9f1c9e2 50 RXNE interrupt and Error Interrupts) will be managed using the macros
AnnaBridge 165:e614a9f1c9e2 51 __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process.
AnnaBridge 165:e614a9f1c9e2 52
AnnaBridge 165:e614a9f1c9e2 53 [..]
AnnaBridge 165:e614a9f1c9e2 54 Three operation modes are available within this driver:
<> 144:ef7eb2e8f9f7 55
AnnaBridge 165:e614a9f1c9e2 56 *** Polling mode IO operation ***
AnnaBridge 165:e614a9f1c9e2 57 =================================
AnnaBridge 165:e614a9f1c9e2 58 [..]
AnnaBridge 165:e614a9f1c9e2 59 (+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit()
AnnaBridge 165:e614a9f1c9e2 60 (+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive()
AnnaBridge 165:e614a9f1c9e2 61 *** Interrupt mode IO operation ***
AnnaBridge 165:e614a9f1c9e2 62 ===================================
AnnaBridge 165:e614a9f1c9e2 63 [..]
AnnaBridge 165:e614a9f1c9e2 64 (+) Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT()
AnnaBridge 165:e614a9f1c9e2 65 (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can
AnnaBridge 165:e614a9f1c9e2 66 add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback
AnnaBridge 165:e614a9f1c9e2 67 (+) Receive an amount of data in non blocking mode using HAL_SMARTCARD_Receive_IT()
AnnaBridge 165:e614a9f1c9e2 68 (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can
AnnaBridge 165:e614a9f1c9e2 69 add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback
AnnaBridge 165:e614a9f1c9e2 70 (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
AnnaBridge 165:e614a9f1c9e2 71 add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback
<> 144:ef7eb2e8f9f7 72
AnnaBridge 165:e614a9f1c9e2 73 *** DMA mode IO operation ***
AnnaBridge 165:e614a9f1c9e2 74 ==============================
AnnaBridge 165:e614a9f1c9e2 75 [..]
AnnaBridge 165:e614a9f1c9e2 76 (+) Send an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA()
AnnaBridge 165:e614a9f1c9e2 77 (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can
AnnaBridge 165:e614a9f1c9e2 78 add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback
AnnaBridge 165:e614a9f1c9e2 79 (+) Receive an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Receive_DMA()
AnnaBridge 165:e614a9f1c9e2 80 (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can
AnnaBridge 165:e614a9f1c9e2 81 add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback
AnnaBridge 165:e614a9f1c9e2 82 (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can
AnnaBridge 165:e614a9f1c9e2 83 add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback
<> 144:ef7eb2e8f9f7 84
AnnaBridge 165:e614a9f1c9e2 85 *** SMARTCARD HAL driver macros list ***
AnnaBridge 165:e614a9f1c9e2 86 =============================================
AnnaBridge 165:e614a9f1c9e2 87 [..]
AnnaBridge 165:e614a9f1c9e2 88 Below the list of most used macros in SMARTCARD HAL driver.
AnnaBridge 165:e614a9f1c9e2 89
AnnaBridge 165:e614a9f1c9e2 90 (+) __HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral
AnnaBridge 165:e614a9f1c9e2 91 (+) __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral
AnnaBridge 165:e614a9f1c9e2 92 (+) __HAL_SMARTCARD_GET_FLAG : Check whether the specified SMARTCARD flag is set or not
AnnaBridge 165:e614a9f1c9e2 93 (+) __HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag
AnnaBridge 165:e614a9f1c9e2 94 (+) __HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt
AnnaBridge 165:e614a9f1c9e2 95 (+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt
AnnaBridge 165:e614a9f1c9e2 96
AnnaBridge 165:e614a9f1c9e2 97 [..]
AnnaBridge 165:e614a9f1c9e2 98 (@) You can refer to the SMARTCARD HAL driver header file for more useful macros
AnnaBridge 165:e614a9f1c9e2 99
AnnaBridge 165:e614a9f1c9e2 100 @endverbatim
<> 144:ef7eb2e8f9f7 101 [..]
AnnaBridge 165:e614a9f1c9e2 102 (@) Additionnal remark: If the parity is enabled, then the MSB bit of the data written
AnnaBridge 165:e614a9f1c9e2 103 in the data register is transmitted but is changed by the parity bit.
AnnaBridge 165:e614a9f1c9e2 104 Depending on the frame length defined by the M bit (8-bits or 9-bits),
AnnaBridge 165:e614a9f1c9e2 105 the possible SMARTCARD frame formats are as listed in the following table:
AnnaBridge 165:e614a9f1c9e2 106 +-------------------------------------------------------------+
AnnaBridge 165:e614a9f1c9e2 107 | M bit | PCE bit | SMARTCARD frame |
AnnaBridge 165:e614a9f1c9e2 108 |---------------------|---------------------------------------|
AnnaBridge 165:e614a9f1c9e2 109 | 1 | 1 | | SB | 8 bit data | PB | STB | |
AnnaBridge 165:e614a9f1c9e2 110 +-------------------------------------------------------------+
<> 144:ef7eb2e8f9f7 111 ******************************************************************************
<> 144:ef7eb2e8f9f7 112 * @attention
<> 144:ef7eb2e8f9f7 113 *
AnnaBridge 165:e614a9f1c9e2 114 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
<> 144:ef7eb2e8f9f7 115 *
<> 144:ef7eb2e8f9f7 116 * Redistribution and use in source and binary forms, with or without modification,
<> 144:ef7eb2e8f9f7 117 * are permitted provided that the following conditions are met:
<> 144:ef7eb2e8f9f7 118 * 1. Redistributions of source code must retain the above copyright notice,
<> 144:ef7eb2e8f9f7 119 * this list of conditions and the following disclaimer.
<> 144:ef7eb2e8f9f7 120 * 2. Redistributions in binary form must reproduce the above copyright notice,
<> 144:ef7eb2e8f9f7 121 * this list of conditions and the following disclaimer in the documentation
<> 144:ef7eb2e8f9f7 122 * and/or other materials provided with the distribution.
<> 144:ef7eb2e8f9f7 123 * 3. Neither the name of STMicroelectronics nor the names of its contributors
<> 144:ef7eb2e8f9f7 124 * may be used to endorse or promote products derived from this software
<> 144:ef7eb2e8f9f7 125 * without specific prior written permission.
<> 144:ef7eb2e8f9f7 126 *
<> 144:ef7eb2e8f9f7 127 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
<> 144:ef7eb2e8f9f7 128 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
<> 144:ef7eb2e8f9f7 129 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
<> 144:ef7eb2e8f9f7 130 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
<> 144:ef7eb2e8f9f7 131 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
<> 144:ef7eb2e8f9f7 132 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
<> 144:ef7eb2e8f9f7 133 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
<> 144:ef7eb2e8f9f7 134 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
<> 144:ef7eb2e8f9f7 135 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
<> 144:ef7eb2e8f9f7 136 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
<> 144:ef7eb2e8f9f7 137 *
<> 144:ef7eb2e8f9f7 138 ******************************************************************************
<> 144:ef7eb2e8f9f7 139 */
<> 144:ef7eb2e8f9f7 140
<> 144:ef7eb2e8f9f7 141 /* Includes ------------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 142 #include "stm32f1xx_hal.h"
<> 144:ef7eb2e8f9f7 143
<> 144:ef7eb2e8f9f7 144 /** @addtogroup STM32F1xx_HAL_Driver
<> 144:ef7eb2e8f9f7 145 * @{
<> 144:ef7eb2e8f9f7 146 */
<> 144:ef7eb2e8f9f7 147
<> 144:ef7eb2e8f9f7 148 /** @defgroup SMARTCARD SMARTCARD
<> 144:ef7eb2e8f9f7 149 * @brief HAL SMARTCARD module driver
<> 144:ef7eb2e8f9f7 150 * @{
<> 144:ef7eb2e8f9f7 151 */
<> 144:ef7eb2e8f9f7 152 #ifdef HAL_SMARTCARD_MODULE_ENABLED
<> 144:ef7eb2e8f9f7 153 /* Private typedef -----------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 154 /* Private define ------------------------------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 155 /** @addtogroup SMARTCARD_Private_Constants
AnnaBridge 165:e614a9f1c9e2 156 * @{
AnnaBridge 165:e614a9f1c9e2 157 */
AnnaBridge 165:e614a9f1c9e2 158 /**
AnnaBridge 165:e614a9f1c9e2 159 * @}
AnnaBridge 165:e614a9f1c9e2 160 */
AnnaBridge 165:e614a9f1c9e2 161 /* Private macro -------------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 162 /* Private variables ---------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 163 /* Private function prototypes -----------------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 164 /** @addtogroup SMARTCARD_Private_Functions
<> 144:ef7eb2e8f9f7 165 * @{
<> 144:ef7eb2e8f9f7 166 */
AnnaBridge 165:e614a9f1c9e2 167 static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 165:e614a9f1c9e2 168 static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsc);
AnnaBridge 165:e614a9f1c9e2 169 static void SMARTCARD_SetConfig (SMARTCARD_HandleTypeDef *hsc);
<> 144:ef7eb2e8f9f7 170 static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc);
<> 144:ef7eb2e8f9f7 171 static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
<> 144:ef7eb2e8f9f7 172 static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc);
<> 144:ef7eb2e8f9f7 173 static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma);
<> 144:ef7eb2e8f9f7 174 static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma);
<> 144:ef7eb2e8f9f7 175 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma);
AnnaBridge 165:e614a9f1c9e2 176 static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma);
AnnaBridge 165:e614a9f1c9e2 177 static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma);
AnnaBridge 165:e614a9f1c9e2 178 static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma);
AnnaBridge 165:e614a9f1c9e2 179 static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
AnnaBridge 165:e614a9f1c9e2 180 static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma);
AnnaBridge 165:e614a9f1c9e2 181 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout);
<> 144:ef7eb2e8f9f7 182 /**
<> 144:ef7eb2e8f9f7 183 * @}
<> 144:ef7eb2e8f9f7 184 */
AnnaBridge 165:e614a9f1c9e2 185 /* Exported functions --------------------------------------------------------*/
<> 144:ef7eb2e8f9f7 186 /** @defgroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions
<> 144:ef7eb2e8f9f7 187 * @{
<> 144:ef7eb2e8f9f7 188 */
<> 144:ef7eb2e8f9f7 189
AnnaBridge 165:e614a9f1c9e2 190 /** @defgroup SMARTCARD_Exported_Functions_Group1 SmartCard Initialization and de-initialization functions
<> 144:ef7eb2e8f9f7 191 * @brief Initialization and Configuration functions
<> 144:ef7eb2e8f9f7 192 *
<> 144:ef7eb2e8f9f7 193 @verbatim
<> 144:ef7eb2e8f9f7 194 ==============================================================================
AnnaBridge 165:e614a9f1c9e2 195 ##### Initialization and Configuration functions #####
<> 144:ef7eb2e8f9f7 196 ==============================================================================
<> 144:ef7eb2e8f9f7 197 [..]
<> 144:ef7eb2e8f9f7 198 This subsection provides a set of functions allowing to initialize the USART
<> 144:ef7eb2e8f9f7 199 in Smartcard mode.
<> 144:ef7eb2e8f9f7 200 [..]
<> 144:ef7eb2e8f9f7 201 The Smartcard interface is designed to support asynchronous protocol Smartcards as
<> 144:ef7eb2e8f9f7 202 defined in the ISO 7816-3 standard.
<> 144:ef7eb2e8f9f7 203 [..]
<> 144:ef7eb2e8f9f7 204 The USART can provide a clock to the smartcard through the SCLK output.
<> 144:ef7eb2e8f9f7 205 In smartcard mode, SCLK is not associated to the communication but is simply derived
<> 144:ef7eb2e8f9f7 206 from the internal peripheral input clock through a 5-bit prescaler.
<> 144:ef7eb2e8f9f7 207 [..]
<> 144:ef7eb2e8f9f7 208 (+) For the Smartcard mode only these parameters can be configured:
<> 144:ef7eb2e8f9f7 209 (++) Baud Rate
<> 144:ef7eb2e8f9f7 210 (++) Word Length => Should be 9 bits (8 bits + parity)
<> 144:ef7eb2e8f9f7 211 (++) Stop Bit
AnnaBridge 165:e614a9f1c9e2 212 (++) Parity: => Should be enabled
<> 144:ef7eb2e8f9f7 213 (++) USART polarity
<> 144:ef7eb2e8f9f7 214 (++) USART phase
<> 144:ef7eb2e8f9f7 215 (++) USART LastBit
<> 144:ef7eb2e8f9f7 216 (++) Receiver/transmitter modes
<> 144:ef7eb2e8f9f7 217 (++) Prescaler
<> 144:ef7eb2e8f9f7 218 (++) GuardTime
<> 144:ef7eb2e8f9f7 219 (++) NACKState: The Smartcard NACK state
<> 144:ef7eb2e8f9f7 220
<> 144:ef7eb2e8f9f7 221 (+) Recommended SmartCard interface configuration to get the Answer to Reset from the Card:
<> 144:ef7eb2e8f9f7 222 (++) Word Length = 9 Bits
<> 144:ef7eb2e8f9f7 223 (++) 1.5 Stop Bit
<> 144:ef7eb2e8f9f7 224 (++) Even parity
<> 144:ef7eb2e8f9f7 225 (++) BaudRate = 12096 baud
<> 144:ef7eb2e8f9f7 226 (++) Tx and Rx enabled
<> 144:ef7eb2e8f9f7 227 [..]
<> 144:ef7eb2e8f9f7 228 Please refer to the ISO 7816-3 specification for more details.
<> 144:ef7eb2e8f9f7 229
<> 144:ef7eb2e8f9f7 230 [..]
AnnaBridge 165:e614a9f1c9e2 231 (@) It is also possible to choose 0.5 stop bit for receiving but it is recommended
AnnaBridge 165:e614a9f1c9e2 232 to use 1.5 stop bits for both transmitting and receiving to avoid switching
AnnaBridge 165:e614a9f1c9e2 233 between the two configurations.
AnnaBridge 165:e614a9f1c9e2 234 [..]
AnnaBridge 165:e614a9f1c9e2 235 The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration
AnnaBridge 165:e614a9f1c9e2 236 procedure (details for the procedure are available in reference manual (RM0329)).
<> 144:ef7eb2e8f9f7 237
<> 144:ef7eb2e8f9f7 238 @endverbatim
<> 144:ef7eb2e8f9f7 239 * @{
<> 144:ef7eb2e8f9f7 240 */
<> 144:ef7eb2e8f9f7 241
<> 144:ef7eb2e8f9f7 242 /**
AnnaBridge 165:e614a9f1c9e2 243 * @brief Initializes the SmartCard mode according to the specified
AnnaBridge 165:e614a9f1c9e2 244 * parameters in the SMARTCARD_InitTypeDef and create the associated handle.
AnnaBridge 165:e614a9f1c9e2 245 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 246 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 247 * @retval HAL status
<> 144:ef7eb2e8f9f7 248 */
<> 144:ef7eb2e8f9f7 249 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 250 {
<> 144:ef7eb2e8f9f7 251 /* Check the SMARTCARD handle allocation */
<> 144:ef7eb2e8f9f7 252 if(hsc == NULL)
<> 144:ef7eb2e8f9f7 253 {
<> 144:ef7eb2e8f9f7 254 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 255 }
<> 144:ef7eb2e8f9f7 256
<> 144:ef7eb2e8f9f7 257 /* Check the parameters */
<> 144:ef7eb2e8f9f7 258 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
AnnaBridge 165:e614a9f1c9e2 259
<> 144:ef7eb2e8f9f7 260
AnnaBridge 165:e614a9f1c9e2 261 if(hsc->gState == HAL_SMARTCARD_STATE_RESET)
<> 144:ef7eb2e8f9f7 262 {
<> 144:ef7eb2e8f9f7 263 /* Allocate lock resource and initialize it */
<> 144:ef7eb2e8f9f7 264 hsc->Lock = HAL_UNLOCKED;
AnnaBridge 165:e614a9f1c9e2 265
AnnaBridge 165:e614a9f1c9e2 266 /* Init the low level hardware : GPIO, CLOCK, CORTEX...etc */
<> 144:ef7eb2e8f9f7 267 HAL_SMARTCARD_MspInit(hsc);
<> 144:ef7eb2e8f9f7 268 }
<> 144:ef7eb2e8f9f7 269
AnnaBridge 165:e614a9f1c9e2 270 hsc->gState = HAL_SMARTCARD_STATE_BUSY;
AnnaBridge 165:e614a9f1c9e2 271
<> 144:ef7eb2e8f9f7 272 /* Set the Prescaler */
<> 144:ef7eb2e8f9f7 273 MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_PSC, hsc->Init.Prescaler);
<> 144:ef7eb2e8f9f7 274
<> 144:ef7eb2e8f9f7 275 /* Set the Guard Time */
AnnaBridge 165:e614a9f1c9e2 276 MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_GT, ((hsc->Init.GuardTime)<<8U));
<> 144:ef7eb2e8f9f7 277
<> 144:ef7eb2e8f9f7 278 /* Set the Smartcard Communication parameters */
<> 144:ef7eb2e8f9f7 279 SMARTCARD_SetConfig(hsc);
<> 144:ef7eb2e8f9f7 280
<> 144:ef7eb2e8f9f7 281 /* In SmartCard mode, the following bits must be kept cleared:
<> 144:ef7eb2e8f9f7 282 - LINEN bit in the USART_CR2 register
<> 144:ef7eb2e8f9f7 283 - HDSEL and IREN bits in the USART_CR3 register.*/
<> 144:ef7eb2e8f9f7 284 CLEAR_BIT(hsc->Instance->CR2, USART_CR2_LINEN);
<> 144:ef7eb2e8f9f7 285 CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_IREN | USART_CR3_HDSEL));
<> 144:ef7eb2e8f9f7 286
AnnaBridge 165:e614a9f1c9e2 287 /* Enable the SMARTCARD Parity Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 288 SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE);
AnnaBridge 165:e614a9f1c9e2 289
AnnaBridge 165:e614a9f1c9e2 290 /* Enable the SMARTCARD Framing Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 291 SET_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 292
AnnaBridge 165:e614a9f1c9e2 293 /* Enable the Peripheral */
<> 144:ef7eb2e8f9f7 294 __HAL_SMARTCARD_ENABLE(hsc);
<> 144:ef7eb2e8f9f7 295
<> 144:ef7eb2e8f9f7 296 /* Configure the Smartcard NACK state */
<> 144:ef7eb2e8f9f7 297 MODIFY_REG(hsc->Instance->CR3, USART_CR3_NACK, hsc->Init.NACKState);
<> 144:ef7eb2e8f9f7 298
<> 144:ef7eb2e8f9f7 299 /* Enable the SC mode by setting the SCEN bit in the CR3 register */
AnnaBridge 165:e614a9f1c9e2 300 hsc->Instance->CR3 |= (USART_CR3_SCEN);
<> 144:ef7eb2e8f9f7 301
<> 144:ef7eb2e8f9f7 302 /* Initialize the SMARTCARD state*/
<> 144:ef7eb2e8f9f7 303 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 304 hsc->gState= HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 305 hsc->RxState= HAL_SMARTCARD_STATE_READY;
<> 144:ef7eb2e8f9f7 306
<> 144:ef7eb2e8f9f7 307 return HAL_OK;
<> 144:ef7eb2e8f9f7 308 }
<> 144:ef7eb2e8f9f7 309
<> 144:ef7eb2e8f9f7 310 /**
AnnaBridge 165:e614a9f1c9e2 311 * @brief DeInitializes the USART SmartCard peripheral
AnnaBridge 165:e614a9f1c9e2 312 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 313 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 314 * @retval HAL status
<> 144:ef7eb2e8f9f7 315 */
<> 144:ef7eb2e8f9f7 316 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 317 {
<> 144:ef7eb2e8f9f7 318 /* Check the SMARTCARD handle allocation */
<> 144:ef7eb2e8f9f7 319 if(hsc == NULL)
<> 144:ef7eb2e8f9f7 320 {
<> 144:ef7eb2e8f9f7 321 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 322 }
<> 144:ef7eb2e8f9f7 323
<> 144:ef7eb2e8f9f7 324 /* Check the parameters */
<> 144:ef7eb2e8f9f7 325 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
<> 144:ef7eb2e8f9f7 326
AnnaBridge 165:e614a9f1c9e2 327 hsc->gState = HAL_SMARTCARD_STATE_BUSY;
<> 144:ef7eb2e8f9f7 328
<> 144:ef7eb2e8f9f7 329 /* DeInit the low level hardware */
<> 144:ef7eb2e8f9f7 330 HAL_SMARTCARD_MspDeInit(hsc);
<> 144:ef7eb2e8f9f7 331
<> 144:ef7eb2e8f9f7 332 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 333 hsc->gState = HAL_SMARTCARD_STATE_RESET;
AnnaBridge 165:e614a9f1c9e2 334 hsc->RxState = HAL_SMARTCARD_STATE_RESET;
<> 144:ef7eb2e8f9f7 335
<> 144:ef7eb2e8f9f7 336 /* Release Lock */
<> 144:ef7eb2e8f9f7 337 __HAL_UNLOCK(hsc);
<> 144:ef7eb2e8f9f7 338
<> 144:ef7eb2e8f9f7 339 return HAL_OK;
<> 144:ef7eb2e8f9f7 340 }
<> 144:ef7eb2e8f9f7 341
<> 144:ef7eb2e8f9f7 342 /**
AnnaBridge 165:e614a9f1c9e2 343 * @brief SMARTCARD MSP Init.
AnnaBridge 165:e614a9f1c9e2 344 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 345 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 346 * @retval None
<> 144:ef7eb2e8f9f7 347 */
AnnaBridge 165:e614a9f1c9e2 348 __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 349 {
<> 144:ef7eb2e8f9f7 350 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 351 UNUSED(hsc);
<> 144:ef7eb2e8f9f7 352 /* NOTE: This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 353 the HAL_SMARTCARD_MspInit could be implemented in the user file
AnnaBridge 165:e614a9f1c9e2 354 */
<> 144:ef7eb2e8f9f7 355 }
<> 144:ef7eb2e8f9f7 356
<> 144:ef7eb2e8f9f7 357 /**
AnnaBridge 165:e614a9f1c9e2 358 * @brief SMARTCARD MSP DeInit
AnnaBridge 165:e614a9f1c9e2 359 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 360 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 361 * @retval None
<> 144:ef7eb2e8f9f7 362 */
AnnaBridge 165:e614a9f1c9e2 363 __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 364 {
<> 144:ef7eb2e8f9f7 365 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 366 UNUSED(hsc);
<> 144:ef7eb2e8f9f7 367 /* NOTE: This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 368 the HAL_SMARTCARD_MspDeInit could be implemented in the user file
AnnaBridge 165:e614a9f1c9e2 369 */
<> 144:ef7eb2e8f9f7 370 }
<> 144:ef7eb2e8f9f7 371
<> 144:ef7eb2e8f9f7 372 /**
<> 144:ef7eb2e8f9f7 373 * @}
<> 144:ef7eb2e8f9f7 374 */
<> 144:ef7eb2e8f9f7 375
<> 144:ef7eb2e8f9f7 376 /** @defgroup SMARTCARD_Exported_Functions_Group2 IO operation functions
<> 144:ef7eb2e8f9f7 377 * @brief SMARTCARD Transmit and Receive functions
<> 144:ef7eb2e8f9f7 378 *
<> 144:ef7eb2e8f9f7 379 @verbatim
AnnaBridge 165:e614a9f1c9e2 380 ===============================================================================
AnnaBridge 165:e614a9f1c9e2 381 ##### IO operation functions #####
AnnaBridge 165:e614a9f1c9e2 382 ===============================================================================
AnnaBridge 165:e614a9f1c9e2 383 [..]
AnnaBridge 165:e614a9f1c9e2 384 This subsection provides a set of functions allowing to manage the SMARTCARD data transfers.
<> 144:ef7eb2e8f9f7 385
AnnaBridge 165:e614a9f1c9e2 386 [..]
<> 144:ef7eb2e8f9f7 387 (#) Smartcard is a single wire half duplex communication protocol.
<> 144:ef7eb2e8f9f7 388 The Smartcard interface is designed to support asynchronous protocol Smartcards as
<> 144:ef7eb2e8f9f7 389 defined in the ISO 7816-3 standard.
<> 144:ef7eb2e8f9f7 390 (#) The USART should be configured as:
AnnaBridge 165:e614a9f1c9e2 391 (++) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register
AnnaBridge 165:e614a9f1c9e2 392 (++) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register.
<> 144:ef7eb2e8f9f7 393
<> 144:ef7eb2e8f9f7 394 (#) There are two modes of transfer:
AnnaBridge 165:e614a9f1c9e2 395 (++) Blocking mode: The communication is performed in polling mode.
AnnaBridge 165:e614a9f1c9e2 396 The HAL status of all data processing is returned by the same function
AnnaBridge 165:e614a9f1c9e2 397 after finishing transfer.
AnnaBridge 165:e614a9f1c9e2 398 (++) Non Blocking mode: The communication is performed using Interrupts
AnnaBridge 165:e614a9f1c9e2 399 or DMA, These APIs return the HAL status.
AnnaBridge 165:e614a9f1c9e2 400 The end of the data processing will be indicated through the
AnnaBridge 165:e614a9f1c9e2 401 dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when
AnnaBridge 165:e614a9f1c9e2 402 using DMA mode.
AnnaBridge 165:e614a9f1c9e2 403 The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks
AnnaBridge 165:e614a9f1c9e2 404 will be executed respectively at the end of the Transmit or Receive process
AnnaBridge 165:e614a9f1c9e2 405 The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication error is detected
<> 144:ef7eb2e8f9f7 406
<> 144:ef7eb2e8f9f7 407 (#) Blocking mode APIs are :
<> 144:ef7eb2e8f9f7 408 (++) HAL_SMARTCARD_Transmit()
<> 144:ef7eb2e8f9f7 409 (++) HAL_SMARTCARD_Receive()
<> 144:ef7eb2e8f9f7 410
<> 144:ef7eb2e8f9f7 411 (#) Non Blocking mode APIs with Interrupt are :
<> 144:ef7eb2e8f9f7 412 (++) HAL_SMARTCARD_Transmit_IT()
<> 144:ef7eb2e8f9f7 413 (++) HAL_SMARTCARD_Receive_IT()
<> 144:ef7eb2e8f9f7 414 (++) HAL_SMARTCARD_IRQHandler()
<> 144:ef7eb2e8f9f7 415
<> 144:ef7eb2e8f9f7 416 (#) Non Blocking mode functions with DMA are :
<> 144:ef7eb2e8f9f7 417 (++) HAL_SMARTCARD_Transmit_DMA()
<> 144:ef7eb2e8f9f7 418 (++) HAL_SMARTCARD_Receive_DMA()
<> 144:ef7eb2e8f9f7 419
<> 144:ef7eb2e8f9f7 420 (#) A set of Transfer Complete Callbacks are provided in non Blocking mode:
<> 144:ef7eb2e8f9f7 421 (++) HAL_SMARTCARD_TxCpltCallback()
<> 144:ef7eb2e8f9f7 422 (++) HAL_SMARTCARD_RxCpltCallback()
<> 144:ef7eb2e8f9f7 423 (++) HAL_SMARTCARD_ErrorCallback()
<> 144:ef7eb2e8f9f7 424
<> 144:ef7eb2e8f9f7 425 @endverbatim
<> 144:ef7eb2e8f9f7 426 * @{
<> 144:ef7eb2e8f9f7 427 */
<> 144:ef7eb2e8f9f7 428
<> 144:ef7eb2e8f9f7 429 /**
AnnaBridge 165:e614a9f1c9e2 430 * @brief Send an amount of data in blocking mode
AnnaBridge 165:e614a9f1c9e2 431 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 432 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 433 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 434 * @param Size: amount of data to be sent
AnnaBridge 165:e614a9f1c9e2 435 * @param Timeout: Timeout duration
<> 144:ef7eb2e8f9f7 436 * @retval HAL status
<> 144:ef7eb2e8f9f7 437 */
<> 144:ef7eb2e8f9f7 438 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
<> 144:ef7eb2e8f9f7 439 {
AnnaBridge 165:e614a9f1c9e2 440 uint16_t* tmp;
AnnaBridge 165:e614a9f1c9e2 441 uint32_t tickstart = 0U;
<> 144:ef7eb2e8f9f7 442
AnnaBridge 165:e614a9f1c9e2 443 if(hsc->gState == HAL_SMARTCARD_STATE_READY)
<> 144:ef7eb2e8f9f7 444 {
AnnaBridge 165:e614a9f1c9e2 445 if((pData == NULL) || (Size == 0U))
<> 144:ef7eb2e8f9f7 446 {
<> 144:ef7eb2e8f9f7 447 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 448 }
<> 144:ef7eb2e8f9f7 449
<> 144:ef7eb2e8f9f7 450 /* Process Locked */
<> 144:ef7eb2e8f9f7 451 __HAL_LOCK(hsc);
<> 144:ef7eb2e8f9f7 452
<> 144:ef7eb2e8f9f7 453 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 454 hsc->gState = HAL_SMARTCARD_STATE_BUSY_TX;
AnnaBridge 165:e614a9f1c9e2 455
AnnaBridge 165:e614a9f1c9e2 456 /* Init tickstart for timeout managment */
AnnaBridge 165:e614a9f1c9e2 457 tickstart = HAL_GetTick();
AnnaBridge 165:e614a9f1c9e2 458
<> 144:ef7eb2e8f9f7 459 hsc->TxXferSize = Size;
<> 144:ef7eb2e8f9f7 460 hsc->TxXferCount = Size;
AnnaBridge 165:e614a9f1c9e2 461 while(hsc->TxXferCount > 0U)
<> 144:ef7eb2e8f9f7 462 {
AnnaBridge 165:e614a9f1c9e2 463 hsc->TxXferCount--;
AnnaBridge 165:e614a9f1c9e2 464 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, tickstart, Timeout) != HAL_OK)
<> 144:ef7eb2e8f9f7 465 {
<> 144:ef7eb2e8f9f7 466 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 467 }
AnnaBridge 165:e614a9f1c9e2 468 tmp = (uint16_t*) pData;
AnnaBridge 165:e614a9f1c9e2 469 hsc->Instance->DR = (*tmp & (uint16_t)0x01FF);
AnnaBridge 165:e614a9f1c9e2 470 pData +=1U;
<> 144:ef7eb2e8f9f7 471 }
AnnaBridge 165:e614a9f1c9e2 472
AnnaBridge 165:e614a9f1c9e2 473 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, tickstart, Timeout) != HAL_OK)
<> 144:ef7eb2e8f9f7 474 {
<> 144:ef7eb2e8f9f7 475 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 476 }
<> 144:ef7eb2e8f9f7 477
AnnaBridge 165:e614a9f1c9e2 478 /* At end of Tx process, restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 479 hsc->gState = HAL_SMARTCARD_STATE_READY;
<> 144:ef7eb2e8f9f7 480
<> 144:ef7eb2e8f9f7 481 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 482 __HAL_UNLOCK(hsc);
<> 144:ef7eb2e8f9f7 483
<> 144:ef7eb2e8f9f7 484 return HAL_OK;
<> 144:ef7eb2e8f9f7 485 }
<> 144:ef7eb2e8f9f7 486 else
<> 144:ef7eb2e8f9f7 487 {
<> 144:ef7eb2e8f9f7 488 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 489 }
<> 144:ef7eb2e8f9f7 490 }
<> 144:ef7eb2e8f9f7 491
<> 144:ef7eb2e8f9f7 492 /**
AnnaBridge 165:e614a9f1c9e2 493 * @brief Receive an amount of data in blocking mode
AnnaBridge 165:e614a9f1c9e2 494 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 495 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 496 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 497 * @param Size: amount of data to be received
AnnaBridge 165:e614a9f1c9e2 498 * @param Timeout: Timeout duration
<> 144:ef7eb2e8f9f7 499 * @retval HAL status
<> 144:ef7eb2e8f9f7 500 */
AnnaBridge 165:e614a9f1c9e2 501 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout)
<> 144:ef7eb2e8f9f7 502 {
AnnaBridge 165:e614a9f1c9e2 503 uint32_t tickstart = 0U;
<> 144:ef7eb2e8f9f7 504
AnnaBridge 165:e614a9f1c9e2 505 if(hsc->RxState == HAL_SMARTCARD_STATE_READY)
<> 144:ef7eb2e8f9f7 506 {
AnnaBridge 165:e614a9f1c9e2 507 if((pData == NULL) || (Size == 0U))
<> 144:ef7eb2e8f9f7 508 {
AnnaBridge 165:e614a9f1c9e2 509 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 510 }
<> 144:ef7eb2e8f9f7 511
<> 144:ef7eb2e8f9f7 512 /* Process Locked */
<> 144:ef7eb2e8f9f7 513 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 514
AnnaBridge 165:e614a9f1c9e2 515 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 516 hsc->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
<> 144:ef7eb2e8f9f7 517
AnnaBridge 165:e614a9f1c9e2 518 /* Init tickstart for timeout managment */
AnnaBridge 165:e614a9f1c9e2 519 tickstart = HAL_GetTick();
AnnaBridge 165:e614a9f1c9e2 520
<> 144:ef7eb2e8f9f7 521 hsc->RxXferSize = Size;
<> 144:ef7eb2e8f9f7 522 hsc->RxXferCount = Size;
<> 144:ef7eb2e8f9f7 523
AnnaBridge 165:e614a9f1c9e2 524 /* Check the remain data to be received */
AnnaBridge 165:e614a9f1c9e2 525 while(hsc->RxXferCount > 0U)
<> 144:ef7eb2e8f9f7 526 {
AnnaBridge 165:e614a9f1c9e2 527 hsc->RxXferCount--;
AnnaBridge 165:e614a9f1c9e2 528 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 529 {
AnnaBridge 165:e614a9f1c9e2 530 return HAL_TIMEOUT;
AnnaBridge 165:e614a9f1c9e2 531 }
AnnaBridge 179:79309dc6340a 532 *pData = (uint8_t)(hsc->Instance->DR & (uint8_t)0xFF);
AnnaBridge 165:e614a9f1c9e2 533 pData +=1U;
<> 144:ef7eb2e8f9f7 534 }
<> 144:ef7eb2e8f9f7 535
AnnaBridge 165:e614a9f1c9e2 536 /* At end of Rx process, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 537 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 538
<> 144:ef7eb2e8f9f7 539 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 540 __HAL_UNLOCK(hsc);
<> 144:ef7eb2e8f9f7 541
<> 144:ef7eb2e8f9f7 542 return HAL_OK;
<> 144:ef7eb2e8f9f7 543 }
<> 144:ef7eb2e8f9f7 544 else
<> 144:ef7eb2e8f9f7 545 {
<> 144:ef7eb2e8f9f7 546 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 547 }
<> 144:ef7eb2e8f9f7 548 }
<> 144:ef7eb2e8f9f7 549
<> 144:ef7eb2e8f9f7 550 /**
AnnaBridge 165:e614a9f1c9e2 551 * @brief Send an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 552 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 553 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 554 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 555 * @param Size: amount of data to be sent
AnnaBridge 165:e614a9f1c9e2 556 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 557 */
AnnaBridge 165:e614a9f1c9e2 558 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 559 {
AnnaBridge 165:e614a9f1c9e2 560 /* Check that a Tx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 561 if(hsc->gState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 562 {
AnnaBridge 165:e614a9f1c9e2 563 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 564 {
AnnaBridge 165:e614a9f1c9e2 565 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 566 }
AnnaBridge 165:e614a9f1c9e2 567 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 568 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 569
AnnaBridge 165:e614a9f1c9e2 570 hsc->pTxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 571 hsc->TxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 572 hsc->TxXferCount = Size;
AnnaBridge 165:e614a9f1c9e2 573
AnnaBridge 165:e614a9f1c9e2 574 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 575 hsc->gState = HAL_SMARTCARD_STATE_BUSY_TX;
AnnaBridge 165:e614a9f1c9e2 576
AnnaBridge 165:e614a9f1c9e2 577 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 578 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 579
AnnaBridge 165:e614a9f1c9e2 580 /* Enable the SMARTCARD Parity Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 581 SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE);
AnnaBridge 165:e614a9f1c9e2 582
AnnaBridge 165:e614a9f1c9e2 583 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 584 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 585
AnnaBridge 165:e614a9f1c9e2 586 /* Enable the SMARTCARD Transmit data register empty Interrupt */
AnnaBridge 165:e614a9f1c9e2 587 SET_BIT(hsc->Instance->CR1, USART_CR1_TXEIE);
AnnaBridge 165:e614a9f1c9e2 588
AnnaBridge 165:e614a9f1c9e2 589 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 590 }
AnnaBridge 165:e614a9f1c9e2 591 else
AnnaBridge 165:e614a9f1c9e2 592 {
AnnaBridge 165:e614a9f1c9e2 593 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 594 }
AnnaBridge 165:e614a9f1c9e2 595 }
AnnaBridge 165:e614a9f1c9e2 596
AnnaBridge 165:e614a9f1c9e2 597 /**
AnnaBridge 165:e614a9f1c9e2 598 * @brief Receive an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 599 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 600 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 601 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 602 * @param Size: amount of data to be received
AnnaBridge 165:e614a9f1c9e2 603 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 604 */
AnnaBridge 165:e614a9f1c9e2 605 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 606 {
AnnaBridge 165:e614a9f1c9e2 607 /* Check that a Rx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 608 if(hsc->RxState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 609 {
AnnaBridge 165:e614a9f1c9e2 610 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 611 {
AnnaBridge 165:e614a9f1c9e2 612 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 613 }
AnnaBridge 165:e614a9f1c9e2 614
AnnaBridge 165:e614a9f1c9e2 615 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 616 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 617
AnnaBridge 165:e614a9f1c9e2 618 hsc->pRxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 619 hsc->RxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 620 hsc->RxXferCount = Size;
AnnaBridge 165:e614a9f1c9e2 621
AnnaBridge 165:e614a9f1c9e2 622 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 623 hsc->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
AnnaBridge 165:e614a9f1c9e2 624
AnnaBridge 165:e614a9f1c9e2 625 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 626 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 627
AnnaBridge 165:e614a9f1c9e2 628 /* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */
AnnaBridge 165:e614a9f1c9e2 629 SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE| USART_CR1_RXNEIE);
AnnaBridge 165:e614a9f1c9e2 630
AnnaBridge 165:e614a9f1c9e2 631 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 632 SET_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 633
AnnaBridge 165:e614a9f1c9e2 634 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 635 }
AnnaBridge 165:e614a9f1c9e2 636 else
AnnaBridge 165:e614a9f1c9e2 637 {
AnnaBridge 165:e614a9f1c9e2 638 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 639 }
AnnaBridge 165:e614a9f1c9e2 640 }
AnnaBridge 165:e614a9f1c9e2 641
AnnaBridge 165:e614a9f1c9e2 642 /**
AnnaBridge 165:e614a9f1c9e2 643 * @brief Send an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 644 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 645 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 646 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 647 * @param Size: amount of data to be sent
AnnaBridge 165:e614a9f1c9e2 648 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 649 */
AnnaBridge 165:e614a9f1c9e2 650 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 651 {
AnnaBridge 165:e614a9f1c9e2 652 uint32_t *tmp;
AnnaBridge 165:e614a9f1c9e2 653
AnnaBridge 165:e614a9f1c9e2 654 /* Check that a Tx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 655 if(hsc->gState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 656 {
AnnaBridge 165:e614a9f1c9e2 657 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 658 {
AnnaBridge 165:e614a9f1c9e2 659 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 660 }
AnnaBridge 165:e614a9f1c9e2 661
AnnaBridge 165:e614a9f1c9e2 662 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 663 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 664
AnnaBridge 165:e614a9f1c9e2 665 hsc->pTxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 666 hsc->TxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 667 hsc->TxXferCount = Size;
AnnaBridge 165:e614a9f1c9e2 668
AnnaBridge 165:e614a9f1c9e2 669 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 670 hsc->gState = HAL_SMARTCARD_STATE_BUSY_TX;
AnnaBridge 165:e614a9f1c9e2 671
AnnaBridge 165:e614a9f1c9e2 672 /* Set the SMARTCARD DMA transfer complete callback */
AnnaBridge 165:e614a9f1c9e2 673 hsc->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt;
AnnaBridge 165:e614a9f1c9e2 674
AnnaBridge 165:e614a9f1c9e2 675 /* Set the DMA error callback */
AnnaBridge 165:e614a9f1c9e2 676 hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError;
AnnaBridge 165:e614a9f1c9e2 677
AnnaBridge 165:e614a9f1c9e2 678 /* Set the DMA abort callback */
AnnaBridge 165:e614a9f1c9e2 679 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 680
AnnaBridge 165:e614a9f1c9e2 681 /* Enable the SMARTCARD transmit DMA Channel */
AnnaBridge 165:e614a9f1c9e2 682 tmp = (uint32_t*)&pData;
AnnaBridge 165:e614a9f1c9e2 683 HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsc->Instance->DR, Size);
AnnaBridge 165:e614a9f1c9e2 684
AnnaBridge 165:e614a9f1c9e2 685 /* Clear the TC flag in the SR register by writing 0 to it */
AnnaBridge 165:e614a9f1c9e2 686 __HAL_SMARTCARD_CLEAR_FLAG(hsc, SMARTCARD_FLAG_TC);
AnnaBridge 165:e614a9f1c9e2 687
AnnaBridge 165:e614a9f1c9e2 688 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 689 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 690
AnnaBridge 165:e614a9f1c9e2 691 /* Enable the DMA transfer for transmit request by setting the DMAT bit
AnnaBridge 165:e614a9f1c9e2 692 in the SMARTCARD CR3 register */
AnnaBridge 165:e614a9f1c9e2 693 SET_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 694
AnnaBridge 165:e614a9f1c9e2 695 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 696 }
AnnaBridge 165:e614a9f1c9e2 697 else
AnnaBridge 165:e614a9f1c9e2 698 {
AnnaBridge 165:e614a9f1c9e2 699 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 700 }
AnnaBridge 165:e614a9f1c9e2 701 }
AnnaBridge 165:e614a9f1c9e2 702
AnnaBridge 165:e614a9f1c9e2 703 /**
AnnaBridge 165:e614a9f1c9e2 704 * @brief Receive an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 705 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 706 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 707 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 708 * @param Size: amount of data to be received
AnnaBridge 165:e614a9f1c9e2 709 * @note When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit.s
AnnaBridge 165:e614a9f1c9e2 710 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 711 */
AnnaBridge 165:e614a9f1c9e2 712 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 713 {
AnnaBridge 165:e614a9f1c9e2 714 uint32_t *tmp;
AnnaBridge 165:e614a9f1c9e2 715
AnnaBridge 165:e614a9f1c9e2 716 /* Check that a Rx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 717 if(hsc->RxState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 718 {
AnnaBridge 165:e614a9f1c9e2 719 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 720 {
AnnaBridge 165:e614a9f1c9e2 721 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 722 }
AnnaBridge 165:e614a9f1c9e2 723
AnnaBridge 165:e614a9f1c9e2 724 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 725 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 726
AnnaBridge 165:e614a9f1c9e2 727 hsc->pRxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 728 hsc->RxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 729
AnnaBridge 165:e614a9f1c9e2 730 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 731 hsc->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
AnnaBridge 165:e614a9f1c9e2 732
AnnaBridge 165:e614a9f1c9e2 733 /* Set the SMARTCARD DMA transfer complete callback */
AnnaBridge 165:e614a9f1c9e2 734 hsc->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt;
AnnaBridge 165:e614a9f1c9e2 735
AnnaBridge 165:e614a9f1c9e2 736 /* Set the DMA error callback */
AnnaBridge 165:e614a9f1c9e2 737 hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError;
AnnaBridge 165:e614a9f1c9e2 738
AnnaBridge 165:e614a9f1c9e2 739 /* Set the DMA abort callback */
AnnaBridge 165:e614a9f1c9e2 740 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 741
AnnaBridge 165:e614a9f1c9e2 742 /* Enable the DMA Channel */
AnnaBridge 165:e614a9f1c9e2 743 tmp = (uint32_t*)&pData;
AnnaBridge 165:e614a9f1c9e2 744 HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->DR, *(uint32_t*)tmp, Size);
AnnaBridge 165:e614a9f1c9e2 745
AnnaBridge 165:e614a9f1c9e2 746 /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
AnnaBridge 165:e614a9f1c9e2 747 __HAL_SMARTCARD_CLEAR_OREFLAG(hsc);
AnnaBridge 165:e614a9f1c9e2 748
AnnaBridge 165:e614a9f1c9e2 749 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 750 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 751
AnnaBridge 165:e614a9f1c9e2 752 /* Enable the SMARTCARD Parity Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 753 SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE);
AnnaBridge 165:e614a9f1c9e2 754
AnnaBridge 165:e614a9f1c9e2 755 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 756 SET_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 757
AnnaBridge 165:e614a9f1c9e2 758 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
AnnaBridge 165:e614a9f1c9e2 759 in the SMARTCARD CR3 register */
AnnaBridge 165:e614a9f1c9e2 760 SET_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 761
AnnaBridge 165:e614a9f1c9e2 762 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 763 }
AnnaBridge 165:e614a9f1c9e2 764 else
AnnaBridge 165:e614a9f1c9e2 765 {
AnnaBridge 165:e614a9f1c9e2 766 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 767 }
AnnaBridge 165:e614a9f1c9e2 768 }
AnnaBridge 165:e614a9f1c9e2 769
AnnaBridge 165:e614a9f1c9e2 770 /**
AnnaBridge 165:e614a9f1c9e2 771 * @brief Abort ongoing transfers (blocking mode).
AnnaBridge 165:e614a9f1c9e2 772 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 773 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 774 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 775 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 776 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 777 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 778 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 779 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
AnnaBridge 165:e614a9f1c9e2 780 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 781 */
AnnaBridge 165:e614a9f1c9e2 782 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 783 {
AnnaBridge 165:e614a9f1c9e2 784 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 785 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 786 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 787
AnnaBridge 165:e614a9f1c9e2 788 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 789 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 790 {
AnnaBridge 165:e614a9f1c9e2 791 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 792
AnnaBridge 165:e614a9f1c9e2 793 /* Abort the SMARTCARD DMA Tx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 794 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 795 {
AnnaBridge 165:e614a9f1c9e2 796 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 797 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 798 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 799
AnnaBridge 165:e614a9f1c9e2 800 HAL_DMA_Abort(hsc->hdmatx);
AnnaBridge 165:e614a9f1c9e2 801 }
AnnaBridge 165:e614a9f1c9e2 802 }
AnnaBridge 165:e614a9f1c9e2 803
AnnaBridge 165:e614a9f1c9e2 804 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 805 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 806 {
AnnaBridge 165:e614a9f1c9e2 807 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 808
AnnaBridge 165:e614a9f1c9e2 809 /* Abort the SMARTCARD DMA Rx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 810 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 811 {
AnnaBridge 165:e614a9f1c9e2 812 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 813 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 814 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 815
AnnaBridge 165:e614a9f1c9e2 816 HAL_DMA_Abort(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 817 }
AnnaBridge 165:e614a9f1c9e2 818 }
AnnaBridge 165:e614a9f1c9e2 819
AnnaBridge 165:e614a9f1c9e2 820 /* Reset Tx and Rx transfer counters */
AnnaBridge 165:e614a9f1c9e2 821 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 822 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 823
AnnaBridge 165:e614a9f1c9e2 824 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 825 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 826
AnnaBridge 165:e614a9f1c9e2 827 /* Restore hsc->RxState and hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 828 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 829 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 830
AnnaBridge 165:e614a9f1c9e2 831 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 832 }
AnnaBridge 165:e614a9f1c9e2 833
AnnaBridge 165:e614a9f1c9e2 834 /**
AnnaBridge 165:e614a9f1c9e2 835 * @brief Abort ongoing Transmit transfer (blocking mode).
AnnaBridge 165:e614a9f1c9e2 836 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 837 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 838 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 839 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 840 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 841 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 842 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 843 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
AnnaBridge 165:e614a9f1c9e2 844 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 845 */
AnnaBridge 165:e614a9f1c9e2 846 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 847 {
AnnaBridge 165:e614a9f1c9e2 848 /* Disable TXEIE and TCIE interrupts */
AnnaBridge 165:e614a9f1c9e2 849 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 850
AnnaBridge 165:e614a9f1c9e2 851 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 852 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 853 {
AnnaBridge 165:e614a9f1c9e2 854 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 855
AnnaBridge 165:e614a9f1c9e2 856 /* Abort the SMARTCARD DMA Tx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 857 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 858 {
AnnaBridge 165:e614a9f1c9e2 859 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 860 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 861 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 862
AnnaBridge 165:e614a9f1c9e2 863 HAL_DMA_Abort(hsc->hdmatx);
AnnaBridge 165:e614a9f1c9e2 864 }
AnnaBridge 165:e614a9f1c9e2 865 }
AnnaBridge 165:e614a9f1c9e2 866
AnnaBridge 165:e614a9f1c9e2 867 /* Reset Tx transfer counter */
AnnaBridge 165:e614a9f1c9e2 868 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 869
AnnaBridge 165:e614a9f1c9e2 870 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 871 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 872
AnnaBridge 165:e614a9f1c9e2 873 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 874 }
AnnaBridge 165:e614a9f1c9e2 875
AnnaBridge 165:e614a9f1c9e2 876 /**
AnnaBridge 165:e614a9f1c9e2 877 * @brief Abort ongoing Receive transfer (blocking mode).
AnnaBridge 165:e614a9f1c9e2 878 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 879 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 880 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 881 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 882 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 883 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 884 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 885 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
AnnaBridge 165:e614a9f1c9e2 886 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 887 */
AnnaBridge 165:e614a9f1c9e2 888 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 889 {
AnnaBridge 165:e614a9f1c9e2 890 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 891 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 892 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 893
AnnaBridge 165:e614a9f1c9e2 894 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 895 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 896 {
AnnaBridge 165:e614a9f1c9e2 897 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 898
AnnaBridge 165:e614a9f1c9e2 899 /* Abort the SMARTCARD DMA Rx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 900 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 901 {
AnnaBridge 165:e614a9f1c9e2 902 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 903 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 904 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 905
AnnaBridge 165:e614a9f1c9e2 906 HAL_DMA_Abort(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 907 }
AnnaBridge 165:e614a9f1c9e2 908 }
AnnaBridge 165:e614a9f1c9e2 909
AnnaBridge 165:e614a9f1c9e2 910 /* Reset Rx transfer counter */
AnnaBridge 165:e614a9f1c9e2 911 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 912
AnnaBridge 165:e614a9f1c9e2 913 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 914 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 915
AnnaBridge 165:e614a9f1c9e2 916 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 917 }
AnnaBridge 165:e614a9f1c9e2 918
AnnaBridge 165:e614a9f1c9e2 919 /**
AnnaBridge 165:e614a9f1c9e2 920 * @brief Abort ongoing transfers (Interrupt mode).
AnnaBridge 165:e614a9f1c9e2 921 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 922 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 923 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 924 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 925 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 926 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 927 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 928 * - At abort completion, call user abort complete callback
AnnaBridge 165:e614a9f1c9e2 929 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
AnnaBridge 165:e614a9f1c9e2 930 * considered as completed only when user abort complete callback is executed (not when exiting function).
AnnaBridge 165:e614a9f1c9e2 931 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 932 */
AnnaBridge 165:e614a9f1c9e2 933 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 934 {
AnnaBridge 165:e614a9f1c9e2 935 uint32_t AbortCplt = 0x01U;
AnnaBridge 165:e614a9f1c9e2 936
AnnaBridge 165:e614a9f1c9e2 937 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 938 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 939 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 940
AnnaBridge 165:e614a9f1c9e2 941 /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised
AnnaBridge 165:e614a9f1c9e2 942 before any call to DMA Abort functions */
AnnaBridge 165:e614a9f1c9e2 943 /* DMA Tx Handle is valid */
AnnaBridge 165:e614a9f1c9e2 944 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 945 {
AnnaBridge 165:e614a9f1c9e2 946 /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled.
AnnaBridge 165:e614a9f1c9e2 947 Otherwise, set it to NULL */
AnnaBridge 165:e614a9f1c9e2 948 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 949 {
AnnaBridge 165:e614a9f1c9e2 950 hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxAbortCallback;
AnnaBridge 165:e614a9f1c9e2 951 }
AnnaBridge 165:e614a9f1c9e2 952 else
AnnaBridge 165:e614a9f1c9e2 953 {
AnnaBridge 165:e614a9f1c9e2 954 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 955 }
AnnaBridge 165:e614a9f1c9e2 956 }
AnnaBridge 165:e614a9f1c9e2 957 /* DMA Rx Handle is valid */
AnnaBridge 165:e614a9f1c9e2 958 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 959 {
AnnaBridge 165:e614a9f1c9e2 960 /* Set DMA Abort Complete callback if SMARTCARD DMA Rx request if enabled.
AnnaBridge 165:e614a9f1c9e2 961 Otherwise, set it to NULL */
AnnaBridge 165:e614a9f1c9e2 962 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 963 {
AnnaBridge 165:e614a9f1c9e2 964 hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxAbortCallback;
AnnaBridge 165:e614a9f1c9e2 965 }
AnnaBridge 165:e614a9f1c9e2 966 else
AnnaBridge 165:e614a9f1c9e2 967 {
AnnaBridge 165:e614a9f1c9e2 968 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 969 }
AnnaBridge 165:e614a9f1c9e2 970 }
AnnaBridge 165:e614a9f1c9e2 971
AnnaBridge 165:e614a9f1c9e2 972 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 973 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 974 {
AnnaBridge 165:e614a9f1c9e2 975 /* Disable DMA Tx at SMARTCARD level */
AnnaBridge 165:e614a9f1c9e2 976 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 977
AnnaBridge 165:e614a9f1c9e2 978 /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */
AnnaBridge 165:e614a9f1c9e2 979 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 980 {
AnnaBridge 165:e614a9f1c9e2 981 /* SMARTCARD Tx DMA Abort callback has already been initialised :
AnnaBridge 165:e614a9f1c9e2 982 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 983
AnnaBridge 165:e614a9f1c9e2 984 /* Abort DMA TX */
AnnaBridge 165:e614a9f1c9e2 985 if(HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 986 {
AnnaBridge 165:e614a9f1c9e2 987 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 988 }
AnnaBridge 165:e614a9f1c9e2 989 else
AnnaBridge 165:e614a9f1c9e2 990 {
AnnaBridge 165:e614a9f1c9e2 991 AbortCplt = 0x00U;
AnnaBridge 165:e614a9f1c9e2 992 }
AnnaBridge 165:e614a9f1c9e2 993 }
AnnaBridge 165:e614a9f1c9e2 994 }
AnnaBridge 165:e614a9f1c9e2 995
AnnaBridge 165:e614a9f1c9e2 996 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 997 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 998 {
AnnaBridge 165:e614a9f1c9e2 999 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1000
AnnaBridge 165:e614a9f1c9e2 1001 /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */
AnnaBridge 165:e614a9f1c9e2 1002 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1003 {
AnnaBridge 165:e614a9f1c9e2 1004 /* SMARTCARD Rx DMA Abort callback has already been initialised :
AnnaBridge 165:e614a9f1c9e2 1005 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1006
AnnaBridge 165:e614a9f1c9e2 1007 /* Abort DMA RX */
AnnaBridge 165:e614a9f1c9e2 1008 if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1009 {
AnnaBridge 165:e614a9f1c9e2 1010 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 1011 AbortCplt = 0x01U;
AnnaBridge 165:e614a9f1c9e2 1012 }
AnnaBridge 165:e614a9f1c9e2 1013 else
AnnaBridge 165:e614a9f1c9e2 1014 {
AnnaBridge 165:e614a9f1c9e2 1015 AbortCplt = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1016 }
AnnaBridge 165:e614a9f1c9e2 1017 }
AnnaBridge 165:e614a9f1c9e2 1018 }
AnnaBridge 165:e614a9f1c9e2 1019
AnnaBridge 165:e614a9f1c9e2 1020 /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
AnnaBridge 165:e614a9f1c9e2 1021 if(AbortCplt == 0x01U)
AnnaBridge 165:e614a9f1c9e2 1022 {
AnnaBridge 165:e614a9f1c9e2 1023 /* Reset Tx and Rx transfer counters */
AnnaBridge 165:e614a9f1c9e2 1024 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1025 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1026
AnnaBridge 165:e614a9f1c9e2 1027 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 1028 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1029
AnnaBridge 165:e614a9f1c9e2 1030 /* Restore hsc->gState and hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1031 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1032 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1033
AnnaBridge 165:e614a9f1c9e2 1034 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1035 HAL_SMARTCARD_AbortCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1036 }
AnnaBridge 165:e614a9f1c9e2 1037 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 1038 }
AnnaBridge 165:e614a9f1c9e2 1039
AnnaBridge 165:e614a9f1c9e2 1040 /**
AnnaBridge 165:e614a9f1c9e2 1041 * @brief Abort ongoing Transmit transfer (Interrupt mode).
AnnaBridge 165:e614a9f1c9e2 1042 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1043 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 1044 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 1045 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 1046 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 1047 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 1048 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 1049 * - At abort completion, call user abort complete callback
AnnaBridge 165:e614a9f1c9e2 1050 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
AnnaBridge 165:e614a9f1c9e2 1051 * considered as completed only when user abort complete callback is executed (not when exiting function).
AnnaBridge 165:e614a9f1c9e2 1052 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 1053 */
AnnaBridge 165:e614a9f1c9e2 1054 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1055 {
AnnaBridge 165:e614a9f1c9e2 1056 /* Disable TXEIE and TCIE interrupts */
AnnaBridge 165:e614a9f1c9e2 1057 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 1058
AnnaBridge 165:e614a9f1c9e2 1059 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 1060 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 1061 {
AnnaBridge 165:e614a9f1c9e2 1062 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 1063
AnnaBridge 165:e614a9f1c9e2 1064 /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 1065 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 1066 {
AnnaBridge 165:e614a9f1c9e2 1067 /* Set the SMARTCARD DMA Abort callback :
AnnaBridge 165:e614a9f1c9e2 1068 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1069 hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxOnlyAbortCallback;
AnnaBridge 165:e614a9f1c9e2 1070
AnnaBridge 165:e614a9f1c9e2 1071 /* Abort DMA TX */
AnnaBridge 165:e614a9f1c9e2 1072 if(HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1073 {
AnnaBridge 165:e614a9f1c9e2 1074 /* Call Directly hsc->hdmatx->XferAbortCallback function in case of error */
AnnaBridge 165:e614a9f1c9e2 1075 hsc->hdmatx->XferAbortCallback(hsc->hdmatx);
AnnaBridge 165:e614a9f1c9e2 1076 }
AnnaBridge 165:e614a9f1c9e2 1077 }
AnnaBridge 165:e614a9f1c9e2 1078 else
AnnaBridge 165:e614a9f1c9e2 1079 {
AnnaBridge 165:e614a9f1c9e2 1080 /* Reset Tx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1081 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1082
AnnaBridge 165:e614a9f1c9e2 1083 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1084 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1085
AnnaBridge 165:e614a9f1c9e2 1086 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1087 HAL_SMARTCARD_AbortTransmitCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1088 }
AnnaBridge 165:e614a9f1c9e2 1089 }
AnnaBridge 165:e614a9f1c9e2 1090 else
AnnaBridge 165:e614a9f1c9e2 1091 {
AnnaBridge 165:e614a9f1c9e2 1092 /* Reset Tx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1093 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1094
AnnaBridge 165:e614a9f1c9e2 1095 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1096 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1097
AnnaBridge 165:e614a9f1c9e2 1098 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1099 HAL_SMARTCARD_AbortTransmitCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1100 }
AnnaBridge 165:e614a9f1c9e2 1101
AnnaBridge 165:e614a9f1c9e2 1102 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 1103 }
AnnaBridge 165:e614a9f1c9e2 1104
AnnaBridge 165:e614a9f1c9e2 1105 /**
AnnaBridge 165:e614a9f1c9e2 1106 * @brief Abort ongoing Receive transfer (Interrupt mode).
AnnaBridge 165:e614a9f1c9e2 1107 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1108 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 1109 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 1110 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 1111 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 1112 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 1113 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 1114 * - At abort completion, call user abort complete callback
AnnaBridge 165:e614a9f1c9e2 1115 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
AnnaBridge 165:e614a9f1c9e2 1116 * considered as completed only when user abort complete callback is executed (not when exiting function).
AnnaBridge 165:e614a9f1c9e2 1117 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 1118 */
AnnaBridge 165:e614a9f1c9e2 1119 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1120 {
AnnaBridge 165:e614a9f1c9e2 1121 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 1122 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 1123 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1124
AnnaBridge 165:e614a9f1c9e2 1125 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 1126 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 1127 {
AnnaBridge 165:e614a9f1c9e2 1128 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1129
AnnaBridge 165:e614a9f1c9e2 1130 /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 1131 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1132 {
AnnaBridge 165:e614a9f1c9e2 1133 /* Set the SMARTCARD DMA Abort callback :
AnnaBridge 165:e614a9f1c9e2 1134 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1135 hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxOnlyAbortCallback;
AnnaBridge 165:e614a9f1c9e2 1136
AnnaBridge 165:e614a9f1c9e2 1137 /* Abort DMA RX */
AnnaBridge 165:e614a9f1c9e2 1138 if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1139 {
AnnaBridge 165:e614a9f1c9e2 1140 /* Call Directly hsc->hdmarx->XferAbortCallback function in case of error */
AnnaBridge 165:e614a9f1c9e2 1141 hsc->hdmarx->XferAbortCallback(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 1142 }
AnnaBridge 165:e614a9f1c9e2 1143 }
AnnaBridge 165:e614a9f1c9e2 1144 else
AnnaBridge 165:e614a9f1c9e2 1145 {
AnnaBridge 165:e614a9f1c9e2 1146 /* Reset Rx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1147 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1148
AnnaBridge 165:e614a9f1c9e2 1149 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1150 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1151
AnnaBridge 165:e614a9f1c9e2 1152 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1153 HAL_SMARTCARD_AbortReceiveCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1154 }
AnnaBridge 165:e614a9f1c9e2 1155 }
AnnaBridge 165:e614a9f1c9e2 1156 else
AnnaBridge 165:e614a9f1c9e2 1157 {
AnnaBridge 165:e614a9f1c9e2 1158 /* Reset Rx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1159 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1160
AnnaBridge 165:e614a9f1c9e2 1161 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1162 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1163
AnnaBridge 165:e614a9f1c9e2 1164 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1165 HAL_SMARTCARD_AbortReceiveCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1166 }
AnnaBridge 165:e614a9f1c9e2 1167
AnnaBridge 165:e614a9f1c9e2 1168 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 1169 }
AnnaBridge 165:e614a9f1c9e2 1170
AnnaBridge 165:e614a9f1c9e2 1171 /**
AnnaBridge 165:e614a9f1c9e2 1172 * @brief This function handles SMARTCARD interrupt request.
AnnaBridge 165:e614a9f1c9e2 1173 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1174 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1175 * @retval None
<> 144:ef7eb2e8f9f7 1176 */
<> 144:ef7eb2e8f9f7 1177 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1178 {
AnnaBridge 165:e614a9f1c9e2 1179 uint32_t isrflags = READ_REG(hsc->Instance->SR);
AnnaBridge 165:e614a9f1c9e2 1180 uint32_t cr1its = READ_REG(hsc->Instance->CR1);
AnnaBridge 165:e614a9f1c9e2 1181 uint32_t cr3its = READ_REG(hsc->Instance->CR3);
AnnaBridge 165:e614a9f1c9e2 1182 uint32_t dmarequest = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1183 uint32_t errorflags = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1184
AnnaBridge 165:e614a9f1c9e2 1185 /* If no error occurs */
AnnaBridge 165:e614a9f1c9e2 1186 errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
AnnaBridge 165:e614a9f1c9e2 1187 if(errorflags == RESET)
<> 144:ef7eb2e8f9f7 1188 {
AnnaBridge 165:e614a9f1c9e2 1189 /* SMARTCARD in mode Receiver -------------------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1190 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1191 {
AnnaBridge 165:e614a9f1c9e2 1192 SMARTCARD_Receive_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1193 return;
AnnaBridge 165:e614a9f1c9e2 1194 }
<> 144:ef7eb2e8f9f7 1195 }
<> 144:ef7eb2e8f9f7 1196
AnnaBridge 165:e614a9f1c9e2 1197 /* If some errors occur */
AnnaBridge 165:e614a9f1c9e2 1198 if((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
<> 144:ef7eb2e8f9f7 1199 {
AnnaBridge 165:e614a9f1c9e2 1200 /* SMARTCARD parity error interrupt occurred ---------------------------*/
AnnaBridge 165:e614a9f1c9e2 1201 if(((isrflags & SMARTCARD_FLAG_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1202 {
AnnaBridge 165:e614a9f1c9e2 1203 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE;
AnnaBridge 165:e614a9f1c9e2 1204 }
AnnaBridge 165:e614a9f1c9e2 1205
AnnaBridge 165:e614a9f1c9e2 1206 /* SMARTCARD noise error interrupt occurred ----------------------------*/
AnnaBridge 165:e614a9f1c9e2 1207 if(((isrflags & SMARTCARD_FLAG_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1208 {
AnnaBridge 165:e614a9f1c9e2 1209 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE;
AnnaBridge 165:e614a9f1c9e2 1210 }
AnnaBridge 165:e614a9f1c9e2 1211
AnnaBridge 165:e614a9f1c9e2 1212 /* SMARTCARD frame error interrupt occurred ----------------------------*/
AnnaBridge 165:e614a9f1c9e2 1213 if(((isrflags & SMARTCARD_FLAG_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1214 {
AnnaBridge 165:e614a9f1c9e2 1215 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE;
AnnaBridge 165:e614a9f1c9e2 1216 }
AnnaBridge 165:e614a9f1c9e2 1217
AnnaBridge 165:e614a9f1c9e2 1218 /* SMARTCARD Over-Run interrupt occurred -------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1219 if(((isrflags & SMARTCARD_FLAG_ORE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1220 {
AnnaBridge 165:e614a9f1c9e2 1221 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE;
AnnaBridge 165:e614a9f1c9e2 1222 }
AnnaBridge 165:e614a9f1c9e2 1223
AnnaBridge 165:e614a9f1c9e2 1224 /* Call SMARTCARD Error Call back function if need be ------------------*/
AnnaBridge 165:e614a9f1c9e2 1225 if(hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE)
AnnaBridge 165:e614a9f1c9e2 1226 {
AnnaBridge 165:e614a9f1c9e2 1227 /* SMARTCARD in mode Receiver ----------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1228 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1229 {
AnnaBridge 165:e614a9f1c9e2 1230 SMARTCARD_Receive_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1231 }
AnnaBridge 165:e614a9f1c9e2 1232
AnnaBridge 165:e614a9f1c9e2 1233 /* If Overrun error occurs, or if any error occurs in DMA mode reception,
AnnaBridge 165:e614a9f1c9e2 1234 consider error as blocking */
AnnaBridge 165:e614a9f1c9e2 1235 dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1236 if(((hsc->ErrorCode & HAL_SMARTCARD_ERROR_ORE) != RESET) || dmarequest)
AnnaBridge 165:e614a9f1c9e2 1237 {
AnnaBridge 165:e614a9f1c9e2 1238 /* Blocking error : transfer is aborted
AnnaBridge 165:e614a9f1c9e2 1239 Set the SMARTCARD state ready to be able to start again the process,
AnnaBridge 165:e614a9f1c9e2 1240 Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
AnnaBridge 165:e614a9f1c9e2 1241 SMARTCARD_EndRxTransfer(hsc);
<> 144:ef7eb2e8f9f7 1242
AnnaBridge 165:e614a9f1c9e2 1243 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 1244 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 1245 {
AnnaBridge 165:e614a9f1c9e2 1246 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1247
AnnaBridge 165:e614a9f1c9e2 1248 /* Abort the SMARTCARD DMA Rx channel */
AnnaBridge 165:e614a9f1c9e2 1249 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1250 {
AnnaBridge 165:e614a9f1c9e2 1251 /* Set the SMARTCARD DMA Abort callback :
AnnaBridge 165:e614a9f1c9e2 1252 will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1253 hsc->hdmarx->XferAbortCallback = SMARTCARD_DMAAbortOnError;
AnnaBridge 165:e614a9f1c9e2 1254 if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1255 {
AnnaBridge 165:e614a9f1c9e2 1256 /* Call Directly XferAbortCallback function in case of error */
AnnaBridge 165:e614a9f1c9e2 1257 hsc->hdmarx->XferAbortCallback(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 1258 }
AnnaBridge 165:e614a9f1c9e2 1259 }
AnnaBridge 165:e614a9f1c9e2 1260 else
AnnaBridge 165:e614a9f1c9e2 1261 {
AnnaBridge 165:e614a9f1c9e2 1262 /* Call user error callback */
AnnaBridge 165:e614a9f1c9e2 1263 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1264 }
AnnaBridge 165:e614a9f1c9e2 1265 }
AnnaBridge 165:e614a9f1c9e2 1266 else
AnnaBridge 165:e614a9f1c9e2 1267 {
AnnaBridge 165:e614a9f1c9e2 1268 /* Call user error callback */
AnnaBridge 165:e614a9f1c9e2 1269 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1270 }
AnnaBridge 165:e614a9f1c9e2 1271 }
AnnaBridge 165:e614a9f1c9e2 1272 else
AnnaBridge 165:e614a9f1c9e2 1273 {
AnnaBridge 165:e614a9f1c9e2 1274 /* Non Blocking error : transfer could go on.
AnnaBridge 165:e614a9f1c9e2 1275 Error is notified to user through user error callback */
AnnaBridge 165:e614a9f1c9e2 1276 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1277 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1278 }
AnnaBridge 165:e614a9f1c9e2 1279 }
AnnaBridge 165:e614a9f1c9e2 1280 return;
AnnaBridge 165:e614a9f1c9e2 1281 } /* End if some error occurs */
AnnaBridge 165:e614a9f1c9e2 1282
AnnaBridge 165:e614a9f1c9e2 1283 /* SMARTCARD in mode Transmitter -------------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1284 if(((isrflags & SMARTCARD_FLAG_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
<> 144:ef7eb2e8f9f7 1285 {
AnnaBridge 165:e614a9f1c9e2 1286 SMARTCARD_Transmit_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1287 return;
<> 144:ef7eb2e8f9f7 1288 }
<> 144:ef7eb2e8f9f7 1289
<> 144:ef7eb2e8f9f7 1290 /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/
AnnaBridge 165:e614a9f1c9e2 1291 if(((isrflags & SMARTCARD_FLAG_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
<> 144:ef7eb2e8f9f7 1292 {
<> 144:ef7eb2e8f9f7 1293 SMARTCARD_EndTransmit_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1294 return;
<> 144:ef7eb2e8f9f7 1295 }
<> 144:ef7eb2e8f9f7 1296 }
<> 144:ef7eb2e8f9f7 1297
<> 144:ef7eb2e8f9f7 1298 /**
AnnaBridge 165:e614a9f1c9e2 1299 * @brief Tx Transfer completed callbacks
AnnaBridge 165:e614a9f1c9e2 1300 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1301 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1302 * @retval None
<> 144:ef7eb2e8f9f7 1303 */
AnnaBridge 165:e614a9f1c9e2 1304 __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1305 {
<> 144:ef7eb2e8f9f7 1306 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 1307 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1308 /* NOTE : This function Should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1309 the HAL_SMARTCARD_TxCpltCallback could be implemented in the user file
AnnaBridge 165:e614a9f1c9e2 1310 */
<> 144:ef7eb2e8f9f7 1311 }
<> 144:ef7eb2e8f9f7 1312
<> 144:ef7eb2e8f9f7 1313 /**
AnnaBridge 165:e614a9f1c9e2 1314 * @brief Rx Transfer completed callbacks
AnnaBridge 165:e614a9f1c9e2 1315 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1316 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1317 * @retval None
<> 144:ef7eb2e8f9f7 1318 */
<> 144:ef7eb2e8f9f7 1319 __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1320 {
<> 144:ef7eb2e8f9f7 1321 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 1322 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1323 /* NOTE : This function Should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1324 the HAL_SMARTCARD_RxCpltCallback could be implemented in the user file
AnnaBridge 165:e614a9f1c9e2 1325 */
AnnaBridge 165:e614a9f1c9e2 1326 }
AnnaBridge 165:e614a9f1c9e2 1327
AnnaBridge 165:e614a9f1c9e2 1328 /**
AnnaBridge 165:e614a9f1c9e2 1329 * @brief SMARTCARD error callbacks
AnnaBridge 165:e614a9f1c9e2 1330 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1331 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 1332 * @retval None
AnnaBridge 165:e614a9f1c9e2 1333 */
AnnaBridge 165:e614a9f1c9e2 1334 __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1335 {
AnnaBridge 165:e614a9f1c9e2 1336 /* Prevent unused argument(s) compilation warning */
AnnaBridge 165:e614a9f1c9e2 1337 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1338 /* NOTE : This function Should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1339 the HAL_SMARTCARD_ErrorCallback could be implemented in the user file
<> 144:ef7eb2e8f9f7 1340 */
<> 144:ef7eb2e8f9f7 1341 }
<> 144:ef7eb2e8f9f7 1342
<> 144:ef7eb2e8f9f7 1343 /**
AnnaBridge 165:e614a9f1c9e2 1344 * @brief SMARTCARD Abort Complete callback.
AnnaBridge 165:e614a9f1c9e2 1345 * @param hsc SMARTCARD handle.
<> 144:ef7eb2e8f9f7 1346 * @retval None
<> 144:ef7eb2e8f9f7 1347 */
AnnaBridge 165:e614a9f1c9e2 1348 __weak void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1349 {
<> 144:ef7eb2e8f9f7 1350 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 1351 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1352
AnnaBridge 165:e614a9f1c9e2 1353 /* NOTE : This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1354 the HAL_SMARTCARD_AbortCpltCallback can be implemented in the user file.
AnnaBridge 165:e614a9f1c9e2 1355 */
AnnaBridge 165:e614a9f1c9e2 1356 }
AnnaBridge 165:e614a9f1c9e2 1357
AnnaBridge 165:e614a9f1c9e2 1358 /**
AnnaBridge 165:e614a9f1c9e2 1359 * @brief SMARTCARD Abort Transmit Complete callback.
AnnaBridge 165:e614a9f1c9e2 1360 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1361 * @retval None
AnnaBridge 165:e614a9f1c9e2 1362 */
AnnaBridge 165:e614a9f1c9e2 1363 __weak void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1364 {
AnnaBridge 165:e614a9f1c9e2 1365 /* Prevent unused argument(s) compilation warning */
AnnaBridge 165:e614a9f1c9e2 1366 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1367
AnnaBridge 165:e614a9f1c9e2 1368 /* NOTE : This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1369 the HAL_SMARTCARD_AbortTransmitCpltCallback can be implemented in the user file.
AnnaBridge 165:e614a9f1c9e2 1370 */
AnnaBridge 165:e614a9f1c9e2 1371 }
AnnaBridge 165:e614a9f1c9e2 1372
AnnaBridge 165:e614a9f1c9e2 1373 /**
AnnaBridge 165:e614a9f1c9e2 1374 * @brief SMARTCARD Abort ReceiveComplete callback.
AnnaBridge 165:e614a9f1c9e2 1375 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1376 * @retval None
AnnaBridge 165:e614a9f1c9e2 1377 */
AnnaBridge 165:e614a9f1c9e2 1378 __weak void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1379 {
AnnaBridge 165:e614a9f1c9e2 1380 /* Prevent unused argument(s) compilation warning */
AnnaBridge 165:e614a9f1c9e2 1381 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1382
AnnaBridge 165:e614a9f1c9e2 1383 /* NOTE : This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1384 the HAL_SMARTCARD_AbortReceiveCpltCallback can be implemented in the user file.
AnnaBridge 165:e614a9f1c9e2 1385 */
<> 144:ef7eb2e8f9f7 1386 }
<> 144:ef7eb2e8f9f7 1387
<> 144:ef7eb2e8f9f7 1388 /**
<> 144:ef7eb2e8f9f7 1389 * @}
<> 144:ef7eb2e8f9f7 1390 */
<> 144:ef7eb2e8f9f7 1391
<> 144:ef7eb2e8f9f7 1392 /** @defgroup SMARTCARD_Exported_Functions_Group3 Peripheral State and Errors functions
<> 144:ef7eb2e8f9f7 1393 * @brief SMARTCARD State and Errors functions
<> 144:ef7eb2e8f9f7 1394 *
<> 144:ef7eb2e8f9f7 1395 @verbatim
AnnaBridge 165:e614a9f1c9e2 1396 ===============================================================================
AnnaBridge 165:e614a9f1c9e2 1397 ##### Peripheral State and Errors functions #####
AnnaBridge 165:e614a9f1c9e2 1398 ===============================================================================
AnnaBridge 165:e614a9f1c9e2 1399 [..]
AnnaBridge 165:e614a9f1c9e2 1400 This subsection provides a set of functions allowing to control the SmartCard.
AnnaBridge 165:e614a9f1c9e2 1401 (+) HAL_SMARTCARD_GetState() API can be helpful to check in run-time the state of the SmartCard peripheral.
AnnaBridge 165:e614a9f1c9e2 1402 (+) HAL_SMARTCARD_GetError() check in run-time errors that could be occurred during communication.
<> 144:ef7eb2e8f9f7 1403 @endverbatim
<> 144:ef7eb2e8f9f7 1404 * @{
<> 144:ef7eb2e8f9f7 1405 */
<> 144:ef7eb2e8f9f7 1406
<> 144:ef7eb2e8f9f7 1407 /**
AnnaBridge 165:e614a9f1c9e2 1408 * @brief return the SMARTCARD state
AnnaBridge 165:e614a9f1c9e2 1409 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1410 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1411 * @retval HAL state
<> 144:ef7eb2e8f9f7 1412 */
<> 144:ef7eb2e8f9f7 1413 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1414 {
AnnaBridge 165:e614a9f1c9e2 1415 uint32_t temp1= 0x00U, temp2 = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1416 temp1 = hsc->gState;
AnnaBridge 165:e614a9f1c9e2 1417 temp2 = hsc->RxState;
AnnaBridge 165:e614a9f1c9e2 1418
AnnaBridge 165:e614a9f1c9e2 1419 return (HAL_SMARTCARD_StateTypeDef)(temp1 | temp2);
<> 144:ef7eb2e8f9f7 1420 }
<> 144:ef7eb2e8f9f7 1421
<> 144:ef7eb2e8f9f7 1422 /**
<> 144:ef7eb2e8f9f7 1423 * @brief Return the SMARTCARD error code
AnnaBridge 165:e614a9f1c9e2 1424 * @param hsc : pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1425 * the configuration information for the specified SMARTCARD.
<> 144:ef7eb2e8f9f7 1426 * @retval SMARTCARD Error Code
<> 144:ef7eb2e8f9f7 1427 */
<> 144:ef7eb2e8f9f7 1428 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1429 {
<> 144:ef7eb2e8f9f7 1430 return hsc->ErrorCode;
<> 144:ef7eb2e8f9f7 1431 }
<> 144:ef7eb2e8f9f7 1432
<> 144:ef7eb2e8f9f7 1433 /**
<> 144:ef7eb2e8f9f7 1434 * @}
<> 144:ef7eb2e8f9f7 1435 */
AnnaBridge 165:e614a9f1c9e2 1436
<> 144:ef7eb2e8f9f7 1437 /**
AnnaBridge 165:e614a9f1c9e2 1438 * @brief DMA SMARTCARD transmit process complete callback
AnnaBridge 165:e614a9f1c9e2 1439 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1440 * the configuration information for the specified DMA module.
<> 144:ef7eb2e8f9f7 1441 * @retval None
<> 144:ef7eb2e8f9f7 1442 */
<> 144:ef7eb2e8f9f7 1443 static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma)
<> 144:ef7eb2e8f9f7 1444 {
<> 144:ef7eb2e8f9f7 1445 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1446
AnnaBridge 165:e614a9f1c9e2 1447 hsc->TxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1448
<> 144:ef7eb2e8f9f7 1449 /* Disable the DMA transfer for transmit request by setting the DMAT bit
AnnaBridge 165:e614a9f1c9e2 1450 in the USART CR3 register */
<> 144:ef7eb2e8f9f7 1451 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
<> 144:ef7eb2e8f9f7 1452
AnnaBridge 165:e614a9f1c9e2 1453 /* Enable the SMARTCARD Transmit Complete Interrupt */
AnnaBridge 165:e614a9f1c9e2 1454 SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE);
<> 144:ef7eb2e8f9f7 1455 }
<> 144:ef7eb2e8f9f7 1456
<> 144:ef7eb2e8f9f7 1457 /**
AnnaBridge 165:e614a9f1c9e2 1458 * @brief DMA SMARTCARD receive process complete callback
AnnaBridge 165:e614a9f1c9e2 1459 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1460 * the configuration information for the specified DMA module.
<> 144:ef7eb2e8f9f7 1461 * @retval None
<> 144:ef7eb2e8f9f7 1462 */
<> 144:ef7eb2e8f9f7 1463 static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
<> 144:ef7eb2e8f9f7 1464 {
<> 144:ef7eb2e8f9f7 1465 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
<> 144:ef7eb2e8f9f7 1466
AnnaBridge 165:e614a9f1c9e2 1467 hsc->RxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1468
AnnaBridge 165:e614a9f1c9e2 1469 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 1470 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 1471 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1472
<> 144:ef7eb2e8f9f7 1473 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
AnnaBridge 165:e614a9f1c9e2 1474 in the USART CR3 register */
<> 144:ef7eb2e8f9f7 1475 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
<> 144:ef7eb2e8f9f7 1476
AnnaBridge 165:e614a9f1c9e2 1477 /* At end of Rx process, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1478 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1479
<> 144:ef7eb2e8f9f7 1480 HAL_SMARTCARD_RxCpltCallback(hsc);
<> 144:ef7eb2e8f9f7 1481 }
<> 144:ef7eb2e8f9f7 1482
<> 144:ef7eb2e8f9f7 1483 /**
AnnaBridge 165:e614a9f1c9e2 1484 * @brief DMA SMARTCARD communication error callback
AnnaBridge 165:e614a9f1c9e2 1485 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1486 * the configuration information for the specified DMA module.
<> 144:ef7eb2e8f9f7 1487 * @retval None
<> 144:ef7eb2e8f9f7 1488 */
<> 144:ef7eb2e8f9f7 1489 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
<> 144:ef7eb2e8f9f7 1490 {
AnnaBridge 165:e614a9f1c9e2 1491 uint32_t dmarequest = 0x00U;
<> 144:ef7eb2e8f9f7 1492 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1493 hsc->RxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1494 hsc->TxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1495 hsc->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
<> 144:ef7eb2e8f9f7 1496
AnnaBridge 165:e614a9f1c9e2 1497 /* Stop SMARTCARD DMA Tx request if ongoing */
AnnaBridge 165:e614a9f1c9e2 1498 dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 1499 if((hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX) && dmarequest)
AnnaBridge 165:e614a9f1c9e2 1500 {
AnnaBridge 165:e614a9f1c9e2 1501 SMARTCARD_EndTxTransfer(hsc);
AnnaBridge 165:e614a9f1c9e2 1502 }
AnnaBridge 165:e614a9f1c9e2 1503
AnnaBridge 165:e614a9f1c9e2 1504 /* Stop SMARTCARD DMA Rx request if ongoing */
AnnaBridge 165:e614a9f1c9e2 1505 dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1506 if((hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX) && dmarequest)
AnnaBridge 165:e614a9f1c9e2 1507 {
AnnaBridge 165:e614a9f1c9e2 1508 SMARTCARD_EndRxTransfer(hsc);
AnnaBridge 165:e614a9f1c9e2 1509 }
AnnaBridge 165:e614a9f1c9e2 1510
<> 144:ef7eb2e8f9f7 1511 HAL_SMARTCARD_ErrorCallback(hsc);
<> 144:ef7eb2e8f9f7 1512 }
<> 144:ef7eb2e8f9f7 1513
<> 144:ef7eb2e8f9f7 1514 /**
<> 144:ef7eb2e8f9f7 1515 * @brief This function handles SMARTCARD Communication Timeout.
AnnaBridge 165:e614a9f1c9e2 1516 * @param hsc: SMARTCARD handle
<> 144:ef7eb2e8f9f7 1517 * @param Flag: specifies the SMARTCARD flag to check.
<> 144:ef7eb2e8f9f7 1518 * @param Status: The new Flag status (SET or RESET).
<> 144:ef7eb2e8f9f7 1519 * @param Timeout: Timeout duration
AnnaBridge 165:e614a9f1c9e2 1520 * @param Tickstart: tick start value
<> 144:ef7eb2e8f9f7 1521 * @retval HAL status
<> 144:ef7eb2e8f9f7 1522 */
AnnaBridge 165:e614a9f1c9e2 1523 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
<> 144:ef7eb2e8f9f7 1524 {
<> 144:ef7eb2e8f9f7 1525 /* Wait until flag is set */
AnnaBridge 165:e614a9f1c9e2 1526 while((__HAL_SMARTCARD_GET_FLAG(hsc, Flag) ? SET : RESET) == Status)
<> 144:ef7eb2e8f9f7 1527 {
AnnaBridge 165:e614a9f1c9e2 1528 /* Check for the Timeout */
AnnaBridge 165:e614a9f1c9e2 1529 if(Timeout != HAL_MAX_DELAY)
<> 144:ef7eb2e8f9f7 1530 {
AnnaBridge 165:e614a9f1c9e2 1531 if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))
<> 144:ef7eb2e8f9f7 1532 {
AnnaBridge 165:e614a9f1c9e2 1533 /* Disable TXE and RXNE interrupts for the interrupt process */
AnnaBridge 165:e614a9f1c9e2 1534 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE);
AnnaBridge 165:e614a9f1c9e2 1535 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE);
<> 144:ef7eb2e8f9f7 1536
AnnaBridge 165:e614a9f1c9e2 1537 hsc->gState= HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1538 hsc->RxState= HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1539
AnnaBridge 165:e614a9f1c9e2 1540 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 1541 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 1542
AnnaBridge 165:e614a9f1c9e2 1543 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1544 }
<> 144:ef7eb2e8f9f7 1545 }
<> 144:ef7eb2e8f9f7 1546 }
<> 144:ef7eb2e8f9f7 1547 return HAL_OK;
<> 144:ef7eb2e8f9f7 1548 }
<> 144:ef7eb2e8f9f7 1549
<> 144:ef7eb2e8f9f7 1550 /**
AnnaBridge 165:e614a9f1c9e2 1551 * @brief End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion).
AnnaBridge 165:e614a9f1c9e2 1552 * @param hsc: SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1553 * @retval None
AnnaBridge 165:e614a9f1c9e2 1554 */
AnnaBridge 165:e614a9f1c9e2 1555 static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1556 {
AnnaBridge 165:e614a9f1c9e2 1557 /* At end of Tx process, restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1558 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1559
AnnaBridge 165:e614a9f1c9e2 1560 /* Disable TXEIE and TCIE interrupts */
AnnaBridge 165:e614a9f1c9e2 1561 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 1562 }
AnnaBridge 165:e614a9f1c9e2 1563
AnnaBridge 165:e614a9f1c9e2 1564
AnnaBridge 165:e614a9f1c9e2 1565 /**
AnnaBridge 165:e614a9f1c9e2 1566 * @brief End ongoing Rx transfer on SMARTCARD peripheral (following error detection or Reception completion).
AnnaBridge 165:e614a9f1c9e2 1567 * @param hsc: SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1568 * @retval None
AnnaBridge 165:e614a9f1c9e2 1569 */
AnnaBridge 165:e614a9f1c9e2 1570 static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1571 {
AnnaBridge 165:e614a9f1c9e2 1572 /* At end of Rx process, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1573 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1574
AnnaBridge 165:e614a9f1c9e2 1575 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 1576 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 1577 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1578 }
AnnaBridge 165:e614a9f1c9e2 1579
AnnaBridge 165:e614a9f1c9e2 1580
AnnaBridge 165:e614a9f1c9e2 1581
AnnaBridge 165:e614a9f1c9e2 1582 /**
AnnaBridge 165:e614a9f1c9e2 1583 * @brief DMA SMARTCARD communication abort callback, when initiated by HAL services on Error
AnnaBridge 165:e614a9f1c9e2 1584 * (To be called at end of DMA Abort procedure following error occurrence).
AnnaBridge 165:e614a9f1c9e2 1585 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1586 * @retval None
AnnaBridge 165:e614a9f1c9e2 1587 */
AnnaBridge 165:e614a9f1c9e2 1588 static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1589 {
AnnaBridge 165:e614a9f1c9e2 1590 SMARTCARD_HandleTypeDef* hsc = (SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1591 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1592 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1593
AnnaBridge 165:e614a9f1c9e2 1594 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1595 }
AnnaBridge 165:e614a9f1c9e2 1596
AnnaBridge 165:e614a9f1c9e2 1597 /**
AnnaBridge 165:e614a9f1c9e2 1598 * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user
AnnaBridge 165:e614a9f1c9e2 1599 * (To be called at end of DMA Tx Abort procedure following user abort request).
AnnaBridge 165:e614a9f1c9e2 1600 * @note When this callback is executed, User Abort complete call back is called only if no
AnnaBridge 165:e614a9f1c9e2 1601 * Abort still ongoing for Rx DMA Handle.
AnnaBridge 165:e614a9f1c9e2 1602 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1603 * @retval None
AnnaBridge 165:e614a9f1c9e2 1604 */
AnnaBridge 165:e614a9f1c9e2 1605 static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1606 {
AnnaBridge 165:e614a9f1c9e2 1607 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1608
AnnaBridge 165:e614a9f1c9e2 1609 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 1610
AnnaBridge 165:e614a9f1c9e2 1611 /* Check if an Abort process is still ongoing */
AnnaBridge 165:e614a9f1c9e2 1612 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1613 {
AnnaBridge 165:e614a9f1c9e2 1614 if(hsc->hdmarx->XferAbortCallback != NULL)
AnnaBridge 165:e614a9f1c9e2 1615 {
AnnaBridge 165:e614a9f1c9e2 1616 return;
AnnaBridge 165:e614a9f1c9e2 1617 }
AnnaBridge 165:e614a9f1c9e2 1618 }
AnnaBridge 165:e614a9f1c9e2 1619
AnnaBridge 165:e614a9f1c9e2 1620 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
AnnaBridge 165:e614a9f1c9e2 1621 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1622 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1623
AnnaBridge 165:e614a9f1c9e2 1624 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 1625 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1626
AnnaBridge 165:e614a9f1c9e2 1627 /* Restore hsc->gState and hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1628 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1629 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1630
AnnaBridge 165:e614a9f1c9e2 1631 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1632 HAL_SMARTCARD_AbortCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1633 }
AnnaBridge 165:e614a9f1c9e2 1634
AnnaBridge 165:e614a9f1c9e2 1635 /**
AnnaBridge 165:e614a9f1c9e2 1636 * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user
AnnaBridge 165:e614a9f1c9e2 1637 * (To be called at end of DMA Rx Abort procedure following user abort request).
AnnaBridge 165:e614a9f1c9e2 1638 * @note When this callback is executed, User Abort complete call back is called only if no
AnnaBridge 165:e614a9f1c9e2 1639 * Abort still ongoing for Tx DMA Handle.
AnnaBridge 165:e614a9f1c9e2 1640 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1641 * @retval None
AnnaBridge 165:e614a9f1c9e2 1642 */
AnnaBridge 165:e614a9f1c9e2 1643 static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1644 {
AnnaBridge 165:e614a9f1c9e2 1645 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1646
AnnaBridge 165:e614a9f1c9e2 1647 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 1648
AnnaBridge 165:e614a9f1c9e2 1649 /* Check if an Abort process is still ongoing */
AnnaBridge 165:e614a9f1c9e2 1650 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 1651 {
AnnaBridge 165:e614a9f1c9e2 1652 if(hsc->hdmatx->XferAbortCallback != NULL)
AnnaBridge 165:e614a9f1c9e2 1653 {
AnnaBridge 165:e614a9f1c9e2 1654 return;
AnnaBridge 165:e614a9f1c9e2 1655 }
AnnaBridge 165:e614a9f1c9e2 1656 }
AnnaBridge 165:e614a9f1c9e2 1657
AnnaBridge 165:e614a9f1c9e2 1658 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
AnnaBridge 165:e614a9f1c9e2 1659 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1660 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1661
AnnaBridge 165:e614a9f1c9e2 1662 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 1663 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1664
AnnaBridge 165:e614a9f1c9e2 1665 /* Restore hsc->gState and hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1666 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1667 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1668
AnnaBridge 165:e614a9f1c9e2 1669 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1670 HAL_SMARTCARD_AbortCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1671 }
AnnaBridge 165:e614a9f1c9e2 1672
AnnaBridge 165:e614a9f1c9e2 1673 /**
AnnaBridge 165:e614a9f1c9e2 1674 * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to
AnnaBridge 165:e614a9f1c9e2 1675 * HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer)
AnnaBridge 165:e614a9f1c9e2 1676 * (This callback is executed at end of DMA Tx Abort procedure following user abort request,
AnnaBridge 165:e614a9f1c9e2 1677 * and leads to user Tx Abort Complete callback execution).
AnnaBridge 165:e614a9f1c9e2 1678 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1679 * @retval None
AnnaBridge 165:e614a9f1c9e2 1680 */
AnnaBridge 165:e614a9f1c9e2 1681 static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1682 {
AnnaBridge 165:e614a9f1c9e2 1683 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1684
AnnaBridge 165:e614a9f1c9e2 1685 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1686
AnnaBridge 165:e614a9f1c9e2 1687 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1688 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1689
AnnaBridge 165:e614a9f1c9e2 1690 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1691 HAL_SMARTCARD_AbortTransmitCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1692 }
AnnaBridge 165:e614a9f1c9e2 1693
AnnaBridge 165:e614a9f1c9e2 1694 /**
AnnaBridge 165:e614a9f1c9e2 1695 * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to
AnnaBridge 165:e614a9f1c9e2 1696 * HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer)
AnnaBridge 165:e614a9f1c9e2 1697 * (This callback is executed at end of DMA Rx Abort procedure following user abort request,
AnnaBridge 165:e614a9f1c9e2 1698 * and leads to user Rx Abort Complete callback execution).
AnnaBridge 165:e614a9f1c9e2 1699 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1700 * @retval None
AnnaBridge 165:e614a9f1c9e2 1701 */
AnnaBridge 165:e614a9f1c9e2 1702 static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1703 {
AnnaBridge 165:e614a9f1c9e2 1704 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1705
AnnaBridge 165:e614a9f1c9e2 1706 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1707
AnnaBridge 165:e614a9f1c9e2 1708 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1709 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1710
AnnaBridge 165:e614a9f1c9e2 1711 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1712 HAL_SMARTCARD_AbortReceiveCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1713 }
AnnaBridge 165:e614a9f1c9e2 1714
AnnaBridge 165:e614a9f1c9e2 1715 /**
AnnaBridge 165:e614a9f1c9e2 1716 * @brief Send an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 1717 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1718 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1719 * @retval HAL status
<> 144:ef7eb2e8f9f7 1720 */
<> 144:ef7eb2e8f9f7 1721 static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1722 {
AnnaBridge 165:e614a9f1c9e2 1723 uint16_t* tmp;
AnnaBridge 165:e614a9f1c9e2 1724
AnnaBridge 165:e614a9f1c9e2 1725 /* Check that a Tx process is ongoing */
AnnaBridge 165:e614a9f1c9e2 1726 if(hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX)
<> 144:ef7eb2e8f9f7 1727 {
AnnaBridge 165:e614a9f1c9e2 1728 tmp = (uint16_t*) hsc->pTxBuffPtr;
AnnaBridge 165:e614a9f1c9e2 1729 hsc->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
AnnaBridge 165:e614a9f1c9e2 1730 hsc->pTxBuffPtr += 1U;
<> 144:ef7eb2e8f9f7 1731
AnnaBridge 165:e614a9f1c9e2 1732 if(--hsc->TxXferCount == 0U)
<> 144:ef7eb2e8f9f7 1733 {
AnnaBridge 165:e614a9f1c9e2 1734 /* Disable the SMARTCARD Transmit data register empty Interrupt */
AnnaBridge 165:e614a9f1c9e2 1735 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE);
<> 144:ef7eb2e8f9f7 1736
AnnaBridge 165:e614a9f1c9e2 1737 /* Enable the SMARTCARD Transmit Complete Interrupt */
AnnaBridge 165:e614a9f1c9e2 1738 SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE);
<> 144:ef7eb2e8f9f7 1739 }
AnnaBridge 165:e614a9f1c9e2 1740
<> 144:ef7eb2e8f9f7 1741 return HAL_OK;
<> 144:ef7eb2e8f9f7 1742 }
<> 144:ef7eb2e8f9f7 1743 else
<> 144:ef7eb2e8f9f7 1744 {
<> 144:ef7eb2e8f9f7 1745 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 1746 }
<> 144:ef7eb2e8f9f7 1747 }
<> 144:ef7eb2e8f9f7 1748
<> 144:ef7eb2e8f9f7 1749 /**
<> 144:ef7eb2e8f9f7 1750 * @brief Wraps up transmission in non blocking mode.
<> 144:ef7eb2e8f9f7 1751 * @param hsmartcard: pointer to a SMARTCARD_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1752 * the configuration information for the specified SMARTCARD module.
<> 144:ef7eb2e8f9f7 1753 * @retval HAL status
<> 144:ef7eb2e8f9f7 1754 */
<> 144:ef7eb2e8f9f7 1755 static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
<> 144:ef7eb2e8f9f7 1756 {
AnnaBridge 165:e614a9f1c9e2 1757 /* Disable the SMARTCARD Transmit Complete Interrupt */
AnnaBridge 165:e614a9f1c9e2 1758 CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TCIE);
<> 144:ef7eb2e8f9f7 1759
AnnaBridge 165:e614a9f1c9e2 1760 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 1761 CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1762
AnnaBridge 165:e614a9f1c9e2 1763 /* Tx process is ended, restore hsmartcard->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1764 hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1765
<> 144:ef7eb2e8f9f7 1766 HAL_SMARTCARD_TxCpltCallback(hsmartcard);
<> 144:ef7eb2e8f9f7 1767
<> 144:ef7eb2e8f9f7 1768 return HAL_OK;
<> 144:ef7eb2e8f9f7 1769 }
<> 144:ef7eb2e8f9f7 1770
<> 144:ef7eb2e8f9f7 1771 /**
AnnaBridge 165:e614a9f1c9e2 1772 * @brief Receive an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 1773 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1774 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1775 * @retval HAL status
<> 144:ef7eb2e8f9f7 1776 */
<> 144:ef7eb2e8f9f7 1777 static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1778 {
AnnaBridge 165:e614a9f1c9e2 1779 uint16_t* tmp;
AnnaBridge 165:e614a9f1c9e2 1780
AnnaBridge 165:e614a9f1c9e2 1781 /* Check that a Rx process is ongoing */
AnnaBridge 165:e614a9f1c9e2 1782 if(hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
<> 144:ef7eb2e8f9f7 1783 {
AnnaBridge 165:e614a9f1c9e2 1784 tmp = (uint16_t*) hsc->pRxBuffPtr;
AnnaBridge 165:e614a9f1c9e2 1785 *tmp = (uint8_t)(hsc->Instance->DR & (uint8_t)0x00FF);
AnnaBridge 165:e614a9f1c9e2 1786 hsc->pRxBuffPtr += 1U;
<> 144:ef7eb2e8f9f7 1787
AnnaBridge 165:e614a9f1c9e2 1788 if(--hsc->RxXferCount == 0U)
<> 144:ef7eb2e8f9f7 1789 {
AnnaBridge 165:e614a9f1c9e2 1790 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE);
<> 144:ef7eb2e8f9f7 1791
<> 144:ef7eb2e8f9f7 1792 /* Disable the SMARTCARD Parity Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 1793 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_PEIE);
AnnaBridge 165:e614a9f1c9e2 1794
<> 144:ef7eb2e8f9f7 1795 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 1796 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
<> 144:ef7eb2e8f9f7 1797
AnnaBridge 165:e614a9f1c9e2 1798 /* Rx process is completed, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1799 hsc->RxState = HAL_SMARTCARD_STATE_READY;
<> 144:ef7eb2e8f9f7 1800
<> 144:ef7eb2e8f9f7 1801 HAL_SMARTCARD_RxCpltCallback(hsc);
<> 144:ef7eb2e8f9f7 1802
<> 144:ef7eb2e8f9f7 1803 return HAL_OK;
<> 144:ef7eb2e8f9f7 1804 }
<> 144:ef7eb2e8f9f7 1805 return HAL_OK;
<> 144:ef7eb2e8f9f7 1806 }
<> 144:ef7eb2e8f9f7 1807 else
<> 144:ef7eb2e8f9f7 1808 {
AnnaBridge 165:e614a9f1c9e2 1809 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 1810 }
<> 144:ef7eb2e8f9f7 1811 }
<> 144:ef7eb2e8f9f7 1812
<> 144:ef7eb2e8f9f7 1813 /**
AnnaBridge 165:e614a9f1c9e2 1814 * @brief Configure the SMARTCARD peripheral
AnnaBridge 165:e614a9f1c9e2 1815 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1816 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1817 * @retval None
<> 144:ef7eb2e8f9f7 1818 */
<> 144:ef7eb2e8f9f7 1819 static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1820 {
AnnaBridge 165:e614a9f1c9e2 1821 uint32_t tmpreg = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1822
<> 144:ef7eb2e8f9f7 1823 /* Check the parameters */
AnnaBridge 165:e614a9f1c9e2 1824 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
<> 144:ef7eb2e8f9f7 1825 assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity));
<> 144:ef7eb2e8f9f7 1826 assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase));
<> 144:ef7eb2e8f9f7 1827 assert_param(IS_SMARTCARD_LASTBIT(hsc->Init.CLKLastBit));
<> 144:ef7eb2e8f9f7 1828 assert_param(IS_SMARTCARD_BAUDRATE(hsc->Init.BaudRate));
<> 144:ef7eb2e8f9f7 1829 assert_param(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength));
<> 144:ef7eb2e8f9f7 1830 assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits));
<> 144:ef7eb2e8f9f7 1831 assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity));
<> 144:ef7eb2e8f9f7 1832 assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode));
<> 144:ef7eb2e8f9f7 1833 assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState));
<> 144:ef7eb2e8f9f7 1834
AnnaBridge 165:e614a9f1c9e2 1835
<> 144:ef7eb2e8f9f7 1836 /* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the
<> 144:ef7eb2e8f9f7 1837 receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */
AnnaBridge 165:e614a9f1c9e2 1838 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TE | USART_CR1_RE));
<> 144:ef7eb2e8f9f7 1839
AnnaBridge 165:e614a9f1c9e2 1840 /*---------------------------- USART CR2 Configuration ---------------------*/
AnnaBridge 165:e614a9f1c9e2 1841 tmpreg = hsc->Instance->CR2;
<> 144:ef7eb2e8f9f7 1842 /* Clear CLKEN, CPOL, CPHA and LBCL bits */
AnnaBridge 165:e614a9f1c9e2 1843 tmpreg &= (uint32_t)~((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_LBCL));
<> 144:ef7eb2e8f9f7 1844 /* Configure the SMARTCARD Clock, CPOL, CPHA and LastBit -----------------------*/
<> 144:ef7eb2e8f9f7 1845 /* Set CPOL bit according to hsc->Init.CLKPolarity value */
<> 144:ef7eb2e8f9f7 1846 /* Set CPHA bit according to hsc->Init.CLKPhase value */
<> 144:ef7eb2e8f9f7 1847 /* Set LBCL bit according to hsc->Init.CLKLastBit value */
AnnaBridge 165:e614a9f1c9e2 1848 /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
AnnaBridge 165:e614a9f1c9e2 1849 tmpreg |= (uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity |
AnnaBridge 165:e614a9f1c9e2 1850 hsc->Init.CLKPhase| hsc->Init.CLKLastBit | hsc->Init.StopBits);
AnnaBridge 165:e614a9f1c9e2 1851 /* Write to USART CR2 */
AnnaBridge 165:e614a9f1c9e2 1852 WRITE_REG(hsc->Instance->CR2, (uint32_t)tmpreg);
<> 144:ef7eb2e8f9f7 1853
AnnaBridge 165:e614a9f1c9e2 1854 tmpreg = hsc->Instance->CR2;
AnnaBridge 165:e614a9f1c9e2 1855
AnnaBridge 165:e614a9f1c9e2 1856 /* Clear STOP[13:12] bits */
AnnaBridge 165:e614a9f1c9e2 1857 tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
AnnaBridge 165:e614a9f1c9e2 1858
<> 144:ef7eb2e8f9f7 1859 /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
AnnaBridge 165:e614a9f1c9e2 1860 tmpreg |= (uint32_t)(hsc->Init.StopBits);
AnnaBridge 165:e614a9f1c9e2 1861
AnnaBridge 165:e614a9f1c9e2 1862 /* Write to USART CR2 */
AnnaBridge 165:e614a9f1c9e2 1863 WRITE_REG(hsc->Instance->CR2, (uint32_t)tmpreg);
<> 144:ef7eb2e8f9f7 1864
AnnaBridge 165:e614a9f1c9e2 1865 /*-------------------------- USART CR1 Configuration -----------------------*/
AnnaBridge 165:e614a9f1c9e2 1866 tmpreg = hsc->Instance->CR1;
AnnaBridge 165:e614a9f1c9e2 1867
<> 144:ef7eb2e8f9f7 1868 /* Clear M, PCE, PS, TE and RE bits */
AnnaBridge 165:e614a9f1c9e2 1869 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
AnnaBridge 165:e614a9f1c9e2 1870 USART_CR1_RE));
AnnaBridge 165:e614a9f1c9e2 1871
<> 144:ef7eb2e8f9f7 1872 /* Configure the SMARTCARD Word Length, Parity and mode:
AnnaBridge 165:e614a9f1c9e2 1873 Set the M bits according to hsc->Init.WordLength value
AnnaBridge 165:e614a9f1c9e2 1874 Set PCE and PS bits according to hsc->Init.Parity value
<> 144:ef7eb2e8f9f7 1875 Set TE and RE bits according to hsc->Init.Mode value */
AnnaBridge 165:e614a9f1c9e2 1876 tmpreg |= (uint32_t)hsc->Init.WordLength | hsc->Init.Parity | hsc->Init.Mode;
<> 144:ef7eb2e8f9f7 1877
AnnaBridge 165:e614a9f1c9e2 1878 /* Write to USART CR1 */
AnnaBridge 165:e614a9f1c9e2 1879 WRITE_REG(hsc->Instance->CR1, (uint32_t)tmpreg);
AnnaBridge 165:e614a9f1c9e2 1880
AnnaBridge 165:e614a9f1c9e2 1881 /*-------------------------- USART CR3 Configuration -----------------------*/
<> 144:ef7eb2e8f9f7 1882 /* Clear CTSE and RTSE bits */
<> 144:ef7eb2e8f9f7 1883 CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
<> 144:ef7eb2e8f9f7 1884
AnnaBridge 165:e614a9f1c9e2 1885 /*-------------------------- USART BRR Configuration -----------------------*/
AnnaBridge 165:e614a9f1c9e2 1886
<> 144:ef7eb2e8f9f7 1887 if(hsc->Instance == USART1)
<> 144:ef7eb2e8f9f7 1888 {
<> 144:ef7eb2e8f9f7 1889 hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK2Freq(), hsc->Init.BaudRate);
<> 144:ef7eb2e8f9f7 1890 }
<> 144:ef7eb2e8f9f7 1891 else
<> 144:ef7eb2e8f9f7 1892 {
<> 144:ef7eb2e8f9f7 1893 hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK1Freq(), hsc->Init.BaudRate);
<> 144:ef7eb2e8f9f7 1894 }
<> 144:ef7eb2e8f9f7 1895 }
<> 144:ef7eb2e8f9f7 1896
<> 144:ef7eb2e8f9f7 1897 /**
<> 144:ef7eb2e8f9f7 1898 * @}
<> 144:ef7eb2e8f9f7 1899 */
<> 144:ef7eb2e8f9f7 1900
<> 144:ef7eb2e8f9f7 1901 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
<> 144:ef7eb2e8f9f7 1902 /**
<> 144:ef7eb2e8f9f7 1903 * @}
<> 144:ef7eb2e8f9f7 1904 */
<> 144:ef7eb2e8f9f7 1905
<> 144:ef7eb2e8f9f7 1906 /**
<> 144:ef7eb2e8f9f7 1907 * @}
<> 144:ef7eb2e8f9f7 1908 */
<> 144:ef7eb2e8f9f7 1909
<> 144:ef7eb2e8f9f7 1910 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/