mbed official / mbed-dev

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Fri May 26 12:39:01 2017 +0100
Revision:
165:e614a9f1c9e2
Parent:
154:37f96f9d4de2
Child:
178:79309dc6340a
This updates the lib to the mbed lib v 143

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 uint16_t* tmp;
AnnaBridge 165:e614a9f1c9e2 504 uint32_t tickstart = 0U;
<> 144:ef7eb2e8f9f7 505
AnnaBridge 165:e614a9f1c9e2 506 if(hsc->RxState == HAL_SMARTCARD_STATE_READY)
<> 144:ef7eb2e8f9f7 507 {
AnnaBridge 165:e614a9f1c9e2 508 if((pData == NULL) || (Size == 0U))
<> 144:ef7eb2e8f9f7 509 {
AnnaBridge 165:e614a9f1c9e2 510 return HAL_ERROR;
<> 144:ef7eb2e8f9f7 511 }
<> 144:ef7eb2e8f9f7 512
<> 144:ef7eb2e8f9f7 513 /* Process Locked */
<> 144:ef7eb2e8f9f7 514 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 515
AnnaBridge 165:e614a9f1c9e2 516 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 517 hsc->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
<> 144:ef7eb2e8f9f7 518
AnnaBridge 165:e614a9f1c9e2 519 /* Init tickstart for timeout managment */
AnnaBridge 165:e614a9f1c9e2 520 tickstart = HAL_GetTick();
AnnaBridge 165:e614a9f1c9e2 521
<> 144:ef7eb2e8f9f7 522 hsc->RxXferSize = Size;
<> 144:ef7eb2e8f9f7 523 hsc->RxXferCount = Size;
<> 144:ef7eb2e8f9f7 524
AnnaBridge 165:e614a9f1c9e2 525 /* Check the remain data to be received */
AnnaBridge 165:e614a9f1c9e2 526 while(hsc->RxXferCount > 0U)
<> 144:ef7eb2e8f9f7 527 {
AnnaBridge 165:e614a9f1c9e2 528 hsc->RxXferCount--;
AnnaBridge 165:e614a9f1c9e2 529 if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, tickstart, Timeout) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 530 {
AnnaBridge 165:e614a9f1c9e2 531 return HAL_TIMEOUT;
AnnaBridge 165:e614a9f1c9e2 532 }
AnnaBridge 165:e614a9f1c9e2 533 tmp = (uint16_t*) pData;
AnnaBridge 165:e614a9f1c9e2 534 *tmp = (uint8_t)(hsc->Instance->DR & (uint8_t)0xFF);
AnnaBridge 165:e614a9f1c9e2 535 pData +=1U;
<> 144:ef7eb2e8f9f7 536 }
<> 144:ef7eb2e8f9f7 537
AnnaBridge 165:e614a9f1c9e2 538 /* At end of Rx process, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 539 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 540
<> 144:ef7eb2e8f9f7 541 /* Process Unlocked */
<> 144:ef7eb2e8f9f7 542 __HAL_UNLOCK(hsc);
<> 144:ef7eb2e8f9f7 543
<> 144:ef7eb2e8f9f7 544 return HAL_OK;
<> 144:ef7eb2e8f9f7 545 }
<> 144:ef7eb2e8f9f7 546 else
<> 144:ef7eb2e8f9f7 547 {
<> 144:ef7eb2e8f9f7 548 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 549 }
<> 144:ef7eb2e8f9f7 550 }
<> 144:ef7eb2e8f9f7 551
<> 144:ef7eb2e8f9f7 552 /**
AnnaBridge 165:e614a9f1c9e2 553 * @brief Send an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 554 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 555 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 556 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 557 * @param Size: amount of data to be sent
AnnaBridge 165:e614a9f1c9e2 558 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 559 */
AnnaBridge 165:e614a9f1c9e2 560 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 561 {
AnnaBridge 165:e614a9f1c9e2 562 /* Check that a Tx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 563 if(hsc->gState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 564 {
AnnaBridge 165:e614a9f1c9e2 565 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 566 {
AnnaBridge 165:e614a9f1c9e2 567 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 568 }
AnnaBridge 165:e614a9f1c9e2 569 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 570 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 571
AnnaBridge 165:e614a9f1c9e2 572 hsc->pTxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 573 hsc->TxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 574 hsc->TxXferCount = Size;
AnnaBridge 165:e614a9f1c9e2 575
AnnaBridge 165:e614a9f1c9e2 576 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 577 hsc->gState = HAL_SMARTCARD_STATE_BUSY_TX;
AnnaBridge 165:e614a9f1c9e2 578
AnnaBridge 165:e614a9f1c9e2 579 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 580 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 581
AnnaBridge 165:e614a9f1c9e2 582 /* Enable the SMARTCARD Parity Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 583 SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE);
AnnaBridge 165:e614a9f1c9e2 584
AnnaBridge 165:e614a9f1c9e2 585 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 586 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 587
AnnaBridge 165:e614a9f1c9e2 588 /* Enable the SMARTCARD Transmit data register empty Interrupt */
AnnaBridge 165:e614a9f1c9e2 589 SET_BIT(hsc->Instance->CR1, USART_CR1_TXEIE);
AnnaBridge 165:e614a9f1c9e2 590
AnnaBridge 165:e614a9f1c9e2 591 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 592 }
AnnaBridge 165:e614a9f1c9e2 593 else
AnnaBridge 165:e614a9f1c9e2 594 {
AnnaBridge 165:e614a9f1c9e2 595 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 596 }
AnnaBridge 165:e614a9f1c9e2 597 }
AnnaBridge 165:e614a9f1c9e2 598
AnnaBridge 165:e614a9f1c9e2 599 /**
AnnaBridge 165:e614a9f1c9e2 600 * @brief Receive an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 601 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 602 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 603 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 604 * @param Size: amount of data to be received
AnnaBridge 165:e614a9f1c9e2 605 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 606 */
AnnaBridge 165:e614a9f1c9e2 607 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 608 {
AnnaBridge 165:e614a9f1c9e2 609 /* Check that a Rx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 610 if(hsc->RxState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 611 {
AnnaBridge 165:e614a9f1c9e2 612 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 613 {
AnnaBridge 165:e614a9f1c9e2 614 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 615 }
AnnaBridge 165:e614a9f1c9e2 616
AnnaBridge 165:e614a9f1c9e2 617 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 618 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 619
AnnaBridge 165:e614a9f1c9e2 620 hsc->pRxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 621 hsc->RxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 622 hsc->RxXferCount = Size;
AnnaBridge 165:e614a9f1c9e2 623
AnnaBridge 165:e614a9f1c9e2 624 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 625 hsc->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
AnnaBridge 165:e614a9f1c9e2 626
AnnaBridge 165:e614a9f1c9e2 627 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 628 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 629
AnnaBridge 165:e614a9f1c9e2 630 /* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */
AnnaBridge 165:e614a9f1c9e2 631 SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE| USART_CR1_RXNEIE);
AnnaBridge 165:e614a9f1c9e2 632
AnnaBridge 165:e614a9f1c9e2 633 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 634 SET_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 635
AnnaBridge 165:e614a9f1c9e2 636 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 637 }
AnnaBridge 165:e614a9f1c9e2 638 else
AnnaBridge 165:e614a9f1c9e2 639 {
AnnaBridge 165:e614a9f1c9e2 640 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 641 }
AnnaBridge 165:e614a9f1c9e2 642 }
AnnaBridge 165:e614a9f1c9e2 643
AnnaBridge 165:e614a9f1c9e2 644 /**
AnnaBridge 165:e614a9f1c9e2 645 * @brief Send an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 646 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 647 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 648 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 649 * @param Size: amount of data to be sent
AnnaBridge 165:e614a9f1c9e2 650 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 651 */
AnnaBridge 165:e614a9f1c9e2 652 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 653 {
AnnaBridge 165:e614a9f1c9e2 654 uint32_t *tmp;
AnnaBridge 165:e614a9f1c9e2 655
AnnaBridge 165:e614a9f1c9e2 656 /* Check that a Tx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 657 if(hsc->gState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 658 {
AnnaBridge 165:e614a9f1c9e2 659 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 660 {
AnnaBridge 165:e614a9f1c9e2 661 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 662 }
AnnaBridge 165:e614a9f1c9e2 663
AnnaBridge 165:e614a9f1c9e2 664 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 665 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 666
AnnaBridge 165:e614a9f1c9e2 667 hsc->pTxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 668 hsc->TxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 669 hsc->TxXferCount = Size;
AnnaBridge 165:e614a9f1c9e2 670
AnnaBridge 165:e614a9f1c9e2 671 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 672 hsc->gState = HAL_SMARTCARD_STATE_BUSY_TX;
AnnaBridge 165:e614a9f1c9e2 673
AnnaBridge 165:e614a9f1c9e2 674 /* Set the SMARTCARD DMA transfer complete callback */
AnnaBridge 165:e614a9f1c9e2 675 hsc->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt;
AnnaBridge 165:e614a9f1c9e2 676
AnnaBridge 165:e614a9f1c9e2 677 /* Set the DMA error callback */
AnnaBridge 165:e614a9f1c9e2 678 hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError;
AnnaBridge 165:e614a9f1c9e2 679
AnnaBridge 165:e614a9f1c9e2 680 /* Set the DMA abort callback */
AnnaBridge 165:e614a9f1c9e2 681 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 682
AnnaBridge 165:e614a9f1c9e2 683 /* Enable the SMARTCARD transmit DMA Channel */
AnnaBridge 165:e614a9f1c9e2 684 tmp = (uint32_t*)&pData;
AnnaBridge 165:e614a9f1c9e2 685 HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsc->Instance->DR, Size);
AnnaBridge 165:e614a9f1c9e2 686
AnnaBridge 165:e614a9f1c9e2 687 /* Clear the TC flag in the SR register by writing 0 to it */
AnnaBridge 165:e614a9f1c9e2 688 __HAL_SMARTCARD_CLEAR_FLAG(hsc, SMARTCARD_FLAG_TC);
AnnaBridge 165:e614a9f1c9e2 689
AnnaBridge 165:e614a9f1c9e2 690 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 691 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 692
AnnaBridge 165:e614a9f1c9e2 693 /* Enable the DMA transfer for transmit request by setting the DMAT bit
AnnaBridge 165:e614a9f1c9e2 694 in the SMARTCARD CR3 register */
AnnaBridge 165:e614a9f1c9e2 695 SET_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 696
AnnaBridge 165:e614a9f1c9e2 697 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 698 }
AnnaBridge 165:e614a9f1c9e2 699 else
AnnaBridge 165:e614a9f1c9e2 700 {
AnnaBridge 165:e614a9f1c9e2 701 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 702 }
AnnaBridge 165:e614a9f1c9e2 703 }
AnnaBridge 165:e614a9f1c9e2 704
AnnaBridge 165:e614a9f1c9e2 705 /**
AnnaBridge 165:e614a9f1c9e2 706 * @brief Receive an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 707 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 708 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 709 * @param pData: pointer to data buffer
AnnaBridge 165:e614a9f1c9e2 710 * @param Size: amount of data to be received
AnnaBridge 165:e614a9f1c9e2 711 * @note When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit.s
AnnaBridge 165:e614a9f1c9e2 712 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 713 */
AnnaBridge 165:e614a9f1c9e2 714 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size)
AnnaBridge 165:e614a9f1c9e2 715 {
AnnaBridge 165:e614a9f1c9e2 716 uint32_t *tmp;
AnnaBridge 165:e614a9f1c9e2 717
AnnaBridge 165:e614a9f1c9e2 718 /* Check that a Rx process is not already ongoing */
AnnaBridge 165:e614a9f1c9e2 719 if(hsc->RxState == HAL_SMARTCARD_STATE_READY)
AnnaBridge 165:e614a9f1c9e2 720 {
AnnaBridge 165:e614a9f1c9e2 721 if((pData == NULL) || (Size == 0U))
AnnaBridge 165:e614a9f1c9e2 722 {
AnnaBridge 165:e614a9f1c9e2 723 return HAL_ERROR;
AnnaBridge 165:e614a9f1c9e2 724 }
AnnaBridge 165:e614a9f1c9e2 725
AnnaBridge 165:e614a9f1c9e2 726 /* Process Locked */
AnnaBridge 165:e614a9f1c9e2 727 __HAL_LOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 728
AnnaBridge 165:e614a9f1c9e2 729 hsc->pRxBuffPtr = pData;
AnnaBridge 165:e614a9f1c9e2 730 hsc->RxXferSize = Size;
AnnaBridge 165:e614a9f1c9e2 731
AnnaBridge 165:e614a9f1c9e2 732 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 733 hsc->RxState = HAL_SMARTCARD_STATE_BUSY_RX;
AnnaBridge 165:e614a9f1c9e2 734
AnnaBridge 165:e614a9f1c9e2 735 /* Set the SMARTCARD DMA transfer complete callback */
AnnaBridge 165:e614a9f1c9e2 736 hsc->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt;
AnnaBridge 165:e614a9f1c9e2 737
AnnaBridge 165:e614a9f1c9e2 738 /* Set the DMA error callback */
AnnaBridge 165:e614a9f1c9e2 739 hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError;
AnnaBridge 165:e614a9f1c9e2 740
AnnaBridge 165:e614a9f1c9e2 741 /* Set the DMA abort callback */
AnnaBridge 165:e614a9f1c9e2 742 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 743
AnnaBridge 165:e614a9f1c9e2 744 /* Enable the DMA Channel */
AnnaBridge 165:e614a9f1c9e2 745 tmp = (uint32_t*)&pData;
AnnaBridge 165:e614a9f1c9e2 746 HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->DR, *(uint32_t*)tmp, Size);
AnnaBridge 165:e614a9f1c9e2 747
AnnaBridge 165:e614a9f1c9e2 748 /* Clear the Overrun flag just before enabling the DMA Rx request: can be mandatory for the second transfer */
AnnaBridge 165:e614a9f1c9e2 749 __HAL_SMARTCARD_CLEAR_OREFLAG(hsc);
AnnaBridge 165:e614a9f1c9e2 750
AnnaBridge 165:e614a9f1c9e2 751 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 752 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 753
AnnaBridge 165:e614a9f1c9e2 754 /* Enable the SMARTCARD Parity Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 755 SET_BIT(hsc->Instance->CR1, USART_CR1_PEIE);
AnnaBridge 165:e614a9f1c9e2 756
AnnaBridge 165:e614a9f1c9e2 757 /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 758 SET_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 759
AnnaBridge 165:e614a9f1c9e2 760 /* Enable the DMA transfer for the receiver request by setting the DMAR bit
AnnaBridge 165:e614a9f1c9e2 761 in the SMARTCARD CR3 register */
AnnaBridge 165:e614a9f1c9e2 762 SET_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 763
AnnaBridge 165:e614a9f1c9e2 764 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 765 }
AnnaBridge 165:e614a9f1c9e2 766 else
AnnaBridge 165:e614a9f1c9e2 767 {
AnnaBridge 165:e614a9f1c9e2 768 return HAL_BUSY;
AnnaBridge 165:e614a9f1c9e2 769 }
AnnaBridge 165:e614a9f1c9e2 770 }
AnnaBridge 165:e614a9f1c9e2 771
AnnaBridge 165:e614a9f1c9e2 772 /**
AnnaBridge 165:e614a9f1c9e2 773 * @brief Abort ongoing transfers (blocking mode).
AnnaBridge 165:e614a9f1c9e2 774 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 775 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 776 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 777 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 778 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 779 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 780 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 781 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
AnnaBridge 165:e614a9f1c9e2 782 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 783 */
AnnaBridge 165:e614a9f1c9e2 784 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 785 {
AnnaBridge 165:e614a9f1c9e2 786 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 787 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 788 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 789
AnnaBridge 165:e614a9f1c9e2 790 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 791 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 792 {
AnnaBridge 165:e614a9f1c9e2 793 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 794
AnnaBridge 165:e614a9f1c9e2 795 /* Abort the SMARTCARD DMA Tx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 796 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 797 {
AnnaBridge 165:e614a9f1c9e2 798 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 799 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 800 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 801
AnnaBridge 165:e614a9f1c9e2 802 HAL_DMA_Abort(hsc->hdmatx);
AnnaBridge 165:e614a9f1c9e2 803 }
AnnaBridge 165:e614a9f1c9e2 804 }
AnnaBridge 165:e614a9f1c9e2 805
AnnaBridge 165:e614a9f1c9e2 806 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 807 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 808 {
AnnaBridge 165:e614a9f1c9e2 809 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 810
AnnaBridge 165:e614a9f1c9e2 811 /* Abort the SMARTCARD DMA Rx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 812 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 813 {
AnnaBridge 165:e614a9f1c9e2 814 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 815 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 816 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 817
AnnaBridge 165:e614a9f1c9e2 818 HAL_DMA_Abort(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 819 }
AnnaBridge 165:e614a9f1c9e2 820 }
AnnaBridge 165:e614a9f1c9e2 821
AnnaBridge 165:e614a9f1c9e2 822 /* Reset Tx and Rx transfer counters */
AnnaBridge 165:e614a9f1c9e2 823 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 824 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 825
AnnaBridge 165:e614a9f1c9e2 826 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 827 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 828
AnnaBridge 165:e614a9f1c9e2 829 /* Restore hsc->RxState and hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 830 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 831 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 832
AnnaBridge 165:e614a9f1c9e2 833 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 834 }
AnnaBridge 165:e614a9f1c9e2 835
AnnaBridge 165:e614a9f1c9e2 836 /**
AnnaBridge 165:e614a9f1c9e2 837 * @brief Abort ongoing Transmit transfer (blocking mode).
AnnaBridge 165:e614a9f1c9e2 838 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 839 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 840 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 841 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 842 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 843 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 844 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 845 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
AnnaBridge 165:e614a9f1c9e2 846 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 847 */
AnnaBridge 165:e614a9f1c9e2 848 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 849 {
AnnaBridge 165:e614a9f1c9e2 850 /* Disable TXEIE and TCIE interrupts */
AnnaBridge 165:e614a9f1c9e2 851 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 852
AnnaBridge 165:e614a9f1c9e2 853 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 854 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 855 {
AnnaBridge 165:e614a9f1c9e2 856 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 857
AnnaBridge 165:e614a9f1c9e2 858 /* Abort the SMARTCARD DMA Tx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 859 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 860 {
AnnaBridge 165:e614a9f1c9e2 861 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 862 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 863 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 864
AnnaBridge 165:e614a9f1c9e2 865 HAL_DMA_Abort(hsc->hdmatx);
AnnaBridge 165:e614a9f1c9e2 866 }
AnnaBridge 165:e614a9f1c9e2 867 }
AnnaBridge 165:e614a9f1c9e2 868
AnnaBridge 165:e614a9f1c9e2 869 /* Reset Tx transfer counter */
AnnaBridge 165:e614a9f1c9e2 870 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 871
AnnaBridge 165:e614a9f1c9e2 872 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 873 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 874
AnnaBridge 165:e614a9f1c9e2 875 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 876 }
AnnaBridge 165:e614a9f1c9e2 877
AnnaBridge 165:e614a9f1c9e2 878 /**
AnnaBridge 165:e614a9f1c9e2 879 * @brief Abort ongoing Receive transfer (blocking mode).
AnnaBridge 165:e614a9f1c9e2 880 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 881 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 882 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 883 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 884 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 885 * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 886 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 887 * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed.
AnnaBridge 165:e614a9f1c9e2 888 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 889 */
AnnaBridge 165:e614a9f1c9e2 890 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 891 {
AnnaBridge 165:e614a9f1c9e2 892 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 893 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 894 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 895
AnnaBridge 165:e614a9f1c9e2 896 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 897 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 898 {
AnnaBridge 165:e614a9f1c9e2 899 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 900
AnnaBridge 165:e614a9f1c9e2 901 /* Abort the SMARTCARD DMA Rx channel: use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 902 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 903 {
AnnaBridge 165:e614a9f1c9e2 904 /* Set the SMARTCARD DMA Abort callback to Null.
AnnaBridge 165:e614a9f1c9e2 905 No call back execution at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 906 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 907
AnnaBridge 165:e614a9f1c9e2 908 HAL_DMA_Abort(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 909 }
AnnaBridge 165:e614a9f1c9e2 910 }
AnnaBridge 165:e614a9f1c9e2 911
AnnaBridge 165:e614a9f1c9e2 912 /* Reset Rx transfer counter */
AnnaBridge 165:e614a9f1c9e2 913 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 914
AnnaBridge 165:e614a9f1c9e2 915 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 916 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 917
AnnaBridge 165:e614a9f1c9e2 918 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 919 }
AnnaBridge 165:e614a9f1c9e2 920
AnnaBridge 165:e614a9f1c9e2 921 /**
AnnaBridge 165:e614a9f1c9e2 922 * @brief Abort ongoing transfers (Interrupt mode).
AnnaBridge 165:e614a9f1c9e2 923 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 924 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 925 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 926 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 927 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 928 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 929 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 930 * - At abort completion, call user abort complete callback
AnnaBridge 165:e614a9f1c9e2 931 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
AnnaBridge 165:e614a9f1c9e2 932 * considered as completed only when user abort complete callback is executed (not when exiting function).
AnnaBridge 165:e614a9f1c9e2 933 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 934 */
AnnaBridge 165:e614a9f1c9e2 935 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 936 {
AnnaBridge 165:e614a9f1c9e2 937 uint32_t AbortCplt = 0x01U;
AnnaBridge 165:e614a9f1c9e2 938
AnnaBridge 165:e614a9f1c9e2 939 /* Disable TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 940 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 941 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 942
AnnaBridge 165:e614a9f1c9e2 943 /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised
AnnaBridge 165:e614a9f1c9e2 944 before any call to DMA Abort functions */
AnnaBridge 165:e614a9f1c9e2 945 /* DMA Tx Handle is valid */
AnnaBridge 165:e614a9f1c9e2 946 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 947 {
AnnaBridge 165:e614a9f1c9e2 948 /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled.
AnnaBridge 165:e614a9f1c9e2 949 Otherwise, set it to NULL */
AnnaBridge 165:e614a9f1c9e2 950 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 951 {
AnnaBridge 165:e614a9f1c9e2 952 hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxAbortCallback;
AnnaBridge 165:e614a9f1c9e2 953 }
AnnaBridge 165:e614a9f1c9e2 954 else
AnnaBridge 165:e614a9f1c9e2 955 {
AnnaBridge 165:e614a9f1c9e2 956 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 957 }
AnnaBridge 165:e614a9f1c9e2 958 }
AnnaBridge 165:e614a9f1c9e2 959 /* DMA Rx Handle is valid */
AnnaBridge 165:e614a9f1c9e2 960 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 961 {
AnnaBridge 165:e614a9f1c9e2 962 /* Set DMA Abort Complete callback if SMARTCARD DMA Rx request if enabled.
AnnaBridge 165:e614a9f1c9e2 963 Otherwise, set it to NULL */
AnnaBridge 165:e614a9f1c9e2 964 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 965 {
AnnaBridge 165:e614a9f1c9e2 966 hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxAbortCallback;
AnnaBridge 165:e614a9f1c9e2 967 }
AnnaBridge 165:e614a9f1c9e2 968 else
AnnaBridge 165:e614a9f1c9e2 969 {
AnnaBridge 165:e614a9f1c9e2 970 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 971 }
AnnaBridge 165:e614a9f1c9e2 972 }
AnnaBridge 165:e614a9f1c9e2 973
AnnaBridge 165:e614a9f1c9e2 974 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 975 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 976 {
AnnaBridge 165:e614a9f1c9e2 977 /* Disable DMA Tx at SMARTCARD level */
AnnaBridge 165:e614a9f1c9e2 978 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 979
AnnaBridge 165:e614a9f1c9e2 980 /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */
AnnaBridge 165:e614a9f1c9e2 981 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 982 {
AnnaBridge 165:e614a9f1c9e2 983 /* SMARTCARD Tx DMA Abort callback has already been initialised :
AnnaBridge 165:e614a9f1c9e2 984 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 985
AnnaBridge 165:e614a9f1c9e2 986 /* Abort DMA TX */
AnnaBridge 165:e614a9f1c9e2 987 if(HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 988 {
AnnaBridge 165:e614a9f1c9e2 989 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 990 }
AnnaBridge 165:e614a9f1c9e2 991 else
AnnaBridge 165:e614a9f1c9e2 992 {
AnnaBridge 165:e614a9f1c9e2 993 AbortCplt = 0x00U;
AnnaBridge 165:e614a9f1c9e2 994 }
AnnaBridge 165:e614a9f1c9e2 995 }
AnnaBridge 165:e614a9f1c9e2 996 }
AnnaBridge 165:e614a9f1c9e2 997
AnnaBridge 165:e614a9f1c9e2 998 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 999 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 1000 {
AnnaBridge 165:e614a9f1c9e2 1001 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1002
AnnaBridge 165:e614a9f1c9e2 1003 /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */
AnnaBridge 165:e614a9f1c9e2 1004 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1005 {
AnnaBridge 165:e614a9f1c9e2 1006 /* SMARTCARD Rx DMA Abort callback has already been initialised :
AnnaBridge 165:e614a9f1c9e2 1007 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1008
AnnaBridge 165:e614a9f1c9e2 1009 /* Abort DMA RX */
AnnaBridge 165:e614a9f1c9e2 1010 if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1011 {
AnnaBridge 165:e614a9f1c9e2 1012 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 1013 AbortCplt = 0x01U;
AnnaBridge 165:e614a9f1c9e2 1014 }
AnnaBridge 165:e614a9f1c9e2 1015 else
AnnaBridge 165:e614a9f1c9e2 1016 {
AnnaBridge 165:e614a9f1c9e2 1017 AbortCplt = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1018 }
AnnaBridge 165:e614a9f1c9e2 1019 }
AnnaBridge 165:e614a9f1c9e2 1020 }
AnnaBridge 165:e614a9f1c9e2 1021
AnnaBridge 165:e614a9f1c9e2 1022 /* if no DMA abort complete callback execution is required => call user Abort Complete callback */
AnnaBridge 165:e614a9f1c9e2 1023 if(AbortCplt == 0x01U)
AnnaBridge 165:e614a9f1c9e2 1024 {
AnnaBridge 165:e614a9f1c9e2 1025 /* Reset Tx and Rx transfer counters */
AnnaBridge 165:e614a9f1c9e2 1026 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1027 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1028
AnnaBridge 165:e614a9f1c9e2 1029 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 1030 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1031
AnnaBridge 165:e614a9f1c9e2 1032 /* Restore hsc->gState and hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1033 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1034 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1035
AnnaBridge 165:e614a9f1c9e2 1036 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1037 HAL_SMARTCARD_AbortCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1038 }
AnnaBridge 165:e614a9f1c9e2 1039 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 1040 }
AnnaBridge 165:e614a9f1c9e2 1041
AnnaBridge 165:e614a9f1c9e2 1042 /**
AnnaBridge 165:e614a9f1c9e2 1043 * @brief Abort ongoing Transmit transfer (Interrupt mode).
AnnaBridge 165:e614a9f1c9e2 1044 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1045 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 1046 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 1047 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 1048 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 1049 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 1050 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 1051 * - At abort completion, call user abort complete callback
AnnaBridge 165:e614a9f1c9e2 1052 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
AnnaBridge 165:e614a9f1c9e2 1053 * considered as completed only when user abort complete callback is executed (not when exiting function).
AnnaBridge 165:e614a9f1c9e2 1054 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 1055 */
AnnaBridge 165:e614a9f1c9e2 1056 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1057 {
AnnaBridge 165:e614a9f1c9e2 1058 /* Disable TXEIE and TCIE interrupts */
AnnaBridge 165:e614a9f1c9e2 1059 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 1060
AnnaBridge 165:e614a9f1c9e2 1061 /* Disable the SMARTCARD DMA Tx request if enabled */
AnnaBridge 165:e614a9f1c9e2 1062 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT))
AnnaBridge 165:e614a9f1c9e2 1063 {
AnnaBridge 165:e614a9f1c9e2 1064 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 1065
AnnaBridge 165:e614a9f1c9e2 1066 /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 1067 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 1068 {
AnnaBridge 165:e614a9f1c9e2 1069 /* Set the SMARTCARD DMA Abort callback :
AnnaBridge 165:e614a9f1c9e2 1070 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1071 hsc->hdmatx->XferAbortCallback = SMARTCARD_DMATxOnlyAbortCallback;
AnnaBridge 165:e614a9f1c9e2 1072
AnnaBridge 165:e614a9f1c9e2 1073 /* Abort DMA TX */
AnnaBridge 165:e614a9f1c9e2 1074 if(HAL_DMA_Abort_IT(hsc->hdmatx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1075 {
AnnaBridge 165:e614a9f1c9e2 1076 /* Call Directly hsc->hdmatx->XferAbortCallback function in case of error */
AnnaBridge 165:e614a9f1c9e2 1077 hsc->hdmatx->XferAbortCallback(hsc->hdmatx);
AnnaBridge 165:e614a9f1c9e2 1078 }
AnnaBridge 165:e614a9f1c9e2 1079 }
AnnaBridge 165:e614a9f1c9e2 1080 else
AnnaBridge 165:e614a9f1c9e2 1081 {
AnnaBridge 165:e614a9f1c9e2 1082 /* Reset Tx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1083 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1084
AnnaBridge 165:e614a9f1c9e2 1085 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1086 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1087
AnnaBridge 165:e614a9f1c9e2 1088 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1089 HAL_SMARTCARD_AbortTransmitCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1090 }
AnnaBridge 165:e614a9f1c9e2 1091 }
AnnaBridge 165:e614a9f1c9e2 1092 else
AnnaBridge 165:e614a9f1c9e2 1093 {
AnnaBridge 165:e614a9f1c9e2 1094 /* Reset Tx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1095 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1096
AnnaBridge 165:e614a9f1c9e2 1097 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1098 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1099
AnnaBridge 165:e614a9f1c9e2 1100 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1101 HAL_SMARTCARD_AbortTransmitCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1102 }
AnnaBridge 165:e614a9f1c9e2 1103
AnnaBridge 165:e614a9f1c9e2 1104 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 1105 }
AnnaBridge 165:e614a9f1c9e2 1106
AnnaBridge 165:e614a9f1c9e2 1107 /**
AnnaBridge 165:e614a9f1c9e2 1108 * @brief Abort ongoing Receive transfer (Interrupt mode).
AnnaBridge 165:e614a9f1c9e2 1109 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1110 * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode.
AnnaBridge 165:e614a9f1c9e2 1111 * This procedure performs following operations :
AnnaBridge 165:e614a9f1c9e2 1112 * - Disable PPP Interrupts
AnnaBridge 165:e614a9f1c9e2 1113 * - Disable the DMA transfer in the peripheral register (if enabled)
AnnaBridge 165:e614a9f1c9e2 1114 * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode)
AnnaBridge 165:e614a9f1c9e2 1115 * - Set handle State to READY
AnnaBridge 165:e614a9f1c9e2 1116 * - At abort completion, call user abort complete callback
AnnaBridge 165:e614a9f1c9e2 1117 * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be
AnnaBridge 165:e614a9f1c9e2 1118 * considered as completed only when user abort complete callback is executed (not when exiting function).
AnnaBridge 165:e614a9f1c9e2 1119 * @retval HAL status
AnnaBridge 165:e614a9f1c9e2 1120 */
AnnaBridge 165:e614a9f1c9e2 1121 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1122 {
AnnaBridge 165:e614a9f1c9e2 1123 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 1124 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 1125 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1126
AnnaBridge 165:e614a9f1c9e2 1127 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 1128 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 1129 {
AnnaBridge 165:e614a9f1c9e2 1130 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1131
AnnaBridge 165:e614a9f1c9e2 1132 /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */
AnnaBridge 165:e614a9f1c9e2 1133 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1134 {
AnnaBridge 165:e614a9f1c9e2 1135 /* Set the SMARTCARD DMA Abort callback :
AnnaBridge 165:e614a9f1c9e2 1136 will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1137 hsc->hdmarx->XferAbortCallback = SMARTCARD_DMARxOnlyAbortCallback;
AnnaBridge 165:e614a9f1c9e2 1138
AnnaBridge 165:e614a9f1c9e2 1139 /* Abort DMA RX */
AnnaBridge 165:e614a9f1c9e2 1140 if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1141 {
AnnaBridge 165:e614a9f1c9e2 1142 /* Call Directly hsc->hdmarx->XferAbortCallback function in case of error */
AnnaBridge 165:e614a9f1c9e2 1143 hsc->hdmarx->XferAbortCallback(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 1144 }
AnnaBridge 165:e614a9f1c9e2 1145 }
AnnaBridge 165:e614a9f1c9e2 1146 else
AnnaBridge 165:e614a9f1c9e2 1147 {
AnnaBridge 165:e614a9f1c9e2 1148 /* Reset Rx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1149 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1150
AnnaBridge 165:e614a9f1c9e2 1151 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1152 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1153
AnnaBridge 165:e614a9f1c9e2 1154 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1155 HAL_SMARTCARD_AbortReceiveCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1156 }
AnnaBridge 165:e614a9f1c9e2 1157 }
AnnaBridge 165:e614a9f1c9e2 1158 else
AnnaBridge 165:e614a9f1c9e2 1159 {
AnnaBridge 165:e614a9f1c9e2 1160 /* Reset Rx transfer counter */
AnnaBridge 165:e614a9f1c9e2 1161 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1162
AnnaBridge 165:e614a9f1c9e2 1163 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1164 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1165
AnnaBridge 165:e614a9f1c9e2 1166 /* As no DMA to be aborted, call directly user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1167 HAL_SMARTCARD_AbortReceiveCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1168 }
AnnaBridge 165:e614a9f1c9e2 1169
AnnaBridge 165:e614a9f1c9e2 1170 return HAL_OK;
AnnaBridge 165:e614a9f1c9e2 1171 }
AnnaBridge 165:e614a9f1c9e2 1172
AnnaBridge 165:e614a9f1c9e2 1173 /**
AnnaBridge 165:e614a9f1c9e2 1174 * @brief This function handles SMARTCARD interrupt request.
AnnaBridge 165:e614a9f1c9e2 1175 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1176 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1177 * @retval None
<> 144:ef7eb2e8f9f7 1178 */
<> 144:ef7eb2e8f9f7 1179 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1180 {
AnnaBridge 165:e614a9f1c9e2 1181 uint32_t isrflags = READ_REG(hsc->Instance->SR);
AnnaBridge 165:e614a9f1c9e2 1182 uint32_t cr1its = READ_REG(hsc->Instance->CR1);
AnnaBridge 165:e614a9f1c9e2 1183 uint32_t cr3its = READ_REG(hsc->Instance->CR3);
AnnaBridge 165:e614a9f1c9e2 1184 uint32_t dmarequest = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1185 uint32_t errorflags = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1186
AnnaBridge 165:e614a9f1c9e2 1187 /* If no error occurs */
AnnaBridge 165:e614a9f1c9e2 1188 errorflags = (isrflags & (uint32_t)(USART_SR_PE | USART_SR_FE | USART_SR_ORE | USART_SR_NE));
AnnaBridge 165:e614a9f1c9e2 1189 if(errorflags == RESET)
<> 144:ef7eb2e8f9f7 1190 {
AnnaBridge 165:e614a9f1c9e2 1191 /* SMARTCARD in mode Receiver -------------------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1192 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1193 {
AnnaBridge 165:e614a9f1c9e2 1194 SMARTCARD_Receive_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1195 return;
AnnaBridge 165:e614a9f1c9e2 1196 }
<> 144:ef7eb2e8f9f7 1197 }
<> 144:ef7eb2e8f9f7 1198
AnnaBridge 165:e614a9f1c9e2 1199 /* If some errors occur */
AnnaBridge 165:e614a9f1c9e2 1200 if((errorflags != RESET) && (((cr3its & USART_CR3_EIE) != RESET) || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE)) != RESET)))
<> 144:ef7eb2e8f9f7 1201 {
AnnaBridge 165:e614a9f1c9e2 1202 /* SMARTCARD parity error interrupt occurred ---------------------------*/
AnnaBridge 165:e614a9f1c9e2 1203 if(((isrflags & SMARTCARD_FLAG_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1204 {
AnnaBridge 165:e614a9f1c9e2 1205 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE;
AnnaBridge 165:e614a9f1c9e2 1206 }
AnnaBridge 165:e614a9f1c9e2 1207
AnnaBridge 165:e614a9f1c9e2 1208 /* SMARTCARD noise error interrupt occurred ----------------------------*/
AnnaBridge 165:e614a9f1c9e2 1209 if(((isrflags & SMARTCARD_FLAG_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1210 {
AnnaBridge 165:e614a9f1c9e2 1211 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE;
AnnaBridge 165:e614a9f1c9e2 1212 }
AnnaBridge 165:e614a9f1c9e2 1213
AnnaBridge 165:e614a9f1c9e2 1214 /* SMARTCARD frame error interrupt occurred ----------------------------*/
AnnaBridge 165:e614a9f1c9e2 1215 if(((isrflags & SMARTCARD_FLAG_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1216 {
AnnaBridge 165:e614a9f1c9e2 1217 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE;
AnnaBridge 165:e614a9f1c9e2 1218 }
AnnaBridge 165:e614a9f1c9e2 1219
AnnaBridge 165:e614a9f1c9e2 1220 /* SMARTCARD Over-Run interrupt occurred -------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1221 if(((isrflags & SMARTCARD_FLAG_ORE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1222 {
AnnaBridge 165:e614a9f1c9e2 1223 hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE;
AnnaBridge 165:e614a9f1c9e2 1224 }
AnnaBridge 165:e614a9f1c9e2 1225
AnnaBridge 165:e614a9f1c9e2 1226 /* Call SMARTCARD Error Call back function if need be ------------------*/
AnnaBridge 165:e614a9f1c9e2 1227 if(hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE)
AnnaBridge 165:e614a9f1c9e2 1228 {
AnnaBridge 165:e614a9f1c9e2 1229 /* SMARTCARD in mode Receiver ----------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1230 if(((isrflags & USART_SR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET))
AnnaBridge 165:e614a9f1c9e2 1231 {
AnnaBridge 165:e614a9f1c9e2 1232 SMARTCARD_Receive_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1233 }
AnnaBridge 165:e614a9f1c9e2 1234
AnnaBridge 165:e614a9f1c9e2 1235 /* If Overrun error occurs, or if any error occurs in DMA mode reception,
AnnaBridge 165:e614a9f1c9e2 1236 consider error as blocking */
AnnaBridge 165:e614a9f1c9e2 1237 dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1238 if(((hsc->ErrorCode & HAL_SMARTCARD_ERROR_ORE) != RESET) || dmarequest)
AnnaBridge 165:e614a9f1c9e2 1239 {
AnnaBridge 165:e614a9f1c9e2 1240 /* Blocking error : transfer is aborted
AnnaBridge 165:e614a9f1c9e2 1241 Set the SMARTCARD state ready to be able to start again the process,
AnnaBridge 165:e614a9f1c9e2 1242 Disable Rx Interrupts, and disable Rx DMA request, if ongoing */
AnnaBridge 165:e614a9f1c9e2 1243 SMARTCARD_EndRxTransfer(hsc);
<> 144:ef7eb2e8f9f7 1244
AnnaBridge 165:e614a9f1c9e2 1245 /* Disable the SMARTCARD DMA Rx request if enabled */
AnnaBridge 165:e614a9f1c9e2 1246 if(HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR))
AnnaBridge 165:e614a9f1c9e2 1247 {
AnnaBridge 165:e614a9f1c9e2 1248 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1249
AnnaBridge 165:e614a9f1c9e2 1250 /* Abort the SMARTCARD DMA Rx channel */
AnnaBridge 165:e614a9f1c9e2 1251 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1252 {
AnnaBridge 165:e614a9f1c9e2 1253 /* Set the SMARTCARD DMA Abort callback :
AnnaBridge 165:e614a9f1c9e2 1254 will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */
AnnaBridge 165:e614a9f1c9e2 1255 hsc->hdmarx->XferAbortCallback = SMARTCARD_DMAAbortOnError;
AnnaBridge 165:e614a9f1c9e2 1256 if(HAL_DMA_Abort_IT(hsc->hdmarx) != HAL_OK)
AnnaBridge 165:e614a9f1c9e2 1257 {
AnnaBridge 165:e614a9f1c9e2 1258 /* Call Directly XferAbortCallback function in case of error */
AnnaBridge 165:e614a9f1c9e2 1259 hsc->hdmarx->XferAbortCallback(hsc->hdmarx);
AnnaBridge 165:e614a9f1c9e2 1260 }
AnnaBridge 165:e614a9f1c9e2 1261 }
AnnaBridge 165:e614a9f1c9e2 1262 else
AnnaBridge 165:e614a9f1c9e2 1263 {
AnnaBridge 165:e614a9f1c9e2 1264 /* Call user error callback */
AnnaBridge 165:e614a9f1c9e2 1265 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1266 }
AnnaBridge 165:e614a9f1c9e2 1267 }
AnnaBridge 165:e614a9f1c9e2 1268 else
AnnaBridge 165:e614a9f1c9e2 1269 {
AnnaBridge 165:e614a9f1c9e2 1270 /* Call user error callback */
AnnaBridge 165:e614a9f1c9e2 1271 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1272 }
AnnaBridge 165:e614a9f1c9e2 1273 }
AnnaBridge 165:e614a9f1c9e2 1274 else
AnnaBridge 165:e614a9f1c9e2 1275 {
AnnaBridge 165:e614a9f1c9e2 1276 /* Non Blocking error : transfer could go on.
AnnaBridge 165:e614a9f1c9e2 1277 Error is notified to user through user error callback */
AnnaBridge 165:e614a9f1c9e2 1278 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1279 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1280 }
AnnaBridge 165:e614a9f1c9e2 1281 }
AnnaBridge 165:e614a9f1c9e2 1282 return;
AnnaBridge 165:e614a9f1c9e2 1283 } /* End if some error occurs */
AnnaBridge 165:e614a9f1c9e2 1284
AnnaBridge 165:e614a9f1c9e2 1285 /* SMARTCARD in mode Transmitter -------------------------------------------*/
AnnaBridge 165:e614a9f1c9e2 1286 if(((isrflags & SMARTCARD_FLAG_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET))
<> 144:ef7eb2e8f9f7 1287 {
AnnaBridge 165:e614a9f1c9e2 1288 SMARTCARD_Transmit_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1289 return;
<> 144:ef7eb2e8f9f7 1290 }
<> 144:ef7eb2e8f9f7 1291
<> 144:ef7eb2e8f9f7 1292 /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/
AnnaBridge 165:e614a9f1c9e2 1293 if(((isrflags & SMARTCARD_FLAG_TC) != RESET) && ((cr1its & USART_CR1_TCIE) != RESET))
<> 144:ef7eb2e8f9f7 1294 {
<> 144:ef7eb2e8f9f7 1295 SMARTCARD_EndTransmit_IT(hsc);
AnnaBridge 165:e614a9f1c9e2 1296 return;
<> 144:ef7eb2e8f9f7 1297 }
<> 144:ef7eb2e8f9f7 1298 }
<> 144:ef7eb2e8f9f7 1299
<> 144:ef7eb2e8f9f7 1300 /**
AnnaBridge 165:e614a9f1c9e2 1301 * @brief Tx Transfer completed callbacks
AnnaBridge 165:e614a9f1c9e2 1302 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1303 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1304 * @retval None
<> 144:ef7eb2e8f9f7 1305 */
AnnaBridge 165:e614a9f1c9e2 1306 __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1307 {
<> 144:ef7eb2e8f9f7 1308 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 1309 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1310 /* NOTE : This function Should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1311 the HAL_SMARTCARD_TxCpltCallback could be implemented in the user file
AnnaBridge 165:e614a9f1c9e2 1312 */
<> 144:ef7eb2e8f9f7 1313 }
<> 144:ef7eb2e8f9f7 1314
<> 144:ef7eb2e8f9f7 1315 /**
AnnaBridge 165:e614a9f1c9e2 1316 * @brief Rx Transfer completed callbacks
AnnaBridge 165:e614a9f1c9e2 1317 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1318 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1319 * @retval None
<> 144:ef7eb2e8f9f7 1320 */
<> 144:ef7eb2e8f9f7 1321 __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1322 {
<> 144:ef7eb2e8f9f7 1323 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 1324 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1325 /* NOTE : This function Should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1326 the HAL_SMARTCARD_RxCpltCallback could be implemented in the user file
AnnaBridge 165:e614a9f1c9e2 1327 */
AnnaBridge 165:e614a9f1c9e2 1328 }
AnnaBridge 165:e614a9f1c9e2 1329
AnnaBridge 165:e614a9f1c9e2 1330 /**
AnnaBridge 165:e614a9f1c9e2 1331 * @brief SMARTCARD error callbacks
AnnaBridge 165:e614a9f1c9e2 1332 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1333 * the configuration information for SMARTCARD module.
AnnaBridge 165:e614a9f1c9e2 1334 * @retval None
AnnaBridge 165:e614a9f1c9e2 1335 */
AnnaBridge 165:e614a9f1c9e2 1336 __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1337 {
AnnaBridge 165:e614a9f1c9e2 1338 /* Prevent unused argument(s) compilation warning */
AnnaBridge 165:e614a9f1c9e2 1339 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1340 /* NOTE : This function Should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1341 the HAL_SMARTCARD_ErrorCallback could be implemented in the user file
<> 144:ef7eb2e8f9f7 1342 */
<> 144:ef7eb2e8f9f7 1343 }
<> 144:ef7eb2e8f9f7 1344
<> 144:ef7eb2e8f9f7 1345 /**
AnnaBridge 165:e614a9f1c9e2 1346 * @brief SMARTCARD Abort Complete callback.
AnnaBridge 165:e614a9f1c9e2 1347 * @param hsc SMARTCARD handle.
<> 144:ef7eb2e8f9f7 1348 * @retval None
<> 144:ef7eb2e8f9f7 1349 */
AnnaBridge 165:e614a9f1c9e2 1350 __weak void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1351 {
<> 144:ef7eb2e8f9f7 1352 /* Prevent unused argument(s) compilation warning */
<> 144:ef7eb2e8f9f7 1353 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1354
AnnaBridge 165:e614a9f1c9e2 1355 /* NOTE : This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1356 the HAL_SMARTCARD_AbortCpltCallback can be implemented in the user file.
AnnaBridge 165:e614a9f1c9e2 1357 */
AnnaBridge 165:e614a9f1c9e2 1358 }
AnnaBridge 165:e614a9f1c9e2 1359
AnnaBridge 165:e614a9f1c9e2 1360 /**
AnnaBridge 165:e614a9f1c9e2 1361 * @brief SMARTCARD Abort Transmit Complete callback.
AnnaBridge 165:e614a9f1c9e2 1362 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1363 * @retval None
AnnaBridge 165:e614a9f1c9e2 1364 */
AnnaBridge 165:e614a9f1c9e2 1365 __weak void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1366 {
AnnaBridge 165:e614a9f1c9e2 1367 /* Prevent unused argument(s) compilation warning */
AnnaBridge 165:e614a9f1c9e2 1368 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1369
AnnaBridge 165:e614a9f1c9e2 1370 /* NOTE : This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1371 the HAL_SMARTCARD_AbortTransmitCpltCallback can be implemented in the user file.
AnnaBridge 165:e614a9f1c9e2 1372 */
AnnaBridge 165:e614a9f1c9e2 1373 }
AnnaBridge 165:e614a9f1c9e2 1374
AnnaBridge 165:e614a9f1c9e2 1375 /**
AnnaBridge 165:e614a9f1c9e2 1376 * @brief SMARTCARD Abort ReceiveComplete callback.
AnnaBridge 165:e614a9f1c9e2 1377 * @param hsc SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1378 * @retval None
AnnaBridge 165:e614a9f1c9e2 1379 */
AnnaBridge 165:e614a9f1c9e2 1380 __weak void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1381 {
AnnaBridge 165:e614a9f1c9e2 1382 /* Prevent unused argument(s) compilation warning */
AnnaBridge 165:e614a9f1c9e2 1383 UNUSED(hsc);
AnnaBridge 165:e614a9f1c9e2 1384
AnnaBridge 165:e614a9f1c9e2 1385 /* NOTE : This function should not be modified, when the callback is needed,
AnnaBridge 165:e614a9f1c9e2 1386 the HAL_SMARTCARD_AbortReceiveCpltCallback can be implemented in the user file.
AnnaBridge 165:e614a9f1c9e2 1387 */
<> 144:ef7eb2e8f9f7 1388 }
<> 144:ef7eb2e8f9f7 1389
<> 144:ef7eb2e8f9f7 1390 /**
<> 144:ef7eb2e8f9f7 1391 * @}
<> 144:ef7eb2e8f9f7 1392 */
<> 144:ef7eb2e8f9f7 1393
<> 144:ef7eb2e8f9f7 1394 /** @defgroup SMARTCARD_Exported_Functions_Group3 Peripheral State and Errors functions
<> 144:ef7eb2e8f9f7 1395 * @brief SMARTCARD State and Errors functions
<> 144:ef7eb2e8f9f7 1396 *
<> 144:ef7eb2e8f9f7 1397 @verbatim
AnnaBridge 165:e614a9f1c9e2 1398 ===============================================================================
AnnaBridge 165:e614a9f1c9e2 1399 ##### Peripheral State and Errors functions #####
AnnaBridge 165:e614a9f1c9e2 1400 ===============================================================================
AnnaBridge 165:e614a9f1c9e2 1401 [..]
AnnaBridge 165:e614a9f1c9e2 1402 This subsection provides a set of functions allowing to control the SmartCard.
AnnaBridge 165:e614a9f1c9e2 1403 (+) HAL_SMARTCARD_GetState() API can be helpful to check in run-time the state of the SmartCard peripheral.
AnnaBridge 165:e614a9f1c9e2 1404 (+) HAL_SMARTCARD_GetError() check in run-time errors that could be occurred during communication.
<> 144:ef7eb2e8f9f7 1405 @endverbatim
<> 144:ef7eb2e8f9f7 1406 * @{
<> 144:ef7eb2e8f9f7 1407 */
<> 144:ef7eb2e8f9f7 1408
<> 144:ef7eb2e8f9f7 1409 /**
AnnaBridge 165:e614a9f1c9e2 1410 * @brief return the SMARTCARD state
AnnaBridge 165:e614a9f1c9e2 1411 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1412 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1413 * @retval HAL state
<> 144:ef7eb2e8f9f7 1414 */
<> 144:ef7eb2e8f9f7 1415 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1416 {
AnnaBridge 165:e614a9f1c9e2 1417 uint32_t temp1= 0x00U, temp2 = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1418 temp1 = hsc->gState;
AnnaBridge 165:e614a9f1c9e2 1419 temp2 = hsc->RxState;
AnnaBridge 165:e614a9f1c9e2 1420
AnnaBridge 165:e614a9f1c9e2 1421 return (HAL_SMARTCARD_StateTypeDef)(temp1 | temp2);
<> 144:ef7eb2e8f9f7 1422 }
<> 144:ef7eb2e8f9f7 1423
<> 144:ef7eb2e8f9f7 1424 /**
<> 144:ef7eb2e8f9f7 1425 * @brief Return the SMARTCARD error code
AnnaBridge 165:e614a9f1c9e2 1426 * @param hsc : pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1427 * the configuration information for the specified SMARTCARD.
<> 144:ef7eb2e8f9f7 1428 * @retval SMARTCARD Error Code
<> 144:ef7eb2e8f9f7 1429 */
<> 144:ef7eb2e8f9f7 1430 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1431 {
<> 144:ef7eb2e8f9f7 1432 return hsc->ErrorCode;
<> 144:ef7eb2e8f9f7 1433 }
<> 144:ef7eb2e8f9f7 1434
<> 144:ef7eb2e8f9f7 1435 /**
<> 144:ef7eb2e8f9f7 1436 * @}
<> 144:ef7eb2e8f9f7 1437 */
AnnaBridge 165:e614a9f1c9e2 1438
<> 144:ef7eb2e8f9f7 1439 /**
AnnaBridge 165:e614a9f1c9e2 1440 * @brief DMA SMARTCARD transmit process complete callback
AnnaBridge 165:e614a9f1c9e2 1441 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1442 * the configuration information for the specified DMA module.
<> 144:ef7eb2e8f9f7 1443 * @retval None
<> 144:ef7eb2e8f9f7 1444 */
<> 144:ef7eb2e8f9f7 1445 static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma)
<> 144:ef7eb2e8f9f7 1446 {
<> 144:ef7eb2e8f9f7 1447 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1448
AnnaBridge 165:e614a9f1c9e2 1449 hsc->TxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1450
<> 144:ef7eb2e8f9f7 1451 /* Disable the DMA transfer for transmit request by setting the DMAT bit
AnnaBridge 165:e614a9f1c9e2 1452 in the USART CR3 register */
<> 144:ef7eb2e8f9f7 1453 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT);
<> 144:ef7eb2e8f9f7 1454
AnnaBridge 165:e614a9f1c9e2 1455 /* Enable the SMARTCARD Transmit Complete Interrupt */
AnnaBridge 165:e614a9f1c9e2 1456 SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE);
<> 144:ef7eb2e8f9f7 1457 }
<> 144:ef7eb2e8f9f7 1458
<> 144:ef7eb2e8f9f7 1459 /**
AnnaBridge 165:e614a9f1c9e2 1460 * @brief DMA SMARTCARD receive process complete callback
AnnaBridge 165:e614a9f1c9e2 1461 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1462 * the configuration information for the specified DMA module.
<> 144:ef7eb2e8f9f7 1463 * @retval None
<> 144:ef7eb2e8f9f7 1464 */
<> 144:ef7eb2e8f9f7 1465 static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma)
<> 144:ef7eb2e8f9f7 1466 {
<> 144:ef7eb2e8f9f7 1467 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
<> 144:ef7eb2e8f9f7 1468
AnnaBridge 165:e614a9f1c9e2 1469 hsc->RxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1470
AnnaBridge 165:e614a9f1c9e2 1471 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 1472 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 1473 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1474
<> 144:ef7eb2e8f9f7 1475 /* Disable the DMA transfer for the receiver request by setting the DMAR bit
AnnaBridge 165:e614a9f1c9e2 1476 in the USART CR3 register */
<> 144:ef7eb2e8f9f7 1477 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR);
<> 144:ef7eb2e8f9f7 1478
AnnaBridge 165:e614a9f1c9e2 1479 /* At end of Rx process, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1480 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1481
<> 144:ef7eb2e8f9f7 1482 HAL_SMARTCARD_RxCpltCallback(hsc);
<> 144:ef7eb2e8f9f7 1483 }
<> 144:ef7eb2e8f9f7 1484
<> 144:ef7eb2e8f9f7 1485 /**
AnnaBridge 165:e614a9f1c9e2 1486 * @brief DMA SMARTCARD communication error callback
AnnaBridge 165:e614a9f1c9e2 1487 * @param hdma: pointer to a DMA_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1488 * the configuration information for the specified DMA module.
<> 144:ef7eb2e8f9f7 1489 * @retval None
<> 144:ef7eb2e8f9f7 1490 */
<> 144:ef7eb2e8f9f7 1491 static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma)
<> 144:ef7eb2e8f9f7 1492 {
AnnaBridge 165:e614a9f1c9e2 1493 uint32_t dmarequest = 0x00U;
<> 144:ef7eb2e8f9f7 1494 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1495 hsc->RxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1496 hsc->TxXferCount = 0U;
AnnaBridge 165:e614a9f1c9e2 1497 hsc->ErrorCode = HAL_SMARTCARD_ERROR_DMA;
<> 144:ef7eb2e8f9f7 1498
AnnaBridge 165:e614a9f1c9e2 1499 /* Stop SMARTCARD DMA Tx request if ongoing */
AnnaBridge 165:e614a9f1c9e2 1500 dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAT);
AnnaBridge 165:e614a9f1c9e2 1501 if((hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX) && dmarequest)
AnnaBridge 165:e614a9f1c9e2 1502 {
AnnaBridge 165:e614a9f1c9e2 1503 SMARTCARD_EndTxTransfer(hsc);
AnnaBridge 165:e614a9f1c9e2 1504 }
AnnaBridge 165:e614a9f1c9e2 1505
AnnaBridge 165:e614a9f1c9e2 1506 /* Stop SMARTCARD DMA Rx request if ongoing */
AnnaBridge 165:e614a9f1c9e2 1507 dmarequest = HAL_IS_BIT_SET(hsc->Instance->CR3, USART_CR3_DMAR);
AnnaBridge 165:e614a9f1c9e2 1508 if((hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX) && dmarequest)
AnnaBridge 165:e614a9f1c9e2 1509 {
AnnaBridge 165:e614a9f1c9e2 1510 SMARTCARD_EndRxTransfer(hsc);
AnnaBridge 165:e614a9f1c9e2 1511 }
AnnaBridge 165:e614a9f1c9e2 1512
<> 144:ef7eb2e8f9f7 1513 HAL_SMARTCARD_ErrorCallback(hsc);
<> 144:ef7eb2e8f9f7 1514 }
<> 144:ef7eb2e8f9f7 1515
<> 144:ef7eb2e8f9f7 1516 /**
<> 144:ef7eb2e8f9f7 1517 * @brief This function handles SMARTCARD Communication Timeout.
AnnaBridge 165:e614a9f1c9e2 1518 * @param hsc: SMARTCARD handle
<> 144:ef7eb2e8f9f7 1519 * @param Flag: specifies the SMARTCARD flag to check.
<> 144:ef7eb2e8f9f7 1520 * @param Status: The new Flag status (SET or RESET).
<> 144:ef7eb2e8f9f7 1521 * @param Timeout: Timeout duration
AnnaBridge 165:e614a9f1c9e2 1522 * @param Tickstart: tick start value
<> 144:ef7eb2e8f9f7 1523 * @retval HAL status
<> 144:ef7eb2e8f9f7 1524 */
AnnaBridge 165:e614a9f1c9e2 1525 static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout)
<> 144:ef7eb2e8f9f7 1526 {
<> 144:ef7eb2e8f9f7 1527 /* Wait until flag is set */
AnnaBridge 165:e614a9f1c9e2 1528 while((__HAL_SMARTCARD_GET_FLAG(hsc, Flag) ? SET : RESET) == Status)
<> 144:ef7eb2e8f9f7 1529 {
AnnaBridge 165:e614a9f1c9e2 1530 /* Check for the Timeout */
AnnaBridge 165:e614a9f1c9e2 1531 if(Timeout != HAL_MAX_DELAY)
<> 144:ef7eb2e8f9f7 1532 {
AnnaBridge 165:e614a9f1c9e2 1533 if((Timeout == 0U)||((HAL_GetTick() - Tickstart ) > Timeout))
<> 144:ef7eb2e8f9f7 1534 {
AnnaBridge 165:e614a9f1c9e2 1535 /* Disable TXE and RXNE interrupts for the interrupt process */
AnnaBridge 165:e614a9f1c9e2 1536 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE);
AnnaBridge 165:e614a9f1c9e2 1537 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE);
<> 144:ef7eb2e8f9f7 1538
AnnaBridge 165:e614a9f1c9e2 1539 hsc->gState= HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1540 hsc->RxState= HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1541
AnnaBridge 165:e614a9f1c9e2 1542 /* Process Unlocked */
AnnaBridge 165:e614a9f1c9e2 1543 __HAL_UNLOCK(hsc);
AnnaBridge 165:e614a9f1c9e2 1544
AnnaBridge 165:e614a9f1c9e2 1545 return HAL_TIMEOUT;
<> 144:ef7eb2e8f9f7 1546 }
<> 144:ef7eb2e8f9f7 1547 }
<> 144:ef7eb2e8f9f7 1548 }
<> 144:ef7eb2e8f9f7 1549 return HAL_OK;
<> 144:ef7eb2e8f9f7 1550 }
<> 144:ef7eb2e8f9f7 1551
<> 144:ef7eb2e8f9f7 1552 /**
AnnaBridge 165:e614a9f1c9e2 1553 * @brief End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion).
AnnaBridge 165:e614a9f1c9e2 1554 * @param hsc: SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1555 * @retval None
AnnaBridge 165:e614a9f1c9e2 1556 */
AnnaBridge 165:e614a9f1c9e2 1557 static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1558 {
AnnaBridge 165:e614a9f1c9e2 1559 /* At end of Tx process, restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1560 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1561
AnnaBridge 165:e614a9f1c9e2 1562 /* Disable TXEIE and TCIE interrupts */
AnnaBridge 165:e614a9f1c9e2 1563 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE));
AnnaBridge 165:e614a9f1c9e2 1564 }
AnnaBridge 165:e614a9f1c9e2 1565
AnnaBridge 165:e614a9f1c9e2 1566
AnnaBridge 165:e614a9f1c9e2 1567 /**
AnnaBridge 165:e614a9f1c9e2 1568 * @brief End ongoing Rx transfer on SMARTCARD peripheral (following error detection or Reception completion).
AnnaBridge 165:e614a9f1c9e2 1569 * @param hsc: SMARTCARD handle.
AnnaBridge 165:e614a9f1c9e2 1570 * @retval None
AnnaBridge 165:e614a9f1c9e2 1571 */
AnnaBridge 165:e614a9f1c9e2 1572 static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsc)
AnnaBridge 165:e614a9f1c9e2 1573 {
AnnaBridge 165:e614a9f1c9e2 1574 /* At end of Rx process, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1575 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1576
AnnaBridge 165:e614a9f1c9e2 1577 /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */
AnnaBridge 165:e614a9f1c9e2 1578 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE));
AnnaBridge 165:e614a9f1c9e2 1579 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1580 }
AnnaBridge 165:e614a9f1c9e2 1581
AnnaBridge 165:e614a9f1c9e2 1582
AnnaBridge 165:e614a9f1c9e2 1583
AnnaBridge 165:e614a9f1c9e2 1584 /**
AnnaBridge 165:e614a9f1c9e2 1585 * @brief DMA SMARTCARD communication abort callback, when initiated by HAL services on Error
AnnaBridge 165:e614a9f1c9e2 1586 * (To be called at end of DMA Abort procedure following error occurrence).
AnnaBridge 165:e614a9f1c9e2 1587 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1588 * @retval None
AnnaBridge 165:e614a9f1c9e2 1589 */
AnnaBridge 165:e614a9f1c9e2 1590 static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1591 {
AnnaBridge 165:e614a9f1c9e2 1592 SMARTCARD_HandleTypeDef* hsc = (SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1593 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1594 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1595
AnnaBridge 165:e614a9f1c9e2 1596 HAL_SMARTCARD_ErrorCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1597 }
AnnaBridge 165:e614a9f1c9e2 1598
AnnaBridge 165:e614a9f1c9e2 1599 /**
AnnaBridge 165:e614a9f1c9e2 1600 * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user
AnnaBridge 165:e614a9f1c9e2 1601 * (To be called at end of DMA Tx Abort procedure following user abort request).
AnnaBridge 165:e614a9f1c9e2 1602 * @note When this callback is executed, User Abort complete call back is called only if no
AnnaBridge 165:e614a9f1c9e2 1603 * Abort still ongoing for Rx DMA Handle.
AnnaBridge 165:e614a9f1c9e2 1604 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1605 * @retval None
AnnaBridge 165:e614a9f1c9e2 1606 */
AnnaBridge 165:e614a9f1c9e2 1607 static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1608 {
AnnaBridge 165:e614a9f1c9e2 1609 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1610
AnnaBridge 165:e614a9f1c9e2 1611 hsc->hdmatx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 1612
AnnaBridge 165:e614a9f1c9e2 1613 /* Check if an Abort process is still ongoing */
AnnaBridge 165:e614a9f1c9e2 1614 if(hsc->hdmarx != NULL)
AnnaBridge 165:e614a9f1c9e2 1615 {
AnnaBridge 165:e614a9f1c9e2 1616 if(hsc->hdmarx->XferAbortCallback != NULL)
AnnaBridge 165:e614a9f1c9e2 1617 {
AnnaBridge 165:e614a9f1c9e2 1618 return;
AnnaBridge 165:e614a9f1c9e2 1619 }
AnnaBridge 165:e614a9f1c9e2 1620 }
AnnaBridge 165:e614a9f1c9e2 1621
AnnaBridge 165:e614a9f1c9e2 1622 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
AnnaBridge 165:e614a9f1c9e2 1623 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1624 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1625
AnnaBridge 165:e614a9f1c9e2 1626 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 1627 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1628
AnnaBridge 165:e614a9f1c9e2 1629 /* Restore hsc->gState and hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1630 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1631 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1632
AnnaBridge 165:e614a9f1c9e2 1633 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1634 HAL_SMARTCARD_AbortCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1635 }
AnnaBridge 165:e614a9f1c9e2 1636
AnnaBridge 165:e614a9f1c9e2 1637 /**
AnnaBridge 165:e614a9f1c9e2 1638 * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user
AnnaBridge 165:e614a9f1c9e2 1639 * (To be called at end of DMA Rx Abort procedure following user abort request).
AnnaBridge 165:e614a9f1c9e2 1640 * @note When this callback is executed, User Abort complete call back is called only if no
AnnaBridge 165:e614a9f1c9e2 1641 * Abort still ongoing for Tx DMA Handle.
AnnaBridge 165:e614a9f1c9e2 1642 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1643 * @retval None
AnnaBridge 165:e614a9f1c9e2 1644 */
AnnaBridge 165:e614a9f1c9e2 1645 static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1646 {
AnnaBridge 165:e614a9f1c9e2 1647 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1648
AnnaBridge 165:e614a9f1c9e2 1649 hsc->hdmarx->XferAbortCallback = NULL;
AnnaBridge 165:e614a9f1c9e2 1650
AnnaBridge 165:e614a9f1c9e2 1651 /* Check if an Abort process is still ongoing */
AnnaBridge 165:e614a9f1c9e2 1652 if(hsc->hdmatx != NULL)
AnnaBridge 165:e614a9f1c9e2 1653 {
AnnaBridge 165:e614a9f1c9e2 1654 if(hsc->hdmatx->XferAbortCallback != NULL)
AnnaBridge 165:e614a9f1c9e2 1655 {
AnnaBridge 165:e614a9f1c9e2 1656 return;
AnnaBridge 165:e614a9f1c9e2 1657 }
AnnaBridge 165:e614a9f1c9e2 1658 }
AnnaBridge 165:e614a9f1c9e2 1659
AnnaBridge 165:e614a9f1c9e2 1660 /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */
AnnaBridge 165:e614a9f1c9e2 1661 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1662 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1663
AnnaBridge 165:e614a9f1c9e2 1664 /* Reset ErrorCode */
AnnaBridge 165:e614a9f1c9e2 1665 hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE;
AnnaBridge 165:e614a9f1c9e2 1666
AnnaBridge 165:e614a9f1c9e2 1667 /* Restore hsc->gState and hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1668 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1669 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1670
AnnaBridge 165:e614a9f1c9e2 1671 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1672 HAL_SMARTCARD_AbortCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1673 }
AnnaBridge 165:e614a9f1c9e2 1674
AnnaBridge 165:e614a9f1c9e2 1675 /**
AnnaBridge 165:e614a9f1c9e2 1676 * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to
AnnaBridge 165:e614a9f1c9e2 1677 * HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer)
AnnaBridge 165:e614a9f1c9e2 1678 * (This callback is executed at end of DMA Tx Abort procedure following user abort request,
AnnaBridge 165:e614a9f1c9e2 1679 * and leads to user Tx Abort Complete callback execution).
AnnaBridge 165:e614a9f1c9e2 1680 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1681 * @retval None
AnnaBridge 165:e614a9f1c9e2 1682 */
AnnaBridge 165:e614a9f1c9e2 1683 static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1684 {
AnnaBridge 165:e614a9f1c9e2 1685 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1686
AnnaBridge 165:e614a9f1c9e2 1687 hsc->TxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1688
AnnaBridge 165:e614a9f1c9e2 1689 /* Restore hsc->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1690 hsc->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1691
AnnaBridge 165:e614a9f1c9e2 1692 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1693 HAL_SMARTCARD_AbortTransmitCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1694 }
AnnaBridge 165:e614a9f1c9e2 1695
AnnaBridge 165:e614a9f1c9e2 1696 /**
AnnaBridge 165:e614a9f1c9e2 1697 * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to
AnnaBridge 165:e614a9f1c9e2 1698 * HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer)
AnnaBridge 165:e614a9f1c9e2 1699 * (This callback is executed at end of DMA Rx Abort procedure following user abort request,
AnnaBridge 165:e614a9f1c9e2 1700 * and leads to user Rx Abort Complete callback execution).
AnnaBridge 165:e614a9f1c9e2 1701 * @param hdma DMA handle.
AnnaBridge 165:e614a9f1c9e2 1702 * @retval None
AnnaBridge 165:e614a9f1c9e2 1703 */
AnnaBridge 165:e614a9f1c9e2 1704 static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma)
AnnaBridge 165:e614a9f1c9e2 1705 {
AnnaBridge 165:e614a9f1c9e2 1706 SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent;
AnnaBridge 165:e614a9f1c9e2 1707
AnnaBridge 165:e614a9f1c9e2 1708 hsc->RxXferCount = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1709
AnnaBridge 165:e614a9f1c9e2 1710 /* Restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1711 hsc->RxState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1712
AnnaBridge 165:e614a9f1c9e2 1713 /* Call user Abort complete callback */
AnnaBridge 165:e614a9f1c9e2 1714 HAL_SMARTCARD_AbortReceiveCpltCallback(hsc);
AnnaBridge 165:e614a9f1c9e2 1715 }
AnnaBridge 165:e614a9f1c9e2 1716
AnnaBridge 165:e614a9f1c9e2 1717 /**
AnnaBridge 165:e614a9f1c9e2 1718 * @brief Send an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 1719 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1720 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1721 * @retval HAL status
<> 144:ef7eb2e8f9f7 1722 */
<> 144:ef7eb2e8f9f7 1723 static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1724 {
AnnaBridge 165:e614a9f1c9e2 1725 uint16_t* tmp;
AnnaBridge 165:e614a9f1c9e2 1726
AnnaBridge 165:e614a9f1c9e2 1727 /* Check that a Tx process is ongoing */
AnnaBridge 165:e614a9f1c9e2 1728 if(hsc->gState == HAL_SMARTCARD_STATE_BUSY_TX)
<> 144:ef7eb2e8f9f7 1729 {
AnnaBridge 165:e614a9f1c9e2 1730 tmp = (uint16_t*) hsc->pTxBuffPtr;
AnnaBridge 165:e614a9f1c9e2 1731 hsc->Instance->DR = (uint16_t)(*tmp & (uint16_t)0x01FF);
AnnaBridge 165:e614a9f1c9e2 1732 hsc->pTxBuffPtr += 1U;
<> 144:ef7eb2e8f9f7 1733
AnnaBridge 165:e614a9f1c9e2 1734 if(--hsc->TxXferCount == 0U)
<> 144:ef7eb2e8f9f7 1735 {
AnnaBridge 165:e614a9f1c9e2 1736 /* Disable the SMARTCARD Transmit data register empty Interrupt */
AnnaBridge 165:e614a9f1c9e2 1737 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_TXEIE);
<> 144:ef7eb2e8f9f7 1738
AnnaBridge 165:e614a9f1c9e2 1739 /* Enable the SMARTCARD Transmit Complete Interrupt */
AnnaBridge 165:e614a9f1c9e2 1740 SET_BIT(hsc->Instance->CR1, USART_CR1_TCIE);
<> 144:ef7eb2e8f9f7 1741 }
AnnaBridge 165:e614a9f1c9e2 1742
<> 144:ef7eb2e8f9f7 1743 return HAL_OK;
<> 144:ef7eb2e8f9f7 1744 }
<> 144:ef7eb2e8f9f7 1745 else
<> 144:ef7eb2e8f9f7 1746 {
<> 144:ef7eb2e8f9f7 1747 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 1748 }
<> 144:ef7eb2e8f9f7 1749 }
<> 144:ef7eb2e8f9f7 1750
<> 144:ef7eb2e8f9f7 1751 /**
<> 144:ef7eb2e8f9f7 1752 * @brief Wraps up transmission in non blocking mode.
<> 144:ef7eb2e8f9f7 1753 * @param hsmartcard: pointer to a SMARTCARD_HandleTypeDef structure that contains
<> 144:ef7eb2e8f9f7 1754 * the configuration information for the specified SMARTCARD module.
<> 144:ef7eb2e8f9f7 1755 * @retval HAL status
<> 144:ef7eb2e8f9f7 1756 */
<> 144:ef7eb2e8f9f7 1757 static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard)
<> 144:ef7eb2e8f9f7 1758 {
AnnaBridge 165:e614a9f1c9e2 1759 /* Disable the SMARTCARD Transmit Complete Interrupt */
AnnaBridge 165:e614a9f1c9e2 1760 CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TCIE);
<> 144:ef7eb2e8f9f7 1761
AnnaBridge 165:e614a9f1c9e2 1762 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 1763 CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE);
AnnaBridge 165:e614a9f1c9e2 1764
AnnaBridge 165:e614a9f1c9e2 1765 /* Tx process is ended, restore hsmartcard->gState to Ready */
AnnaBridge 165:e614a9f1c9e2 1766 hsmartcard->gState = HAL_SMARTCARD_STATE_READY;
AnnaBridge 165:e614a9f1c9e2 1767
<> 144:ef7eb2e8f9f7 1768 HAL_SMARTCARD_TxCpltCallback(hsmartcard);
<> 144:ef7eb2e8f9f7 1769
<> 144:ef7eb2e8f9f7 1770 return HAL_OK;
<> 144:ef7eb2e8f9f7 1771 }
<> 144:ef7eb2e8f9f7 1772
<> 144:ef7eb2e8f9f7 1773 /**
AnnaBridge 165:e614a9f1c9e2 1774 * @brief Receive an amount of data in non blocking mode
AnnaBridge 165:e614a9f1c9e2 1775 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1776 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1777 * @retval HAL status
<> 144:ef7eb2e8f9f7 1778 */
<> 144:ef7eb2e8f9f7 1779 static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1780 {
AnnaBridge 165:e614a9f1c9e2 1781 uint16_t* tmp;
AnnaBridge 165:e614a9f1c9e2 1782
AnnaBridge 165:e614a9f1c9e2 1783 /* Check that a Rx process is ongoing */
AnnaBridge 165:e614a9f1c9e2 1784 if(hsc->RxState == HAL_SMARTCARD_STATE_BUSY_RX)
<> 144:ef7eb2e8f9f7 1785 {
AnnaBridge 165:e614a9f1c9e2 1786 tmp = (uint16_t*) hsc->pRxBuffPtr;
AnnaBridge 165:e614a9f1c9e2 1787 *tmp = (uint8_t)(hsc->Instance->DR & (uint8_t)0x00FF);
AnnaBridge 165:e614a9f1c9e2 1788 hsc->pRxBuffPtr += 1U;
<> 144:ef7eb2e8f9f7 1789
AnnaBridge 165:e614a9f1c9e2 1790 if(--hsc->RxXferCount == 0U)
<> 144:ef7eb2e8f9f7 1791 {
AnnaBridge 165:e614a9f1c9e2 1792 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_RXNEIE);
<> 144:ef7eb2e8f9f7 1793
<> 144:ef7eb2e8f9f7 1794 /* Disable the SMARTCARD Parity Error Interrupt */
AnnaBridge 165:e614a9f1c9e2 1795 CLEAR_BIT(hsc->Instance->CR1, USART_CR1_PEIE);
AnnaBridge 165:e614a9f1c9e2 1796
<> 144:ef7eb2e8f9f7 1797 /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */
AnnaBridge 165:e614a9f1c9e2 1798 CLEAR_BIT(hsc->Instance->CR3, USART_CR3_EIE);
<> 144:ef7eb2e8f9f7 1799
AnnaBridge 165:e614a9f1c9e2 1800 /* Rx process is completed, restore hsc->RxState to Ready */
AnnaBridge 165:e614a9f1c9e2 1801 hsc->RxState = HAL_SMARTCARD_STATE_READY;
<> 144:ef7eb2e8f9f7 1802
<> 144:ef7eb2e8f9f7 1803 HAL_SMARTCARD_RxCpltCallback(hsc);
<> 144:ef7eb2e8f9f7 1804
<> 144:ef7eb2e8f9f7 1805 return HAL_OK;
<> 144:ef7eb2e8f9f7 1806 }
<> 144:ef7eb2e8f9f7 1807 return HAL_OK;
<> 144:ef7eb2e8f9f7 1808 }
<> 144:ef7eb2e8f9f7 1809 else
<> 144:ef7eb2e8f9f7 1810 {
AnnaBridge 165:e614a9f1c9e2 1811 return HAL_BUSY;
<> 144:ef7eb2e8f9f7 1812 }
<> 144:ef7eb2e8f9f7 1813 }
<> 144:ef7eb2e8f9f7 1814
<> 144:ef7eb2e8f9f7 1815 /**
AnnaBridge 165:e614a9f1c9e2 1816 * @brief Configure the SMARTCARD peripheral
AnnaBridge 165:e614a9f1c9e2 1817 * @param hsc: pointer to a SMARTCARD_HandleTypeDef structure that contains
AnnaBridge 165:e614a9f1c9e2 1818 * the configuration information for SMARTCARD module.
<> 144:ef7eb2e8f9f7 1819 * @retval None
<> 144:ef7eb2e8f9f7 1820 */
<> 144:ef7eb2e8f9f7 1821 static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc)
<> 144:ef7eb2e8f9f7 1822 {
AnnaBridge 165:e614a9f1c9e2 1823 uint32_t tmpreg = 0x00U;
AnnaBridge 165:e614a9f1c9e2 1824
<> 144:ef7eb2e8f9f7 1825 /* Check the parameters */
AnnaBridge 165:e614a9f1c9e2 1826 assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance));
<> 144:ef7eb2e8f9f7 1827 assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity));
<> 144:ef7eb2e8f9f7 1828 assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase));
<> 144:ef7eb2e8f9f7 1829 assert_param(IS_SMARTCARD_LASTBIT(hsc->Init.CLKLastBit));
<> 144:ef7eb2e8f9f7 1830 assert_param(IS_SMARTCARD_BAUDRATE(hsc->Init.BaudRate));
<> 144:ef7eb2e8f9f7 1831 assert_param(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength));
<> 144:ef7eb2e8f9f7 1832 assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits));
<> 144:ef7eb2e8f9f7 1833 assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity));
<> 144:ef7eb2e8f9f7 1834 assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode));
<> 144:ef7eb2e8f9f7 1835 assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState));
<> 144:ef7eb2e8f9f7 1836
AnnaBridge 165:e614a9f1c9e2 1837
<> 144:ef7eb2e8f9f7 1838 /* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the
<> 144:ef7eb2e8f9f7 1839 receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */
AnnaBridge 165:e614a9f1c9e2 1840 CLEAR_BIT(hsc->Instance->CR1, (USART_CR1_TE | USART_CR1_RE));
<> 144:ef7eb2e8f9f7 1841
AnnaBridge 165:e614a9f1c9e2 1842 /*---------------------------- USART CR2 Configuration ---------------------*/
AnnaBridge 165:e614a9f1c9e2 1843 tmpreg = hsc->Instance->CR2;
<> 144:ef7eb2e8f9f7 1844 /* Clear CLKEN, CPOL, CPHA and LBCL bits */
AnnaBridge 165:e614a9f1c9e2 1845 tmpreg &= (uint32_t)~((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_LBCL));
<> 144:ef7eb2e8f9f7 1846 /* Configure the SMARTCARD Clock, CPOL, CPHA and LastBit -----------------------*/
<> 144:ef7eb2e8f9f7 1847 /* Set CPOL bit according to hsc->Init.CLKPolarity value */
<> 144:ef7eb2e8f9f7 1848 /* Set CPHA bit according to hsc->Init.CLKPhase value */
<> 144:ef7eb2e8f9f7 1849 /* Set LBCL bit according to hsc->Init.CLKLastBit value */
AnnaBridge 165:e614a9f1c9e2 1850 /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
AnnaBridge 165:e614a9f1c9e2 1851 tmpreg |= (uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity |
AnnaBridge 165:e614a9f1c9e2 1852 hsc->Init.CLKPhase| hsc->Init.CLKLastBit | hsc->Init.StopBits);
AnnaBridge 165:e614a9f1c9e2 1853 /* Write to USART CR2 */
AnnaBridge 165:e614a9f1c9e2 1854 WRITE_REG(hsc->Instance->CR2, (uint32_t)tmpreg);
<> 144:ef7eb2e8f9f7 1855
AnnaBridge 165:e614a9f1c9e2 1856 tmpreg = hsc->Instance->CR2;
AnnaBridge 165:e614a9f1c9e2 1857
AnnaBridge 165:e614a9f1c9e2 1858 /* Clear STOP[13:12] bits */
AnnaBridge 165:e614a9f1c9e2 1859 tmpreg &= (uint32_t)~((uint32_t)USART_CR2_STOP);
AnnaBridge 165:e614a9f1c9e2 1860
<> 144:ef7eb2e8f9f7 1861 /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */
AnnaBridge 165:e614a9f1c9e2 1862 tmpreg |= (uint32_t)(hsc->Init.StopBits);
AnnaBridge 165:e614a9f1c9e2 1863
AnnaBridge 165:e614a9f1c9e2 1864 /* Write to USART CR2 */
AnnaBridge 165:e614a9f1c9e2 1865 WRITE_REG(hsc->Instance->CR2, (uint32_t)tmpreg);
<> 144:ef7eb2e8f9f7 1866
AnnaBridge 165:e614a9f1c9e2 1867 /*-------------------------- USART CR1 Configuration -----------------------*/
AnnaBridge 165:e614a9f1c9e2 1868 tmpreg = hsc->Instance->CR1;
AnnaBridge 165:e614a9f1c9e2 1869
<> 144:ef7eb2e8f9f7 1870 /* Clear M, PCE, PS, TE and RE bits */
AnnaBridge 165:e614a9f1c9e2 1871 tmpreg &= (uint32_t)~((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | \
AnnaBridge 165:e614a9f1c9e2 1872 USART_CR1_RE));
AnnaBridge 165:e614a9f1c9e2 1873
<> 144:ef7eb2e8f9f7 1874 /* Configure the SMARTCARD Word Length, Parity and mode:
AnnaBridge 165:e614a9f1c9e2 1875 Set the M bits according to hsc->Init.WordLength value
AnnaBridge 165:e614a9f1c9e2 1876 Set PCE and PS bits according to hsc->Init.Parity value
<> 144:ef7eb2e8f9f7 1877 Set TE and RE bits according to hsc->Init.Mode value */
AnnaBridge 165:e614a9f1c9e2 1878 tmpreg |= (uint32_t)hsc->Init.WordLength | hsc->Init.Parity | hsc->Init.Mode;
<> 144:ef7eb2e8f9f7 1879
AnnaBridge 165:e614a9f1c9e2 1880 /* Write to USART CR1 */
AnnaBridge 165:e614a9f1c9e2 1881 WRITE_REG(hsc->Instance->CR1, (uint32_t)tmpreg);
AnnaBridge 165:e614a9f1c9e2 1882
AnnaBridge 165:e614a9f1c9e2 1883 /*-------------------------- USART CR3 Configuration -----------------------*/
<> 144:ef7eb2e8f9f7 1884 /* Clear CTSE and RTSE bits */
<> 144:ef7eb2e8f9f7 1885 CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE));
<> 144:ef7eb2e8f9f7 1886
AnnaBridge 165:e614a9f1c9e2 1887 /*-------------------------- USART BRR Configuration -----------------------*/
AnnaBridge 165:e614a9f1c9e2 1888
<> 144:ef7eb2e8f9f7 1889 if(hsc->Instance == USART1)
<> 144:ef7eb2e8f9f7 1890 {
<> 144:ef7eb2e8f9f7 1891 hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK2Freq(), hsc->Init.BaudRate);
<> 144:ef7eb2e8f9f7 1892 }
<> 144:ef7eb2e8f9f7 1893 else
<> 144:ef7eb2e8f9f7 1894 {
<> 144:ef7eb2e8f9f7 1895 hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK1Freq(), hsc->Init.BaudRate);
<> 144:ef7eb2e8f9f7 1896 }
<> 144:ef7eb2e8f9f7 1897 }
<> 144:ef7eb2e8f9f7 1898
<> 144:ef7eb2e8f9f7 1899 /**
<> 144:ef7eb2e8f9f7 1900 * @}
<> 144:ef7eb2e8f9f7 1901 */
<> 144:ef7eb2e8f9f7 1902
<> 144:ef7eb2e8f9f7 1903 #endif /* HAL_SMARTCARD_MODULE_ENABLED */
<> 144:ef7eb2e8f9f7 1904 /**
<> 144:ef7eb2e8f9f7 1905 * @}
<> 144:ef7eb2e8f9f7 1906 */
<> 144:ef7eb2e8f9f7 1907
<> 144:ef7eb2e8f9f7 1908 /**
<> 144:ef7eb2e8f9f7 1909 * @}
<> 144:ef7eb2e8f9f7 1910 */
<> 144:ef7eb2e8f9f7 1911
<> 144:ef7eb2e8f9f7 1912 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/