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


