MBED-DEV only fro Nucleo STM32F303K8T6
Fork of mbed-dev by
targets/cmsis/TARGET_STM/TARGET_STM32F3/stm32f3xx_hal_smartcard.c@144:ef7eb2e8f9f7, 2016-09-02 (annotated)
- Committer:
- <>
- Date:
- Fri Sep 02 15:07:44 2016 +0100
- Revision:
- 144:ef7eb2e8f9f7
- Parent:
- 0:9b334a45a8ff
This updates the lib to the mbed lib v125
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /** |
<> | 144:ef7eb2e8f9f7 | 2 | ****************************************************************************** |
<> | 144:ef7eb2e8f9f7 | 3 | * @file stm32f3xx_hal_smartcard.c |
<> | 144:ef7eb2e8f9f7 | 4 | * @author MCD Application Team |
<> | 144:ef7eb2e8f9f7 | 5 | * @version V1.3.0 |
<> | 144:ef7eb2e8f9f7 | 6 | * @date 01-July-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 State and Errors functions |
<> | 144:ef7eb2e8f9f7 | 13 | * + Peripheral Control 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: |
<> | 144:ef7eb2e8f9f7 | 27 | (+++) Enable the clock for the USART GPIOs. |
<> | 144:ef7eb2e8f9f7 | 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): |
<> | 144:ef7eb2e8f9f7 | 31 | (+++) Configure the USARTx interrupt priority. |
<> | 144:ef7eb2e8f9f7 | 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): |
<> | 144:ef7eb2e8f9f7 | 35 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
<> | 144:ef7eb2e8f9f7 | 36 | (+++) Enable the DMAx interface clock. |
<> | 144:ef7eb2e8f9f7 | 37 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
<> | 144:ef7eb2e8f9f7 | 38 | (+++) Configure the DMA Tx/Rx channel. |
<> | 144:ef7eb2e8f9f7 | 39 | (+++) Associate the initialized DMA handle to the SMARTCARD DMA Tx/Rx handle. |
<> | 144:ef7eb2e8f9f7 | 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_ENABLE: Enable the SMARTCARD peripheral |
<> | 144:ef7eb2e8f9f7 | 96 | (+) __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral |
<> | 144:ef7eb2e8f9f7 | 97 | (+) __HAL_SMARTCARD_GET_FLAG : Check whether or not the specified SMARTCARD flag is set |
<> | 144:ef7eb2e8f9f7 | 98 | (+) __HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag |
<> | 144:ef7eb2e8f9f7 | 99 | (+) __HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt |
<> | 144:ef7eb2e8f9f7 | 100 | (+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt |
<> | 144:ef7eb2e8f9f7 | 101 | (+) __HAL_SMARTCARD_GET_IT_SOURCE: Check whether or not the specified SMARTCARD interrupt is enabled |
<> | 144:ef7eb2e8f9f7 | 102 | |
<> | 144:ef7eb2e8f9f7 | 103 | [..] |
<> | 144:ef7eb2e8f9f7 | 104 | (@) You can refer to the SMARTCARD HAL driver header file for more useful macros |
<> | 144:ef7eb2e8f9f7 | 105 | |
<> | 144:ef7eb2e8f9f7 | 106 | @endverbatim |
<> | 144:ef7eb2e8f9f7 | 107 | ****************************************************************************** |
<> | 144:ef7eb2e8f9f7 | 108 | * @attention |
<> | 144:ef7eb2e8f9f7 | 109 | * |
<> | 144:ef7eb2e8f9f7 | 110 | * <h2><center>© COPYRIGHT(c) 2016 STMicroelectronics</center></h2> |
<> | 144:ef7eb2e8f9f7 | 111 | * |
<> | 144:ef7eb2e8f9f7 | 112 | * Redistribution and use in source and binary forms, with or without modification, |
<> | 144:ef7eb2e8f9f7 | 113 | * are permitted provided that the following conditions are met: |
<> | 144:ef7eb2e8f9f7 | 114 | * 1. Redistributions of source code must retain the above copyright notice, |
<> | 144:ef7eb2e8f9f7 | 115 | * this list of conditions and the following disclaimer. |
<> | 144:ef7eb2e8f9f7 | 116 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
<> | 144:ef7eb2e8f9f7 | 117 | * this list of conditions and the following disclaimer in the documentation |
<> | 144:ef7eb2e8f9f7 | 118 | * and/or other materials provided with the distribution. |
<> | 144:ef7eb2e8f9f7 | 119 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
<> | 144:ef7eb2e8f9f7 | 120 | * may be used to endorse or promote products derived from this software |
<> | 144:ef7eb2e8f9f7 | 121 | * without specific prior written permission. |
<> | 144:ef7eb2e8f9f7 | 122 | * |
<> | 144:ef7eb2e8f9f7 | 123 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
<> | 144:ef7eb2e8f9f7 | 124 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
<> | 144:ef7eb2e8f9f7 | 125 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
<> | 144:ef7eb2e8f9f7 | 126 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
<> | 144:ef7eb2e8f9f7 | 127 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
<> | 144:ef7eb2e8f9f7 | 128 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
<> | 144:ef7eb2e8f9f7 | 129 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
<> | 144:ef7eb2e8f9f7 | 130 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
<> | 144:ef7eb2e8f9f7 | 131 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
<> | 144:ef7eb2e8f9f7 | 132 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
<> | 144:ef7eb2e8f9f7 | 133 | * |
<> | 144:ef7eb2e8f9f7 | 134 | ****************************************************************************** |
<> | 144:ef7eb2e8f9f7 | 135 | */ |
<> | 144:ef7eb2e8f9f7 | 136 | |
<> | 144:ef7eb2e8f9f7 | 137 | /* Includes ------------------------------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 138 | #include "stm32f3xx_hal.h" |
<> | 144:ef7eb2e8f9f7 | 139 | |
<> | 144:ef7eb2e8f9f7 | 140 | #ifdef HAL_SMARTCARD_MODULE_ENABLED |
<> | 144:ef7eb2e8f9f7 | 141 | |
<> | 144:ef7eb2e8f9f7 | 142 | /** @addtogroup STM32F3xx_HAL_Driver |
<> | 144:ef7eb2e8f9f7 | 143 | * @{ |
<> | 144:ef7eb2e8f9f7 | 144 | */ |
<> | 144:ef7eb2e8f9f7 | 145 | |
<> | 144:ef7eb2e8f9f7 | 146 | /** @defgroup SMARTCARD SMARTCARD |
<> | 144:ef7eb2e8f9f7 | 147 | * @brief SMARTCARD HAL module driver |
<> | 144:ef7eb2e8f9f7 | 148 | * @{ |
<> | 144:ef7eb2e8f9f7 | 149 | */ |
<> | 144:ef7eb2e8f9f7 | 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 | */ |
<> | 144:ef7eb2e8f9f7 | 156 | #define SMARTCARD_TEACK_REACK_TIMEOUT 1000 /*!< SMARTCARD TX or RX enable acknowledge time-out value */ |
<> | 144:ef7eb2e8f9f7 | 157 | #define SMARTCARD_TXDMA_TIMEOUTVALUE 22000 |
<> | 144:ef7eb2e8f9f7 | 158 | #define SMARTCARD_TIMEOUT_VALUE 22000 |
<> | 144:ef7eb2e8f9f7 | 159 | #define USART_CR1_FIELDS ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | \ |
<> | 144:ef7eb2e8f9f7 | 160 | USART_CR1_TE | USART_CR1_RE | USART_CR1_OVER8)) /*!< USART CR1 fields of parameters set by SMARTCARD_SetConfig API */ |
<> | 144:ef7eb2e8f9f7 | 161 | #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 | 162 | #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 | 163 | #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 | 164 | /** |
<> | 144:ef7eb2e8f9f7 | 165 | * @} |
<> | 144:ef7eb2e8f9f7 | 166 | */ |
<> | 144:ef7eb2e8f9f7 | 167 | |
<> | 144:ef7eb2e8f9f7 | 168 | /* Private macros ------------------------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 169 | /* Private variables ---------------------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 170 | /* Private function prototypes -----------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 171 | /** @addtogroup SMARTCARD_Private_Functions SMARTCARD Private Functions |
<> | 144:ef7eb2e8f9f7 | 172 | * @{ |
<> | 144:ef7eb2e8f9f7 | 173 | */ |
<> | 144:ef7eb2e8f9f7 | 174 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
<> | 144:ef7eb2e8f9f7 | 175 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
<> | 144:ef7eb2e8f9f7 | 176 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma); |
<> | 144:ef7eb2e8f9f7 | 177 | static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 178 | static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 179 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Timeout); |
<> | 144:ef7eb2e8f9f7 | 180 | static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 181 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 182 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 183 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 184 | /** |
<> | 144:ef7eb2e8f9f7 | 185 | * @} |
<> | 144:ef7eb2e8f9f7 | 186 | */ |
<> | 144:ef7eb2e8f9f7 | 187 | |
<> | 144:ef7eb2e8f9f7 | 188 | /* Exported functions --------------------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 189 | |
<> | 144:ef7eb2e8f9f7 | 190 | /** @defgroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions |
<> | 144:ef7eb2e8f9f7 | 191 | * @{ |
<> | 144:ef7eb2e8f9f7 | 192 | */ |
<> | 144:ef7eb2e8f9f7 | 193 | |
<> | 144:ef7eb2e8f9f7 | 194 | /** @defgroup SMARTCARD_Exported_Functions_Group1 Initialization and de-initialization functions |
<> | 144:ef7eb2e8f9f7 | 195 | * @brief Initialization and Configuration functions |
<> | 144:ef7eb2e8f9f7 | 196 | * |
<> | 144:ef7eb2e8f9f7 | 197 | @verbatim |
<> | 144:ef7eb2e8f9f7 | 198 | =============================================================================== |
<> | 144:ef7eb2e8f9f7 | 199 | ##### Initialization and Configuration functions ##### |
<> | 144:ef7eb2e8f9f7 | 200 | =============================================================================== |
<> | 144:ef7eb2e8f9f7 | 201 | [..] |
<> | 144:ef7eb2e8f9f7 | 202 | This subsection provides a set of functions allowing to initialize the USARTx |
<> | 144:ef7eb2e8f9f7 | 203 | associated to the SmartCard. |
<> | 144:ef7eb2e8f9f7 | 204 | [..] |
<> | 144:ef7eb2e8f9f7 | 205 | The Smartcard interface is designed to support asynchronous protocol Smartcards as |
<> | 144:ef7eb2e8f9f7 | 206 | defined in the ISO 7816-3 standard. |
<> | 144:ef7eb2e8f9f7 | 207 | [..] |
<> | 144:ef7eb2e8f9f7 | 208 | The USART can provide a clock to the smartcard through the SCLK output. |
<> | 144:ef7eb2e8f9f7 | 209 | In smartcard mode, SCLK is not associated to the communication but is simply derived |
<> | 144:ef7eb2e8f9f7 | 210 | from the internal peripheral input clock through a 5-bit prescaler. |
<> | 144:ef7eb2e8f9f7 | 211 | [..] |
<> | 144:ef7eb2e8f9f7 | 212 | (+) These parameters can be configured: |
<> | 144:ef7eb2e8f9f7 | 213 | (++) Baud Rate |
<> | 144:ef7eb2e8f9f7 | 214 | (++) Parity: should be enabled |
<> | 144:ef7eb2e8f9f7 | 215 | (++) Receiver/transmitter modes |
<> | 144:ef7eb2e8f9f7 | 216 | (++) Synchronous mode (and if enabled, phase, polarity and last bit parameters) |
<> | 144:ef7eb2e8f9f7 | 217 | (++) Prescaler value |
<> | 144:ef7eb2e8f9f7 | 218 | (++) Guard bit time |
<> | 144:ef7eb2e8f9f7 | 219 | (++) NACK enabling or disabling on transmission error |
<> | 144:ef7eb2e8f9f7 | 220 | |
<> | 144:ef7eb2e8f9f7 | 221 | (+) The following advanced features can be configured as well: |
<> | 144:ef7eb2e8f9f7 | 222 | (++) TX and/or RX pin level inversion |
<> | 144:ef7eb2e8f9f7 | 223 | (++) data logical level inversion |
<> | 144:ef7eb2e8f9f7 | 224 | (++) RX and TX pins swap |
<> | 144:ef7eb2e8f9f7 | 225 | (++) RX overrun detection disabling |
<> | 144:ef7eb2e8f9f7 | 226 | (++) DMA disabling on RX error |
<> | 144:ef7eb2e8f9f7 | 227 | (++) MSB first on communication line |
<> | 144:ef7eb2e8f9f7 | 228 | (++) Time out enabling (and if activated, timeout value) |
<> | 144:ef7eb2e8f9f7 | 229 | (++) Block length |
<> | 144:ef7eb2e8f9f7 | 230 | (++) Auto-retry counter |
<> | 144:ef7eb2e8f9f7 | 231 | [..] |
<> | 144:ef7eb2e8f9f7 | 232 | The HAL_SMARTCARD_Init() API follows the USART synchronous configuration procedures |
<> | 144:ef7eb2e8f9f7 | 233 | (details for the procedures are available in reference manual). |
<> | 144:ef7eb2e8f9f7 | 234 | |
<> | 144:ef7eb2e8f9f7 | 235 | @endverbatim |
<> | 144:ef7eb2e8f9f7 | 236 | * @{ |
<> | 144:ef7eb2e8f9f7 | 237 | */ |
<> | 144:ef7eb2e8f9f7 | 238 | |
<> | 144:ef7eb2e8f9f7 | 239 | /* |
<> | 144:ef7eb2e8f9f7 | 240 | Additional Table: |
<> | 144:ef7eb2e8f9f7 | 241 | Frame Length is fixed to 8 bits plus parity: |
<> | 144:ef7eb2e8f9f7 | 242 | SMARTCARD frame format is given in the following table: |
<> | 144:ef7eb2e8f9f7 | 243 | +---------------------------------------------------------------+ |
<> | 144:ef7eb2e8f9f7 | 244 | | M bit | PCE bit | SMARTCARD frame | |
<> | 144:ef7eb2e8f9f7 | 245 | |---------------------|-----------------------------------------| |
<> | 144:ef7eb2e8f9f7 | 246 | | 1 | 1 | | SB | 8 bit data | PB | STB | | |
<> | 144:ef7eb2e8f9f7 | 247 | +---------------------------------------------------------------+ |
<> | 144:ef7eb2e8f9f7 | 248 | or |
<> | 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 | |
<> | 144:ef7eb2e8f9f7 | 272 | /* Check the USART associated to the SmartCard */ |
<> | 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 | |
<> | 144:ef7eb2e8f9f7 | 286 | /* Disable the Peripheral */ |
<> | 144:ef7eb2e8f9f7 | 287 | __HAL_SMARTCARD_DISABLE(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 288 | |
<> | 144:ef7eb2e8f9f7 | 289 | /* Set the SMARTCARD Communication parameters */ |
<> | 144:ef7eb2e8f9f7 | 290 | if (SMARTCARD_SetConfig(hsmartcard) == HAL_ERROR) |
<> | 144:ef7eb2e8f9f7 | 291 | { |
<> | 144:ef7eb2e8f9f7 | 292 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 293 | } |
<> | 144:ef7eb2e8f9f7 | 294 | |
<> | 144:ef7eb2e8f9f7 | 295 | if (hsmartcard->AdvancedInit.AdvFeatureInit != SMARTCARD_ADVFEATURE_NO_INIT) |
<> | 144:ef7eb2e8f9f7 | 296 | { |
<> | 144:ef7eb2e8f9f7 | 297 | SMARTCARD_AdvFeatureConfig(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 298 | } |
<> | 144:ef7eb2e8f9f7 | 299 | |
<> | 144:ef7eb2e8f9f7 | 300 | /* In SmartCard mode, the following bits must be kept cleared: |
<> | 144:ef7eb2e8f9f7 | 301 | - LINEN in the USART_CR2 register, |
<> | 144:ef7eb2e8f9f7 | 302 | - HDSEL and IREN bits in the USART_CR3 register.*/ |
<> | 144:ef7eb2e8f9f7 | 303 | hsmartcard->Instance->CR2 &= ~(USART_CR2_LINEN); |
<> | 144:ef7eb2e8f9f7 | 304 | hsmartcard->Instance->CR3 &= ~(USART_CR3_HDSEL | USART_CR3_IREN); |
<> | 144:ef7eb2e8f9f7 | 305 | |
<> | 144:ef7eb2e8f9f7 | 306 | /* set the USART in SMARTCARD mode */ |
<> | 144:ef7eb2e8f9f7 | 307 | hsmartcard->Instance->CR3 |= USART_CR3_SCEN; |
<> | 144:ef7eb2e8f9f7 | 308 | |
<> | 144:ef7eb2e8f9f7 | 309 | /* Enable the Peripheral */ |
<> | 144:ef7eb2e8f9f7 | 310 | __HAL_SMARTCARD_ENABLE(hsmartcard); |
<> | 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 | /** |
<> | 144:ef7eb2e8f9f7 | 318 | * @brief DeInitialize the SMARTCARD peripheral. |
<> | 144:ef7eb2e8f9f7 | 319 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 320 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 321 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 322 | */ |
<> | 144:ef7eb2e8f9f7 | 323 | HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 324 | { |
<> | 144:ef7eb2e8f9f7 | 325 | /* Check the SMARTCARD handle allocation */ |
<> | 144:ef7eb2e8f9f7 | 326 | if(hsmartcard == NULL) |
<> | 144:ef7eb2e8f9f7 | 327 | { |
<> | 144:ef7eb2e8f9f7 | 328 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 329 | } |
<> | 144:ef7eb2e8f9f7 | 330 | |
<> | 144:ef7eb2e8f9f7 | 331 | /* Check the parameters */ |
<> | 144:ef7eb2e8f9f7 | 332 | assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance)); |
<> | 144:ef7eb2e8f9f7 | 333 | |
<> | 144:ef7eb2e8f9f7 | 334 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY; |
<> | 144:ef7eb2e8f9f7 | 335 | |
<> | 144:ef7eb2e8f9f7 | 336 | /* Disable the Peripheral */ |
<> | 144:ef7eb2e8f9f7 | 337 | __HAL_SMARTCARD_DISABLE(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 338 | |
<> | 144:ef7eb2e8f9f7 | 339 | hsmartcard->Instance->CR1 = 0x0; |
<> | 144:ef7eb2e8f9f7 | 340 | hsmartcard->Instance->CR2 = 0x0; |
<> | 144:ef7eb2e8f9f7 | 341 | hsmartcard->Instance->CR3 = 0x0; |
<> | 144:ef7eb2e8f9f7 | 342 | hsmartcard->Instance->RTOR = 0x0; |
<> | 144:ef7eb2e8f9f7 | 343 | hsmartcard->Instance->GTPR = 0x0; |
<> | 144:ef7eb2e8f9f7 | 344 | |
<> | 144:ef7eb2e8f9f7 | 345 | /* DeInit the low level hardware */ |
<> | 144:ef7eb2e8f9f7 | 346 | HAL_SMARTCARD_MspDeInit(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 347 | |
<> | 144:ef7eb2e8f9f7 | 348 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 349 | hsmartcard->gState = HAL_SMARTCARD_STATE_RESET; |
<> | 144:ef7eb2e8f9f7 | 350 | hsmartcard->RxState = HAL_SMARTCARD_STATE_RESET; |
<> | 144:ef7eb2e8f9f7 | 351 | |
<> | 144:ef7eb2e8f9f7 | 352 | /* Process Unlock */ |
<> | 144:ef7eb2e8f9f7 | 353 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 354 | |
<> | 144:ef7eb2e8f9f7 | 355 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 356 | } |
<> | 144:ef7eb2e8f9f7 | 357 | |
<> | 144:ef7eb2e8f9f7 | 358 | /** |
<> | 144:ef7eb2e8f9f7 | 359 | * @brief Initialize the SMARTCARD MSP. |
<> | 144:ef7eb2e8f9f7 | 360 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 361 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 362 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 363 | */ |
<> | 144:ef7eb2e8f9f7 | 364 | __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 365 | { |
<> | 144:ef7eb2e8f9f7 | 366 | /* Prevent unused argument(s) compilation warning */ |
<> | 144:ef7eb2e8f9f7 | 367 | UNUSED(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 368 | |
<> | 144:ef7eb2e8f9f7 | 369 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 144:ef7eb2e8f9f7 | 370 | the HAL_SMARTCARD_MspInit can be implemented in the user file |
<> | 144:ef7eb2e8f9f7 | 371 | */ |
<> | 144:ef7eb2e8f9f7 | 372 | } |
<> | 144:ef7eb2e8f9f7 | 373 | |
<> | 144:ef7eb2e8f9f7 | 374 | /** |
<> | 144:ef7eb2e8f9f7 | 375 | * @brief DeInitialize the SMARTCARD MSP. |
<> | 144:ef7eb2e8f9f7 | 376 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 377 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 378 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 379 | */ |
<> | 144:ef7eb2e8f9f7 | 380 | __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 381 | { |
<> | 144:ef7eb2e8f9f7 | 382 | /* Prevent unused argument(s) compilation warning */ |
<> | 144:ef7eb2e8f9f7 | 383 | UNUSED(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 384 | |
<> | 144:ef7eb2e8f9f7 | 385 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 144:ef7eb2e8f9f7 | 386 | the HAL_SMARTCARD_MspDeInit can be implemented in the user file |
<> | 144:ef7eb2e8f9f7 | 387 | */ |
<> | 144:ef7eb2e8f9f7 | 388 | } |
<> | 144:ef7eb2e8f9f7 | 389 | |
<> | 144:ef7eb2e8f9f7 | 390 | /** |
<> | 144:ef7eb2e8f9f7 | 391 | * @} |
<> | 144:ef7eb2e8f9f7 | 392 | */ |
<> | 144:ef7eb2e8f9f7 | 393 | |
<> | 144:ef7eb2e8f9f7 | 394 | /** @defgroup SMARTCARD_Exported_Functions_Group2 IO operation functions |
<> | 144:ef7eb2e8f9f7 | 395 | * @brief SMARTCARD Transmit and Receive functions |
<> | 144:ef7eb2e8f9f7 | 396 | * |
<> | 144:ef7eb2e8f9f7 | 397 | @verbatim |
<> | 144:ef7eb2e8f9f7 | 398 | ============================================================================== |
<> | 144:ef7eb2e8f9f7 | 399 | ##### IO operation functions ##### |
<> | 144:ef7eb2e8f9f7 | 400 | ============================================================================== |
<> | 144:ef7eb2e8f9f7 | 401 | [..] |
<> | 144:ef7eb2e8f9f7 | 402 | This subsection provides a set of functions allowing to manage the SMARTCARD data transfers. |
<> | 144:ef7eb2e8f9f7 | 403 | |
<> | 144:ef7eb2e8f9f7 | 404 | [..] |
<> | 144:ef7eb2e8f9f7 | 405 | Smartcard is a single wire half duplex communication protocol. |
<> | 144:ef7eb2e8f9f7 | 406 | The Smartcard interface is designed to support asynchronous protocol Smartcards as |
<> | 144:ef7eb2e8f9f7 | 407 | defined in the ISO 7816-3 standard. The USART should be configured as: |
<> | 144:ef7eb2e8f9f7 | 408 | (+) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register |
<> | 144:ef7eb2e8f9f7 | 409 | (+) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register. |
<> | 144:ef7eb2e8f9f7 | 410 | |
<> | 144:ef7eb2e8f9f7 | 411 | [..] |
<> | 144:ef7eb2e8f9f7 | 412 | (+) There are two modes of transfer: |
<> | 144:ef7eb2e8f9f7 | 413 | (++) Blocking mode: The communication is performed in polling mode. |
<> | 144:ef7eb2e8f9f7 | 414 | The HAL status of all data processing is returned by the same function |
<> | 144:ef7eb2e8f9f7 | 415 | after finishing transfer. |
<> | 144:ef7eb2e8f9f7 | 416 | (++) No-Blocking mode: The communication is performed using Interrupts |
<> | 144:ef7eb2e8f9f7 | 417 | or DMA, the relevant API's return the HAL status. |
<> | 144:ef7eb2e8f9f7 | 418 | The end of the data processing will be indicated through the |
<> | 144:ef7eb2e8f9f7 | 419 | dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when |
<> | 144:ef7eb2e8f9f7 | 420 | using DMA mode. |
<> | 144:ef7eb2e8f9f7 | 421 | (++) The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks |
<> | 144:ef7eb2e8f9f7 | 422 | will be executed respectively at the end of the Transmit or Receive process |
<> | 144:ef7eb2e8f9f7 | 423 | The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication |
<> | 144:ef7eb2e8f9f7 | 424 | error is detected. |
<> | 144:ef7eb2e8f9f7 | 425 | |
<> | 144:ef7eb2e8f9f7 | 426 | (+) Blocking mode APIs are : |
<> | 144:ef7eb2e8f9f7 | 427 | (++) HAL_SMARTCARD_Transmit() |
<> | 144:ef7eb2e8f9f7 | 428 | (++) HAL_SMARTCARD_Receive() |
<> | 144:ef7eb2e8f9f7 | 429 | |
<> | 144:ef7eb2e8f9f7 | 430 | (+) Non Blocking mode APIs with Interrupt are : |
<> | 144:ef7eb2e8f9f7 | 431 | (++) HAL_SMARTCARD_Transmit_IT() |
<> | 144:ef7eb2e8f9f7 | 432 | (++) HAL_SMARTCARD_Receive_IT() |
<> | 144:ef7eb2e8f9f7 | 433 | (++) HAL_SMARTCARD_IRQHandler() |
<> | 144:ef7eb2e8f9f7 | 434 | |
<> | 144:ef7eb2e8f9f7 | 435 | (+) Non Blocking mode functions with DMA are : |
<> | 144:ef7eb2e8f9f7 | 436 | (++) HAL_SMARTCARD_Transmit_DMA() |
<> | 144:ef7eb2e8f9f7 | 437 | (++) HAL_SMARTCARD_Receive_DMA() |
<> | 144:ef7eb2e8f9f7 | 438 | |
<> | 144:ef7eb2e8f9f7 | 439 | (+) A set of Transfer Complete Callbacks are provided in non Blocking mode: |
<> | 144:ef7eb2e8f9f7 | 440 | (++) HAL_SMARTCARD_TxCpltCallback() |
<> | 144:ef7eb2e8f9f7 | 441 | (++) HAL_SMARTCARD_RxCpltCallback() |
<> | 144:ef7eb2e8f9f7 | 442 | (++) HAL_SMARTCARD_ErrorCallback() |
<> | 144:ef7eb2e8f9f7 | 443 | |
<> | 144:ef7eb2e8f9f7 | 444 | @endverbatim |
<> | 144:ef7eb2e8f9f7 | 445 | * @{ |
<> | 144:ef7eb2e8f9f7 | 446 | */ |
<> | 144:ef7eb2e8f9f7 | 447 | |
<> | 144:ef7eb2e8f9f7 | 448 | /** |
<> | 144:ef7eb2e8f9f7 | 449 | * @brief Send an amount of data in blocking mode. |
<> | 144:ef7eb2e8f9f7 | 450 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 451 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 452 | * @param pData: pointer to data buffer. |
<> | 144:ef7eb2e8f9f7 | 453 | * @param Size: amount of data to be sent. |
<> | 144:ef7eb2e8f9f7 | 454 | * @param Timeout : Timeout duration. |
<> | 144:ef7eb2e8f9f7 | 455 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 456 | */ |
<> | 144:ef7eb2e8f9f7 | 457 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
<> | 144:ef7eb2e8f9f7 | 458 | { |
<> | 144:ef7eb2e8f9f7 | 459 | /* Check that a Tx process is not already ongoing */ |
<> | 144:ef7eb2e8f9f7 | 460 | if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 461 | { |
<> | 144:ef7eb2e8f9f7 | 462 | if((pData == NULL) || (Size == 0)) |
<> | 144:ef7eb2e8f9f7 | 463 | { |
<> | 144:ef7eb2e8f9f7 | 464 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 465 | } |
<> | 144:ef7eb2e8f9f7 | 466 | |
<> | 144:ef7eb2e8f9f7 | 467 | /* Process Locked */ |
<> | 144:ef7eb2e8f9f7 | 468 | __HAL_LOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 469 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 470 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 144:ef7eb2e8f9f7 | 471 | |
<> | 144:ef7eb2e8f9f7 | 472 | hsmartcard->TxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 473 | hsmartcard->TxXferCount = Size; |
<> | 144:ef7eb2e8f9f7 | 474 | while(hsmartcard->TxXferCount > 0) |
<> | 144:ef7eb2e8f9f7 | 475 | { |
<> | 144:ef7eb2e8f9f7 | 476 | hsmartcard->TxXferCount--; |
<> | 144:ef7eb2e8f9f7 | 477 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_TXE, RESET, Timeout) != HAL_OK) |
<> | 144:ef7eb2e8f9f7 | 478 | { |
<> | 144:ef7eb2e8f9f7 | 479 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 480 | } |
<> | 144:ef7eb2e8f9f7 | 481 | hsmartcard->Instance->TDR = (*pData++ & (uint8_t)0xFF); |
<> | 144:ef7eb2e8f9f7 | 482 | } |
<> | 144:ef7eb2e8f9f7 | 483 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_TC, RESET, Timeout) != HAL_OK) |
<> | 144:ef7eb2e8f9f7 | 484 | { |
<> | 144:ef7eb2e8f9f7 | 485 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 486 | } |
<> | 144:ef7eb2e8f9f7 | 487 | |
<> | 144:ef7eb2e8f9f7 | 488 | /* At end of Tx process, restore hsmartcard->gState to Ready */ |
<> | 144:ef7eb2e8f9f7 | 489 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 490 | |
<> | 144:ef7eb2e8f9f7 | 491 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 492 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 493 | |
<> | 144:ef7eb2e8f9f7 | 494 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 495 | } |
<> | 144:ef7eb2e8f9f7 | 496 | else |
<> | 144:ef7eb2e8f9f7 | 497 | { |
<> | 144:ef7eb2e8f9f7 | 498 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 499 | } |
<> | 144:ef7eb2e8f9f7 | 500 | } |
<> | 144:ef7eb2e8f9f7 | 501 | |
<> | 144:ef7eb2e8f9f7 | 502 | /** |
<> | 144:ef7eb2e8f9f7 | 503 | * @brief Receive an amount of data in blocking mode. |
<> | 144:ef7eb2e8f9f7 | 504 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 505 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 506 | * @param pData: pointer to data buffer. |
<> | 144:ef7eb2e8f9f7 | 507 | * @param Size: amount of data to be received. |
<> | 144:ef7eb2e8f9f7 | 508 | * @param Timeout : Timeout duration. |
<> | 144:ef7eb2e8f9f7 | 509 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 510 | */ |
<> | 144:ef7eb2e8f9f7 | 511 | HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
<> | 144:ef7eb2e8f9f7 | 512 | { |
<> | 144:ef7eb2e8f9f7 | 513 | /* Check that a Rx process is not already ongoing */ |
<> | 144:ef7eb2e8f9f7 | 514 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 515 | { |
<> | 144:ef7eb2e8f9f7 | 516 | if((pData == NULL) || (Size == 0)) |
<> | 144:ef7eb2e8f9f7 | 517 | { |
<> | 144:ef7eb2e8f9f7 | 518 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 519 | } |
<> | 144:ef7eb2e8f9f7 | 520 | |
<> | 144:ef7eb2e8f9f7 | 521 | /* Process Locked */ |
<> | 144:ef7eb2e8f9f7 | 522 | __HAL_LOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 523 | |
<> | 144:ef7eb2e8f9f7 | 524 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 525 | hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 144:ef7eb2e8f9f7 | 526 | |
<> | 144:ef7eb2e8f9f7 | 527 | hsmartcard->RxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 528 | hsmartcard->RxXferCount = Size; |
<> | 144:ef7eb2e8f9f7 | 529 | /* Check the remain data to be received */ |
<> | 144:ef7eb2e8f9f7 | 530 | while(hsmartcard->RxXferCount > 0) |
<> | 144:ef7eb2e8f9f7 | 531 | { |
<> | 144:ef7eb2e8f9f7 | 532 | hsmartcard->RxXferCount--; |
<> | 144:ef7eb2e8f9f7 | 533 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, SMARTCARD_FLAG_RXNE, RESET, Timeout) != HAL_OK) |
<> | 144:ef7eb2e8f9f7 | 534 | { |
<> | 144:ef7eb2e8f9f7 | 535 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 536 | } |
<> | 144:ef7eb2e8f9f7 | 537 | *pData++ = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0x00FF); |
<> | 144:ef7eb2e8f9f7 | 538 | } |
<> | 144:ef7eb2e8f9f7 | 539 | |
<> | 144:ef7eb2e8f9f7 | 540 | /* At end of Rx process, restore hsmartcard->RxState to Ready */ |
<> | 144:ef7eb2e8f9f7 | 541 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 542 | |
<> | 144:ef7eb2e8f9f7 | 543 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 544 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 545 | |
<> | 144:ef7eb2e8f9f7 | 546 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 547 | } |
<> | 144:ef7eb2e8f9f7 | 548 | else |
<> | 144:ef7eb2e8f9f7 | 549 | { |
<> | 144:ef7eb2e8f9f7 | 550 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 551 | } |
<> | 144:ef7eb2e8f9f7 | 552 | } |
<> | 144:ef7eb2e8f9f7 | 553 | |
<> | 144:ef7eb2e8f9f7 | 554 | /** |
<> | 144:ef7eb2e8f9f7 | 555 | * @brief Send an amount of data in interrupt mode. |
<> | 144:ef7eb2e8f9f7 | 556 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 557 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 558 | * @param pData: pointer to data buffer. |
<> | 144:ef7eb2e8f9f7 | 559 | * @param Size: amount of data to be sent. |
<> | 144:ef7eb2e8f9f7 | 560 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 561 | */ |
<> | 144:ef7eb2e8f9f7 | 562 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size) |
<> | 144:ef7eb2e8f9f7 | 563 | { |
<> | 144:ef7eb2e8f9f7 | 564 | /* Check that a Tx process is not already ongoing */ |
<> | 144:ef7eb2e8f9f7 | 565 | if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 566 | { |
<> | 144:ef7eb2e8f9f7 | 567 | if((pData == NULL) || (Size == 0)) |
<> | 144:ef7eb2e8f9f7 | 568 | { |
<> | 144:ef7eb2e8f9f7 | 569 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 570 | } |
<> | 144:ef7eb2e8f9f7 | 571 | |
<> | 144:ef7eb2e8f9f7 | 572 | /* Process Locked */ |
<> | 144:ef7eb2e8f9f7 | 573 | __HAL_LOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 574 | |
<> | 144:ef7eb2e8f9f7 | 575 | hsmartcard->pTxBuffPtr = pData; |
<> | 144:ef7eb2e8f9f7 | 576 | hsmartcard->TxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 577 | hsmartcard->TxXferCount = Size; |
<> | 144:ef7eb2e8f9f7 | 578 | |
<> | 144:ef7eb2e8f9f7 | 579 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 580 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 144:ef7eb2e8f9f7 | 581 | |
<> | 144:ef7eb2e8f9f7 | 582 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 144:ef7eb2e8f9f7 | 583 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_ERR); |
<> | 144:ef7eb2e8f9f7 | 584 | |
<> | 144:ef7eb2e8f9f7 | 585 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 586 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 587 | |
<> | 144:ef7eb2e8f9f7 | 588 | /* Enable the SMARTCARD Transmit Data Register Empty Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 589 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_TXE); |
<> | 144:ef7eb2e8f9f7 | 590 | |
<> | 144:ef7eb2e8f9f7 | 591 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 592 | } |
<> | 144:ef7eb2e8f9f7 | 593 | else |
<> | 144:ef7eb2e8f9f7 | 594 | { |
<> | 144:ef7eb2e8f9f7 | 595 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 596 | } |
<> | 144:ef7eb2e8f9f7 | 597 | } |
<> | 144:ef7eb2e8f9f7 | 598 | |
<> | 144:ef7eb2e8f9f7 | 599 | /** |
<> | 144:ef7eb2e8f9f7 | 600 | * @brief Receive an amount of data in interrupt mode. |
<> | 144:ef7eb2e8f9f7 | 601 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 602 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 603 | * @param pData: pointer to data buffer. |
<> | 144:ef7eb2e8f9f7 | 604 | * @param Size: amount of data to be received. |
<> | 144:ef7eb2e8f9f7 | 605 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 606 | */ |
<> | 144:ef7eb2e8f9f7 | 607 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size) |
<> | 144:ef7eb2e8f9f7 | 608 | { |
<> | 144:ef7eb2e8f9f7 | 609 | /* Check that a Rx process is not already ongoing */ |
<> | 144:ef7eb2e8f9f7 | 610 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 611 | { |
<> | 144:ef7eb2e8f9f7 | 612 | if((pData == NULL) || (Size == 0)) |
<> | 144:ef7eb2e8f9f7 | 613 | { |
<> | 144:ef7eb2e8f9f7 | 614 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 615 | } |
<> | 144:ef7eb2e8f9f7 | 616 | |
<> | 144:ef7eb2e8f9f7 | 617 | /* Process Locked */ |
<> | 144:ef7eb2e8f9f7 | 618 | __HAL_LOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 619 | |
<> | 144:ef7eb2e8f9f7 | 620 | hsmartcard->pRxBuffPtr = pData; |
<> | 144:ef7eb2e8f9f7 | 621 | hsmartcard->RxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 622 | hsmartcard->RxXferCount = Size; |
<> | 144:ef7eb2e8f9f7 | 623 | |
<> | 144:ef7eb2e8f9f7 | 624 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 625 | hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 144:ef7eb2e8f9f7 | 626 | |
<> | 144:ef7eb2e8f9f7 | 627 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 628 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 629 | |
<> | 144:ef7eb2e8f9f7 | 630 | /* Enable the SMARTCARD Parity Error Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 631 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_PE); |
<> | 144:ef7eb2e8f9f7 | 632 | |
<> | 144:ef7eb2e8f9f7 | 633 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 144:ef7eb2e8f9f7 | 634 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_ERR); |
<> | 144:ef7eb2e8f9f7 | 635 | |
<> | 144:ef7eb2e8f9f7 | 636 | /* Enable the SMARTCARD Data Register not empty Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 637 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_RXNE); |
<> | 144:ef7eb2e8f9f7 | 638 | |
<> | 144:ef7eb2e8f9f7 | 639 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 640 | } |
<> | 144:ef7eb2e8f9f7 | 641 | else |
<> | 144:ef7eb2e8f9f7 | 642 | { |
<> | 144:ef7eb2e8f9f7 | 643 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 644 | } |
<> | 144:ef7eb2e8f9f7 | 645 | } |
<> | 144:ef7eb2e8f9f7 | 646 | |
<> | 144:ef7eb2e8f9f7 | 647 | /** |
<> | 144:ef7eb2e8f9f7 | 648 | * @brief Send an amount of data in DMA mode. |
<> | 144:ef7eb2e8f9f7 | 649 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 650 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 651 | * @param pData: pointer to data buffer. |
<> | 144:ef7eb2e8f9f7 | 652 | * @param Size: amount of data to be sent. |
<> | 144:ef7eb2e8f9f7 | 653 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 654 | */ |
<> | 144:ef7eb2e8f9f7 | 655 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size) |
<> | 144:ef7eb2e8f9f7 | 656 | { |
<> | 144:ef7eb2e8f9f7 | 657 | uint32_t *tmp; |
<> | 144:ef7eb2e8f9f7 | 658 | |
<> | 144:ef7eb2e8f9f7 | 659 | /* Check that a Tx process is not already ongoing */ |
<> | 144:ef7eb2e8f9f7 | 660 | if (hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 661 | { |
<> | 144:ef7eb2e8f9f7 | 662 | if((pData == NULL) || (Size == 0)) |
<> | 144:ef7eb2e8f9f7 | 663 | { |
<> | 144:ef7eb2e8f9f7 | 664 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 665 | } |
<> | 144:ef7eb2e8f9f7 | 666 | |
<> | 144:ef7eb2e8f9f7 | 667 | /* Process Locked */ |
<> | 144:ef7eb2e8f9f7 | 668 | __HAL_LOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 669 | |
<> | 144:ef7eb2e8f9f7 | 670 | hsmartcard->pTxBuffPtr = pData; |
<> | 144:ef7eb2e8f9f7 | 671 | hsmartcard->TxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 672 | hsmartcard->TxXferCount = Size; |
<> | 144:ef7eb2e8f9f7 | 673 | |
<> | 144:ef7eb2e8f9f7 | 674 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 675 | /* Check if a receive process is ongoing or not */ |
<> | 144:ef7eb2e8f9f7 | 676 | hsmartcard->gState = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 144:ef7eb2e8f9f7 | 677 | |
<> | 144:ef7eb2e8f9f7 | 678 | /* Set the SMARTCARD DMA transfer complete callback */ |
<> | 144:ef7eb2e8f9f7 | 679 | hsmartcard->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt; |
<> | 144:ef7eb2e8f9f7 | 680 | |
<> | 144:ef7eb2e8f9f7 | 681 | /* Set the SMARTCARD error callback */ |
<> | 144:ef7eb2e8f9f7 | 682 | hsmartcard->hdmatx->XferErrorCallback = SMARTCARD_DMAError; |
<> | 144:ef7eb2e8f9f7 | 683 | |
<> | 144:ef7eb2e8f9f7 | 684 | /* Enable the SMARTCARD transmit DMA channel */ |
<> | 144:ef7eb2e8f9f7 | 685 | tmp = (uint32_t*)&pData; |
<> | 144:ef7eb2e8f9f7 | 686 | HAL_DMA_Start_IT(hsmartcard->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsmartcard->Instance->TDR, Size); |
<> | 144:ef7eb2e8f9f7 | 687 | |
<> | 144:ef7eb2e8f9f7 | 688 | /* Clear the TC flag in the ICR register */ |
<> | 144:ef7eb2e8f9f7 | 689 | __HAL_SMARTCARD_CLEAR_FLAG(hsmartcard, SMARTCARD_CLEAR_TCF); |
<> | 144:ef7eb2e8f9f7 | 690 | |
<> | 144:ef7eb2e8f9f7 | 691 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
<> | 144:ef7eb2e8f9f7 | 692 | in the SMARTCARD associated USART CR3 register */ |
<> | 144:ef7eb2e8f9f7 | 693 | SET_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 144:ef7eb2e8f9f7 | 694 | |
<> | 144:ef7eb2e8f9f7 | 695 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 696 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 697 | |
<> | 144:ef7eb2e8f9f7 | 698 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 699 | } |
<> | 144:ef7eb2e8f9f7 | 700 | else |
<> | 144:ef7eb2e8f9f7 | 701 | { |
<> | 144:ef7eb2e8f9f7 | 702 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 703 | } |
<> | 144:ef7eb2e8f9f7 | 704 | } |
<> | 144:ef7eb2e8f9f7 | 705 | |
<> | 144:ef7eb2e8f9f7 | 706 | /** |
<> | 144:ef7eb2e8f9f7 | 707 | * @brief Receive an amount of data in DMA mode. |
<> | 144:ef7eb2e8f9f7 | 708 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 709 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 710 | * @param pData: pointer to data buffer. |
<> | 144:ef7eb2e8f9f7 | 711 | * @param Size: amount of data to be received. |
<> | 144:ef7eb2e8f9f7 | 712 | * @note The SMARTCARD-associated USART parity is enabled (PCE = 1), |
<> | 144:ef7eb2e8f9f7 | 713 | * the received data contain the parity bit (MSB position). |
<> | 144:ef7eb2e8f9f7 | 714 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 715 | */ |
<> | 144:ef7eb2e8f9f7 | 716 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size) |
<> | 144:ef7eb2e8f9f7 | 717 | { |
<> | 144:ef7eb2e8f9f7 | 718 | uint32_t *tmp; |
<> | 144:ef7eb2e8f9f7 | 719 | |
<> | 144:ef7eb2e8f9f7 | 720 | /* Check that a Rx process is not already ongoing */ |
<> | 144:ef7eb2e8f9f7 | 721 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 722 | { |
<> | 144:ef7eb2e8f9f7 | 723 | if((pData == NULL) || (Size == 0)) |
<> | 144:ef7eb2e8f9f7 | 724 | { |
<> | 144:ef7eb2e8f9f7 | 725 | return HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 726 | } |
<> | 144:ef7eb2e8f9f7 | 727 | |
<> | 144:ef7eb2e8f9f7 | 728 | /* Process Locked */ |
<> | 144:ef7eb2e8f9f7 | 729 | __HAL_LOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 730 | |
<> | 144:ef7eb2e8f9f7 | 731 | hsmartcard->pRxBuffPtr = pData; |
<> | 144:ef7eb2e8f9f7 | 732 | hsmartcard->RxXferSize = Size; |
<> | 144:ef7eb2e8f9f7 | 733 | |
<> | 144:ef7eb2e8f9f7 | 734 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 735 | hsmartcard->RxState = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 144:ef7eb2e8f9f7 | 736 | |
<> | 144:ef7eb2e8f9f7 | 737 | /* Set the SMARTCARD DMA transfer complete callback */ |
<> | 144:ef7eb2e8f9f7 | 738 | hsmartcard->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt; |
<> | 144:ef7eb2e8f9f7 | 739 | |
<> | 144:ef7eb2e8f9f7 | 740 | /* Set the SMARTCARD DMA error callback */ |
<> | 144:ef7eb2e8f9f7 | 741 | hsmartcard->hdmarx->XferErrorCallback = SMARTCARD_DMAError; |
<> | 144:ef7eb2e8f9f7 | 742 | |
<> | 144:ef7eb2e8f9f7 | 743 | /* Enable the DMA channel */ |
<> | 144:ef7eb2e8f9f7 | 744 | tmp = (uint32_t*)&pData; |
<> | 144:ef7eb2e8f9f7 | 745 | HAL_DMA_Start_IT(hsmartcard->hdmarx, (uint32_t)&hsmartcard->Instance->RDR, *(uint32_t*)tmp, Size); |
<> | 144:ef7eb2e8f9f7 | 746 | |
<> | 144:ef7eb2e8f9f7 | 747 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
<> | 144:ef7eb2e8f9f7 | 748 | in the SMARTCARD associated USART CR3 register */ |
<> | 144:ef7eb2e8f9f7 | 749 | SET_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 144:ef7eb2e8f9f7 | 750 | |
<> | 144:ef7eb2e8f9f7 | 751 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 752 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 753 | |
<> | 144:ef7eb2e8f9f7 | 754 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 755 | } |
<> | 144:ef7eb2e8f9f7 | 756 | else |
<> | 144:ef7eb2e8f9f7 | 757 | { |
<> | 144:ef7eb2e8f9f7 | 758 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 759 | } |
<> | 144:ef7eb2e8f9f7 | 760 | } |
<> | 144:ef7eb2e8f9f7 | 761 | |
<> | 144:ef7eb2e8f9f7 | 762 | /** |
<> | 144:ef7eb2e8f9f7 | 763 | * @brief Handle SMARTCARD interrupt requests. |
<> | 144:ef7eb2e8f9f7 | 764 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 765 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 766 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 767 | */ |
<> | 144:ef7eb2e8f9f7 | 768 | void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 769 | { |
<> | 144:ef7eb2e8f9f7 | 770 | /* SMARTCARD parity error interrupt occurred -------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 771 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_PE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_PE) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 772 | { |
<> | 144:ef7eb2e8f9f7 | 773 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_PEF); |
<> | 144:ef7eb2e8f9f7 | 774 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_PE; |
<> | 144:ef7eb2e8f9f7 | 775 | /* Set the SMARTCARD states ready to be able to start again the process */ |
<> | 144:ef7eb2e8f9f7 | 776 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 777 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 778 | } |
<> | 144:ef7eb2e8f9f7 | 779 | |
<> | 144:ef7eb2e8f9f7 | 780 | /* SMARTCARD frame error interrupt occurred --------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 781 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_FE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_ERR) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 782 | { |
<> | 144:ef7eb2e8f9f7 | 783 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_FEF); |
<> | 144:ef7eb2e8f9f7 | 784 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_FE; |
<> | 144:ef7eb2e8f9f7 | 785 | /* Set the SMARTCARD states ready to be able to start again the process */ |
<> | 144:ef7eb2e8f9f7 | 786 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 787 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 788 | } |
<> | 144:ef7eb2e8f9f7 | 789 | |
<> | 144:ef7eb2e8f9f7 | 790 | /* SMARTCARD noise error interrupt occurred --------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 791 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_NE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_ERR) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 792 | { |
<> | 144:ef7eb2e8f9f7 | 793 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_NEF); |
<> | 144:ef7eb2e8f9f7 | 794 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_NE; |
<> | 144:ef7eb2e8f9f7 | 795 | /* Set the SMARTCARD states ready to be able to start again the process */ |
<> | 144:ef7eb2e8f9f7 | 796 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 797 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 798 | } |
<> | 144:ef7eb2e8f9f7 | 799 | |
<> | 144:ef7eb2e8f9f7 | 800 | /* SMARTCARD Over-Run interrupt occurred -----------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 801 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_ORE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_ERR) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 802 | { |
<> | 144:ef7eb2e8f9f7 | 803 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_OREF); |
<> | 144:ef7eb2e8f9f7 | 804 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_ORE; |
<> | 144:ef7eb2e8f9f7 | 805 | /* Set the SMARTCARD states ready to be able to start again the process */ |
<> | 144:ef7eb2e8f9f7 | 806 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 807 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 808 | } |
<> | 144:ef7eb2e8f9f7 | 809 | |
<> | 144:ef7eb2e8f9f7 | 810 | /* SMARTCARD receiver timeout interrupt occurred -----------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 811 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_RTO) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_RTO) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 812 | { |
<> | 144:ef7eb2e8f9f7 | 813 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_RTOF); |
<> | 144:ef7eb2e8f9f7 | 814 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_RTO; |
<> | 144:ef7eb2e8f9f7 | 815 | /* Set the SMARTCARD states ready to be able to start again the process */ |
<> | 144:ef7eb2e8f9f7 | 816 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 817 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 818 | } |
<> | 144:ef7eb2e8f9f7 | 819 | |
<> | 144:ef7eb2e8f9f7 | 820 | /* Call SMARTCARD Error Call back function if need be --------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 821 | if(hsmartcard->ErrorCode != HAL_SMARTCARD_ERROR_NONE) |
<> | 144:ef7eb2e8f9f7 | 822 | { |
<> | 144:ef7eb2e8f9f7 | 823 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 824 | } |
<> | 144:ef7eb2e8f9f7 | 825 | |
<> | 144:ef7eb2e8f9f7 | 826 | /* SMARTCARD in mode Receiver ---------------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 827 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_RXNE) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_RXNE) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 828 | { |
<> | 144:ef7eb2e8f9f7 | 829 | SMARTCARD_Receive_IT(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 830 | } |
<> | 144:ef7eb2e8f9f7 | 831 | |
<> | 144:ef7eb2e8f9f7 | 832 | /* SMARTCARD in mode Receiver, end of block interruption ------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 833 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_EOB) != RESET) && (__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_EOB) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 834 | { |
<> | 144:ef7eb2e8f9f7 | 835 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 836 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 837 | HAL_SMARTCARD_RxCpltCallback(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 838 | /* Clear EOBF interrupt after HAL_SMARTCARD_RxCpltCallback() call for the End of Block information |
<> | 144:ef7eb2e8f9f7 | 839 | * to be available during HAL_SMARTCARD_RxCpltCallback() processing */ |
<> | 144:ef7eb2e8f9f7 | 840 | __HAL_SMARTCARD_CLEAR_IT(hsmartcard, SMARTCARD_CLEAR_EOBF); |
<> | 144:ef7eb2e8f9f7 | 841 | } |
<> | 144:ef7eb2e8f9f7 | 842 | |
<> | 144:ef7eb2e8f9f7 | 843 | /* SMARTCARD in mode Transmitter ------------------------------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 844 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_TXE) != RESET) &&(__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_TXE) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 845 | { |
<> | 144:ef7eb2e8f9f7 | 846 | SMARTCARD_Transmit_IT(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 847 | } |
<> | 144:ef7eb2e8f9f7 | 848 | |
<> | 144:ef7eb2e8f9f7 | 849 | /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/ |
<> | 144:ef7eb2e8f9f7 | 850 | if((__HAL_SMARTCARD_GET_IT(hsmartcard, SMARTCARD_IT_TC) != RESET) &&(__HAL_SMARTCARD_GET_IT_SOURCE(hsmartcard, SMARTCARD_IT_TC) != RESET)) |
<> | 144:ef7eb2e8f9f7 | 851 | { |
<> | 144:ef7eb2e8f9f7 | 852 | SMARTCARD_EndTransmit_IT(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 853 | } |
<> | 144:ef7eb2e8f9f7 | 854 | } |
<> | 144:ef7eb2e8f9f7 | 855 | |
<> | 144:ef7eb2e8f9f7 | 856 | /** |
<> | 144:ef7eb2e8f9f7 | 857 | * @brief Tx Transfer completed callback. |
<> | 144:ef7eb2e8f9f7 | 858 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 859 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 860 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 861 | */ |
<> | 144:ef7eb2e8f9f7 | 862 | __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 863 | { |
<> | 144:ef7eb2e8f9f7 | 864 | /* Prevent unused argument(s) compilation warning */ |
<> | 144:ef7eb2e8f9f7 | 865 | UNUSED(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 866 | |
<> | 144:ef7eb2e8f9f7 | 867 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 144:ef7eb2e8f9f7 | 868 | the HAL_SMARTCARD_TxCpltCallback can be implemented in the user file. |
<> | 144:ef7eb2e8f9f7 | 869 | */ |
<> | 144:ef7eb2e8f9f7 | 870 | } |
<> | 144:ef7eb2e8f9f7 | 871 | |
<> | 144:ef7eb2e8f9f7 | 872 | /** |
<> | 144:ef7eb2e8f9f7 | 873 | * @brief Rx Transfer completed callback. |
<> | 144:ef7eb2e8f9f7 | 874 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 875 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 876 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 877 | */ |
<> | 144:ef7eb2e8f9f7 | 878 | __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 879 | { |
<> | 144:ef7eb2e8f9f7 | 880 | /* Prevent unused argument(s) compilation warning */ |
<> | 144:ef7eb2e8f9f7 | 881 | UNUSED(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 882 | |
<> | 144:ef7eb2e8f9f7 | 883 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 144:ef7eb2e8f9f7 | 884 | the HAL_SMARTCARD_RxCpltCallback can be implemented in the user file. |
<> | 144:ef7eb2e8f9f7 | 885 | */ |
<> | 144:ef7eb2e8f9f7 | 886 | } |
<> | 144:ef7eb2e8f9f7 | 887 | |
<> | 144:ef7eb2e8f9f7 | 888 | /** |
<> | 144:ef7eb2e8f9f7 | 889 | * @brief SMARTCARD error callback. |
<> | 144:ef7eb2e8f9f7 | 890 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 891 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 892 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 893 | */ |
<> | 144:ef7eb2e8f9f7 | 894 | __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 895 | { |
<> | 144:ef7eb2e8f9f7 | 896 | /* Prevent unused argument(s) compilation warning */ |
<> | 144:ef7eb2e8f9f7 | 897 | UNUSED(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 898 | |
<> | 144:ef7eb2e8f9f7 | 899 | /* NOTE : This function should not be modified, when the callback is needed, |
<> | 144:ef7eb2e8f9f7 | 900 | the HAL_SMARTCARD_ErrorCallback can be implemented in the user file. |
<> | 144:ef7eb2e8f9f7 | 901 | */ |
<> | 144:ef7eb2e8f9f7 | 902 | } |
<> | 144:ef7eb2e8f9f7 | 903 | |
<> | 144:ef7eb2e8f9f7 | 904 | /** |
<> | 144:ef7eb2e8f9f7 | 905 | * @} |
<> | 144:ef7eb2e8f9f7 | 906 | */ |
<> | 144:ef7eb2e8f9f7 | 907 | |
<> | 144:ef7eb2e8f9f7 | 908 | /** @defgroup SMARTCARD_Exported_Functions_Group3 Peripheral State and Errors functions |
<> | 144:ef7eb2e8f9f7 | 909 | * @brief SMARTCARD State and Errors functions |
<> | 144:ef7eb2e8f9f7 | 910 | * |
<> | 144:ef7eb2e8f9f7 | 911 | @verbatim |
<> | 144:ef7eb2e8f9f7 | 912 | ============================================================================== |
<> | 144:ef7eb2e8f9f7 | 913 | ##### Peripheral State and Errors functions ##### |
<> | 144:ef7eb2e8f9f7 | 914 | ============================================================================== |
<> | 144:ef7eb2e8f9f7 | 915 | [..] |
<> | 144:ef7eb2e8f9f7 | 916 | This subsection provides a set of functions allowing to return the State of SmartCard |
<> | 144:ef7eb2e8f9f7 | 917 | handle and also return Peripheral Errors occurred during communication process |
<> | 144:ef7eb2e8f9f7 | 918 | (+) HAL_SMARTCARD_GetState() API can be helpful to check in run-time the state |
<> | 144:ef7eb2e8f9f7 | 919 | of the SMARTCARD peripheral. |
<> | 144:ef7eb2e8f9f7 | 920 | (+) HAL_SMARTCARD_GetError() checks in run-time errors that could occur during |
<> | 144:ef7eb2e8f9f7 | 921 | communication. |
<> | 144:ef7eb2e8f9f7 | 922 | |
<> | 144:ef7eb2e8f9f7 | 923 | @endverbatim |
<> | 144:ef7eb2e8f9f7 | 924 | * @{ |
<> | 144:ef7eb2e8f9f7 | 925 | */ |
<> | 144:ef7eb2e8f9f7 | 926 | |
<> | 144:ef7eb2e8f9f7 | 927 | |
<> | 144:ef7eb2e8f9f7 | 928 | /** |
<> | 144:ef7eb2e8f9f7 | 929 | * @brief Return the SMARTCARD handle state. |
<> | 144:ef7eb2e8f9f7 | 930 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 931 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 932 | * @retval SMARTCARD handle state |
<> | 144:ef7eb2e8f9f7 | 933 | */ |
<> | 144:ef7eb2e8f9f7 | 934 | HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 935 | { |
<> | 144:ef7eb2e8f9f7 | 936 | uint32_t temp1= 0x00, temp2 = 0x00; |
<> | 144:ef7eb2e8f9f7 | 937 | temp1 = hsmartcard->gState; |
<> | 144:ef7eb2e8f9f7 | 938 | temp2 = hsmartcard->RxState; |
<> | 144:ef7eb2e8f9f7 | 939 | |
<> | 144:ef7eb2e8f9f7 | 940 | return (HAL_SMARTCARD_StateTypeDef)(temp1 | temp2); |
<> | 144:ef7eb2e8f9f7 | 941 | } |
<> | 144:ef7eb2e8f9f7 | 942 | |
<> | 144:ef7eb2e8f9f7 | 943 | /** |
<> | 144:ef7eb2e8f9f7 | 944 | * @brief Return the SMARTCARD handle error code. |
<> | 144:ef7eb2e8f9f7 | 945 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 946 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 947 | * @retval SMARTCARD handle Error Code |
<> | 144:ef7eb2e8f9f7 | 948 | */ |
<> | 144:ef7eb2e8f9f7 | 949 | uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 950 | { |
<> | 144:ef7eb2e8f9f7 | 951 | return hsmartcard->ErrorCode; |
<> | 144:ef7eb2e8f9f7 | 952 | } |
<> | 144:ef7eb2e8f9f7 | 953 | |
<> | 144:ef7eb2e8f9f7 | 954 | /** |
<> | 144:ef7eb2e8f9f7 | 955 | * @} |
<> | 144:ef7eb2e8f9f7 | 956 | */ |
<> | 144:ef7eb2e8f9f7 | 957 | |
<> | 144:ef7eb2e8f9f7 | 958 | /** |
<> | 144:ef7eb2e8f9f7 | 959 | * @} |
<> | 144:ef7eb2e8f9f7 | 960 | */ |
<> | 144:ef7eb2e8f9f7 | 961 | |
<> | 144:ef7eb2e8f9f7 | 962 | /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions |
<> | 144:ef7eb2e8f9f7 | 963 | * @{ |
<> | 144:ef7eb2e8f9f7 | 964 | */ |
<> | 144:ef7eb2e8f9f7 | 965 | |
<> | 144:ef7eb2e8f9f7 | 966 | /** |
<> | 144:ef7eb2e8f9f7 | 967 | * @brief Send an amount of data in non-blocking mode. |
<> | 144:ef7eb2e8f9f7 | 968 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 969 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 970 | * Function called under interruption only, once |
<> | 144:ef7eb2e8f9f7 | 971 | * interruptions have been enabled by HAL_SMARTCARD_Transmit_IT() |
<> | 144:ef7eb2e8f9f7 | 972 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 973 | */ |
<> | 144:ef7eb2e8f9f7 | 974 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 975 | { |
<> | 144:ef7eb2e8f9f7 | 976 | /* Check that a Tx process is ongoing */ |
<> | 144:ef7eb2e8f9f7 | 977 | if (hsmartcard->gState == HAL_SMARTCARD_STATE_BUSY_TX) |
<> | 144:ef7eb2e8f9f7 | 978 | { |
<> | 144:ef7eb2e8f9f7 | 979 | |
<> | 144:ef7eb2e8f9f7 | 980 | if(hsmartcard->TxXferCount == 0) |
<> | 144:ef7eb2e8f9f7 | 981 | { |
<> | 144:ef7eb2e8f9f7 | 982 | /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 983 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TXE); |
<> | 144:ef7eb2e8f9f7 | 984 | |
<> | 144:ef7eb2e8f9f7 | 985 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 986 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_TC); |
<> | 144:ef7eb2e8f9f7 | 987 | |
<> | 144:ef7eb2e8f9f7 | 988 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 989 | } |
<> | 144:ef7eb2e8f9f7 | 990 | else |
<> | 144:ef7eb2e8f9f7 | 991 | { |
<> | 144:ef7eb2e8f9f7 | 992 | hsmartcard->Instance->TDR = (*hsmartcard->pTxBuffPtr++ & (uint8_t)0xFF); |
<> | 144:ef7eb2e8f9f7 | 993 | hsmartcard->TxXferCount--; |
<> | 144:ef7eb2e8f9f7 | 994 | |
<> | 144:ef7eb2e8f9f7 | 995 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 996 | } |
<> | 144:ef7eb2e8f9f7 | 997 | } |
<> | 144:ef7eb2e8f9f7 | 998 | else |
<> | 144:ef7eb2e8f9f7 | 999 | { |
<> | 144:ef7eb2e8f9f7 | 1000 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 1001 | } |
<> | 144:ef7eb2e8f9f7 | 1002 | } |
<> | 144:ef7eb2e8f9f7 | 1003 | |
<> | 144:ef7eb2e8f9f7 | 1004 | /** |
<> | 144:ef7eb2e8f9f7 | 1005 | * @brief Wrap up transmission in non-blocking mode. |
<> | 144:ef7eb2e8f9f7 | 1006 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1007 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1008 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 1009 | */ |
<> | 144:ef7eb2e8f9f7 | 1010 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1011 | { |
<> | 144:ef7eb2e8f9f7 | 1012 | /* Disable the SMARTCARD Transmit Complete Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 1013 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TC); |
<> | 144:ef7eb2e8f9f7 | 1014 | |
<> | 144:ef7eb2e8f9f7 | 1015 | /* Check if a receive process is ongoing or not. If not disable ERR IT */ |
<> | 144:ef7eb2e8f9f7 | 1016 | if(hsmartcard->RxState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 1017 | { |
<> | 144:ef7eb2e8f9f7 | 1018 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 144:ef7eb2e8f9f7 | 1019 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_ERR); |
<> | 144:ef7eb2e8f9f7 | 1020 | } |
<> | 144:ef7eb2e8f9f7 | 1021 | |
<> | 144:ef7eb2e8f9f7 | 1022 | /* Tx process is ended, restore hsmartcard->gState to Ready */ |
<> | 144:ef7eb2e8f9f7 | 1023 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1024 | |
<> | 144:ef7eb2e8f9f7 | 1025 | HAL_SMARTCARD_TxCpltCallback(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1026 | |
<> | 144:ef7eb2e8f9f7 | 1027 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1028 | } |
<> | 144:ef7eb2e8f9f7 | 1029 | |
<> | 144:ef7eb2e8f9f7 | 1030 | |
<> | 144:ef7eb2e8f9f7 | 1031 | /** |
<> | 144:ef7eb2e8f9f7 | 1032 | * @brief Receive an amount of data in non-blocking mode. |
<> | 144:ef7eb2e8f9f7 | 1033 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1034 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1035 | * Function called under interruption only, once |
<> | 144:ef7eb2e8f9f7 | 1036 | * interruptions have been enabled by HAL_SMARTCARD_Receive_IT(). |
<> | 144:ef7eb2e8f9f7 | 1037 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 1038 | */ |
<> | 144:ef7eb2e8f9f7 | 1039 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1040 | { |
<> | 144:ef7eb2e8f9f7 | 1041 | /* Check that a Rx process is ongoing */ |
<> | 144:ef7eb2e8f9f7 | 1042 | if (hsmartcard->RxState == HAL_SMARTCARD_STATE_BUSY_RX) |
<> | 144:ef7eb2e8f9f7 | 1043 | { |
<> | 144:ef7eb2e8f9f7 | 1044 | *hsmartcard->pRxBuffPtr++ = (uint8_t)(hsmartcard->Instance->RDR & (uint8_t)0xFF); |
<> | 144:ef7eb2e8f9f7 | 1045 | |
<> | 144:ef7eb2e8f9f7 | 1046 | if(--hsmartcard->RxXferCount == 0) |
<> | 144:ef7eb2e8f9f7 | 1047 | { |
<> | 144:ef7eb2e8f9f7 | 1048 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_RXNE); |
<> | 144:ef7eb2e8f9f7 | 1049 | |
<> | 144:ef7eb2e8f9f7 | 1050 | /* Check if a transmit process is ongoing or not. If not disable ERR IT */ |
<> | 144:ef7eb2e8f9f7 | 1051 | if(hsmartcard->gState == HAL_SMARTCARD_STATE_READY) |
<> | 144:ef7eb2e8f9f7 | 1052 | { |
<> | 144:ef7eb2e8f9f7 | 1053 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 144:ef7eb2e8f9f7 | 1054 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_ERR); |
<> | 144:ef7eb2e8f9f7 | 1055 | } |
<> | 144:ef7eb2e8f9f7 | 1056 | |
<> | 144:ef7eb2e8f9f7 | 1057 | /* Disable the SMARTCARD Parity Error Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 1058 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_PE); |
<> | 144:ef7eb2e8f9f7 | 1059 | |
<> | 144:ef7eb2e8f9f7 | 1060 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1061 | |
<> | 144:ef7eb2e8f9f7 | 1062 | HAL_SMARTCARD_RxCpltCallback(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1063 | |
<> | 144:ef7eb2e8f9f7 | 1064 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1065 | } |
<> | 144:ef7eb2e8f9f7 | 1066 | |
<> | 144:ef7eb2e8f9f7 | 1067 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1068 | } |
<> | 144:ef7eb2e8f9f7 | 1069 | else |
<> | 144:ef7eb2e8f9f7 | 1070 | { |
<> | 144:ef7eb2e8f9f7 | 1071 | /* Clear RXNE interrupt flag */ |
<> | 144:ef7eb2e8f9f7 | 1072 | __HAL_SMARTCARD_SEND_REQ(hsmartcard, SMARTCARD_RXDATA_FLUSH_REQUEST); |
<> | 144:ef7eb2e8f9f7 | 1073 | |
<> | 144:ef7eb2e8f9f7 | 1074 | return HAL_BUSY; |
<> | 144:ef7eb2e8f9f7 | 1075 | } |
<> | 144:ef7eb2e8f9f7 | 1076 | } |
<> | 144:ef7eb2e8f9f7 | 1077 | |
<> | 144:ef7eb2e8f9f7 | 1078 | /** |
<> | 144:ef7eb2e8f9f7 | 1079 | * @brief Handle SMARTCARD Communication Timeout. |
<> | 144:ef7eb2e8f9f7 | 1080 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1081 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1082 | * @param Flag: specifies the SMARTCARD flag to check. |
<> | 144:ef7eb2e8f9f7 | 1083 | * @param Status: The new Flag status (SET or RESET). |
<> | 144:ef7eb2e8f9f7 | 1084 | * @param Timeout: Timeout duration. |
<> | 144:ef7eb2e8f9f7 | 1085 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 1086 | */ |
<> | 144:ef7eb2e8f9f7 | 1087 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t Flag, FlagStatus Status, uint32_t Timeout) |
<> | 144:ef7eb2e8f9f7 | 1088 | { |
<> | 144:ef7eb2e8f9f7 | 1089 | uint32_t tickstart = HAL_GetTick(); |
<> | 144:ef7eb2e8f9f7 | 1090 | |
<> | 144:ef7eb2e8f9f7 | 1091 | /* Wait until flag is set */ |
<> | 144:ef7eb2e8f9f7 | 1092 | if(Status == RESET) |
<> | 144:ef7eb2e8f9f7 | 1093 | { |
<> | 144:ef7eb2e8f9f7 | 1094 | while(__HAL_SMARTCARD_GET_FLAG(hsmartcard, Flag) == RESET) |
<> | 144:ef7eb2e8f9f7 | 1095 | { |
<> | 144:ef7eb2e8f9f7 | 1096 | /* Check for the Timeout */ |
<> | 144:ef7eb2e8f9f7 | 1097 | if(Timeout != HAL_MAX_DELAY) |
<> | 144:ef7eb2e8f9f7 | 1098 | { |
<> | 144:ef7eb2e8f9f7 | 1099 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
<> | 144:ef7eb2e8f9f7 | 1100 | { |
<> | 144:ef7eb2e8f9f7 | 1101 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
<> | 144:ef7eb2e8f9f7 | 1102 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TXE); |
<> | 144:ef7eb2e8f9f7 | 1103 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_RXNE); |
<> | 144:ef7eb2e8f9f7 | 1104 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_PE); |
<> | 144:ef7eb2e8f9f7 | 1105 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_ERR); |
<> | 144:ef7eb2e8f9f7 | 1106 | |
<> | 144:ef7eb2e8f9f7 | 1107 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1108 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1109 | |
<> | 144:ef7eb2e8f9f7 | 1110 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 1111 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1112 | |
<> | 144:ef7eb2e8f9f7 | 1113 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 1114 | } |
<> | 144:ef7eb2e8f9f7 | 1115 | } |
<> | 144:ef7eb2e8f9f7 | 1116 | } |
<> | 144:ef7eb2e8f9f7 | 1117 | } |
<> | 144:ef7eb2e8f9f7 | 1118 | else |
<> | 144:ef7eb2e8f9f7 | 1119 | { |
<> | 144:ef7eb2e8f9f7 | 1120 | while(__HAL_SMARTCARD_GET_FLAG(hsmartcard, Flag) != RESET) |
<> | 144:ef7eb2e8f9f7 | 1121 | { |
<> | 144:ef7eb2e8f9f7 | 1122 | /* Check for the Timeout */ |
<> | 144:ef7eb2e8f9f7 | 1123 | if(Timeout != HAL_MAX_DELAY) |
<> | 144:ef7eb2e8f9f7 | 1124 | { |
<> | 144:ef7eb2e8f9f7 | 1125 | if((Timeout == 0) || ((HAL_GetTick()-tickstart) > Timeout)) |
<> | 144:ef7eb2e8f9f7 | 1126 | { |
<> | 144:ef7eb2e8f9f7 | 1127 | /* Disable TXE, RXNE, PE and ERR (Frame error, noise error, overrun error) interrupts for the interrupt process */ |
<> | 144:ef7eb2e8f9f7 | 1128 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TXE); |
<> | 144:ef7eb2e8f9f7 | 1129 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_RXNE); |
<> | 144:ef7eb2e8f9f7 | 1130 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_PE); |
<> | 144:ef7eb2e8f9f7 | 1131 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_ERR); |
<> | 144:ef7eb2e8f9f7 | 1132 | |
<> | 144:ef7eb2e8f9f7 | 1133 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1134 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1135 | |
<> | 144:ef7eb2e8f9f7 | 1136 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 1137 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1138 | |
<> | 144:ef7eb2e8f9f7 | 1139 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 1140 | } |
<> | 144:ef7eb2e8f9f7 | 1141 | } |
<> | 144:ef7eb2e8f9f7 | 1142 | } |
<> | 144:ef7eb2e8f9f7 | 1143 | } |
<> | 144:ef7eb2e8f9f7 | 1144 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1145 | } |
<> | 144:ef7eb2e8f9f7 | 1146 | |
<> | 144:ef7eb2e8f9f7 | 1147 | /** |
<> | 144:ef7eb2e8f9f7 | 1148 | * @brief DMA SMARTCARD transmit process complete callback. |
<> | 144:ef7eb2e8f9f7 | 1149 | * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1150 | * the configuration information for the specified DMA module. |
<> | 144:ef7eb2e8f9f7 | 1151 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 1152 | */ |
<> | 144:ef7eb2e8f9f7 | 1153 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
<> | 144:ef7eb2e8f9f7 | 1154 | { |
<> | 144:ef7eb2e8f9f7 | 1155 | SMARTCARD_HandleTypeDef* hsmartcard = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
<> | 144:ef7eb2e8f9f7 | 1156 | hsmartcard->TxXferCount = 0; |
<> | 144:ef7eb2e8f9f7 | 1157 | |
<> | 144:ef7eb2e8f9f7 | 1158 | /* Disable the DMA transfer for transmit request by resetting the DMAT bit |
<> | 144:ef7eb2e8f9f7 | 1159 | in the SMARTCARD associated USART CR3 register */ |
<> | 144:ef7eb2e8f9f7 | 1160 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAT); |
<> | 144:ef7eb2e8f9f7 | 1161 | |
<> | 144:ef7eb2e8f9f7 | 1162 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
<> | 144:ef7eb2e8f9f7 | 1163 | __HAL_SMARTCARD_ENABLE_IT(hsmartcard, SMARTCARD_IT_TC); |
<> | 144:ef7eb2e8f9f7 | 1164 | } |
<> | 144:ef7eb2e8f9f7 | 1165 | |
<> | 144:ef7eb2e8f9f7 | 1166 | /** |
<> | 144:ef7eb2e8f9f7 | 1167 | * @brief DMA SMARTCARD receive process complete callback. |
<> | 144:ef7eb2e8f9f7 | 1168 | * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1169 | * the configuration information for the specified DMA module. |
<> | 144:ef7eb2e8f9f7 | 1170 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 1171 | */ |
<> | 144:ef7eb2e8f9f7 | 1172 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
<> | 144:ef7eb2e8f9f7 | 1173 | { |
<> | 144:ef7eb2e8f9f7 | 1174 | SMARTCARD_HandleTypeDef* hsmartcard = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
<> | 144:ef7eb2e8f9f7 | 1175 | hsmartcard->RxXferCount = 0; |
<> | 144:ef7eb2e8f9f7 | 1176 | |
<> | 144:ef7eb2e8f9f7 | 1177 | /* Disable the DMA transfer for the receiver request by resetting the DMAR bit |
<> | 144:ef7eb2e8f9f7 | 1178 | in the SMARTCARD associated USART CR3 register */ |
<> | 144:ef7eb2e8f9f7 | 1179 | CLEAR_BIT(hsmartcard->Instance->CR3, USART_CR3_DMAR); |
<> | 144:ef7eb2e8f9f7 | 1180 | |
<> | 144:ef7eb2e8f9f7 | 1181 | /* At end of Rx process, restore hsmartcard->RxState to Ready */ |
<> | 144:ef7eb2e8f9f7 | 1182 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1183 | |
<> | 144:ef7eb2e8f9f7 | 1184 | HAL_SMARTCARD_RxCpltCallback(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1185 | } |
<> | 144:ef7eb2e8f9f7 | 1186 | |
<> | 144:ef7eb2e8f9f7 | 1187 | /** |
<> | 144:ef7eb2e8f9f7 | 1188 | * @brief DMA SMARTCARD communication error callback. |
<> | 144:ef7eb2e8f9f7 | 1189 | * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1190 | * the configuration information for the specified DMA module. |
<> | 144:ef7eb2e8f9f7 | 1191 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 1192 | */ |
<> | 144:ef7eb2e8f9f7 | 1193 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma) |
<> | 144:ef7eb2e8f9f7 | 1194 | { |
<> | 144:ef7eb2e8f9f7 | 1195 | SMARTCARD_HandleTypeDef* hsmartcard = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
<> | 144:ef7eb2e8f9f7 | 1196 | hsmartcard->RxXferCount = 0; |
<> | 144:ef7eb2e8f9f7 | 1197 | hsmartcard->TxXferCount = 0; |
<> | 144:ef7eb2e8f9f7 | 1198 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1199 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1200 | hsmartcard->ErrorCode |= HAL_SMARTCARD_ERROR_DMA; |
<> | 144:ef7eb2e8f9f7 | 1201 | HAL_SMARTCARD_ErrorCallback(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1202 | } |
<> | 144:ef7eb2e8f9f7 | 1203 | |
<> | 144:ef7eb2e8f9f7 | 1204 | /** |
<> | 144:ef7eb2e8f9f7 | 1205 | * @brief Configure the SMARTCARD associated USART peripheral. |
<> | 144:ef7eb2e8f9f7 | 1206 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1207 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1208 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 1209 | */ |
<> | 144:ef7eb2e8f9f7 | 1210 | static HAL_StatusTypeDef SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1211 | { |
<> | 144:ef7eb2e8f9f7 | 1212 | uint32_t tmpreg = 0x00000000; |
<> | 144:ef7eb2e8f9f7 | 1213 | SMARTCARD_ClockSourceTypeDef clocksource = SMARTCARD_CLOCKSOURCE_UNDEFINED; |
<> | 144:ef7eb2e8f9f7 | 1214 | HAL_StatusTypeDef ret = HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1215 | |
<> | 144:ef7eb2e8f9f7 | 1216 | /* Check the parameters */ |
<> | 144:ef7eb2e8f9f7 | 1217 | assert_param(IS_SMARTCARD_INSTANCE(hsmartcard->Instance)); |
<> | 144:ef7eb2e8f9f7 | 1218 | assert_param(IS_SMARTCARD_BAUDRATE(hsmartcard->Init.BaudRate)); |
<> | 144:ef7eb2e8f9f7 | 1219 | assert_param(IS_SMARTCARD_WORD_LENGTH(hsmartcard->Init.WordLength)); |
<> | 144:ef7eb2e8f9f7 | 1220 | assert_param(IS_SMARTCARD_STOPBITS(hsmartcard->Init.StopBits)); |
<> | 144:ef7eb2e8f9f7 | 1221 | assert_param(IS_SMARTCARD_PARITY(hsmartcard->Init.Parity)); |
<> | 144:ef7eb2e8f9f7 | 1222 | assert_param(IS_SMARTCARD_MODE(hsmartcard->Init.Mode)); |
<> | 144:ef7eb2e8f9f7 | 1223 | assert_param(IS_SMARTCARD_POLARITY(hsmartcard->Init.CLKPolarity)); |
<> | 144:ef7eb2e8f9f7 | 1224 | assert_param(IS_SMARTCARD_PHASE(hsmartcard->Init.CLKPhase)); |
<> | 144:ef7eb2e8f9f7 | 1225 | assert_param(IS_SMARTCARD_LASTBIT(hsmartcard->Init.CLKLastBit)); |
<> | 144:ef7eb2e8f9f7 | 1226 | assert_param(IS_SMARTCARD_ONE_BIT_SAMPLE(hsmartcard->Init.OneBitSampling)); |
<> | 144:ef7eb2e8f9f7 | 1227 | assert_param(IS_SMARTCARD_NACK(hsmartcard->Init.NACKEnable)); |
<> | 144:ef7eb2e8f9f7 | 1228 | assert_param(IS_SMARTCARD_TIMEOUT(hsmartcard->Init.TimeOutEnable)); |
<> | 144:ef7eb2e8f9f7 | 1229 | assert_param(IS_SMARTCARD_AUTORETRY_COUNT(hsmartcard->Init.AutoRetryCount)); |
<> | 144:ef7eb2e8f9f7 | 1230 | |
<> | 144:ef7eb2e8f9f7 | 1231 | /*-------------------------- USART CR1 Configuration -----------------------*/ |
<> | 144:ef7eb2e8f9f7 | 1232 | /* In SmartCard mode, M and PCE are forced to 1 (8 bits + parity). |
<> | 144:ef7eb2e8f9f7 | 1233 | * Oversampling is forced to 16 (OVER8 = 0). |
<> | 144:ef7eb2e8f9f7 | 1234 | * Configure the Parity and Mode: |
<> | 144:ef7eb2e8f9f7 | 1235 | * set PS bit according to hsmartcard->Init.Parity value |
<> | 144:ef7eb2e8f9f7 | 1236 | * set TE and RE bits according to hsmartcard->Init.Mode value */ |
<> | 144:ef7eb2e8f9f7 | 1237 | tmpreg = (uint32_t) hsmartcard->Init.Parity | hsmartcard->Init.Mode; |
<> | 144:ef7eb2e8f9f7 | 1238 | /* in case of TX-only mode, if NACK is enabled, the USART must be able to monitor |
<> | 144:ef7eb2e8f9f7 | 1239 | the bidirectional line to detect a NACK signal in case of parity error. |
<> | 144:ef7eb2e8f9f7 | 1240 | Therefore, the receiver block must be enabled as well (RE bit must be set). */ |
<> | 144:ef7eb2e8f9f7 | 1241 | if ((hsmartcard->Init.Mode == SMARTCARD_MODE_TX) |
<> | 144:ef7eb2e8f9f7 | 1242 | && (hsmartcard->Init.NACKEnable == SMARTCARD_NACK_ENABLE)) |
<> | 144:ef7eb2e8f9f7 | 1243 | { |
<> | 144:ef7eb2e8f9f7 | 1244 | tmpreg |= USART_CR1_RE; |
<> | 144:ef7eb2e8f9f7 | 1245 | } |
<> | 144:ef7eb2e8f9f7 | 1246 | tmpreg |= (uint32_t) hsmartcard->Init.WordLength; |
<> | 144:ef7eb2e8f9f7 | 1247 | MODIFY_REG(hsmartcard->Instance->CR1, USART_CR1_FIELDS, tmpreg); |
<> | 144:ef7eb2e8f9f7 | 1248 | |
<> | 144:ef7eb2e8f9f7 | 1249 | /*-------------------------- USART CR2 Configuration -----------------------*/ |
<> | 144:ef7eb2e8f9f7 | 1250 | /* Stop bits are forced to 1.5 (STOP = 11) */ |
<> | 144:ef7eb2e8f9f7 | 1251 | tmpreg = hsmartcard->Init.StopBits; |
<> | 144:ef7eb2e8f9f7 | 1252 | /* Synchronous mode is activated by default */ |
<> | 144:ef7eb2e8f9f7 | 1253 | tmpreg |= (uint32_t) USART_CR2_CLKEN | hsmartcard->Init.CLKPolarity; |
<> | 144:ef7eb2e8f9f7 | 1254 | tmpreg |= (uint32_t) hsmartcard->Init.CLKPhase | hsmartcard->Init.CLKLastBit; |
<> | 144:ef7eb2e8f9f7 | 1255 | tmpreg |= (uint32_t) hsmartcard->Init.TimeOutEnable; |
<> | 144:ef7eb2e8f9f7 | 1256 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_FIELDS, tmpreg); |
<> | 144:ef7eb2e8f9f7 | 1257 | |
<> | 144:ef7eb2e8f9f7 | 1258 | /*-------------------------- USART CR3 Configuration -----------------------*/ |
<> | 144:ef7eb2e8f9f7 | 1259 | /* Configure |
<> | 144:ef7eb2e8f9f7 | 1260 | * - one-bit sampling method versus three samples' majority rule |
<> | 144:ef7eb2e8f9f7 | 1261 | * according to hsmartcard->Init.OneBitSampling |
<> | 144:ef7eb2e8f9f7 | 1262 | * - NACK transmission in case of parity error according |
<> | 144:ef7eb2e8f9f7 | 1263 | * to hsmartcard->Init.NACKEnable |
<> | 144:ef7eb2e8f9f7 | 1264 | * - autoretry counter according to hsmartcard->Init.AutoRetryCount */ |
<> | 144:ef7eb2e8f9f7 | 1265 | tmpreg = (uint32_t) hsmartcard->Init.OneBitSampling | hsmartcard->Init.NACKEnable; |
<> | 144:ef7eb2e8f9f7 | 1266 | tmpreg |= ((uint32_t)hsmartcard->Init.AutoRetryCount << SMARTCARD_CR3_SCARCNT_LSB_POS); |
<> | 144:ef7eb2e8f9f7 | 1267 | MODIFY_REG(hsmartcard->Instance-> CR3,USART_CR3_FIELDS, tmpreg); |
<> | 144:ef7eb2e8f9f7 | 1268 | |
<> | 144:ef7eb2e8f9f7 | 1269 | /*-------------------------- USART GTPR Configuration ----------------------*/ |
<> | 144:ef7eb2e8f9f7 | 1270 | tmpreg = (hsmartcard->Init.Prescaler | ((uint32_t)hsmartcard->Init.GuardTime << SMARTCARD_GTPR_GT_LSB_POS)); |
<> | 144:ef7eb2e8f9f7 | 1271 | MODIFY_REG(hsmartcard->Instance->GTPR, (USART_GTPR_GT|USART_GTPR_PSC), tmpreg); |
<> | 144:ef7eb2e8f9f7 | 1272 | |
<> | 144:ef7eb2e8f9f7 | 1273 | /*-------------------------- USART RTOR Configuration ----------------------*/ |
<> | 144:ef7eb2e8f9f7 | 1274 | tmpreg = ((uint32_t)hsmartcard->Init.BlockLength << SMARTCARD_RTOR_BLEN_LSB_POS); |
<> | 144:ef7eb2e8f9f7 | 1275 | if (hsmartcard->Init.TimeOutEnable == SMARTCARD_TIMEOUT_ENABLE) |
<> | 144:ef7eb2e8f9f7 | 1276 | { |
<> | 144:ef7eb2e8f9f7 | 1277 | assert_param(IS_SMARTCARD_TIMEOUT_VALUE(hsmartcard->Init.TimeOutValue)); |
<> | 144:ef7eb2e8f9f7 | 1278 | tmpreg |= (uint32_t) hsmartcard->Init.TimeOutValue; |
<> | 144:ef7eb2e8f9f7 | 1279 | } |
<> | 144:ef7eb2e8f9f7 | 1280 | MODIFY_REG(hsmartcard->Instance->RTOR, (USART_RTOR_RTO|USART_RTOR_BLEN), tmpreg); |
<> | 144:ef7eb2e8f9f7 | 1281 | |
<> | 144:ef7eb2e8f9f7 | 1282 | /*-------------------------- USART BRR Configuration -----------------------*/ |
<> | 144:ef7eb2e8f9f7 | 1283 | SMARTCARD_GETCLOCKSOURCE(hsmartcard, clocksource); |
<> | 144:ef7eb2e8f9f7 | 1284 | switch (clocksource) |
<> | 144:ef7eb2e8f9f7 | 1285 | { |
<> | 144:ef7eb2e8f9f7 | 1286 | case SMARTCARD_CLOCKSOURCE_PCLK1: |
<> | 144:ef7eb2e8f9f7 | 1287 | hsmartcard->Instance->BRR = (uint16_t)((HAL_RCC_GetPCLK1Freq() + (hsmartcard->Init.BaudRate/2)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1288 | break; |
<> | 144:ef7eb2e8f9f7 | 1289 | case SMARTCARD_CLOCKSOURCE_PCLK2: |
<> | 144:ef7eb2e8f9f7 | 1290 | hsmartcard->Instance->BRR = (uint16_t)((HAL_RCC_GetPCLK2Freq() + (hsmartcard->Init.BaudRate/2)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1291 | break; |
<> | 144:ef7eb2e8f9f7 | 1292 | case SMARTCARD_CLOCKSOURCE_HSI: |
<> | 144:ef7eb2e8f9f7 | 1293 | hsmartcard->Instance->BRR = (uint16_t)((HSI_VALUE + (hsmartcard->Init.BaudRate/2)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1294 | break; |
<> | 144:ef7eb2e8f9f7 | 1295 | case SMARTCARD_CLOCKSOURCE_SYSCLK: |
<> | 144:ef7eb2e8f9f7 | 1296 | hsmartcard->Instance->BRR = (uint16_t)((HAL_RCC_GetSysClockFreq() + (hsmartcard->Init.BaudRate/2)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1297 | break; |
<> | 144:ef7eb2e8f9f7 | 1298 | case SMARTCARD_CLOCKSOURCE_LSE: |
<> | 144:ef7eb2e8f9f7 | 1299 | hsmartcard->Instance->BRR = (uint16_t)((LSE_VALUE + (hsmartcard->Init.BaudRate/2)) / hsmartcard->Init.BaudRate); |
<> | 144:ef7eb2e8f9f7 | 1300 | break; |
<> | 144:ef7eb2e8f9f7 | 1301 | case SMARTCARD_CLOCKSOURCE_UNDEFINED: |
<> | 144:ef7eb2e8f9f7 | 1302 | default: |
<> | 144:ef7eb2e8f9f7 | 1303 | ret = HAL_ERROR; |
<> | 144:ef7eb2e8f9f7 | 1304 | break; |
<> | 144:ef7eb2e8f9f7 | 1305 | } |
<> | 144:ef7eb2e8f9f7 | 1306 | |
<> | 144:ef7eb2e8f9f7 | 1307 | return ret; |
<> | 144:ef7eb2e8f9f7 | 1308 | } |
<> | 144:ef7eb2e8f9f7 | 1309 | |
<> | 144:ef7eb2e8f9f7 | 1310 | |
<> | 144:ef7eb2e8f9f7 | 1311 | /** |
<> | 144:ef7eb2e8f9f7 | 1312 | * @brief Configure the SMARTCARD associated USART peripheral advanced features. |
<> | 144:ef7eb2e8f9f7 | 1313 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1314 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1315 | * @retval None |
<> | 144:ef7eb2e8f9f7 | 1316 | */ |
<> | 144:ef7eb2e8f9f7 | 1317 | static void SMARTCARD_AdvFeatureConfig(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1318 | { |
<> | 144:ef7eb2e8f9f7 | 1319 | /* Check whether the set of advanced features to configure is properly set */ |
<> | 144:ef7eb2e8f9f7 | 1320 | assert_param(IS_SMARTCARD_ADVFEATURE_INIT(hsmartcard->AdvancedInit.AdvFeatureInit)); |
<> | 144:ef7eb2e8f9f7 | 1321 | |
<> | 144:ef7eb2e8f9f7 | 1322 | /* if required, configure TX pin active level inversion */ |
<> | 144:ef7eb2e8f9f7 | 1323 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXINVERT_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1324 | { |
<> | 144:ef7eb2e8f9f7 | 1325 | assert_param(IS_SMARTCARD_ADVFEATURE_TXINV(hsmartcard->AdvancedInit.TxPinLevelInvert)); |
<> | 144:ef7eb2e8f9f7 | 1326 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_TXINV, hsmartcard->AdvancedInit.TxPinLevelInvert); |
<> | 144:ef7eb2e8f9f7 | 1327 | } |
<> | 144:ef7eb2e8f9f7 | 1328 | |
<> | 144:ef7eb2e8f9f7 | 1329 | /* if required, configure RX pin active level inversion */ |
<> | 144:ef7eb2e8f9f7 | 1330 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXINVERT_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1331 | { |
<> | 144:ef7eb2e8f9f7 | 1332 | assert_param(IS_SMARTCARD_ADVFEATURE_RXINV(hsmartcard->AdvancedInit.RxPinLevelInvert)); |
<> | 144:ef7eb2e8f9f7 | 1333 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_RXINV, hsmartcard->AdvancedInit.RxPinLevelInvert); |
<> | 144:ef7eb2e8f9f7 | 1334 | } |
<> | 144:ef7eb2e8f9f7 | 1335 | |
<> | 144:ef7eb2e8f9f7 | 1336 | /* if required, configure data inversion */ |
<> | 144:ef7eb2e8f9f7 | 1337 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DATAINVERT_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1338 | { |
<> | 144:ef7eb2e8f9f7 | 1339 | assert_param(IS_SMARTCARD_ADVFEATURE_DATAINV(hsmartcard->AdvancedInit.DataInvert)); |
<> | 144:ef7eb2e8f9f7 | 1340 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_DATAINV, hsmartcard->AdvancedInit.DataInvert); |
<> | 144:ef7eb2e8f9f7 | 1341 | } |
<> | 144:ef7eb2e8f9f7 | 1342 | |
<> | 144:ef7eb2e8f9f7 | 1343 | /* if required, configure RX/TX pins swap */ |
<> | 144:ef7eb2e8f9f7 | 1344 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_SWAP_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1345 | { |
<> | 144:ef7eb2e8f9f7 | 1346 | assert_param(IS_SMARTCARD_ADVFEATURE_SWAP(hsmartcard->AdvancedInit.Swap)); |
<> | 144:ef7eb2e8f9f7 | 1347 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_SWAP, hsmartcard->AdvancedInit.Swap); |
<> | 144:ef7eb2e8f9f7 | 1348 | } |
<> | 144:ef7eb2e8f9f7 | 1349 | |
<> | 144:ef7eb2e8f9f7 | 1350 | /* if required, configure RX overrun detection disabling */ |
<> | 144:ef7eb2e8f9f7 | 1351 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1352 | { |
<> | 144:ef7eb2e8f9f7 | 1353 | assert_param(IS_SMARTCARD_OVERRUN(hsmartcard->AdvancedInit.OverrunDisable)); |
<> | 144:ef7eb2e8f9f7 | 1354 | MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_OVRDIS, hsmartcard->AdvancedInit.OverrunDisable); |
<> | 144:ef7eb2e8f9f7 | 1355 | } |
<> | 144:ef7eb2e8f9f7 | 1356 | |
<> | 144:ef7eb2e8f9f7 | 1357 | /* if required, configure DMA disabling on reception error */ |
<> | 144:ef7eb2e8f9f7 | 1358 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1359 | { |
<> | 144:ef7eb2e8f9f7 | 1360 | assert_param(IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(hsmartcard->AdvancedInit.DMADisableonRxError)); |
<> | 144:ef7eb2e8f9f7 | 1361 | MODIFY_REG(hsmartcard->Instance->CR3, USART_CR3_DDRE, hsmartcard->AdvancedInit.DMADisableonRxError); |
<> | 144:ef7eb2e8f9f7 | 1362 | } |
<> | 144:ef7eb2e8f9f7 | 1363 | |
<> | 144:ef7eb2e8f9f7 | 1364 | /* if required, configure MSB first on communication line */ |
<> | 144:ef7eb2e8f9f7 | 1365 | if (HAL_IS_BIT_SET(hsmartcard->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_MSBFIRST_INIT)) |
<> | 144:ef7eb2e8f9f7 | 1366 | { |
<> | 144:ef7eb2e8f9f7 | 1367 | assert_param(IS_SMARTCARD_ADVFEATURE_MSBFIRST(hsmartcard->AdvancedInit.MSBFirst)); |
<> | 144:ef7eb2e8f9f7 | 1368 | MODIFY_REG(hsmartcard->Instance->CR2, USART_CR2_MSBFIRST, hsmartcard->AdvancedInit.MSBFirst); |
<> | 144:ef7eb2e8f9f7 | 1369 | } |
<> | 144:ef7eb2e8f9f7 | 1370 | |
<> | 144:ef7eb2e8f9f7 | 1371 | } |
<> | 144:ef7eb2e8f9f7 | 1372 | |
<> | 144:ef7eb2e8f9f7 | 1373 | /** |
<> | 144:ef7eb2e8f9f7 | 1374 | * @brief Check the SMARTCARD Idle State. |
<> | 144:ef7eb2e8f9f7 | 1375 | * @param hsmartcard: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 144:ef7eb2e8f9f7 | 1376 | * the configuration information for the specified SMARTCARD module. |
<> | 144:ef7eb2e8f9f7 | 1377 | * @retval HAL status |
<> | 144:ef7eb2e8f9f7 | 1378 | */ |
<> | 144:ef7eb2e8f9f7 | 1379 | static HAL_StatusTypeDef SMARTCARD_CheckIdleState(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 144:ef7eb2e8f9f7 | 1380 | { |
<> | 144:ef7eb2e8f9f7 | 1381 | |
<> | 144:ef7eb2e8f9f7 | 1382 | /* Initialize the SMARTCARD ErrorCode */ |
<> | 144:ef7eb2e8f9f7 | 1383 | hsmartcard->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 144:ef7eb2e8f9f7 | 1384 | |
<> | 144:ef7eb2e8f9f7 | 1385 | /* Check if the Transmitter is enabled */ |
<> | 144:ef7eb2e8f9f7 | 1386 | if((hsmartcard->Instance->CR1 & USART_CR1_TE) == USART_CR1_TE) |
<> | 144:ef7eb2e8f9f7 | 1387 | { |
<> | 144:ef7eb2e8f9f7 | 1388 | /* Wait until TEACK flag is set */ |
<> | 144:ef7eb2e8f9f7 | 1389 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_TEACK, RESET, SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK) |
<> | 144:ef7eb2e8f9f7 | 1390 | { |
<> | 144:ef7eb2e8f9f7 | 1391 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 1392 | } |
<> | 144:ef7eb2e8f9f7 | 1393 | } |
<> | 144:ef7eb2e8f9f7 | 1394 | |
<> | 144:ef7eb2e8f9f7 | 1395 | /* Check if the Receiver is enabled */ |
<> | 144:ef7eb2e8f9f7 | 1396 | if((hsmartcard->Instance->CR1 & USART_CR1_RE) == USART_CR1_RE) |
<> | 144:ef7eb2e8f9f7 | 1397 | { |
<> | 144:ef7eb2e8f9f7 | 1398 | /* Wait until REACK flag is set */ |
<> | 144:ef7eb2e8f9f7 | 1399 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsmartcard, USART_ISR_REACK, RESET, SMARTCARD_TEACK_REACK_TIMEOUT) != HAL_OK) |
<> | 144:ef7eb2e8f9f7 | 1400 | { |
<> | 144:ef7eb2e8f9f7 | 1401 | return HAL_TIMEOUT; |
<> | 144:ef7eb2e8f9f7 | 1402 | } |
<> | 144:ef7eb2e8f9f7 | 1403 | } |
<> | 144:ef7eb2e8f9f7 | 1404 | |
<> | 144:ef7eb2e8f9f7 | 1405 | /* Initialize the SMARTCARD state*/ |
<> | 144:ef7eb2e8f9f7 | 1406 | hsmartcard->gState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1407 | hsmartcard->RxState = HAL_SMARTCARD_STATE_READY; |
<> | 144:ef7eb2e8f9f7 | 1408 | |
<> | 144:ef7eb2e8f9f7 | 1409 | /* Process Unlocked */ |
<> | 144:ef7eb2e8f9f7 | 1410 | __HAL_UNLOCK(hsmartcard); |
<> | 144:ef7eb2e8f9f7 | 1411 | |
<> | 144:ef7eb2e8f9f7 | 1412 | return HAL_OK; |
<> | 144:ef7eb2e8f9f7 | 1413 | } |
<> | 144:ef7eb2e8f9f7 | 1414 | |
<> | 144:ef7eb2e8f9f7 | 1415 | /** |
<> | 144:ef7eb2e8f9f7 | 1416 | * @} |
<> | 144:ef7eb2e8f9f7 | 1417 | */ |
<> | 144:ef7eb2e8f9f7 | 1418 | |
<> | 144:ef7eb2e8f9f7 | 1419 | /** |
<> | 144:ef7eb2e8f9f7 | 1420 | * @} |
<> | 144:ef7eb2e8f9f7 | 1421 | */ |
<> | 144:ef7eb2e8f9f7 | 1422 | |
<> | 144:ef7eb2e8f9f7 | 1423 | /** |
<> | 144:ef7eb2e8f9f7 | 1424 | * @} |
<> | 144:ef7eb2e8f9f7 | 1425 | */ |
<> | 144:ef7eb2e8f9f7 | 1426 | |
<> | 144:ef7eb2e8f9f7 | 1427 | |
<> | 144:ef7eb2e8f9f7 | 1428 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ |
<> | 144:ef7eb2e8f9f7 | 1429 | |
<> | 144:ef7eb2e8f9f7 | 1430 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |