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