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