mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_STM/TARGET_STM32F0/device/stm32f0xx_hal_smartcard.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
- Parent:
- 180:96ed750bd169
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /** |
<> | 144:ef7eb2e8f9f7 | 2 | ****************************************************************************** |
<> | 144:ef7eb2e8f9f7 | 3 | * @file stm32f0xx_hal_smartcard.c |
<> | 144:ef7eb2e8f9f7 | 4 | * @author MCD Application Team |
<> | 144:ef7eb2e8f9f7 | 5 | * @brief SMARTCARD HAL module driver. |
<> | 144:ef7eb2e8f9f7 | 6 | * This file provides firmware functions to manage the following |
<> | 144:ef7eb2e8f9f7 | 7 | * functionalities of the SMARTCARD peripheral: |
<> | 144:ef7eb2e8f9f7 | 8 | * + Initialization and de-initialization functions |
<> | 144:ef7eb2e8f9f7 | 9 | * + IO operation functions |
<> | 144:ef7eb2e8f9f7 | 10 | * + Peripheral Control functions |
<> | 156:95d6b41a828b | 11 | * + Peripheral State and Error functions |
<> | 144:ef7eb2e8f9f7 | 12 | * |
<> | 144:ef7eb2e8f9f7 | 13 | @verbatim |
<> | 144:ef7eb2e8f9f7 | 14 | ============================================================================== |
<> | 144:ef7eb2e8f9f7 | 15 | ##### How to use this driver ##### |
<> | 144:ef7eb2e8f9f7 | 16 | ============================================================================== |
<> | 144:ef7eb2e8f9f7 | 17 | [..] |
<> | 144:ef7eb2e8f9f7 | 18 | The SMARTCARD HAL driver can be used as follows: |
<> | 144:ef7eb2e8f9f7 | 19 | |
<> | 144:ef7eb2e8f9f7 | 20 | (#) Declare a SMARTCARD_HandleTypeDef handle structure (eg. SMARTCARD_HandleTypeDef hsmartcard). |
<> | 144:ef7eb2e8f9f7 | 21 | (#) Associate a USART to the SMARTCARD handle hsmartcard. |
<> | 144:ef7eb2e8f9f7 | 22 | (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API: |
<> | 144:ef7eb2e8f9f7 | 23 | (++) Enable the USARTx interface clock. |
<> | 144:ef7eb2e8f9f7 | 24 | (++) USART pins configuration: |
<> | 156:95d6b41a828b | 25 | (+++) Enable the clock for the USART GPIOs. |
<> | 156:95d6b41a828b | 26 | (+++) Configure the USART pins (TX as alternate function pull-up, RX as alternate function Input). |
<> | 144:ef7eb2e8f9f7 | 27 | (++) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT() |
<> | 144:ef7eb2e8f9f7 | 28 | and HAL_SMARTCARD_Receive_IT() APIs): |
<> | 156:95d6b41a828b | 29 | (+++) Configure the USARTx interrupt priority. |
<> | 156:95d6b41a828b | 30 | (+++) Enable the NVIC USART IRQ handle. |
<> | 144:ef7eb2e8f9f7 | 31 | (++) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA() |
<> | 144:ef7eb2e8f9f7 | 32 | and HAL_SMARTCARD_Receive_DMA() APIs): |
<> | 156:95d6b41a828b | 33 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
<> | 156:95d6b41a828b | 34 | (+++) Enable the DMAx interface clock. |
<> | 156:95d6b41a828b | 35 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
<> | 156:95d6b41a828b | 36 | (+++) Configure the DMA Tx/Rx channel. |
<> | 156:95d6b41a828b | 37 | (+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle. |
<> | 156:95d6b41a828b | 38 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. |
<> | 144:ef7eb2e8f9f7 | 39 | |
<> | 144:ef7eb2e8f9f7 | 40 | (#) Program the Baud Rate, Parity, Mode(Receiver/Transmitter), clock enabling/disabling and accordingly, |
<> | 144:ef7eb2e8f9f7 | 41 | the clock parameters (parity, phase, last bit), prescaler value, guard time and NACK on transmission |
<> | 144:ef7eb2e8f9f7 | 42 | error enabling or disabling in the hsmartcard handle Init structure. |
<> | 144:ef7eb2e8f9f7 | 43 | |
<> | 144:ef7eb2e8f9f7 | 44 | (#) If required, program SMARTCARD advanced features (TX/RX pins swap, TimeOut, auto-retry counter,...) |
<> | 144:ef7eb2e8f9f7 | 45 | in the hsmartcard handle AdvancedInit structure. |
<> | 144:ef7eb2e8f9f7 | 46 | |
<> | 144:ef7eb2e8f9f7 | 47 | (#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API: |
<> | 144:ef7eb2e8f9f7 | 48 | (++) This API configures also the low level Hardware (GPIO, CLOCK, CORTEX...etc) |
<> | 144:ef7eb2e8f9f7 | 49 | by calling the customized HAL_SMARTCARD_MspInit() API. |
<> | 144:ef7eb2e8f9f7 | 50 | [..] |
<> | 144:ef7eb2e8f9f7 | 51 | (@) The specific SMARTCARD interrupts (Transmission complete interrupt, |
<> | 144:ef7eb2e8f9f7 | 52 | RXNE interrupt and Error Interrupts) will be managed using the macros |
<> | 144:ef7eb2e8f9f7 | 53 | __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process. |
<> | 144:ef7eb2e8f9f7 | 54 | |
<> | 144:ef7eb2e8f9f7 | 55 | [..] |
<> | 144:ef7eb2e8f9f7 | 56 | [..] Three operation modes are available within this driver : |
<> | 144:ef7eb2e8f9f7 | 57 | |
<> | 144:ef7eb2e8f9f7 | 58 | *** Polling mode IO operation *** |
<> | 144:ef7eb2e8f9f7 | 59 | ================================= |
<> | 144:ef7eb2e8f9f7 | 60 | [..] |
<> | 144:ef7eb2e8f9f7 | 61 | (+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit() |
<> | 144:ef7eb2e8f9f7 | 62 | (+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive() |
<> | 144:ef7eb2e8f9f7 | 63 | |
<> | 144:ef7eb2e8f9f7 | 64 | *** Interrupt mode IO operation *** |
<> | 144:ef7eb2e8f9f7 | 65 | =================================== |
<> | 144:ef7eb2e8f9f7 | 66 | [..] |
<> | 144:ef7eb2e8f9f7 | 67 | (+) Send an amount of data in non-blocking mode using HAL_SMARTCARD_Transmit_IT() |
<> | 144:ef7eb2e8f9f7 | 68 | (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback() is executed and user can |
<> | 144:ef7eb2e8f9f7 | 69 | add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback() |
<> | 144:ef7eb2e8f9f7 | 70 | (+) Receive an amount of data in non-blocking mode using HAL_SMARTCARD_Receive_IT() |
<> | 144:ef7eb2e8f9f7 | 71 | (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback() is executed and user can |
<> | 144:ef7eb2e8f9f7 | 72 | add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback() |
<> | 144:ef7eb2e8f9f7 | 73 | (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can |
<> | 144:ef7eb2e8f9f7 | 74 | add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback() |
<> | 144:ef7eb2e8f9f7 | 75 | |
<> | 144:ef7eb2e8f9f7 | 76 | *** DMA mode IO operation *** |
<> | 144:ef7eb2e8f9f7 | 77 | ============================== |
<> | 144:ef7eb2e8f9f7 | 78 | [..] |
<> | 144:ef7eb2e8f9f7 | 79 | (+) Send an amount of data in non-blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA() |
<> | 144:ef7eb2e8f9f7 | 80 | (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback() is executed and user can |
<> | 144:ef7eb2e8f9f7 | 81 | add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback() |
<> | 144:ef7eb2e8f9f7 | 82 | (+) Receive an amount of data in non-blocking mode (DMA) using HAL_SMARTCARD_Receive_DMA() |
<> | 144:ef7eb2e8f9f7 | 83 | (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback() is executed and user can |
<> | 144:ef7eb2e8f9f7 | 84 | add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback() |
<> | 144:ef7eb2e8f9f7 | 85 | (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can |
<> | 144:ef7eb2e8f9f7 | 86 | add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback() |
<> | 144:ef7eb2e8f9f7 | 87 | |
<> | 144:ef7eb2e8f9f7 | 88 | *** SMARTCARD HAL driver macros list *** |
<> | 144:ef7eb2e8f9f7 | 89 | ======================================== |
<> | 144:ef7eb2e8f9f7 | 90 | [..] |
<> | 144:ef7eb2e8f9f7 | 91 | Below the list of most used macros in SMARTCARD HAL driver. |
<> | 144:ef7eb2e8f9f7 | 92 | |
<> | 144:ef7eb2e8f9f7 | 93 | (+) __HAL_SMARTCARD_GET_FLAG : Check whether or not the specified SMARTCARD flag is set |
<> | 144:ef7eb2e8f9f7 | 94 | (+) __HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag |
<> | 144:ef7eb2e8f9f7 | 95 | (+) __HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt |
<> | 144:ef7eb2e8f9f7 | 96 | (+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt |
<> | 144:ef7eb2e8f9f7 | 97 | (+) __HAL_SMARTCARD_GET_IT_SOURCE: Check whether or not the specified SMARTCARD interrupt is enabled |
<> | 144:ef7eb2e8f9f7 | 98 | |
<> | 144:ef7eb2e8f9f7 | 99 | [..] |
<> | 144:ef7eb2e8f9f7 | 100 | (@) You can refer to the SMARTCARD HAL driver header file for more useful macros |
<> | 144:ef7eb2e8f9f7 | 101 | |
<> | 144:ef7eb2e8f9f7 | 102 | @endverbatim |
<> | 144:ef7eb2e8f9f7 | 103 | ****************************************************************************** |
<> | 144:ef7eb2e8f9f7 | 104 | * @attention |
<> | 144:ef7eb2e8f9f7 | 105 | * |
<> | 144:ef7eb2e8f9f7 | 106 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
<> | 144:ef7eb2e8f9f7 | 107 | * |
<> | 144:ef7eb2e8f9f7 | 108 | * Redistribution and use in source and binary forms, with or without modification, |
<> | 144:ef7eb2e8f9f7 | 109 | * are permitted provided that the following conditions are met: |
<> | 144:ef7eb2e8f9f7 | 110 | * 1. Redistributions of source code must retain the above copyright notice, |
<> | 144:ef7eb2e8f9f7 | 111 | * this list of conditions and the following disclaimer. |
<> | 144:ef7eb2e8f9f7 | 112 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
<> | 144:ef7eb2e8f9f7 | 113 | * this list of conditions and the following disclaimer in the documentation |
<> | 144:ef7eb2e8f9f7 | 114 | * and/or other materials provided with the distribution. |
<> | 144:ef7eb2e8f9f7 | 115 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
<> | 144:ef7eb2e8f9f7 | 116 | * may be used to endorse or promote products derived from this software |
<> | 144:ef7eb2e8f9f7 | 117 | * without specific prior written permission. |
<> | 144:ef7eb2e8f9f7 | 118 | * |
<> | 144:ef7eb2e8f9f7 | 119 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
<> | 144:ef7eb2e8f9f7 | 120 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
<> | 144:ef7eb2e8f9f7 | 121 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
<> | 144:ef7eb2e8f9f7 | 122 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
<> | 144:ef7eb2e8f9f7 | 123 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
<> | 144:ef7eb2e8f9f7 | 124 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
<> | 144:ef7eb2e8f9f7 | 125 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
<> | 144:ef7eb2e8f9f7 | 126 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
<> | 144:ef7eb2e8f9f7 | 127 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
<> | 144:ef7eb2e8f9f7 | 128 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
<> | 144:ef7eb2e8f9f7 | 129 | * |
<> | 144:ef7eb2e8f9f7 | 130 | ****************************************************************************** |
<> | 144:ef7eb2e8f9f7 | 131 | */ |
<> | 144:ef7eb2e8f9f7 | 132 | |
<> | 144:ef7eb2e8f9f7 | 133 | /* Includes ------------------------------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 134 | #include "stm32f0xx_hal.h" |
<> | 144:ef7eb2e8f9f7 | 135 | |
<> | 144:ef7eb2e8f9f7 | 136 | #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) |
<> | 144:ef7eb2e8f9f7 | 137 | |
<> | 144:ef7eb2e8f9f7 | 138 | /** @addtogroup STM32F0xx_HAL_Driver |
<> | 144:ef7eb2e8f9f7 | 139 | * @{ |
<> | 144:ef7eb2e8f9f7 | 140 | */ |
<> | 144:ef7eb2e8f9f7 | 141 | |
<> | 144:ef7eb2e8f9f7 | 142 | /** @defgroup SMARTCARD SMARTCARD |
<> | 144:ef7eb2e8f9f7 | 143 | * @brief HAL SMARTCARD module driver |
<> | 144:ef7eb2e8f9f7 | 144 | * @{ |
<> | 144:ef7eb2e8f9f7 | 145 | */ |
<> | 144:ef7eb2e8f9f7 | 146 | |
<> | 156:95d6b41a828b | 147 | #ifdef HAL_SMARTCARD_MODULE_ENABLED |
<> | 156:95d6b41a828b | 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 | */ |
<> | 156:95d6b41a828b | 154 | #define SMARTCARD_TEACK_REACK_TIMEOUT 1000U /*!< SMARTCARD TX or RX enable acknowledge time-out value */ |
<> | 156:95d6b41a828b | 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 -----------------------------------------------*/ |
<> | 156:95d6b41a828b | 168 | /** @addtogroup SMARTCARD_Private_Functions |
<> | 144:ef7eb2e8f9f7 | 169 | * @{ |
<> | 144:ef7eb2e8f9f7 | 170 | */ |
<> | 156:95d6b41a828b | 171 | static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 156:95d6b41a828b | 172 | static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 156:95d6b41a828b | 173 | static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 156:95d6b41a828b | 174 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout); |
<> | 156:95d6b41a828b | 175 | static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 156:95d6b41a828b | 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); |
<> | 156:95d6b41a828b | 180 | static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma); |
<> | 156:95d6b41a828b | 181 | static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma); |
<> | 156:95d6b41a828b | 182 | static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma); |
<> | 156:95d6b41a828b | 183 | static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma); |
<> | 156:95d6b41a828b | 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 |
<> | 156:95d6b41a828b | 202 | ============================================================================== |
<> | 144:ef7eb2e8f9f7 | 203 | ##### Initialization and Configuration functions ##### |
<> | 156:95d6b41a828b | 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 | /** |
<> | 144:ef7eb2e8f9f7 | 256 | * @brief Initialize the SMARTCARD mode according to the specified |
<> | 144:ef7eb2e8f9f7 | 257 | * parameters in the SMARTCARD_HandleTypeDef and initialize the associated handle. |
<> | 144:ef7eb2e8f9f7 | 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 | |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 284 | /* Disable the Peripheral to set smartcard mode */ |
<> | 156:95d6b41a828b | 285 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 286 | |
<> | 156:95d6b41a828b | 287 | /* In SmartCard mode, the following bits must be kept cleared: |
<> | 156:95d6b41a828b | 288 | - LINEN in the USART_CR2 register, |
<> | 156:95d6b41a828b | 289 | - HDSEL and IREN bits in the USART_CR3 register.*/ |
<> | 156:95d6b41a828b | 290 | CLEAR_BIT(hsmartcard->Instance->CR2, USART_CR2_LINEN); |
<> | 156:95d6b41a828b | 291 | CLEAR_BIT(hsmartcard->Instance->CR3, (USART_CR3_HDSEL | USART_CR3_IREN)); |
<> | 156:95d6b41a828b | 292 | |
<> | 156:95d6b41a828b | 293 | /* set the USART in SMARTCARD mode */ |
<> | 156:95d6b41a828b | 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 */ |
<> | 156:95d6b41a828b | 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 | /** |
<> | 144:ef7eb2e8f9f7 | 315 | * @brief DeInitialize the SMARTCARD peripheral. |
<> | 144:ef7eb2e8f9f7 | 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 | |
<> | 156:95d6b41a828b | 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 */ |
<> | 156:95d6b41a828b | 334 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 144:ef7eb2e8f9f7 | 335 | |
<> | 156:95d6b41a828b | 336 | WRITE_REG(hsmartcard->Instance->CR1, 0x0U); |
<> | 156:95d6b41a828b | 337 | WRITE_REG(hsmartcard->Instance->CR2, 0x0U); |
<> | 156:95d6b41a828b | 338 | WRITE_REG(hsmartcard->Instance->CR3, 0x0U); |
<> | 156:95d6b41a828b | 339 | WRITE_REG(hsmartcard->Instance->RTOR, 0x0U); |
<> | 156:95d6b41a828b | 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; |
<> | 156:95d6b41a828b | 346 | hsmartcard->gState = HAL_SMARTCARD_STATE_RESET; |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 356 | * @brief Initialize the SMARTCARD MSP. |
<> | 156:95d6b41a828b | 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 | */ |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 372 | * @brief DeInitialize the SMARTCARD MSP. |
<> | 156:95d6b41a828b | 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 | */ |
<> | 156:95d6b41a828b | 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 | [..] |
<> | 156:95d6b41a828b | 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. |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 423 | (#) Blocking mode APIs are : |
<> | 144:ef7eb2e8f9f7 | 424 | (++) HAL_SMARTCARD_Transmit() |
<> | 144:ef7eb2e8f9f7 | 425 | (++) HAL_SMARTCARD_Receive() |
<> | 144:ef7eb2e8f9f7 | 426 | |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 441 | (#) Non-Blocking mode transfers could be aborted using Abort API's : |
<> | 156:95d6b41a828b | 442 | (++) HAL_SMARTCARD_Abort() |
<> | 156:95d6b41a828b | 443 | (++) HAL_SMARTCARD_AbortTransmit() |
<> | 156:95d6b41a828b | 444 | (++) HAL_SMARTCARD_AbortReceive() |
<> | 156:95d6b41a828b | 445 | (++) HAL_SMARTCARD_Abort_IT() |
<> | 156:95d6b41a828b | 446 | (++) HAL_SMARTCARD_AbortTransmit_IT() |
<> | 156:95d6b41a828b | 447 | (++) HAL_SMARTCARD_AbortReceive_IT() |
<> | 156:95d6b41a828b | 448 | |
<> | 156:95d6b41a828b | 449 | (#) For Abort services based on interrupts (HAL_SMARTCARD_Abortxxx_IT), a set of Abort Complete Callbacks are provided: |
<> | 156:95d6b41a828b | 450 | (++) HAL_SMARTCARD_AbortCpltCallback() |
<> | 156:95d6b41a828b | 451 | (++) HAL_SMARTCARD_AbortTransmitCpltCallback() |
<> | 156:95d6b41a828b | 452 | (++) HAL_SMARTCARD_AbortReceiveCpltCallback() |
<> | 156:95d6b41a828b | 453 | |
<> | 156:95d6b41a828b | 454 | (#) In Non-Blocking mode transfers, possible errors are split into 2 categories. |
<> | 156:95d6b41a828b | 455 | Errors are handled as follows : |
<> | 156:95d6b41a828b | 456 | (++) Error is considered as Recoverable and non blocking : Transfer could go till end, but error severity is |
<> | 156:95d6b41a828b | 457 | to be evaluated by user : this concerns Frame Error, Parity Error or Noise Error in Interrupt mode reception . |
<> | 156:95d6b41a828b | 458 | Received character is then retrieved and stored in Rx buffer, Error code is set to allow user to identify error type, |
<> | 156:95d6b41a828b | 459 | and HAL_SMARTCARD_ErrorCallback() user callback is executed. Transfer is kept ongoing on SMARTCARD side. |
<> | 156:95d6b41a828b | 460 | If user wants to abort it, Abort services should be called by user. |
<> | 156:95d6b41a828b | 461 | (++) Error is considered as Blocking : Transfer could not be completed properly and is aborted. |
<> | 156:95d6b41a828b | 462 | This concerns Frame Error in Interrupt mode tranmission, Overrun Error in Interrupt mode reception and all errors in DMA mode. |
<> | 156:95d6b41a828b | 463 | Error code is set to allow user to identify error type, and HAL_SMARTCARD_ErrorCallback() user callback is executed. |
<> | 156:95d6b41a828b | 464 | |
<> | 144:ef7eb2e8f9f7 | 465 | @endverbatim |
<> | 144:ef7eb2e8f9f7 | 466 | * @{ |
<> | 144:ef7eb2e8f9f7 | 467 | */ |
<> | 144:ef7eb2e8f9f7 | 468 | |
<> | 144:ef7eb2e8f9f7 | 469 | /** |
<> | 156:95d6b41a828b | 470 | * @brief Send an amount of data in blocking mode. |
<> | 156:95d6b41a828b | 471 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 472 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 473 | * @param pData pointer to data buffer. |
<> | 156:95d6b41a828b | 474 | * @param Size amount of data to be sent. |
<> | 156:95d6b41a828b | 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 | { |
<> | 156:95d6b41a828b | 480 | uint32_t tickstart = 0U; |
<> | 156:95d6b41a828b | 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 | { |
<> | 156:95d6b41a828b | 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); |
<> | 156:95d6b41a828b | 492 | |
<> | 144:ef7eb2e8f9f7 | 493 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 144:ef7eb2e8f9f7 | 494 | |
<> | 156:95d6b41a828b | 495 | /* Init tickstart for timeout managment*/ |
<> | 156:95d6b41a828b | 496 | tickstart = HAL_GetTick(); |
<> | 156:95d6b41a828b | 497 | |
<> | 156:95d6b41a828b | 498 | /* Disable the Peripheral first to update mode for TX master */ |
<> | 156:95d6b41a828b | 499 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 500 | |
<> | 156:95d6b41a828b | 501 | /* Disable Rx, enable Tx */ |
<> | 156:95d6b41a828b | 502 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE); |
<> | 156:95d6b41a828b | 503 | SET_BIT(hsmartcard->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST); |
<> | 156:95d6b41a828b | 504 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE); |
<> | 156:95d6b41a828b | 505 | |
<> | 156:95d6b41a828b | 506 | /* Enable the Peripheral */ |
<> | 156:95d6b41a828b | 507 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 508 | |
<> | 156:95d6b41a828b | 509 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 510 | hsmartcard->TxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 511 | hsmartcard->TxXferCount = Size; |
<> | 156:95d6b41a828b | 512 | |
<> | 156:95d6b41a828b | 513 | while(hsmartcard->TxXferCount > 0U) |
<> | 144:ef7eb2e8f9f7 | 514 | { |
<> | 144:ef7eb2e8f9f7 | 515 | hsmartcard->TxXferCount--; |
<> | 156:95d6b41a828b | 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 | } |
<> | 156:95d6b41a828b | 520 | hsmartcard->Instance->TDR = (*pData++ & (uint8_t)0xFFU); |
<> | 144:ef7eb2e8f9f7 | 521 | } |
<> | 156:95d6b41a828b | 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 | } |
<> | 156:95d6b41a828b | 526 | /* Re-enable Rx at end of transmission if initial mode is Rx/Tx */ |
<> | 156:95d6b41a828b | 527 | if(hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX) |
<> | 156:95d6b41a828b | 528 | { |
<> | 156:95d6b41a828b | 529 | /* Disable the Peripheral first to update modes */ |
<> | 156:95d6b41a828b | 530 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 531 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE); |
<> | 156:95d6b41a828b | 532 | /* Enable the Peripheral */ |
<> | 156:95d6b41a828b | 533 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 534 | } |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 551 | * @brief Receive an amount of data in blocking mode. |
<> | 156:95d6b41a828b | 552 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 553 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 554 | * @param pData pointer to data buffer. |
<> | 156:95d6b41a828b | 555 | * @param Size amount of data to be received. |
<> | 156:95d6b41a828b | 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 | { |
<> | 156:95d6b41a828b | 561 | uint32_t tickstart = 0U; |
<> | 156:95d6b41a828b | 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 | { |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 577 | /* Init tickstart for timeout managment*/ |
<> | 156:95d6b41a828b | 578 | tickstart = HAL_GetTick(); |
<> | 156:95d6b41a828b | 579 | |
<> | 144:ef7eb2e8f9f7 | 580 | hsmartcard->RxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 581 | hsmartcard->RxXferCount = Size; |
<> | 156:95d6b41a828b | 582 | |
<> | 144:ef7eb2e8f9f7 | 583 | /* Check the remain data to be received */ |
<> | 156:95d6b41a828b | 584 | while(hsmartcard->RxXferCount > 0U) |
<> | 144:ef7eb2e8f9f7 | 585 | { |
<> | 144:ef7eb2e8f9f7 | 586 | hsmartcard->RxXferCount--; |
<> | 156:95d6b41a828b | 587 | |
<> | 156:95d6b41a828b | 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 | } |
<> | 156:95d6b41a828b | 592 | *pData++ = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0x00FFU); |
<> | 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 | /** |
<> | 156:95d6b41a828b | 610 | * @brief Send an amount of data in interrupt mode. |
<> | 156:95d6b41a828b | 611 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 612 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 613 | * @param pData pointer to data buffer. |
<> | 156:95d6b41a828b | 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 | { |
<> | 144:ef7eb2e8f9f7 | 622 | if((pData == NULL) || (Size == 0)) |
<> | 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 | |
<> | 156:95d6b41a828b | 630 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 631 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 156:95d6b41a828b | 632 | |
<> | 144:ef7eb2e8f9f7 | 633 | hsmartcard->pTxBuffPtr = pData; |
<> | 144:ef7eb2e8f9f7 | 634 | hsmartcard->TxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 635 | hsmartcard->TxXferCount = Size; |
<> | 144:ef7eb2e8f9f7 | 636 | |
<> | 156:95d6b41a828b | 637 | /* Disable the Peripheral first to update mode for TX master */ |
<> | 156:95d6b41a828b | 638 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 144:ef7eb2e8f9f7 | 639 | |
<> | 156:95d6b41a828b | 640 | /* Disable Rx, enable Tx */ |
<> | 156:95d6b41a828b | 641 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE); |
<> | 156:95d6b41a828b | 642 | SET_BIT(hsmartcard->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST); |
<> | 156:95d6b41a828b | 643 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE); |
<> | 156:95d6b41a828b | 644 | |
<> | 156:95d6b41a828b | 645 | /* Enable the Peripheral */ |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 651 | /* Enable the SMARTCARD Error Interrupt: (Frame error) */ |
<> | 156:95d6b41a828b | 652 | SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 653 | |
<> | 144:ef7eb2e8f9f7 | 654 | /* Enable the SMARTCARD Transmit Data Register Empty Interrupt */ |
<> | 156:95d6b41a828b | 655 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE); |
<> | 156:95d6b41a828b | 656 | |
<> | 156:95d6b41a828b | 657 | return HAL_OK; |
<> | 156:95d6b41a828b | 658 | } |
<> | 156:95d6b41a828b | 659 | else |
<> | 156:95d6b41a828b | 660 | { |
<> | 156:95d6b41a828b | 661 | return HAL_BUSY; |
<> | 156:95d6b41a828b | 662 | } |
<> | 156:95d6b41a828b | 663 | } |
<> | 156:95d6b41a828b | 664 | |
<> | 156:95d6b41a828b | 665 | /** |
<> | 156:95d6b41a828b | 666 | * @brief Receive an amount of data in interrupt mode. |
<> | 156:95d6b41a828b | 667 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 668 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 669 | * @param pData pointer to data buffer. |
<> | 156:95d6b41a828b | 670 | * @param Size amount of data to be received. |
<> | 156:95d6b41a828b | 671 | * @retval HAL status |
<> | 156:95d6b41a828b | 672 | */ |
<> | 156:95d6b41a828b | 673 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size) |
<> | 156:95d6b41a828b | 674 | { |
<> | 156:95d6b41a828b | 675 | /* Check that a Rx process is not already ongoing */ |
<> | 156:95d6b41a828b | 676 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 156:95d6b41a828b | 677 | { |
<> | 156:95d6b41a828b | 678 | if((pData == NULL) || (Size == 0U)) |
<> | 156:95d6b41a828b | 679 | { |
<> | 156:95d6b41a828b | 680 | return HAL_ERROR; |
<> | 156:95d6b41a828b | 681 | } |
<> | 156:95d6b41a828b | 682 | |
<> | 156:95d6b41a828b | 683 | /* Process Locked */ |
<> | 156:95d6b41a828b | 684 | __HAL_LOCK(hsmartcard); |
<> | 156:95d6b41a828b | 685 | |
<> | 156:95d6b41a828b | 686 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 687 | hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 156:95d6b41a828b | 688 | |
<> | 156:95d6b41a828b | 689 | hsmartcard->pRxBuffPtr = pData; |
<> | 156:95d6b41a828b | 690 | hsmartcard->RxXferSize = Size; |
<> | 156:95d6b41a828b | 691 | hsmartcard->RxXferCount = Size; |
<> | 156:95d6b41a828b | 692 | |
<> | 156:95d6b41a828b | 693 | /* Process Unlocked */ |
<> | 156:95d6b41a828b | 694 | __HAL_UNLOCK(hsmartcard); |
<> | 156:95d6b41a828b | 695 | |
<> | 156:95d6b41a828b | 696 | /* Enable the SMARTCARD Parity Error and Data Register not empty Interrupts */ |
<> | 156:95d6b41a828b | 697 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE| USART_CR1_RXNEIE); |
<> | 156:95d6b41a828b | 698 | |
<> | 156:95d6b41a828b | 699 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 711 | * @brief Send an amount of data in DMA mode. |
<> | 156:95d6b41a828b | 712 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 713 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 714 | * @param pData pointer to data buffer. |
<> | 156:95d6b41a828b | 715 | * @param Size amount of data to be sent. |
<> | 144:ef7eb2e8f9f7 | 716 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 717 | */ |
<> | 156:95d6b41a828b | 718 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size) |
<> | 144:ef7eb2e8f9f7 | 719 | { |
<> | 156:95d6b41a828b | 720 | /* Check that a Tx process is not already ongoing */ |
<> | 156:95d6b41a828b | 721 | if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 722 | { |
<> | 156:95d6b41a828b | 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 */ |
<> | 156:95d6b41a828b | 729 | __HAL_LOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 730 | |
<> | 156:95d6b41a828b | 731 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 144:ef7eb2e8f9f7 | 732 | |
<> | 144:ef7eb2e8f9f7 | 733 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 734 | hsmartcard->pTxBuffPtr = pData; |
<> | 156:95d6b41a828b | 735 | hsmartcard->TxXferSize = Size; |
<> | 156:95d6b41a828b | 736 | hsmartcard->TxXferCount = Size; |
<> | 156:95d6b41a828b | 737 | |
<> | 156:95d6b41a828b | 738 | /* Disable the Peripheral first to update mode for TX master */ |
<> | 156:95d6b41a828b | 739 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 740 | |
<> | 156:95d6b41a828b | 741 | /* Disable Rx, enable Tx */ |
<> | 156:95d6b41a828b | 742 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RE); |
<> | 156:95d6b41a828b | 743 | SET_BIT(hsmartcard->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST); |
<> | 156:95d6b41a828b | 744 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_TE); |
<> | 156:95d6b41a828b | 745 | |
<> | 156:95d6b41a828b | 746 | /* Enable the Peripheral */ |
<> | 156:95d6b41a828b | 747 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 748 | |
<> | 156:95d6b41a828b | 749 | /* Set the SMARTCARD DMA transfer complete callback */ |
<> | 156:95d6b41a828b | 750 | hsmartcard->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt; |
<> | 156:95d6b41a828b | 751 | |
<> | 156:95d6b41a828b | 752 | /* Set the SMARTCARD error callback */ |
<> | 156:95d6b41a828b | 753 | hsmartcard->hdmatx->XferErrorCallback = SMARTCARD_DMAError; |
<> | 156:95d6b41a828b | 754 | |
<> | 156:95d6b41a828b | 755 | /* Set the DMA abort callback */ |
<> | 156:95d6b41a828b | 756 | hsmartcard->hdmatx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 757 | |
<> | 156:95d6b41a828b | 758 | /* Enable the SMARTCARD transmit DMA channel */ |
<> | 156:95d6b41a828b | 759 | HAL_DMA_Start_IT(hsmartcard->hdmatx, (uint32_t)hsmartcard->pTxBuffPtr, (uint32_t)&hsmartcard->Instance->TDR, Size); |
<> | 156:95d6b41a828b | 760 | |
<> | 156:95d6b41a828b | 761 | /* Clear the TC flag in the ICR register */ |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 767 | /* Enable the UART Error Interrupt: (Frame error) */ |
<> | 156:95d6b41a828b | 768 | SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 144:ef7eb2e8f9f7 | 769 | |
<> | 156:95d6b41a828b | 770 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
<> | 156:95d6b41a828b | 771 | in the SMARTCARD associated USART CR3 register */ |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 783 | * @brief Receive an amount of data in DMA mode. |
<> | 156:95d6b41a828b | 784 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 785 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 786 | * @param pData pointer to data buffer. |
<> | 156:95d6b41a828b | 787 | * @param Size amount of data to be received. |
<> | 156:95d6b41a828b | 788 | * @note The SMARTCARD-associated USART parity is enabled (PCE = 1), |
<> | 156:95d6b41a828b | 789 | * the received data contain the parity bit (MSB position). |
<> | 144:ef7eb2e8f9f7 | 790 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 791 | */ |
<> | 156:95d6b41a828b | 792 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size) |
<> | 144:ef7eb2e8f9f7 | 793 | { |
<> | 156:95d6b41a828b | 794 | /* Check that a Rx process is not already ongoing */ |
<> | 156:95d6b41a828b | 795 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 796 | { |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 805 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 806 | hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 144:ef7eb2e8f9f7 | 807 | |
<> | 156:95d6b41a828b | 808 | hsmartcard->pRxBuffPtr = pData; |
<> | 156:95d6b41a828b | 809 | hsmartcard->RxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 810 | |
<> | 144:ef7eb2e8f9f7 | 811 | /* Set the SMARTCARD DMA transfer complete callback */ |
<> | 156:95d6b41a828b | 812 | hsmartcard->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt; |
<> | 144:ef7eb2e8f9f7 | 813 | |
<> | 156:95d6b41a828b | 814 | /* Set the SMARTCARD DMA error callback */ |
<> | 156:95d6b41a828b | 815 | hsmartcard->hdmarx->XferErrorCallback = SMARTCARD_DMAError; |
<> | 144:ef7eb2e8f9f7 | 816 | |
<> | 156:95d6b41a828b | 817 | /* Set the DMA abort callback */ |
<> | 156:95d6b41a828b | 818 | hsmartcard->hdmarx->XferAbortCallback = NULL; |
<> | 144:ef7eb2e8f9f7 | 819 | |
<> | 156:95d6b41a828b | 820 | /* Enable the DMA channel */ |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 826 | /* Enable the UART Parity Error Interrupt */ |
<> | 156:95d6b41a828b | 827 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE); |
<> | 156:95d6b41a828b | 828 | |
<> | 156:95d6b41a828b | 829 | /* Enable the UART Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 156:95d6b41a828b | 830 | SET_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 831 | |
<> | 156:95d6b41a828b | 832 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
<> | 156:95d6b41a828b | 833 | in the SMARTCARD associated USART CR3 register */ |
<> | 156:95d6b41a828b | 834 | SET_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 845 | * @brief Abort ongoing transfers (blocking mode). |
<> | 156:95d6b41a828b | 846 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 847 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 848 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
<> | 156:95d6b41a828b | 849 | * This procedure performs following operations : |
<> | 156:95d6b41a828b | 850 | * - Disable SMARTCARD Interrupts (Tx and Rx) |
<> | 156:95d6b41a828b | 851 | * - Disable the DMA transfer in the peripheral register (if enabled) |
<> | 156:95d6b41a828b | 852 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
<> | 156:95d6b41a828b | 853 | * - Set handle State to READY |
<> | 156:95d6b41a828b | 854 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
<> | 144:ef7eb2e8f9f7 | 855 | * @retval HAL status |
<> | 156:95d6b41a828b | 856 | */ |
<> | 156:95d6b41a828b | 857 | HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 858 | { |
<> | 156:95d6b41a828b | 859 | /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
<> | 156:95d6b41a828b | 860 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE)); |
<> | 156:95d6b41a828b | 861 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 862 | |
<> | 156:95d6b41a828b | 863 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
<> | 156:95d6b41a828b | 864 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) |
<> | 156:95d6b41a828b | 865 | { |
<> | 156:95d6b41a828b | 866 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 156:95d6b41a828b | 867 | |
<> | 156:95d6b41a828b | 868 | /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */ |
<> | 156:95d6b41a828b | 869 | if(hsmartcard->hdmatx != NULL) |
<> | 156:95d6b41a828b | 870 | { |
<> | 156:95d6b41a828b | 871 | /* Set the SMARTCARD DMA Abort callback to Null. |
<> | 156:95d6b41a828b | 872 | No call back execution at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 873 | hsmartcard->hdmatx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 874 | |
<> | 156:95d6b41a828b | 875 | HAL_DMA_Abort(hsmartcard->hdmatx); |
<> | 156:95d6b41a828b | 876 | } |
<> | 156:95d6b41a828b | 877 | } |
<> | 156:95d6b41a828b | 878 | |
<> | 156:95d6b41a828b | 879 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
<> | 156:95d6b41a828b | 880 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) |
<> | 156:95d6b41a828b | 881 | { |
<> | 156:95d6b41a828b | 882 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 156:95d6b41a828b | 883 | |
<> | 156:95d6b41a828b | 884 | /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */ |
<> | 156:95d6b41a828b | 885 | if(hsmartcard->hdmarx != NULL) |
<> | 156:95d6b41a828b | 886 | { |
<> | 156:95d6b41a828b | 887 | /* Set the SMARTCARD DMA Abort callback to Null. |
<> | 156:95d6b41a828b | 888 | No call back execution at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 889 | hsmartcard->hdmarx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 890 | |
<> | 156:95d6b41a828b | 891 | HAL_DMA_Abort(hsmartcard->hdmarx); |
<> | 156:95d6b41a828b | 892 | } |
<> | 156:95d6b41a828b | 893 | } |
<> | 144:ef7eb2e8f9f7 | 894 | |
<> | 156:95d6b41a828b | 895 | /* Reset Tx and Rx transfer counters */ |
<> | 156:95d6b41a828b | 896 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 897 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 898 | |
<> | 156:95d6b41a828b | 899 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 900 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF); |
<> | 156:95d6b41a828b | 901 | |
<> | 156:95d6b41a828b | 902 | /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 903 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 904 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 905 | |
<> | 156:95d6b41a828b | 906 | /* Reset Handle ErrorCode to No Error */ |
<> | 156:95d6b41a828b | 907 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 908 | |
<> | 156:95d6b41a828b | 909 | return HAL_OK; |
<> | 156:95d6b41a828b | 910 | } |
<> | 156:95d6b41a828b | 911 | |
<> | 156:95d6b41a828b | 912 | /** |
<> | 156:95d6b41a828b | 913 | * @brief Abort ongoing Transmit transfer (blocking mode). |
<> | 156:95d6b41a828b | 914 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 915 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 916 | * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. |
<> | 156:95d6b41a828b | 917 | * This procedure performs following operations : |
<> | 156:95d6b41a828b | 918 | * - Disable SMARTCARD Interrupts (Tx) |
<> | 156:95d6b41a828b | 919 | * - Disable the DMA transfer in the peripheral register (if enabled) |
<> | 156:95d6b41a828b | 920 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
<> | 156:95d6b41a828b | 921 | * - Set handle State to READY |
<> | 156:95d6b41a828b | 922 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
<> | 156:95d6b41a828b | 923 | * @retval HAL status |
<> | 156:95d6b41a828b | 924 | */ |
<> | 156:95d6b41a828b | 925 | HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 926 | { |
<> | 156:95d6b41a828b | 927 | /* Disable TXEIE and TCIE interrupts */ |
<> | 156:95d6b41a828b | 928 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
<> | 156:95d6b41a828b | 929 | |
<> | 156:95d6b41a828b | 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 | { |
<> | 156:95d6b41a828b | 933 | /* Disable the SMARTCARD Error Interrupt: (Frame error) */ |
<> | 156:95d6b41a828b | 934 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 935 | } |
<> | 156:95d6b41a828b | 936 | |
<> | 156:95d6b41a828b | 937 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
<> | 156:95d6b41a828b | 938 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) |
<> | 156:95d6b41a828b | 939 | { |
<> | 156:95d6b41a828b | 940 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 156:95d6b41a828b | 941 | |
<> | 156:95d6b41a828b | 942 | /* Abort the SMARTCARD DMA Tx channel : use blocking DMA Abort API (no callback) */ |
<> | 156:95d6b41a828b | 943 | if(hsmartcard->hdmatx != NULL) |
<> | 144:ef7eb2e8f9f7 | 944 | { |
<> | 156:95d6b41a828b | 945 | /* Set the SMARTCARD DMA Abort callback to Null. |
<> | 156:95d6b41a828b | 946 | No call back execution at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 947 | hsmartcard->hdmatx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 948 | |
<> | 156:95d6b41a828b | 949 | HAL_DMA_Abort(hsmartcard->hdmatx); |
<> | 144:ef7eb2e8f9f7 | 950 | } |
<> | 156:95d6b41a828b | 951 | } |
<> | 156:95d6b41a828b | 952 | |
<> | 156:95d6b41a828b | 953 | /* Reset Tx transfer counter */ |
<> | 156:95d6b41a828b | 954 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 955 | |
<> | 156:95d6b41a828b | 956 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 957 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF); |
<> | 156:95d6b41a828b | 958 | |
<> | 156:95d6b41a828b | 959 | /* Restore hsmartcard->gState to Ready */ |
<> | 156:95d6b41a828b | 960 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 961 | |
<> | 156:95d6b41a828b | 962 | return HAL_OK; |
<> | 156:95d6b41a828b | 963 | } |
<> | 156:95d6b41a828b | 964 | |
<> | 156:95d6b41a828b | 965 | /** |
<> | 156:95d6b41a828b | 966 | * @brief Abort ongoing Receive transfer (blocking mode). |
<> | 156:95d6b41a828b | 967 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 968 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 969 | * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. |
<> | 156:95d6b41a828b | 970 | * This procedure performs following operations : |
<> | 156:95d6b41a828b | 971 | * - Disable SMARTCARD Interrupts (Rx) |
<> | 156:95d6b41a828b | 972 | * - Disable the DMA transfer in the peripheral register (if enabled) |
<> | 156:95d6b41a828b | 973 | * - Abort DMA transfer by calling HAL_DMA_Abort (in case of transfer in DMA mode) |
<> | 156:95d6b41a828b | 974 | * - Set handle State to READY |
<> | 156:95d6b41a828b | 975 | * @note This procedure is executed in blocking mode : when exiting function, Abort is considered as completed. |
<> | 156:95d6b41a828b | 976 | * @retval HAL status |
<> | 156:95d6b41a828b | 977 | */ |
<> | 156:95d6b41a828b | 978 | HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 979 | { |
<> | 156:95d6b41a828b | 980 | /* Disable RTOIE, EOBIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
<> | 156:95d6b41a828b | 981 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE)); |
<> | 144:ef7eb2e8f9f7 | 982 | |
<> | 156:95d6b41a828b | 983 | /* Check if a Transmit process is ongoing or not. If not disable ERR IT */ |
<> | 156:95d6b41a828b | 984 | if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 156:95d6b41a828b | 985 | { |
<> | 156:95d6b41a828b | 986 | /* Disable the SMARTCARD Error Interrupt: (Frame error) */ |
<> | 156:95d6b41a828b | 987 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 988 | } |
<> | 156:95d6b41a828b | 989 | |
<> | 156:95d6b41a828b | 990 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
<> | 156:95d6b41a828b | 991 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) |
<> | 156:95d6b41a828b | 992 | { |
<> | 156:95d6b41a828b | 993 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 156:95d6b41a828b | 994 | |
<> | 156:95d6b41a828b | 995 | /* Abort the SMARTCARD DMA Rx channel : use blocking DMA Abort API (no callback) */ |
<> | 156:95d6b41a828b | 996 | if(hsmartcard->hdmarx != NULL) |
<> | 156:95d6b41a828b | 997 | { |
<> | 156:95d6b41a828b | 998 | /* Set the SMARTCARD DMA Abort callback to Null. |
<> | 156:95d6b41a828b | 999 | No call back execution at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 1000 | hsmartcard->hdmarx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 1001 | |
<> | 156:95d6b41a828b | 1002 | HAL_DMA_Abort(hsmartcard->hdmarx); |
<> | 156:95d6b41a828b | 1003 | } |
<> | 156:95d6b41a828b | 1004 | } |
<> | 156:95d6b41a828b | 1005 | |
<> | 156:95d6b41a828b | 1006 | /* Reset Rx transfer counter */ |
<> | 156:95d6b41a828b | 1007 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 1008 | |
<> | 156:95d6b41a828b | 1009 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 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 | |
<> | 156:95d6b41a828b | 1012 | /* Restore hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 1013 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1014 | |
<> | 156:95d6b41a828b | 1015 | return HAL_OK; |
<> | 156:95d6b41a828b | 1016 | } |
<> | 144:ef7eb2e8f9f7 | 1017 | |
<> | 156:95d6b41a828b | 1018 | /** |
<> | 156:95d6b41a828b | 1019 | * @brief Abort ongoing transfers (Interrupt mode). |
<> | 156:95d6b41a828b | 1020 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1021 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1022 | * @note This procedure could be used for aborting any ongoing transfer started in Interrupt or DMA mode. |
<> | 156:95d6b41a828b | 1023 | * This procedure performs following operations : |
<> | 156:95d6b41a828b | 1024 | * - Disable SMARTCARD Interrupts (Tx and Rx) |
<> | 156:95d6b41a828b | 1025 | * - Disable the DMA transfer in the peripheral register (if enabled) |
<> | 156:95d6b41a828b | 1026 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
<> | 156:95d6b41a828b | 1027 | * - Set handle State to READY |
<> | 156:95d6b41a828b | 1028 | * - At abort completion, call user abort complete callback |
<> | 156:95d6b41a828b | 1029 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
<> | 156:95d6b41a828b | 1030 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
<> | 156:95d6b41a828b | 1031 | * @retval HAL status |
<> | 156:95d6b41a828b | 1032 | */ |
<> | 156:95d6b41a828b | 1033 | HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1034 | { |
<> | 156:95d6b41a828b | 1035 | uint32_t abortcplt = 1U; |
<> | 156:95d6b41a828b | 1036 | |
<> | 156:95d6b41a828b | 1037 | /* Disable RTOIE, EOBIE, TXEIE, TCIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
<> | 156:95d6b41a828b | 1038 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RTOIE | USART_CR1_EOBIE)); |
<> | 156:95d6b41a828b | 1039 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 144:ef7eb2e8f9f7 | 1040 | |
<> | 156:95d6b41a828b | 1041 | /* If DMA Tx and/or DMA Rx Handles are associated to SMARTCARD Handle, DMA Abort complete callbacks should be initialised |
<> | 156:95d6b41a828b | 1042 | before any call to DMA Abort functions */ |
<> | 156:95d6b41a828b | 1043 | /* DMA Tx Handle is valid */ |
<> | 156:95d6b41a828b | 1044 | if(hsmartcard->hdmatx != NULL) |
<> | 156:95d6b41a828b | 1045 | { |
<> | 156:95d6b41a828b | 1046 | /* Set DMA Abort Complete callback if SMARTCARD DMA Tx request if enabled. |
<> | 156:95d6b41a828b | 1047 | Otherwise, set it to NULL */ |
<> | 156:95d6b41a828b | 1048 | if(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) |
<> | 156:95d6b41a828b | 1049 | { |
<> | 156:95d6b41a828b | 1050 | hsmartcard->hdmatx->XferAbortCallback = SMARTCARD_DMATxAbortCallback; |
<> | 156:95d6b41a828b | 1051 | } |
<> | 156:95d6b41a828b | 1052 | else |
<> | 156:95d6b41a828b | 1053 | { |
<> | 156:95d6b41a828b | 1054 | hsmartcard->hdmatx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 1055 | } |
<> | 156:95d6b41a828b | 1056 | } |
<> | 156:95d6b41a828b | 1057 | /* DMA Rx Handle is valid */ |
<> | 156:95d6b41a828b | 1058 | if(hsmartcard->hdmarx != NULL) |
<> | 156:95d6b41a828b | 1059 | { |
<> | 156:95d6b41a828b | 1060 | /* Set DMA Abort Complete callback if SMARTCARD DMA Rx request if enabled. |
<> | 156:95d6b41a828b | 1061 | Otherwise, set it to NULL */ |
<> | 156:95d6b41a828b | 1062 | if(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) |
<> | 156:95d6b41a828b | 1063 | { |
<> | 156:95d6b41a828b | 1064 | hsmartcard->hdmarx->XferAbortCallback = SMARTCARD_DMARxAbortCallback; |
<> | 156:95d6b41a828b | 1065 | } |
<> | 156:95d6b41a828b | 1066 | else |
<> | 156:95d6b41a828b | 1067 | { |
<> | 156:95d6b41a828b | 1068 | hsmartcard->hdmarx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 1069 | } |
<> | 156:95d6b41a828b | 1070 | } |
<> | 156:95d6b41a828b | 1071 | |
<> | 156:95d6b41a828b | 1072 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
<> | 156:95d6b41a828b | 1073 | if(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) |
<> | 156:95d6b41a828b | 1074 | { |
<> | 156:95d6b41a828b | 1075 | /* Disable DMA Tx at UART level */ |
<> | 156:95d6b41a828b | 1076 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 144:ef7eb2e8f9f7 | 1077 | |
<> | 156:95d6b41a828b | 1078 | /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */ |
<> | 156:95d6b41a828b | 1079 | if(hsmartcard->hdmatx != NULL) |
<> | 156:95d6b41a828b | 1080 | { |
<> | 156:95d6b41a828b | 1081 | /* SMARTCARD Tx DMA Abort callback has already been initialised : |
<> | 156:95d6b41a828b | 1082 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 1083 | |
<> | 156:95d6b41a828b | 1084 | /* Abort DMA TX */ |
<> | 156:95d6b41a828b | 1085 | if(HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK) |
<> | 156:95d6b41a828b | 1086 | { |
<> | 156:95d6b41a828b | 1087 | hsmartcard->hdmatx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 1088 | } |
<> | 156:95d6b41a828b | 1089 | else |
<> | 156:95d6b41a828b | 1090 | { |
<> | 156:95d6b41a828b | 1091 | abortcplt = 0U; |
<> | 156:95d6b41a828b | 1092 | } |
<> | 156:95d6b41a828b | 1093 | } |
<> | 156:95d6b41a828b | 1094 | } |
<> | 156:95d6b41a828b | 1095 | |
<> | 156:95d6b41a828b | 1096 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
<> | 156:95d6b41a828b | 1097 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) |
<> | 156:95d6b41a828b | 1098 | { |
<> | 156:95d6b41a828b | 1099 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 156:95d6b41a828b | 1100 | |
<> | 156:95d6b41a828b | 1101 | /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */ |
<> | 156:95d6b41a828b | 1102 | if(hsmartcard->hdmarx != NULL) |
<> | 156:95d6b41a828b | 1103 | { |
<> | 156:95d6b41a828b | 1104 | /* SMARTCARD Rx DMA Abort callback has already been initialised : |
<> | 156:95d6b41a828b | 1105 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 1106 | |
<> | 156:95d6b41a828b | 1107 | /* Abort DMA RX */ |
<> | 156:95d6b41a828b | 1108 | if(HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK) |
<> | 156:95d6b41a828b | 1109 | { |
<> | 156:95d6b41a828b | 1110 | hsmartcard->hdmarx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 1111 | abortcplt = 1U; |
<> | 156:95d6b41a828b | 1112 | } |
<> | 156:95d6b41a828b | 1113 | else |
<> | 156:95d6b41a828b | 1114 | { |
<> | 156:95d6b41a828b | 1115 | abortcplt = 0U; |
<> | 156:95d6b41a828b | 1116 | } |
<> | 156:95d6b41a828b | 1117 | } |
<> | 156:95d6b41a828b | 1118 | } |
<> | 144:ef7eb2e8f9f7 | 1119 | |
<> | 156:95d6b41a828b | 1120 | /* if no DMA abort complete callback execution is required => call user Abort Complete callback */ |
<> | 156:95d6b41a828b | 1121 | if (abortcplt == 1U) |
<> | 156:95d6b41a828b | 1122 | { |
<> | 156:95d6b41a828b | 1123 | /* Reset Tx and Rx transfer counters */ |
<> | 156:95d6b41a828b | 1124 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 1125 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 1126 | |
<> | 156:95d6b41a828b | 1127 | /* Reset errorCode */ |
<> | 156:95d6b41a828b | 1128 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 1129 | |
<> | 156:95d6b41a828b | 1130 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 1131 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF); |
<> | 156:95d6b41a828b | 1132 | |
<> | 156:95d6b41a828b | 1133 | /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 1134 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1135 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1136 | |
<> | 156:95d6b41a828b | 1137 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
<> | 156:95d6b41a828b | 1138 | HAL_SMARTCARD_AbortCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1139 | } |
<> | 156:95d6b41a828b | 1140 | |
<> | 156:95d6b41a828b | 1141 | return HAL_OK; |
<> | 156:95d6b41a828b | 1142 | } |
<> | 144:ef7eb2e8f9f7 | 1143 | |
<> | 156:95d6b41a828b | 1144 | /** |
<> | 156:95d6b41a828b | 1145 | * @brief Abort ongoing Transmit transfer (Interrupt mode). |
<> | 156:95d6b41a828b | 1146 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1147 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1148 | * @note This procedure could be used for aborting any ongoing Tx transfer started in Interrupt or DMA mode. |
<> | 156:95d6b41a828b | 1149 | * This procedure performs following operations : |
<> | 156:95d6b41a828b | 1150 | * - Disable SMARTCARD Interrupts (Tx) |
<> | 156:95d6b41a828b | 1151 | * - Disable the DMA transfer in the peripheral register (if enabled) |
<> | 156:95d6b41a828b | 1152 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
<> | 156:95d6b41a828b | 1153 | * - Set handle State to READY |
<> | 156:95d6b41a828b | 1154 | * - At abort completion, call user abort complete callback |
<> | 156:95d6b41a828b | 1155 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
<> | 156:95d6b41a828b | 1156 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
<> | 156:95d6b41a828b | 1157 | * @retval HAL status |
<> | 156:95d6b41a828b | 1158 | */ |
<> | 156:95d6b41a828b | 1159 | HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1160 | { |
<> | 156:95d6b41a828b | 1161 | /* Disable TXEIE and TCIE interrupts */ |
<> | 156:95d6b41a828b | 1162 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
<> | 156:95d6b41a828b | 1163 | |
<> | 156:95d6b41a828b | 1164 | /* Check if a receive process is ongoing or not. If not disable ERR IT */ |
<> | 156:95d6b41a828b | 1165 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 156:95d6b41a828b | 1166 | { |
<> | 156:95d6b41a828b | 1167 | /* Disable the SMARTCARD Error Interrupt: (Frame error) */ |
<> | 156:95d6b41a828b | 1168 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 1169 | } |
<> | 144:ef7eb2e8f9f7 | 1170 | |
<> | 156:95d6b41a828b | 1171 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
<> | 156:95d6b41a828b | 1172 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) |
<> | 156:95d6b41a828b | 1173 | { |
<> | 156:95d6b41a828b | 1174 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 156:95d6b41a828b | 1175 | |
<> | 156:95d6b41a828b | 1176 | /* Abort the SMARTCARD DMA Tx channel : use non blocking DMA Abort API (callback) */ |
<> | 156:95d6b41a828b | 1177 | if(hsmartcard->hdmatx != NULL) |
<> | 156:95d6b41a828b | 1178 | { |
<> | 156:95d6b41a828b | 1179 | /* Set the SMARTCARD DMA Abort callback : |
<> | 156:95d6b41a828b | 1180 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 1181 | hsmartcard->hdmatx->XferAbortCallback = SMARTCARD_DMATxOnlyAbortCallback; |
<> | 144:ef7eb2e8f9f7 | 1182 | |
<> | 156:95d6b41a828b | 1183 | /* Abort DMA TX */ |
<> | 156:95d6b41a828b | 1184 | if(HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK) |
<> | 156:95d6b41a828b | 1185 | { |
<> | 156:95d6b41a828b | 1186 | /* Call Directly hsmartcard->hdmatx->XferAbortCallback function in case of error */ |
<> | 156:95d6b41a828b | 1187 | hsmartcard->hdmatx->XferAbortCallback(hsmartcard->hdmatx); |
<> | 156:95d6b41a828b | 1188 | } |
<> | 156:95d6b41a828b | 1189 | } |
<> | 156:95d6b41a828b | 1190 | else |
<> | 156:95d6b41a828b | 1191 | { |
<> | 156:95d6b41a828b | 1192 | /* Reset Tx transfer counter */ |
<> | 156:95d6b41a828b | 1193 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 1194 | |
<> | 156:95d6b41a828b | 1195 | /* Restore hsmartcard->gState to Ready */ |
<> | 156:95d6b41a828b | 1196 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1197 | |
<> | 156:95d6b41a828b | 1198 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
<> | 156:95d6b41a828b | 1199 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1200 | } |
<> | 144:ef7eb2e8f9f7 | 1201 | } |
<> | 144:ef7eb2e8f9f7 | 1202 | else |
<> | 144:ef7eb2e8f9f7 | 1203 | { |
<> | 156:95d6b41a828b | 1204 | /* Reset Tx transfer counter */ |
<> | 156:95d6b41a828b | 1205 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 1206 | |
<> | 156:95d6b41a828b | 1207 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 1208 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF); |
<> | 156:95d6b41a828b | 1209 | |
<> | 156:95d6b41a828b | 1210 | /* Restore hsmartcard->gState to Ready */ |
<> | 156:95d6b41a828b | 1211 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1212 | |
<> | 156:95d6b41a828b | 1213 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
<> | 156:95d6b41a828b | 1214 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1215 | } |
<> | 156:95d6b41a828b | 1216 | |
<> | 156:95d6b41a828b | 1217 | return HAL_OK; |
<> | 156:95d6b41a828b | 1218 | } |
<> | 156:95d6b41a828b | 1219 | |
<> | 156:95d6b41a828b | 1220 | /** |
<> | 156:95d6b41a828b | 1221 | * @brief Abort ongoing Receive transfer (Interrupt mode). |
<> | 156:95d6b41a828b | 1222 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1223 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1224 | * @note This procedure could be used for aborting any ongoing Rx transfer started in Interrupt or DMA mode. |
<> | 156:95d6b41a828b | 1225 | * This procedure performs following operations : |
<> | 156:95d6b41a828b | 1226 | * - Disable SMARTCARD Interrupts (Rx) |
<> | 156:95d6b41a828b | 1227 | * - Disable the DMA transfer in the peripheral register (if enabled) |
<> | 156:95d6b41a828b | 1228 | * - Abort DMA transfer by calling HAL_DMA_Abort_IT (in case of transfer in DMA mode) |
<> | 156:95d6b41a828b | 1229 | * - Set handle State to READY |
<> | 156:95d6b41a828b | 1230 | * - At abort completion, call user abort complete callback |
<> | 156:95d6b41a828b | 1231 | * @note This procedure is executed in Interrupt mode, meaning that abort procedure could be |
<> | 156:95d6b41a828b | 1232 | * considered as completed only when user abort complete callback is executed (not when exiting function). |
<> | 156:95d6b41a828b | 1233 | * @retval HAL status |
<> | 156:95d6b41a828b | 1234 | */ |
<> | 156:95d6b41a828b | 1235 | HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1236 | { |
<> | 156:95d6b41a828b | 1237 | /* Disable RTOIE, EOBIE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
<> | 156:95d6b41a828b | 1238 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE | USART_CR1_EOBIE)); |
<> | 156:95d6b41a828b | 1239 | |
<> | 156:95d6b41a828b | 1240 | /* Check if a Transmit process is ongoing or not. If not disable ERR IT */ |
<> | 156:95d6b41a828b | 1241 | if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 156:95d6b41a828b | 1242 | { |
<> | 156:95d6b41a828b | 1243 | /* Disable the SMARTCARD Error Interrupt: (Frame error) */ |
<> | 156:95d6b41a828b | 1244 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 144:ef7eb2e8f9f7 | 1245 | } |
<> | 156:95d6b41a828b | 1246 | |
<> | 156:95d6b41a828b | 1247 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
<> | 156:95d6b41a828b | 1248 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) |
<> | 156:95d6b41a828b | 1249 | { |
<> | 156:95d6b41a828b | 1250 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 156:95d6b41a828b | 1251 | |
<> | 156:95d6b41a828b | 1252 | /* Abort the SMARTCARD DMA Rx channel : use non blocking DMA Abort API (callback) */ |
<> | 156:95d6b41a828b | 1253 | if(hsmartcard->hdmarx != NULL) |
<> | 156:95d6b41a828b | 1254 | { |
<> | 156:95d6b41a828b | 1255 | /* Set the SMARTCARD DMA Abort callback : |
<> | 156:95d6b41a828b | 1256 | will lead to call HAL_SMARTCARD_AbortCpltCallback() at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 1257 | hsmartcard->hdmarx->XferAbortCallback = SMARTCARD_DMARxOnlyAbortCallback; |
<> | 156:95d6b41a828b | 1258 | |
<> | 156:95d6b41a828b | 1259 | /* Abort DMA RX */ |
<> | 156:95d6b41a828b | 1260 | if(HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK) |
<> | 156:95d6b41a828b | 1261 | { |
<> | 156:95d6b41a828b | 1262 | /* Call Directly hsmartcard->hdmarx->XferAbortCallback function in case of error */ |
<> | 156:95d6b41a828b | 1263 | hsmartcard->hdmarx->XferAbortCallback(hsmartcard->hdmarx); |
<> | 156:95d6b41a828b | 1264 | } |
<> | 156:95d6b41a828b | 1265 | } |
<> | 156:95d6b41a828b | 1266 | else |
<> | 156:95d6b41a828b | 1267 | { |
<> | 156:95d6b41a828b | 1268 | /* Reset Rx transfer counter */ |
<> | 156:95d6b41a828b | 1269 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 1270 | |
<> | 156:95d6b41a828b | 1271 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 1272 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF); |
<> | 156:95d6b41a828b | 1273 | |
<> | 156:95d6b41a828b | 1274 | /* Restore hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 1275 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1276 | |
<> | 156:95d6b41a828b | 1277 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
<> | 156:95d6b41a828b | 1278 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1279 | } |
<> | 156:95d6b41a828b | 1280 | } |
<> | 156:95d6b41a828b | 1281 | else |
<> | 156:95d6b41a828b | 1282 | { |
<> | 156:95d6b41a828b | 1283 | /* Reset Rx transfer counter */ |
<> | 156:95d6b41a828b | 1284 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 1285 | |
<> | 156:95d6b41a828b | 1286 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 1287 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF); |
<> | 156:95d6b41a828b | 1288 | |
<> | 156:95d6b41a828b | 1289 | /* Restore hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 1290 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1291 | |
<> | 156:95d6b41a828b | 1292 | /* As no DMA to be aborted, call directly user Abort complete callback */ |
<> | 156:95d6b41a828b | 1293 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1294 | } |
<> | 156:95d6b41a828b | 1295 | |
<> | 156:95d6b41a828b | 1296 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1297 | } |
<> | 144:ef7eb2e8f9f7 | 1298 | |
<> | 144:ef7eb2e8f9f7 | 1299 | /** |
<> | 144:ef7eb2e8f9f7 | 1300 | * @brief Handle SMARTCARD interrupt requests. |
Anna Bridge |
180:96ed750bd169 | 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 | { |
<> | 156:95d6b41a828b | 1307 | uint32_t isrflags = READ_REG(hsmartcard->Instance->ISR); |
<> | 156:95d6b41a828b | 1308 | uint32_t cr1its = READ_REG(hsmartcard->Instance->CR1); |
<> | 156:95d6b41a828b | 1309 | uint32_t cr3its; |
<> | 156:95d6b41a828b | 1310 | uint32_t errorflags; |
<> | 156:95d6b41a828b | 1311 | |
<> | 156:95d6b41a828b | 1312 | /* If no error occurs */ |
<> | 156:95d6b41a828b | 1313 | errorflags = (isrflags & (uint32_t)(USART_ISR_PE | USART_ISR_FE | USART_ISR_ORE | USART_ISR_NE | USART_ISR_RTOF)); |
<> | 156:95d6b41a828b | 1314 | if (errorflags == RESET) |
<> | 144:ef7eb2e8f9f7 | 1315 | { |
<> | 156:95d6b41a828b | 1316 | /* SMARTCARD in mode Receiver ---------------------------------------------------*/ |
<> | 156:95d6b41a828b | 1317 | if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
<> | 156:95d6b41a828b | 1318 | { |
<> | 156:95d6b41a828b | 1319 | SMARTCARD_Receive_IT(hsmartcard); |
<> | 156:95d6b41a828b | 1320 | /* Clear RXNE interrupt flag done by reading RDR in SMARTCARD_Receive_IT() */ |
<> | 156:95d6b41a828b | 1321 | return; |
<> | 156:95d6b41a828b | 1322 | } |
<> | 156:95d6b41a828b | 1323 | } |
<> | 144:ef7eb2e8f9f7 | 1324 | |
<> | 156:95d6b41a828b | 1325 | /* If some errors occur */ |
<> | 156:95d6b41a828b | 1326 | cr3its = READ_REG(hsmartcard->Instance->CR3); |
<> | 156:95d6b41a828b | 1327 | if( (errorflags != RESET) |
<> | 156:95d6b41a828b | 1328 | && ( ((cr3its & USART_CR3_EIE) != RESET) |
<> | 156:95d6b41a828b | 1329 | || ((cr1its & (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_RTOIE)) != RESET)) ) |
<> | 144:ef7eb2e8f9f7 | 1330 | { |
<> | 156:95d6b41a828b | 1331 | /* SMARTCARD parity error interrupt occurred -------------------------------------*/ |
<> | 156:95d6b41a828b | 1332 | if(((isrflags & USART_ISR_PE) != RESET) && ((cr1its & USART_CR1_PEIE) != RESET)) |
<> | 156:95d6b41a828b | 1333 | { |
<> | 156:95d6b41a828b | 1334 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_PEF); |
<> | 156:95d6b41a828b | 1335 | |
<> | 156:95d6b41a828b | 1336 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_PE; |
<> | 156:95d6b41a828b | 1337 | } |
<> | 156:95d6b41a828b | 1338 | |
<> | 156:95d6b41a828b | 1339 | /* SMARTCARD frame error interrupt occurred --------------------------------------*/ |
<> | 156:95d6b41a828b | 1340 | if(((isrflags & USART_ISR_FE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
<> | 156:95d6b41a828b | 1341 | { |
<> | 156:95d6b41a828b | 1342 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_FEF); |
<> | 156:95d6b41a828b | 1343 | |
<> | 156:95d6b41a828b | 1344 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_FE; |
<> | 156:95d6b41a828b | 1345 | } |
<> | 156:95d6b41a828b | 1346 | |
<> | 156:95d6b41a828b | 1347 | /* SMARTCARD noise error interrupt occurred --------------------------------------*/ |
<> | 156:95d6b41a828b | 1348 | if(((isrflags & USART_ISR_NE) != RESET) && ((cr3its & USART_CR3_EIE) != RESET)) |
<> | 156:95d6b41a828b | 1349 | { |
<> | 156:95d6b41a828b | 1350 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_NEF); |
<> | 156:95d6b41a828b | 1351 | |
<> | 156:95d6b41a828b | 1352 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_NE; |
<> | 156:95d6b41a828b | 1353 | } |
<> | 144:ef7eb2e8f9f7 | 1354 | |
<> | 156:95d6b41a828b | 1355 | /* SMARTCARD Over-Run interrupt occurred -----------------------------------------*/ |
<> | 156:95d6b41a828b | 1356 | if(((isrflags & USART_ISR_ORE) != RESET) && |
<> | 156:95d6b41a828b | 1357 | (((cr1its & USART_CR1_RXNEIE) != RESET) || ((cr3its & USART_CR3_EIE) != RESET))) |
<> | 156:95d6b41a828b | 1358 | { |
<> | 156:95d6b41a828b | 1359 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_OREF); |
<> | 156:95d6b41a828b | 1360 | |
<> | 156:95d6b41a828b | 1361 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_ORE; |
<> | 156:95d6b41a828b | 1362 | } |
<> | 156:95d6b41a828b | 1363 | |
<> | 156:95d6b41a828b | 1364 | /* SMARTCARD receiver timeout interrupt occurred -----------------------------------------*/ |
<> | 156:95d6b41a828b | 1365 | if(((isrflags & USART_ISR_RTOF) != RESET) && ((cr1its & USART_CR1_RTOIE) != RESET)) |
<> | 156:95d6b41a828b | 1366 | { |
<> | 156:95d6b41a828b | 1367 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_RTOF); |
<> | 156:95d6b41a828b | 1368 | |
<> | 156:95d6b41a828b | 1369 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_RTO; |
<> | 156:95d6b41a828b | 1370 | } |
<> | 156:95d6b41a828b | 1371 | |
<> | 156:95d6b41a828b | 1372 | /* Call SMARTCARD Error Call back function if need be --------------------------*/ |
<> | 156:95d6b41a828b | 1373 | if(hsmartcard->ErrorCode != HAL_SMARTCARD_ERROR_NONE) |
<> | 156:95d6b41a828b | 1374 | { |
<> | 156:95d6b41a828b | 1375 | /* SMARTCARD in mode Receiver ---------------------------------------------------*/ |
<> | 156:95d6b41a828b | 1376 | if(((isrflags & USART_ISR_RXNE) != RESET) && ((cr1its & USART_CR1_RXNEIE) != RESET)) |
<> | 156:95d6b41a828b | 1377 | { |
<> | 156:95d6b41a828b | 1378 | SMARTCARD_Receive_IT(hsmartcard); |
<> | 156:95d6b41a828b | 1379 | } |
<> | 144:ef7eb2e8f9f7 | 1380 | |
<> | 156:95d6b41a828b | 1381 | /* If Error is to be considered as blocking : |
<> | 156:95d6b41a828b | 1382 | - Receiver Timeout error in Reception |
<> | 156:95d6b41a828b | 1383 | - Overrun error in Reception |
<> | 156:95d6b41a828b | 1384 | - any error occurs in DMA mode reception |
<> | 156:95d6b41a828b | 1385 | */ |
<> | 156:95d6b41a828b | 1386 | if ( ((hsmartcard->ErrorCode & (HAL_SMARTCARD_ERROR_RTO | HAL_SMARTCARD_ERROR_ORE)) != RESET) |
<> | 156:95d6b41a828b | 1387 | || (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR))) |
<> | 156:95d6b41a828b | 1388 | { |
<> | 156:95d6b41a828b | 1389 | /* Blocking error : transfer is aborted |
<> | 156:95d6b41a828b | 1390 | Set the SMARTCARD state ready to be able to start again the process, |
<> | 156:95d6b41a828b | 1391 | Disable Rx Interrupts, and disable Rx DMA request, if ongoing */ |
<> | 156:95d6b41a828b | 1392 | SMARTCARD_EndRxTransfer(hsmartcard); |
<> | 156:95d6b41a828b | 1393 | |
<> | 156:95d6b41a828b | 1394 | /* Disable the SMARTCARD DMA Rx request if enabled */ |
<> | 156:95d6b41a828b | 1395 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) |
<> | 156:95d6b41a828b | 1396 | { |
<> | 156:95d6b41a828b | 1397 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 156:95d6b41a828b | 1398 | |
<> | 156:95d6b41a828b | 1399 | /* Abort the SMARTCARD DMA Rx channel */ |
<> | 156:95d6b41a828b | 1400 | if(hsmartcard->hdmarx != NULL) |
<> | 156:95d6b41a828b | 1401 | { |
<> | 156:95d6b41a828b | 1402 | /* Set the SMARTCARD DMA Abort callback : |
<> | 156:95d6b41a828b | 1403 | will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 1404 | hsmartcard->hdmarx->XferAbortCallback = SMARTCARD_DMAAbortOnError; |
<> | 144:ef7eb2e8f9f7 | 1405 | |
<> | 156:95d6b41a828b | 1406 | /* Abort DMA RX */ |
<> | 156:95d6b41a828b | 1407 | if(HAL_DMA_Abort_IT(hsmartcard->hdmarx) != HAL_OK) |
<> | 156:95d6b41a828b | 1408 | { |
<> | 156:95d6b41a828b | 1409 | /* Call Directly hsmartcard->hdmarx->XferAbortCallback function in case of error */ |
<> | 156:95d6b41a828b | 1410 | hsmartcard->hdmarx->XferAbortCallback(hsmartcard->hdmarx); |
<> | 156:95d6b41a828b | 1411 | } |
<> | 156:95d6b41a828b | 1412 | } |
<> | 156:95d6b41a828b | 1413 | else |
<> | 156:95d6b41a828b | 1414 | { |
<> | 156:95d6b41a828b | 1415 | /* Call user error callback */ |
<> | 156:95d6b41a828b | 1416 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1417 | } |
<> | 156:95d6b41a828b | 1418 | } |
<> | 156:95d6b41a828b | 1419 | else |
<> | 156:95d6b41a828b | 1420 | { |
<> | 156:95d6b41a828b | 1421 | /* Call user error callback */ |
<> | 156:95d6b41a828b | 1422 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1423 | } |
<> | 156:95d6b41a828b | 1424 | } |
<> | 156:95d6b41a828b | 1425 | /* other error type to be considered as blocking : |
<> | 156:95d6b41a828b | 1426 | - Frame error in Transmission |
<> | 156:95d6b41a828b | 1427 | */ |
<> | 156:95d6b41a828b | 1428 | else if ((hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX) && ((hsmartcard->ErrorCode & HAL_SMARTCARD_ERROR_FE) != RESET)) |
<> | 156:95d6b41a828b | 1429 | { |
<> | 156:95d6b41a828b | 1430 | /* Blocking error : transfer is aborted |
<> | 156:95d6b41a828b | 1431 | Set the SMARTCARD state ready to be able to start again the process, |
<> | 156:95d6b41a828b | 1432 | Disable Tx Interrupts, and disable Tx DMA request, if ongoing */ |
<> | 156:95d6b41a828b | 1433 | SMARTCARD_EndTxTransfer(hsmartcard); |
<> | 156:95d6b41a828b | 1434 | |
<> | 156:95d6b41a828b | 1435 | /* Disable the SMARTCARD DMA Tx request if enabled */ |
<> | 156:95d6b41a828b | 1436 | if (HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) |
<> | 156:95d6b41a828b | 1437 | { |
<> | 156:95d6b41a828b | 1438 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 144:ef7eb2e8f9f7 | 1439 | |
<> | 156:95d6b41a828b | 1440 | /* Abort the SMARTCARD DMA Tx channel */ |
<> | 156:95d6b41a828b | 1441 | if(hsmartcard->hdmatx != NULL) |
<> | 156:95d6b41a828b | 1442 | { |
<> | 156:95d6b41a828b | 1443 | /* Set the SMARTCARD DMA Abort callback : |
<> | 156:95d6b41a828b | 1444 | will lead to call HAL_SMARTCARD_ErrorCallback() at end of DMA abort procedure */ |
<> | 156:95d6b41a828b | 1445 | hsmartcard->hdmatx->XferAbortCallback = SMARTCARD_DMAAbortOnError; |
<> | 144:ef7eb2e8f9f7 | 1446 | |
<> | 156:95d6b41a828b | 1447 | /* Abort DMA TX */ |
<> | 156:95d6b41a828b | 1448 | if(HAL_DMA_Abort_IT(hsmartcard->hdmatx) != HAL_OK) |
<> | 156:95d6b41a828b | 1449 | { |
<> | 156:95d6b41a828b | 1450 | /* Call Directly hsmartcard->hdmatx->XferAbortCallback function in case of error */ |
<> | 156:95d6b41a828b | 1451 | hsmartcard->hdmatx->XferAbortCallback(hsmartcard->hdmatx); |
<> | 156:95d6b41a828b | 1452 | } |
<> | 156:95d6b41a828b | 1453 | } |
<> | 156:95d6b41a828b | 1454 | else |
<> | 156:95d6b41a828b | 1455 | { |
<> | 156:95d6b41a828b | 1456 | /* Call user error callback */ |
<> | 156:95d6b41a828b | 1457 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1458 | } |
<> | 156:95d6b41a828b | 1459 | } |
<> | 156:95d6b41a828b | 1460 | else |
<> | 156:95d6b41a828b | 1461 | { |
<> | 156:95d6b41a828b | 1462 | /* Call user error callback */ |
<> | 156:95d6b41a828b | 1463 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1464 | } |
<> | 156:95d6b41a828b | 1465 | } |
<> | 156:95d6b41a828b | 1466 | else |
<> | 156:95d6b41a828b | 1467 | { |
<> | 156:95d6b41a828b | 1468 | /* Non Blocking error : transfer could go on. |
<> | 156:95d6b41a828b | 1469 | Error is notified to user through user error callback */ |
<> | 156:95d6b41a828b | 1470 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1471 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 1472 | } |
<> | 156:95d6b41a828b | 1473 | } |
<> | 156:95d6b41a828b | 1474 | return; |
<> | 156:95d6b41a828b | 1475 | |
<> | 156:95d6b41a828b | 1476 | } /* End if some error occurs */ |
<> | 144:ef7eb2e8f9f7 | 1477 | |
<> | 144:ef7eb2e8f9f7 | 1478 | /* SMARTCARD in mode Receiver, end of block interruption ------------------------*/ |
<> | 156:95d6b41a828b | 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); |
<> | 156:95d6b41a828b | 1487 | return; |
<> | 144:ef7eb2e8f9f7 | 1488 | } |
<> | 144:ef7eb2e8f9f7 | 1489 | |
<> | 144:ef7eb2e8f9f7 | 1490 | /* SMARTCARD in mode Transmitter ------------------------------------------------*/ |
<> | 156:95d6b41a828b | 1491 | if(((isrflags & USART_ISR_TXE) != RESET) && ((cr1its & USART_CR1_TXEIE) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 1492 | { |
<> | 144:ef7eb2e8f9f7 | 1493 | SMARTCARD_Transmit_IT(hsmartcard); |
<> | 156:95d6b41a828b | 1494 | return; |
<> | 144:ef7eb2e8f9f7 | 1495 | } |
<> | 144:ef7eb2e8f9f7 | 1496 | |
<> | 144:ef7eb2e8f9f7 | 1497 | /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 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); |
<> | 156:95d6b41a828b | 1501 | return; |
<> | 144:ef7eb2e8f9f7 | 1502 | } |
<> | 144:ef7eb2e8f9f7 | 1503 | } |
<> | 144:ef7eb2e8f9f7 | 1504 | |
<> | 144:ef7eb2e8f9f7 | 1505 | /** |
<> | 156:95d6b41a828b | 1506 | * @brief Tx Transfer completed callback. |
<> | 156:95d6b41a828b | 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 | */ |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 1522 | * @brief Rx Transfer completed callback. |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 1538 | * @brief SMARTCARD error callback. |
<> | 156:95d6b41a828b | 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 | /** |
<> | 156:95d6b41a828b | 1554 | * @brief SMARTCARD Abort Complete callback. |
<> | 156:95d6b41a828b | 1555 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1556 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1557 | * @retval None |
<> | 156:95d6b41a828b | 1558 | */ |
<> | 156:95d6b41a828b | 1559 | __weak void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1560 | { |
<> | 156:95d6b41a828b | 1561 | /* Prevent unused argument(s) compilation warning */ |
<> | 156:95d6b41a828b | 1562 | UNUSED(hsmartcard); |
<> | 156:95d6b41a828b | 1563 | |
<> | 156:95d6b41a828b | 1564 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 156:95d6b41a828b | 1565 | the HAL_SMARTCARD_AbortCpltCallback can be implemented in the user file. |
<> | 156:95d6b41a828b | 1566 | */ |
<> | 156:95d6b41a828b | 1567 | } |
<> | 156:95d6b41a828b | 1568 | |
<> | 156:95d6b41a828b | 1569 | /** |
<> | 156:95d6b41a828b | 1570 | * @brief SMARTCARD Abort Complete callback. |
<> | 156:95d6b41a828b | 1571 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1572 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1573 | * @retval None |
<> | 156:95d6b41a828b | 1574 | */ |
<> | 156:95d6b41a828b | 1575 | __weak void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1576 | { |
<> | 156:95d6b41a828b | 1577 | /* Prevent unused argument(s) compilation warning */ |
<> | 156:95d6b41a828b | 1578 | UNUSED(hsmartcard); |
<> | 156:95d6b41a828b | 1579 | |
<> | 156:95d6b41a828b | 1580 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 156:95d6b41a828b | 1581 | the HAL_SMARTCARD_AbortTransmitCpltCallback can be implemented in the user file. |
<> | 156:95d6b41a828b | 1582 | */ |
<> | 156:95d6b41a828b | 1583 | } |
<> | 156:95d6b41a828b | 1584 | |
<> | 156:95d6b41a828b | 1585 | /** |
<> | 156:95d6b41a828b | 1586 | * @brief SMARTCARD Abort Receive Complete callback. |
<> | 156:95d6b41a828b | 1587 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1588 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1589 | * @retval None |
<> | 156:95d6b41a828b | 1590 | */ |
<> | 156:95d6b41a828b | 1591 | __weak void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1592 | { |
<> | 156:95d6b41a828b | 1593 | /* Prevent unused argument(s) compilation warning */ |
<> | 156:95d6b41a828b | 1594 | UNUSED(hsmartcard); |
<> | 156:95d6b41a828b | 1595 | |
<> | 156:95d6b41a828b | 1596 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 156:95d6b41a828b | 1597 | the HAL_SMARTCARD_AbortReceiveCpltCallback can be implemented in the user file. |
<> | 156:95d6b41a828b | 1598 | */ |
<> | 156:95d6b41a828b | 1599 | } |
<> | 156:95d6b41a828b | 1600 | |
<> | 156:95d6b41a828b | 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. |
<> | 144:ef7eb2e8f9f7 | 1626 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 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 | { |
<> | 156:95d6b41a828b | 1632 | /* Return SMARTCARD handle state */ |
<> | 156:95d6b41a828b | 1633 | uint32_t temp1= 0x00U, temp2 = 0x00U; |
<> | 144:ef7eb2e8f9f7 | 1634 | temp1 = hsmartcard->gState; |
<> | 144:ef7eb2e8f9f7 | 1635 | temp2 = hsmartcard->RxState; |
<> | 156:95d6b41a828b | 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. |
<> | 144:ef7eb2e8f9f7 | 1642 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 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 | |
<> | 156:95d6b41a828b | 1659 | /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions |
<> | 144:ef7eb2e8f9f7 | 1660 | * @{ |
<> | 144:ef7eb2e8f9f7 | 1661 | */ |
<> | 144:ef7eb2e8f9f7 | 1662 | |
<> | 144:ef7eb2e8f9f7 | 1663 | /** |
<> | 144:ef7eb2e8f9f7 | 1664 | * @brief Configure the SMARTCARD associated USART peripheral. |
Anna Bridge |
180:96ed750bd169 | 1665 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1666 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1667 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 1668 | */ |
<> | 144:ef7eb2e8f9f7 | 1669 | static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1670 | { |
<> | 156:95d6b41a828b | 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 ----------------------*/ |
<> | 156:95d6b41a828b | 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: |
<> | 156:95d6b41a828b | 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_HSI: |
<> | 156:95d6b41a828b | 1740 | hsmartcard->Instance->BRR = (uint16_t)((HSI_VALUE + (hsmartcard->Init.BaudRate/2U)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1741 | break; |
<> | 144:ef7eb2e8f9f7 | 1742 | case SMARTCARD_CLOCKSOURCE_SYSCLK: |
<> | 156:95d6b41a828b | 1743 | hsmartcard->Instance->BRR = (uint16_t)((HAL_RCC_GetSysClockFreq() + (hsmartcard->Init.BaudRate/2U)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1744 | break; |
<> | 144:ef7eb2e8f9f7 | 1745 | case SMARTCARD_CLOCKSOURCE_LSE: |
<> | 156:95d6b41a828b | 1746 | hsmartcard->Instance->BRR = (uint16_t)((LSE_VALUE + (hsmartcard->Init.BaudRate/2U)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1747 | break; |
<> | 144:ef7eb2e8f9f7 | 1748 | case SMARTCARD_CLOCKSOURCE_UNDEFINED: |
<> | 144:ef7eb2e8f9f7 | 1749 | default: |
<> | 144:ef7eb2e8f9f7 | 1750 | ret = HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 1751 | break; |
<> | 144:ef7eb2e8f9f7 | 1752 | } |
<> | 144:ef7eb2e8f9f7 | 1753 | |
<> | 144:ef7eb2e8f9f7 | 1754 | return ret; |
<> | 144:ef7eb2e8f9f7 | 1755 | } |
<> | 144:ef7eb2e8f9f7 | 1756 | |
<> | 144:ef7eb2e8f9f7 | 1757 | |
<> | 144:ef7eb2e8f9f7 | 1758 | /** |
<> | 144:ef7eb2e8f9f7 | 1759 | * @brief Configure the SMARTCARD associated USART peripheral advanced features. |
Anna Bridge |
180:96ed750bd169 | 1760 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1761 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1762 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 1763 | */ |
<> | 144:ef7eb2e8f9f7 | 1764 | static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1765 | { |
<> | 144:ef7eb2e8f9f7 | 1766 | /* Check whether the set of advanced features to configure is properly set */ |
<> | 144:ef7eb2e8f9f7 | 1767 | assert_param(IS_SMARTCARD_ADVFEATURE_INIT(hsmartcard->AdvancedInit.AdvFeatureInit)); |
<> | 144:ef7eb2e8f9f7 | 1768 | |
<> | 144:ef7eb2e8f9f7 | 1769 | /* if required, configure TX pin active level inversion */ |
<> | 144:ef7eb2e8f9f7 | 1770 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXINVERT_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1771 | { |
<> | 144:ef7eb2e8f9f7 | 1772 | assert_param(IS_SMARTCARD_ADVFEATURE_TXINV(hsmartcard->AdvancedInit.TxPinLevelInvert)); |
<> | 144:ef7eb2e8f9f7 | 1773 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_TXINV, hsmartcard->AdvancedInit.TxPinLevelInvert); |
<> | 144:ef7eb2e8f9f7 | 1774 | } |
<> | 144:ef7eb2e8f9f7 | 1775 | |
<> | 144:ef7eb2e8f9f7 | 1776 | /* if required, configure RX pin active level inversion */ |
<> | 144:ef7eb2e8f9f7 | 1777 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXINVERT_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1778 | { |
<> | 144:ef7eb2e8f9f7 | 1779 | assert_param(IS_SMARTCARD_ADVFEATURE_RXINV(hsmartcard->AdvancedInit.RxPinLevelInvert)); |
<> | 144:ef7eb2e8f9f7 | 1780 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_RXINV, hsmartcard->AdvancedInit.RxPinLevelInvert); |
<> | 144:ef7eb2e8f9f7 | 1781 | } |
<> | 144:ef7eb2e8f9f7 | 1782 | |
<> | 144:ef7eb2e8f9f7 | 1783 | /* if required, configure data inversion */ |
<> | 144:ef7eb2e8f9f7 | 1784 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DATAINVERT_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1785 | { |
<> | 144:ef7eb2e8f9f7 | 1786 | assert_param(IS_SMARTCARD_ADVFEATURE_DATAINV(hsmartcard->AdvancedInit.DataInvert)); |
<> | 144:ef7eb2e8f9f7 | 1787 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_DATAINV, hsmartcard->AdvancedInit.DataInvert); |
<> | 144:ef7eb2e8f9f7 | 1788 | } |
<> | 144:ef7eb2e8f9f7 | 1789 | |
<> | 144:ef7eb2e8f9f7 | 1790 | /* if required, configure RX/TX pins swap */ |
<> | 144:ef7eb2e8f9f7 | 1791 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_SWAP_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1792 | { |
<> | 144:ef7eb2e8f9f7 | 1793 | assert_param(IS_SMARTCARD_ADVFEATURE_SWAP(hsmartcard->AdvancedInit.Swap)); |
<> | 144:ef7eb2e8f9f7 | 1794 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_SWAP, hsmartcard->AdvancedInit.Swap); |
<> | 144:ef7eb2e8f9f7 | 1795 | } |
<> | 144:ef7eb2e8f9f7 | 1796 | |
<> | 144:ef7eb2e8f9f7 | 1797 | /* if required, configure RX overrun detection disabling */ |
<> | 144:ef7eb2e8f9f7 | 1798 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1799 | { |
<> | 144:ef7eb2e8f9f7 | 1800 | assert_param(IS_SMARTCARD_OVERRUN(hsmartcard->AdvancedInit.OverrunDisable)); |
<> | 144:ef7eb2e8f9f7 | 1801 | MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_OVRDIS, hsmartcard->AdvancedInit.OverrunDisable); |
<> | 144:ef7eb2e8f9f7 | 1802 | } |
<> | 144:ef7eb2e8f9f7 | 1803 | |
<> | 144:ef7eb2e8f9f7 | 1804 | /* if required, configure DMA disabling on reception error */ |
<> | 144:ef7eb2e8f9f7 | 1805 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1806 | { |
<> | 144:ef7eb2e8f9f7 | 1807 | assert_param(IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(hsmartcard->AdvancedInit.DMADisableonRxError)); |
<> | 144:ef7eb2e8f9f7 | 1808 | MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_DDRE, hsmartcard->AdvancedInit.DMADisableonRxError); |
<> | 144:ef7eb2e8f9f7 | 1809 | } |
<> | 144:ef7eb2e8f9f7 | 1810 | |
<> | 144:ef7eb2e8f9f7 | 1811 | /* if required, configure MSB first on communication line */ |
<> | 144:ef7eb2e8f9f7 | 1812 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_MSBFIRST_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1813 | { |
<> | 144:ef7eb2e8f9f7 | 1814 | assert_param(IS_SMARTCARD_ADVFEATURE_MSBFIRST(hsmartcard->AdvancedInit.MSBFirst)); |
<> | 144:ef7eb2e8f9f7 | 1815 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_MSBFIRST, hsmartcard->AdvancedInit.MSBFirst); |
<> | 144:ef7eb2e8f9f7 | 1816 | } |
<> | 144:ef7eb2e8f9f7 | 1817 | |
<> | 144:ef7eb2e8f9f7 | 1818 | } |
<> | 144:ef7eb2e8f9f7 | 1819 | |
<> | 144:ef7eb2e8f9f7 | 1820 | /** |
<> | 144:ef7eb2e8f9f7 | 1821 | * @brief Check the SMARTCARD Idle State. |
Anna Bridge |
180:96ed750bd169 | 1822 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1823 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1824 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 1825 | */ |
<> | 144:ef7eb2e8f9f7 | 1826 | static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1827 | { |
<> | 156:95d6b41a828b | 1828 | uint32_t tickstart = 0U; |
<> | 144:ef7eb2e8f9f7 | 1829 | |
<> | 144:ef7eb2e8f9f7 | 1830 | /* Initialize the SMARTCARD ErrorCode */ |
<> | 144:ef7eb2e8f9f7 | 1831 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 1832 | |
<> | 156:95d6b41a828b | 1833 | /* Init tickstart for timeout managment*/ |
<> | 156:95d6b41a828b | 1834 | tickstart = HAL_GetTick(); |
<> | 156:95d6b41a828b | 1835 | |
<> | 144:ef7eb2e8f9f7 | 1836 | /* TEACK and REACK bits in ISR are checked only when available (not available on all F0 devices). |
<> | 144:ef7eb2e8f9f7 | 1837 | Bits are defined for some specific devices, and are available only for UART instances supporting WakeUp from Stop Mode feature. |
<> | 144:ef7eb2e8f9f7 | 1838 | */ |
<> | 144:ef7eb2e8f9f7 | 1839 | #if !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) |
<> | 144:ef7eb2e8f9f7 | 1840 | if (IS_UART_WAKEUP_FROMSTOP_INSTANCE(hsmartcard->Instance)) |
<> | 144:ef7eb2e8f9f7 | 1841 | { |
<> | 144:ef7eb2e8f9f7 | 1842 | /* Check if the Transmitter is enabled */ |
<> | 144:ef7eb2e8f9f7 | 1843 | if((hsmartcard->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE) |
<> | 144:ef7eb2e8f9f7 | 1844 | { |
<> | 144:ef7eb2e8f9f7 | 1845 | /* Wait until TEACK flag is set */ |
<> | 156:95d6b41a828b | 1846 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_TEACK, RESET, tickstart, SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK) |
<> | 144:ef7eb2e8f9f7 | 1847 | { |
<> | 156:95d6b41a828b | 1848 | /* Timeout occurred */ |
<> | 144:ef7eb2e8f9f7 | 1849 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 1850 | } |
<> | 144:ef7eb2e8f9f7 | 1851 | } |
<> | 144:ef7eb2e8f9f7 | 1852 | |
<> | 144:ef7eb2e8f9f7 | 1853 | /* Check if the Receiver is enabled */ |
<> | 144:ef7eb2e8f9f7 | 1854 | if((hsmartcard->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE) |
<> | 144:ef7eb2e8f9f7 | 1855 | { |
<> | 144:ef7eb2e8f9f7 | 1856 | /* Wait until REACK flag is set */ |
<> | 156:95d6b41a828b | 1857 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_REACK, RESET, tickstart, SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK) |
<> | 144:ef7eb2e8f9f7 | 1858 | { |
<> | 156:95d6b41a828b | 1859 | /* Timeout occurred */ |
<> | 144:ef7eb2e8f9f7 | 1860 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 1861 | } |
<> | 144:ef7eb2e8f9f7 | 1862 | } |
<> | 144:ef7eb2e8f9f7 | 1863 | } |
<> | 144:ef7eb2e8f9f7 | 1864 | #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070xB)&& !defined(STM32F070x6)&& !defined(STM32F030xC) */ |
<> | 144:ef7eb2e8f9f7 | 1865 | |
<> | 144:ef7eb2e8f9f7 | 1866 | /* Initialize the SMARTCARD states */ |
<> | 144:ef7eb2e8f9f7 | 1867 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1868 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1869 | |
<> | 144:ef7eb2e8f9f7 | 1870 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 1871 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1872 | |
<> | 144:ef7eb2e8f9f7 | 1873 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1874 | } |
<> | 144:ef7eb2e8f9f7 | 1875 | |
<> | 144:ef7eb2e8f9f7 | 1876 | /** |
<> | 156:95d6b41a828b | 1877 | * @brief Handle SMARTCARD Communication Timeout. |
<> | 156:95d6b41a828b | 1878 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1879 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1880 | * @param Flag Specifies the SMARTCARD flag to check. |
<> | 156:95d6b41a828b | 1881 | * @param Status The new Flag status (SET or RESET). |
<> | 156:95d6b41a828b | 1882 | * @param Tickstart Tick start value |
<> | 156:95d6b41a828b | 1883 | * @param Timeout Timeout duration. |
<> | 156:95d6b41a828b | 1884 | * @retval HAL status |
<> | 156:95d6b41a828b | 1885 | */ |
<> | 156:95d6b41a828b | 1886 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Tickstart, uint32_t Timeout) |
<> | 156:95d6b41a828b | 1887 | { |
<> | 156:95d6b41a828b | 1888 | /* Wait until flag is set */ |
<> | 156:95d6b41a828b | 1889 | while((__HAL_SMARTCARD_GET_FLAG(hsmartcard, Flag) ? SET : RESET) == Status) |
<> | 156:95d6b41a828b | 1890 | { |
<> | 156:95d6b41a828b | 1891 | /* Check for the Timeout */ |
<> | 156:95d6b41a828b | 1892 | if(Timeout != HAL_MAX_DELAY) |
<> | 156:95d6b41a828b | 1893 | { |
<> | 156:95d6b41a828b | 1894 | if((Timeout == 0U) || ((HAL_GetTick()-Tickstart) > Timeout)) |
<> | 156:95d6b41a828b | 1895 | { |
<> | 156:95d6b41a828b | 1896 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
<> | 156:95d6b41a828b | 1897 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE | USART_CR1_TXEIE)); |
<> | 156:95d6b41a828b | 1898 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 1899 | |
<> | 156:95d6b41a828b | 1900 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1901 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1902 | |
<> | 156:95d6b41a828b | 1903 | /* Process Unlocked */ |
<> | 156:95d6b41a828b | 1904 | __HAL_UNLOCK(hsmartcard); |
<> | 156:95d6b41a828b | 1905 | return HAL_TIMEOUT; |
<> | 156:95d6b41a828b | 1906 | } |
<> | 156:95d6b41a828b | 1907 | } |
<> | 156:95d6b41a828b | 1908 | } |
<> | 156:95d6b41a828b | 1909 | return HAL_OK; |
<> | 156:95d6b41a828b | 1910 | } |
<> | 156:95d6b41a828b | 1911 | |
<> | 156:95d6b41a828b | 1912 | |
<> | 156:95d6b41a828b | 1913 | /** |
<> | 156:95d6b41a828b | 1914 | * @brief End ongoing Tx transfer on SMARTCARD peripheral (following error detection or Transmit completion). |
<> | 156:95d6b41a828b | 1915 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1916 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1917 | * @retval None |
<> | 156:95d6b41a828b | 1918 | */ |
<> | 156:95d6b41a828b | 1919 | static void SMARTCARD_EndTxTransfer(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1920 | { |
<> | 156:95d6b41a828b | 1921 | /* Disable TXEIE, TCIE and ERR (Frame error, noise error, overrun error) interrupts */ |
<> | 156:95d6b41a828b | 1922 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_TXEIE | USART_CR1_TCIE)); |
<> | 156:95d6b41a828b | 1923 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 1924 | |
<> | 156:95d6b41a828b | 1925 | /* At end of Tx process, restore hsmartcard->gState to Ready */ |
<> | 156:95d6b41a828b | 1926 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1927 | } |
<> | 156:95d6b41a828b | 1928 | |
<> | 156:95d6b41a828b | 1929 | |
<> | 156:95d6b41a828b | 1930 | /** |
<> | 156:95d6b41a828b | 1931 | * @brief End ongoing Rx transfer on UART peripheral (following error detection or Reception completion). |
<> | 156:95d6b41a828b | 1932 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1933 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 1934 | * @retval None |
<> | 156:95d6b41a828b | 1935 | */ |
<> | 156:95d6b41a828b | 1936 | static void SMARTCARD_EndRxTransfer(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 1937 | { |
<> | 156:95d6b41a828b | 1938 | /* Disable RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts */ |
<> | 156:95d6b41a828b | 1939 | CLEAR_BIT(hsmartcard->Instance->CR1, (USART_CR1_RXNEIE | USART_CR1_PEIE)); |
<> | 156:95d6b41a828b | 1940 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 1941 | |
<> | 156:95d6b41a828b | 1942 | /* At end of Rx process, restore hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 1943 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1944 | } |
<> | 156:95d6b41a828b | 1945 | |
<> | 156:95d6b41a828b | 1946 | |
<> | 156:95d6b41a828b | 1947 | /** |
<> | 156:95d6b41a828b | 1948 | * @brief DMA SMARTCARD transmit process complete callback. |
<> | 156:95d6b41a828b | 1949 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1950 | * the configuration information for the specified DMA module. |
<> | 156:95d6b41a828b | 1951 | * @retval None |
<> | 156:95d6b41a828b | 1952 | */ |
<> | 156:95d6b41a828b | 1953 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 1954 | { |
<> | 156:95d6b41a828b | 1955 | SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent); |
<> | 156:95d6b41a828b | 1956 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 1957 | |
<> | 156:95d6b41a828b | 1958 | /* Disable the DMA transfer for transmit request by resetting the DMAT bit |
<> | 156:95d6b41a828b | 1959 | in the SMARTCARD associated USART CR3 register */ |
<> | 156:95d6b41a828b | 1960 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 156:95d6b41a828b | 1961 | |
<> | 156:95d6b41a828b | 1962 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
<> | 156:95d6b41a828b | 1963 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_TC); |
<> | 156:95d6b41a828b | 1964 | } |
<> | 156:95d6b41a828b | 1965 | |
<> | 156:95d6b41a828b | 1966 | /** |
<> | 156:95d6b41a828b | 1967 | * @brief DMA SMARTCARD receive process complete callback. |
<> | 156:95d6b41a828b | 1968 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1969 | * the configuration information for the specified DMA module. |
<> | 156:95d6b41a828b | 1970 | * @retval None |
<> | 156:95d6b41a828b | 1971 | */ |
<> | 156:95d6b41a828b | 1972 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 1973 | { |
<> | 156:95d6b41a828b | 1974 | SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent); |
<> | 156:95d6b41a828b | 1975 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 1976 | |
<> | 156:95d6b41a828b | 1977 | /* Disable PE and ERR (Frame error, noise error, overrun error) interrupts */ |
<> | 156:95d6b41a828b | 1978 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE); |
<> | 156:95d6b41a828b | 1979 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 1980 | |
<> | 156:95d6b41a828b | 1981 | /* Disable the DMA transfer for the receiver request by resetting the DMAR bit |
<> | 156:95d6b41a828b | 1982 | in the SMARTCARD associated USART CR3 register */ |
<> | 156:95d6b41a828b | 1983 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 156:95d6b41a828b | 1984 | |
<> | 156:95d6b41a828b | 1985 | /* At end of Rx process, restore hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 1986 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 1987 | |
<> | 156:95d6b41a828b | 1988 | HAL_SMARTCARD_RxCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 1989 | } |
<> | 156:95d6b41a828b | 1990 | |
<> | 156:95d6b41a828b | 1991 | /** |
<> | 156:95d6b41a828b | 1992 | * @brief DMA SMARTCARD communication error callback. |
<> | 156:95d6b41a828b | 1993 | * @param hdma Pointer to a DMA_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 1994 | * the configuration information for the specified DMA module. |
<> | 156:95d6b41a828b | 1995 | * @retval None |
<> | 156:95d6b41a828b | 1996 | */ |
<> | 156:95d6b41a828b | 1997 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 1998 | { |
<> | 156:95d6b41a828b | 1999 | SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent); |
<> | 156:95d6b41a828b | 2000 | |
<> | 156:95d6b41a828b | 2001 | /* Stop SMARTCARD DMA Tx request if ongoing */ |
<> | 156:95d6b41a828b | 2002 | if ( (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX) |
<> | 156:95d6b41a828b | 2003 | &&(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAT)) ) |
<> | 156:95d6b41a828b | 2004 | { |
<> | 156:95d6b41a828b | 2005 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 2006 | SMARTCARD_EndTxTransfer(hsmartcard); |
<> | 156:95d6b41a828b | 2007 | } |
<> | 156:95d6b41a828b | 2008 | |
<> | 156:95d6b41a828b | 2009 | /* Stop SMARTCARD DMA Rx request if ongoing */ |
<> | 156:95d6b41a828b | 2010 | if ( (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX) |
<> | 156:95d6b41a828b | 2011 | &&(HAL_IS_BIT_SET(hsmartcard->Instance->CR3, USART_CR3_DMAR)) ) |
<> | 156:95d6b41a828b | 2012 | { |
<> | 156:95d6b41a828b | 2013 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 2014 | SMARTCARD_EndRxTransfer(hsmartcard); |
<> | 156:95d6b41a828b | 2015 | } |
<> | 156:95d6b41a828b | 2016 | |
<> | 156:95d6b41a828b | 2017 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_DMA; |
<> | 156:95d6b41a828b | 2018 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2019 | } |
<> | 156:95d6b41a828b | 2020 | |
<> | 156:95d6b41a828b | 2021 | /** |
<> | 156:95d6b41a828b | 2022 | * @brief DMA SMARTCARD communication abort callback, when initiated by HAL services on Error |
<> | 156:95d6b41a828b | 2023 | * (To be called at end of DMA Abort procedure following error occurrence). |
<> | 156:95d6b41a828b | 2024 | * @param hdma DMA handle. |
<> | 156:95d6b41a828b | 2025 | * @retval None |
<> | 156:95d6b41a828b | 2026 | */ |
<> | 156:95d6b41a828b | 2027 | static void SMARTCARD_DMAAbortOnError(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 2028 | { |
<> | 156:95d6b41a828b | 2029 | SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent); |
<> | 156:95d6b41a828b | 2030 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 2031 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 2032 | |
<> | 156:95d6b41a828b | 2033 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2034 | } |
<> | 156:95d6b41a828b | 2035 | |
<> | 156:95d6b41a828b | 2036 | /** |
<> | 156:95d6b41a828b | 2037 | * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user |
<> | 156:95d6b41a828b | 2038 | * (To be called at end of DMA Tx Abort procedure following user abort request). |
<> | 156:95d6b41a828b | 2039 | * @note When this callback is executed, User Abort complete call back is called only if no |
<> | 156:95d6b41a828b | 2040 | * Abort still ongoing for Rx DMA Handle. |
<> | 156:95d6b41a828b | 2041 | * @param hdma DMA handle. |
<> | 156:95d6b41a828b | 2042 | * @retval None |
<> | 156:95d6b41a828b | 2043 | */ |
<> | 156:95d6b41a828b | 2044 | static void SMARTCARD_DMATxAbortCallback(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 2045 | { |
<> | 156:95d6b41a828b | 2046 | SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef* )(hdma->Parent); |
<> | 156:95d6b41a828b | 2047 | |
<> | 156:95d6b41a828b | 2048 | hsmartcard->hdmatx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 2049 | |
<> | 156:95d6b41a828b | 2050 | /* Check if an Abort process is still ongoing */ |
<> | 156:95d6b41a828b | 2051 | if(hsmartcard->hdmarx != NULL) |
<> | 156:95d6b41a828b | 2052 | { |
<> | 156:95d6b41a828b | 2053 | if(hsmartcard->hdmarx->XferAbortCallback != NULL) |
<> | 156:95d6b41a828b | 2054 | { |
<> | 156:95d6b41a828b | 2055 | return; |
<> | 156:95d6b41a828b | 2056 | } |
<> | 156:95d6b41a828b | 2057 | } |
<> | 156:95d6b41a828b | 2058 | |
<> | 156:95d6b41a828b | 2059 | /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */ |
<> | 156:95d6b41a828b | 2060 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 2061 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 2062 | |
<> | 156:95d6b41a828b | 2063 | /* Reset errorCode */ |
<> | 156:95d6b41a828b | 2064 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 2065 | |
<> | 156:95d6b41a828b | 2066 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 2067 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF); |
<> | 156:95d6b41a828b | 2068 | |
<> | 156:95d6b41a828b | 2069 | /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 2070 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2071 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2072 | |
<> | 156:95d6b41a828b | 2073 | /* Call user Abort complete callback */ |
<> | 156:95d6b41a828b | 2074 | HAL_SMARTCARD_AbortCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2075 | } |
<> | 156:95d6b41a828b | 2076 | |
<> | 156:95d6b41a828b | 2077 | |
<> | 156:95d6b41a828b | 2078 | /** |
<> | 156:95d6b41a828b | 2079 | * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user |
<> | 156:95d6b41a828b | 2080 | * (To be called at end of DMA Rx Abort procedure following user abort request). |
<> | 156:95d6b41a828b | 2081 | * @note When this callback is executed, User Abort complete call back is called only if no |
<> | 156:95d6b41a828b | 2082 | * Abort still ongoing for Tx DMA Handle. |
<> | 156:95d6b41a828b | 2083 | * @param hdma DMA handle. |
<> | 156:95d6b41a828b | 2084 | * @retval None |
<> | 156:95d6b41a828b | 2085 | */ |
<> | 156:95d6b41a828b | 2086 | static void SMARTCARD_DMARxAbortCallback(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 2087 | { |
<> | 156:95d6b41a828b | 2088 | SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef* )(hdma->Parent); |
<> | 156:95d6b41a828b | 2089 | |
<> | 156:95d6b41a828b | 2090 | hsmartcard->hdmarx->XferAbortCallback = NULL; |
<> | 156:95d6b41a828b | 2091 | |
<> | 156:95d6b41a828b | 2092 | /* Check if an Abort process is still ongoing */ |
<> | 156:95d6b41a828b | 2093 | if(hsmartcard->hdmatx != NULL) |
<> | 156:95d6b41a828b | 2094 | { |
<> | 156:95d6b41a828b | 2095 | if(hsmartcard->hdmatx->XferAbortCallback != NULL) |
<> | 156:95d6b41a828b | 2096 | { |
<> | 156:95d6b41a828b | 2097 | return; |
<> | 156:95d6b41a828b | 2098 | } |
<> | 156:95d6b41a828b | 2099 | } |
<> | 156:95d6b41a828b | 2100 | |
<> | 156:95d6b41a828b | 2101 | /* No Abort process still ongoing : All DMA channels are aborted, call user Abort Complete callback */ |
<> | 156:95d6b41a828b | 2102 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 2103 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 2104 | |
<> | 156:95d6b41a828b | 2105 | /* Reset errorCode */ |
<> | 156:95d6b41a828b | 2106 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 156:95d6b41a828b | 2107 | |
<> | 156:95d6b41a828b | 2108 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 2109 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF); |
<> | 156:95d6b41a828b | 2110 | |
<> | 156:95d6b41a828b | 2111 | /* Restore hsmartcard->gState and hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 2112 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2113 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2114 | |
<> | 156:95d6b41a828b | 2115 | /* Call user Abort complete callback */ |
<> | 156:95d6b41a828b | 2116 | HAL_SMARTCARD_AbortCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2117 | } |
<> | 156:95d6b41a828b | 2118 | |
<> | 156:95d6b41a828b | 2119 | |
<> | 156:95d6b41a828b | 2120 | /** |
<> | 156:95d6b41a828b | 2121 | * @brief DMA SMARTCARD Tx communication abort callback, when initiated by user by a call to |
<> | 156:95d6b41a828b | 2122 | * HAL_SMARTCARD_AbortTransmit_IT API (Abort only Tx transfer) |
<> | 156:95d6b41a828b | 2123 | * (This callback is executed at end of DMA Tx Abort procedure following user abort request, |
<> | 156:95d6b41a828b | 2124 | * and leads to user Tx Abort Complete callback execution). |
<> | 156:95d6b41a828b | 2125 | * @param hdma DMA handle. |
<> | 156:95d6b41a828b | 2126 | * @retval None |
<> | 156:95d6b41a828b | 2127 | */ |
<> | 156:95d6b41a828b | 2128 | static void SMARTCARD_DMATxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 2129 | { |
<> | 156:95d6b41a828b | 2130 | SMARTCARD_HandleTypeDef* hsmartcard = (SMARTCARD_HandleTypeDef*)(hdma->Parent); |
<> | 156:95d6b41a828b | 2131 | |
<> | 156:95d6b41a828b | 2132 | hsmartcard->TxXferCount = 0U; |
<> | 156:95d6b41a828b | 2133 | |
<> | 156:95d6b41a828b | 2134 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 2135 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_FEF); |
<> | 156:95d6b41a828b | 2136 | |
<> | 156:95d6b41a828b | 2137 | /* Restore hsmartcard->gState to Ready */ |
<> | 156:95d6b41a828b | 2138 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2139 | |
<> | 156:95d6b41a828b | 2140 | /* Call user Abort complete callback */ |
<> | 156:95d6b41a828b | 2141 | HAL_SMARTCARD_AbortTransmitCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2142 | } |
<> | 156:95d6b41a828b | 2143 | |
<> | 156:95d6b41a828b | 2144 | /** |
<> | 156:95d6b41a828b | 2145 | * @brief DMA SMARTCARD Rx communication abort callback, when initiated by user by a call to |
<> | 156:95d6b41a828b | 2146 | * HAL_SMARTCARD_AbortReceive_IT API (Abort only Rx transfer) |
<> | 156:95d6b41a828b | 2147 | * (This callback is executed at end of DMA Rx Abort procedure following user abort request, |
<> | 156:95d6b41a828b | 2148 | * and leads to user Rx Abort Complete callback execution). |
<> | 156:95d6b41a828b | 2149 | * @param hdma DMA handle. |
<> | 156:95d6b41a828b | 2150 | * @retval None |
<> | 156:95d6b41a828b | 2151 | */ |
<> | 156:95d6b41a828b | 2152 | static void SMARTCARD_DMARxOnlyAbortCallback(DMA_HandleTypeDef *hdma) |
<> | 156:95d6b41a828b | 2153 | { |
<> | 156:95d6b41a828b | 2154 | SMARTCARD_HandleTypeDef* hsmartcard = ( SMARTCARD_HandleTypeDef* )(hdma->Parent); |
<> | 156:95d6b41a828b | 2155 | |
<> | 156:95d6b41a828b | 2156 | hsmartcard->RxXferCount = 0U; |
<> | 156:95d6b41a828b | 2157 | |
<> | 156:95d6b41a828b | 2158 | /* Clear the Error flags in the ICR register */ |
<> | 156:95d6b41a828b | 2159 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_OREF | SMARTCARD_CLEAR_NEF | SMARTCARD_CLEAR_PEF | SMARTCARD_CLEAR_FEF | SMARTCARD_CLEAR_RTOF | SMARTCARD_CLEAR_EOBF); |
<> | 156:95d6b41a828b | 2160 | |
<> | 156:95d6b41a828b | 2161 | /* Restore hsmartcard->RxState to Ready */ |
<> | 156:95d6b41a828b | 2162 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2163 | |
<> | 156:95d6b41a828b | 2164 | /* Call user Abort complete callback */ |
<> | 156:95d6b41a828b | 2165 | HAL_SMARTCARD_AbortReceiveCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2166 | } |
<> | 156:95d6b41a828b | 2167 | |
<> | 156:95d6b41a828b | 2168 | /** |
<> | 156:95d6b41a828b | 2169 | * @brief Send an amount of data in non-blocking mode. |
Anna Bridge |
180:96ed750bd169 | 2170 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 2171 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 2172 | * Function called under interruption only, once |
<> | 156:95d6b41a828b | 2173 | * interruptions have been enabled by HAL_SMARTCARD_Transmit_IT() |
<> | 156:95d6b41a828b | 2174 | * @retval HAL status |
<> | 156:95d6b41a828b | 2175 | */ |
<> | 156:95d6b41a828b | 2176 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 2177 | { |
<> | 156:95d6b41a828b | 2178 | /* Check that a Tx process is ongoing */ |
<> | 156:95d6b41a828b | 2179 | if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX) |
<> | 156:95d6b41a828b | 2180 | { |
<> | 156:95d6b41a828b | 2181 | if(hsmartcard->TxXferCount == 0U) |
<> | 156:95d6b41a828b | 2182 | { |
<> | 156:95d6b41a828b | 2183 | /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */ |
<> | 156:95d6b41a828b | 2184 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_TXEIE); |
<> | 156:95d6b41a828b | 2185 | |
<> | 156:95d6b41a828b | 2186 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
<> | 156:95d6b41a828b | 2187 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_TC); |
<> | 156:95d6b41a828b | 2188 | |
<> | 156:95d6b41a828b | 2189 | return HAL_OK; |
<> | 156:95d6b41a828b | 2190 | } |
<> | 156:95d6b41a828b | 2191 | else |
<> | 156:95d6b41a828b | 2192 | { |
<> | 156:95d6b41a828b | 2193 | hsmartcard->Instance->TDR = (*hsmartcard->pTxBuffPtr++ & (uint8_t)0xFFU); |
<> | 156:95d6b41a828b | 2194 | hsmartcard->TxXferCount--; |
<> | 156:95d6b41a828b | 2195 | |
<> | 156:95d6b41a828b | 2196 | return HAL_OK; |
<> | 156:95d6b41a828b | 2197 | } |
<> | 156:95d6b41a828b | 2198 | } |
<> | 156:95d6b41a828b | 2199 | else |
<> | 156:95d6b41a828b | 2200 | { |
<> | 156:95d6b41a828b | 2201 | return HAL_BUSY; |
<> | 156:95d6b41a828b | 2202 | } |
<> | 156:95d6b41a828b | 2203 | } |
<> | 156:95d6b41a828b | 2204 | |
<> | 156:95d6b41a828b | 2205 | /** |
<> | 156:95d6b41a828b | 2206 | * @brief Wrap up transmission in non-blocking mode. |
<> | 156:95d6b41a828b | 2207 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 2208 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 2209 | * @retval HAL status |
<> | 156:95d6b41a828b | 2210 | */ |
<> | 156:95d6b41a828b | 2211 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 2212 | { |
<> | 156:95d6b41a828b | 2213 | /* Disable the SMARTCARD Transmit Complete Interrupt */ |
<> | 156:95d6b41a828b | 2214 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TC); |
<> | 156:95d6b41a828b | 2215 | |
<> | 156:95d6b41a828b | 2216 | /* Check if a receive process is ongoing or not. If not disable ERR IT */ |
<> | 156:95d6b41a828b | 2217 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 156:95d6b41a828b | 2218 | { |
<> | 156:95d6b41a828b | 2219 | /* Disable the SMARTCARD Error Interrupt: (Frame error) */ |
<> | 156:95d6b41a828b | 2220 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 2221 | } |
<> | 156:95d6b41a828b | 2222 | |
<> | 156:95d6b41a828b | 2223 | /* Re-enable Rx at end of transmission if initial mode is Rx/Tx */ |
<> | 156:95d6b41a828b | 2224 | if(hsmartcard->Init.Mode == SMARTCARD_MODE_TX_RX) |
<> | 156:95d6b41a828b | 2225 | { |
<> | 156:95d6b41a828b | 2226 | /* Disable the Peripheral first to update modes */ |
<> | 156:95d6b41a828b | 2227 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 2228 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_RE); |
<> | 156:95d6b41a828b | 2229 | /* Enable the Peripheral */ |
<> | 156:95d6b41a828b | 2230 | SET_BIT(hsmartcard->Instance->CR1, USART_CR1_UE); |
<> | 156:95d6b41a828b | 2231 | } |
<> | 156:95d6b41a828b | 2232 | |
<> | 156:95d6b41a828b | 2233 | /* Tx process is ended, restore hsmartcard->gState to Ready */ |
<> | 156:95d6b41a828b | 2234 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2235 | |
<> | 156:95d6b41a828b | 2236 | HAL_SMARTCARD_TxCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2237 | |
<> | 156:95d6b41a828b | 2238 | return HAL_OK; |
<> | 156:95d6b41a828b | 2239 | } |
<> | 156:95d6b41a828b | 2240 | |
<> | 156:95d6b41a828b | 2241 | /** |
<> | 156:95d6b41a828b | 2242 | * @brief Receive an amount of data in non-blocking mode. |
Anna Bridge |
180:96ed750bd169 | 2243 | * @param hsmartcard Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 156:95d6b41a828b | 2244 | * the configuration information for the specified SMARTCARD module. |
<> | 156:95d6b41a828b | 2245 | * Function called under interruption only, once |
<> | 156:95d6b41a828b | 2246 | * interruptions have been enabled by HAL_SMARTCARD_Receive_IT(). |
<> | 156:95d6b41a828b | 2247 | * @retval HAL status |
<> | 156:95d6b41a828b | 2248 | */ |
<> | 156:95d6b41a828b | 2249 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 156:95d6b41a828b | 2250 | { |
<> | 156:95d6b41a828b | 2251 | /* Check that a Rx process is ongoing */ |
<> | 156:95d6b41a828b | 2252 | if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX) |
<> | 156:95d6b41a828b | 2253 | { |
<> | 156:95d6b41a828b | 2254 | *hsmartcard->pRxBuffPtr++ = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0xFFU); |
<> | 156:95d6b41a828b | 2255 | |
<> | 156:95d6b41a828b | 2256 | if(--hsmartcard->RxXferCount == 0U) |
<> | 156:95d6b41a828b | 2257 | { |
<> | 156:95d6b41a828b | 2258 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_RXNEIE); |
<> | 156:95d6b41a828b | 2259 | |
<> | 156:95d6b41a828b | 2260 | /* Check if a transmit process is ongoing or not. If not disable ERR IT */ |
<> | 156:95d6b41a828b | 2261 | if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 156:95d6b41a828b | 2262 | { |
<> | 156:95d6b41a828b | 2263 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 156:95d6b41a828b | 2264 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_EIE); |
<> | 156:95d6b41a828b | 2265 | } |
<> | 156:95d6b41a828b | 2266 | |
<> | 156:95d6b41a828b | 2267 | /* Disable the SMARTCARD Parity Error Interrupt */ |
<> | 156:95d6b41a828b | 2268 | CLEAR_BIT(hsmartcard->Instance->CR1, USART_CR1_PEIE); |
<> | 156:95d6b41a828b | 2269 | |
<> | 156:95d6b41a828b | 2270 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 156:95d6b41a828b | 2271 | |
<> | 156:95d6b41a828b | 2272 | HAL_SMARTCARD_RxCpltCallback(hsmartcard); |
<> | 156:95d6b41a828b | 2273 | |
<> | 156:95d6b41a828b | 2274 | return HAL_OK; |
<> | 156:95d6b41a828b | 2275 | } |
<> | 156:95d6b41a828b | 2276 | |
<> | 156:95d6b41a828b | 2277 | return HAL_OK; |
<> | 156:95d6b41a828b | 2278 | } |
<> | 156:95d6b41a828b | 2279 | else |
<> | 156:95d6b41a828b | 2280 | { |
<> | 156:95d6b41a828b | 2281 | /* Clear RXNE interrupt flag */ |
<> | 156:95d6b41a828b | 2282 | __HAL_SMARTCARD_SEND_REQ(hsmartcard, SMARTCARD_RXDATA_FLUSH_REQUEST); |
<> | 156:95d6b41a828b | 2283 | |
<> | 156:95d6b41a828b | 2284 | return HAL_BUSY; |
<> | 156:95d6b41a828b | 2285 | } |
<> | 156:95d6b41a828b | 2286 | } |
<> | 156:95d6b41a828b | 2287 | |
<> | 156:95d6b41a828b | 2288 | /** |
<> | 144:ef7eb2e8f9f7 | 2289 | * @} |
<> | 144:ef7eb2e8f9f7 | 2290 | */ |
<> | 144:ef7eb2e8f9f7 | 2291 | |
<> | 156:95d6b41a828b | 2292 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ |
<> | 144:ef7eb2e8f9f7 | 2293 | /** |
<> | 144:ef7eb2e8f9f7 | 2294 | * @} |
<> | 144:ef7eb2e8f9f7 | 2295 | */ |
<> | 144:ef7eb2e8f9f7 | 2296 | |
<> | 144:ef7eb2e8f9f7 | 2297 | /** |
<> | 144:ef7eb2e8f9f7 | 2298 | * @} |
<> | 144:ef7eb2e8f9f7 | 2299 | */ |
<> | 144:ef7eb2e8f9f7 | 2300 | |
<> | 144:ef7eb2e8f9f7 | 2301 | #endif /* !defined(STM32F030x6) && !defined(STM32F030x8)&& !defined(STM32F070x6) && !defined(STM32F070xB) && !defined(STM32F030xC) */ |
<> | 144:ef7eb2e8f9f7 | 2302 | |
<> | 144:ef7eb2e8f9f7 | 2303 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |