mbed library sources. Supersedes mbed-src.
Dependents: Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more
targets/TARGET_STM/TARGET_STM32L1/device/stm32l1xx_hal_smartcard.c@189:f392fc9709a3, 2019-02-20 (annotated)
- Committer:
- AnnaBridge
- Date:
- Wed Feb 20 22:31:08 2019 +0000
- Revision:
- 189:f392fc9709a3
- Parent:
- 184:08ed48f1de7f
mbed library release version 165
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 149:156823d33999 | 1 | /** |
<> | 149:156823d33999 | 2 | ****************************************************************************** |
<> | 149:156823d33999 | 3 | * @file stm32l1xx_hal_smartcard.c |
<> | 149:156823d33999 | 4 | * @author MCD Application Team |
<> | 149:156823d33999 | 5 | * @brief SMARTCARD HAL module driver. |
<> | 149:156823d33999 | 6 | * This file provides firmware functions to manage the following |
<> | 149:156823d33999 | 7 | * functionalities of the SMARTCARD peripheral: |
<> | 149:156823d33999 | 8 | * + Initialization and de-initialization functions |
<> | 149:156823d33999 | 9 | * + IO operation functions |
<> | 149:156823d33999 | 10 | * + Peripheral State and Errors functions |
<> | 149:156823d33999 | 11 | * + Peripheral Control functions |
<> | 149:156823d33999 | 12 | * |
<> | 149:156823d33999 | 13 | @verbatim |
<> | 149:156823d33999 | 14 | ============================================================================== |
<> | 149:156823d33999 | 15 | ##### How to use this driver ##### |
<> | 149:156823d33999 | 16 | ============================================================================== |
<> | 149:156823d33999 | 17 | [..] |
<> | 149:156823d33999 | 18 | The SMARTCARD HAL driver can be used as follows: |
<> | 149:156823d33999 | 19 | |
<> | 149:156823d33999 | 20 | (#) Declare a SMARTCARD_HandleTypeDef handle structure. |
<> | 149:156823d33999 | 21 | (#) Initialize the SMARTCARD low level resources by implementing the HAL_SMARTCARD_MspInit() API: |
<> | 149:156823d33999 | 22 | (##) Enable the interface clock of the USARTx associated to the SMARTCARD. |
<> | 149:156823d33999 | 23 | (##) SMARTCARD pins configuration: |
<> | 149:156823d33999 | 24 | (+++) Enable the clock for the SMARTCARD GPIOs. |
<> | 149:156823d33999 | 25 | (+++) Configure the SMARTCARD pins as alternate function pull-up. |
<> | 149:156823d33999 | 26 | (##) NVIC configuration if you need to use interrupt process (HAL_SMARTCARD_Transmit_IT() |
<> | 149:156823d33999 | 27 | and HAL_SMARTCARD_Receive_IT() APIs): |
<> | 149:156823d33999 | 28 | (+++) Configure the USARTx interrupt priority. |
<> | 149:156823d33999 | 29 | (+++) Enable the NVIC USART IRQ handle. |
<> | 149:156823d33999 | 30 | (##) DMA Configuration if you need to use DMA process (HAL_SMARTCARD_Transmit_DMA() |
<> | 149:156823d33999 | 31 | and HAL_SMARTCARD_Receive_DMA() APIs): |
<> | 149:156823d33999 | 32 | (+++) Declare a DMA handle structure for the Tx/Rx channel. |
<> | 149:156823d33999 | 33 | (+++) Enable the DMAx interface clock. |
<> | 149:156823d33999 | 34 | (+++) Configure the declared DMA handle structure with the required Tx/Rx parameters. |
<> | 149:156823d33999 | 35 | (+++) Configure the DMA Tx/Rx channel. |
<> | 149:156823d33999 | 36 | (+++) Associate the initilalized DMA handle to the SMARTCARD DMA Tx/Rx handle. |
<> | 149:156823d33999 | 37 | (+++) Configure the priority and enable the NVIC for the transfer complete interrupt on the DMA Tx/Rx channel. |
<> | 149:156823d33999 | 38 | (+++) Configure the USARTx interrupt priority and enable the NVIC USART IRQ handle |
<> | 149:156823d33999 | 39 | (used for last byte sending completion detection in DMA non circular mode) |
<> | 149:156823d33999 | 40 | |
<> | 149:156823d33999 | 41 | (#) Program the Baud Rate, Word Length , Stop Bit, Parity, Hardware |
<> | 149:156823d33999 | 42 | flow control and Mode(Receiver/Transmitter) in the SMARTCARD Init structure. |
<> | 149:156823d33999 | 43 | |
<> | 149:156823d33999 | 44 | (#) Initialize the SMARTCARD registers by calling the HAL_SMARTCARD_Init() API: |
<> | 149:156823d33999 | 45 | (++) This API configures also the low level Hardware GPIO, CLOCK, CORTEX...etc) |
<> | 149:156823d33999 | 46 | by calling the customed HAL_SMARTCARD_MspInit(&hsc) API. |
<> | 149:156823d33999 | 47 | |
<> | 149:156823d33999 | 48 | -@@- The specific SMARTCARD interrupts (Transmission complete interrupt, |
<> | 149:156823d33999 | 49 | RXNE interrupt and Error Interrupts) will be managed using the macros |
<> | 149:156823d33999 | 50 | __HAL_SMARTCARD_ENABLE_IT() and __HAL_SMARTCARD_DISABLE_IT() inside the transmit and receive process. |
<> | 149:156823d33999 | 51 | |
<> | 149:156823d33999 | 52 | (#) Three operation modes are available within this driver : |
<> | 149:156823d33999 | 53 | |
<> | 149:156823d33999 | 54 | *** Polling mode IO operation *** |
<> | 149:156823d33999 | 55 | ================================= |
<> | 149:156823d33999 | 56 | [..] |
<> | 149:156823d33999 | 57 | (+) Send an amount of data in blocking mode using HAL_SMARTCARD_Transmit() |
<> | 149:156823d33999 | 58 | (+) Receive an amount of data in blocking mode using HAL_SMARTCARD_Receive() |
<> | 149:156823d33999 | 59 | |
<> | 149:156823d33999 | 60 | *** Interrupt mode IO operation *** |
<> | 149:156823d33999 | 61 | =================================== |
<> | 149:156823d33999 | 62 | [..] |
<> | 149:156823d33999 | 63 | (+) Send an amount of data in non blocking mode using HAL_SMARTCARD_Transmit_IT() |
<> | 149:156823d33999 | 64 | (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can |
<> | 149:156823d33999 | 65 | add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback |
<> | 149:156823d33999 | 66 | (+) Receive an amount of data in non blocking mode using HAL_SMARTCARD_Receive_IT() |
<> | 149:156823d33999 | 67 | (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can |
<> | 149:156823d33999 | 68 | add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback |
<> | 149:156823d33999 | 69 | (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can |
<> | 149:156823d33999 | 70 | add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback |
<> | 149:156823d33999 | 71 | |
<> | 149:156823d33999 | 72 | *** DMA mode IO operation *** |
<> | 149:156823d33999 | 73 | ============================== |
<> | 149:156823d33999 | 74 | [..] |
<> | 149:156823d33999 | 75 | (+) Send an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Transmit_DMA() |
<> | 149:156823d33999 | 76 | (+) At transmission end of transfer HAL_SMARTCARD_TxCpltCallback is executed and user can |
<> | 149:156823d33999 | 77 | add his own code by customization of function pointer HAL_SMARTCARD_TxCpltCallback |
<> | 149:156823d33999 | 78 | (+) Receive an amount of data in non blocking mode (DMA) using HAL_SMARTCARD_Receive_DMA() |
<> | 149:156823d33999 | 79 | (+) At reception end of transfer HAL_SMARTCARD_RxCpltCallback is executed and user can |
<> | 149:156823d33999 | 80 | add his own code by customization of function pointer HAL_SMARTCARD_RxCpltCallback |
<> | 149:156823d33999 | 81 | (+) In case of transfer Error, HAL_SMARTCARD_ErrorCallback() function is executed and user can |
<> | 149:156823d33999 | 82 | add his own code by customization of function pointer HAL_SMARTCARD_ErrorCallback |
<> | 149:156823d33999 | 83 | |
<> | 149:156823d33999 | 84 | *** SMARTCARD HAL driver macros list *** |
<> | 149:156823d33999 | 85 | ======================================== |
<> | 149:156823d33999 | 86 | [..] |
<> | 149:156823d33999 | 87 | Below the list of most used macros in SMARTCARD HAL driver. |
<> | 149:156823d33999 | 88 | |
<> | 149:156823d33999 | 89 | (+) __HAL_SMARTCARD_ENABLE: Enable the SMARTCARD peripheral |
<> | 149:156823d33999 | 90 | (+) __HAL_SMARTCARD_DISABLE: Disable the SMARTCARD peripheral |
<> | 149:156823d33999 | 91 | (+) __HAL_SMARTCARD_GET_FLAG : Check whether the specified SMARTCARD flag is set or not |
<> | 149:156823d33999 | 92 | (+) __HAL_SMARTCARD_CLEAR_FLAG : Clear the specified SMARTCARD pending flag |
<> | 149:156823d33999 | 93 | (+) __HAL_SMARTCARD_ENABLE_IT: Enable the specified SMARTCARD interrupt |
<> | 149:156823d33999 | 94 | (+) __HAL_SMARTCARD_DISABLE_IT: Disable the specified SMARTCARD interrupt |
<> | 149:156823d33999 | 95 | (+) __HAL_SMARTCARD_GET_IT_SOURCE: Check whether the specified SMARTCARD interrupt has occurred or not |
<> | 149:156823d33999 | 96 | |
<> | 149:156823d33999 | 97 | [..] |
<> | 149:156823d33999 | 98 | (@) You can refer to the SMARTCARD HAL driver header file for more useful macros |
<> | 149:156823d33999 | 99 | |
<> | 149:156823d33999 | 100 | @endverbatim |
<> | 149:156823d33999 | 101 | ****************************************************************************** |
<> | 149:156823d33999 | 102 | * @attention |
<> | 149:156823d33999 | 103 | * |
AnnaBridge | 184:08ed48f1de7f | 104 | * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2> |
<> | 149:156823d33999 | 105 | * |
<> | 149:156823d33999 | 106 | * Redistribution and use in source and binary forms, with or without modification, |
<> | 149:156823d33999 | 107 | * are permitted provided that the following conditions are met: |
<> | 149:156823d33999 | 108 | * 1. Redistributions of source code must retain the above copyright notice, |
<> | 149:156823d33999 | 109 | * this list of conditions and the following disclaimer. |
<> | 149:156823d33999 | 110 | * 2. Redistributions in binary form must reproduce the above copyright notice, |
<> | 149:156823d33999 | 111 | * this list of conditions and the following disclaimer in the documentation |
<> | 149:156823d33999 | 112 | * and/or other materials provided with the distribution. |
<> | 149:156823d33999 | 113 | * 3. Neither the name of STMicroelectronics nor the names of its contributors |
<> | 149:156823d33999 | 114 | * may be used to endorse or promote products derived from this software |
<> | 149:156823d33999 | 115 | * without specific prior written permission. |
<> | 149:156823d33999 | 116 | * |
<> | 149:156823d33999 | 117 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
<> | 149:156823d33999 | 118 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
<> | 149:156823d33999 | 119 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
<> | 149:156823d33999 | 120 | * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE |
<> | 149:156823d33999 | 121 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
<> | 149:156823d33999 | 122 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
<> | 149:156823d33999 | 123 | * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
<> | 149:156823d33999 | 124 | * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
<> | 149:156823d33999 | 125 | * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
<> | 149:156823d33999 | 126 | * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
<> | 149:156823d33999 | 127 | * |
<> | 149:156823d33999 | 128 | ****************************************************************************** |
<> | 149:156823d33999 | 129 | */ |
<> | 149:156823d33999 | 130 | |
<> | 149:156823d33999 | 131 | /* Includes ------------------------------------------------------------------*/ |
<> | 149:156823d33999 | 132 | #include "stm32l1xx_hal.h" |
<> | 149:156823d33999 | 133 | |
<> | 149:156823d33999 | 134 | /** @addtogroup STM32L1xx_HAL_Driver |
<> | 149:156823d33999 | 135 | * @{ |
<> | 149:156823d33999 | 136 | */ |
<> | 149:156823d33999 | 137 | |
<> | 149:156823d33999 | 138 | /** @defgroup SMARTCARD SMARTCARD |
<> | 149:156823d33999 | 139 | * @brief HAL SMARTCARD module driver |
<> | 149:156823d33999 | 140 | * @{ |
<> | 149:156823d33999 | 141 | */ |
<> | 149:156823d33999 | 142 | |
<> | 149:156823d33999 | 143 | #ifdef HAL_SMARTCARD_MODULE_ENABLED |
<> | 149:156823d33999 | 144 | |
<> | 149:156823d33999 | 145 | /* Private typedef -----------------------------------------------------------*/ |
<> | 149:156823d33999 | 146 | /* Private define ------------------------------------------------------------*/ |
<> | 149:156823d33999 | 147 | /* Private macros --------------------------------------------------------*/ |
<> | 149:156823d33999 | 148 | /* Private variables ---------------------------------------------------------*/ |
<> | 149:156823d33999 | 149 | /* Private function prototypes -----------------------------------------------*/ |
<> | 149:156823d33999 | 150 | /** @addtogroup SMARTCARD_Private_Functions SMARTCARD Private Functions |
<> | 149:156823d33999 | 151 | * @{ |
<> | 149:156823d33999 | 152 | */ |
<> | 149:156823d33999 | 153 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc); |
<> | 149:156823d33999 | 154 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard); |
<> | 149:156823d33999 | 155 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc); |
<> | 149:156823d33999 | 156 | static void SMARTCARD_SetConfig (SMARTCARD_HandleTypeDef *hsc); |
<> | 149:156823d33999 | 157 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma); |
<> | 149:156823d33999 | 158 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma); |
<> | 149:156823d33999 | 159 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma); |
<> | 149:156823d33999 | 160 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout); |
<> | 149:156823d33999 | 161 | /** |
<> | 149:156823d33999 | 162 | * @} |
<> | 149:156823d33999 | 163 | */ |
<> | 149:156823d33999 | 164 | |
<> | 149:156823d33999 | 165 | /* Exported functions ---------------------------------------------------------*/ |
<> | 149:156823d33999 | 166 | |
<> | 149:156823d33999 | 167 | /** @defgroup SMARTCARD_Exported_Functions SMARTCARD Exported Functions |
<> | 149:156823d33999 | 168 | * @{ |
<> | 149:156823d33999 | 169 | */ |
<> | 149:156823d33999 | 170 | |
<> | 149:156823d33999 | 171 | /** @defgroup SMARTCARD_Exported_Functions_Group1 Initialization and de-initialization functions |
<> | 149:156823d33999 | 172 | * @brief Initialization and Configuration functions |
<> | 149:156823d33999 | 173 | * |
<> | 149:156823d33999 | 174 | @verbatim |
<> | 149:156823d33999 | 175 | |
<> | 149:156823d33999 | 176 | ============================================================================== |
<> | 149:156823d33999 | 177 | ##### Initialization and Configuration functions ##### |
<> | 149:156823d33999 | 178 | ============================================================================== |
<> | 149:156823d33999 | 179 | [..] |
<> | 149:156823d33999 | 180 | This subsection provides a set of functions allowing to initialize the USART |
<> | 149:156823d33999 | 181 | in Smartcard mode. |
<> | 149:156823d33999 | 182 | [..] |
<> | 149:156823d33999 | 183 | The Smartcard interface is designed to support asynchronous protocol Smartcards as |
<> | 149:156823d33999 | 184 | defined in the ISO 7816-3 standard. |
<> | 149:156823d33999 | 185 | [..] |
<> | 149:156823d33999 | 186 | The USART can provide a clock to the smartcard through the SCLK output. |
<> | 149:156823d33999 | 187 | In smartcard mode, SCLK is not associated to the communication but is simply derived |
<> | 149:156823d33999 | 188 | from the internal peripheral input clock through a 5-bit prescaler. |
<> | 149:156823d33999 | 189 | [..] |
<> | 149:156823d33999 | 190 | (+) For the Smartcard mode only these parameters can be configured: |
<> | 149:156823d33999 | 191 | (++) Baud Rate |
<> | 149:156823d33999 | 192 | (++) Word Length => Should be 9 bits (8 bits + parity) |
<> | 149:156823d33999 | 193 | (++) Stop Bit |
<> | 149:156823d33999 | 194 | (++) Parity: => Should be enabled |
<> | 149:156823d33999 | 195 | (++) USART polarity |
<> | 149:156823d33999 | 196 | (++) USART phase |
<> | 149:156823d33999 | 197 | (++) USART LastBit |
<> | 149:156823d33999 | 198 | (++) Receiver/transmitter modes |
<> | 149:156823d33999 | 199 | (++) Prescaler |
<> | 149:156823d33999 | 200 | (++) GuardTime |
<> | 149:156823d33999 | 201 | (++) NACKState: The Smartcard NACK state |
<> | 149:156823d33999 | 202 | |
<> | 149:156823d33999 | 203 | (+) Recommended SmartCard interface configuration to get the Answer to Reset from the Card: |
<> | 149:156823d33999 | 204 | (++) Word Length = 9 Bits |
<> | 149:156823d33999 | 205 | (++) 1.5 Stop Bit |
<> | 149:156823d33999 | 206 | (++) Even parity |
<> | 149:156823d33999 | 207 | (++) BaudRate = 12096 baud |
<> | 149:156823d33999 | 208 | (++) Tx and Rx enabled |
<> | 149:156823d33999 | 209 | [..] |
<> | 149:156823d33999 | 210 | Please refer to the ISO 7816-3 specification for more details. |
<> | 149:156823d33999 | 211 | |
<> | 149:156823d33999 | 212 | (@) It is also possible to choose 0.5 stop bit for receiving but it is recommended |
<> | 149:156823d33999 | 213 | to use 1.5 stop bits for both transmitting and receiving to avoid switching |
<> | 149:156823d33999 | 214 | between the two configurations. |
<> | 149:156823d33999 | 215 | [..] |
<> | 149:156823d33999 | 216 | The HAL_SMARTCARD_Init() function follows the USART SmartCard configuration |
<> | 149:156823d33999 | 217 | procedure (details for the procedure are available in reference manual (RM0038)). |
<> | 149:156823d33999 | 218 | |
<> | 149:156823d33999 | 219 | @endverbatim |
<> | 149:156823d33999 | 220 | * @{ |
<> | 149:156823d33999 | 221 | */ |
<> | 149:156823d33999 | 222 | |
<> | 149:156823d33999 | 223 | /* |
<> | 149:156823d33999 | 224 | Additionnal remark on the smartcard frame: |
<> | 149:156823d33999 | 225 | +-------------------------------------------------------------+ |
<> | 149:156823d33999 | 226 | | M bit | PCE bit | SMARTCARD frame | |
<> | 149:156823d33999 | 227 | |---------------------|---------------------------------------| |
<> | 149:156823d33999 | 228 | | 1 | 1 | | SB | 8 bit data | PB | STB | | |
<> | 149:156823d33999 | 229 | +-------------------------------------------------------------+ |
<> | 149:156823d33999 | 230 | */ |
<> | 149:156823d33999 | 231 | |
<> | 149:156823d33999 | 232 | /** |
<> | 149:156823d33999 | 233 | * @brief Initializes the SmartCard mode according to the specified |
<> | 149:156823d33999 | 234 | * parameters in the SMARTCARD_HandleTypeDef and create the associated handle. |
<> | 149:156823d33999 | 235 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 236 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 237 | * @retval HAL status |
<> | 149:156823d33999 | 238 | */ |
<> | 149:156823d33999 | 239 | HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 240 | { |
<> | 149:156823d33999 | 241 | /* Check the SMARTCARD handle allocation */ |
<> | 149:156823d33999 | 242 | if(hsc == NULL) |
<> | 149:156823d33999 | 243 | { |
<> | 149:156823d33999 | 244 | return HAL_ERROR; |
<> | 149:156823d33999 | 245 | } |
<> | 149:156823d33999 | 246 | |
<> | 149:156823d33999 | 247 | /* Check Wordlength, Parity and Stop bits parameters */ |
<> | 149:156823d33999 | 248 | if ( (!(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength))) |
<> | 149:156823d33999 | 249 | ||(!(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits))) |
<> | 149:156823d33999 | 250 | ||(!(IS_SMARTCARD_PARITY(hsc->Init.Parity))) ) |
<> | 149:156823d33999 | 251 | { |
<> | 149:156823d33999 | 252 | return HAL_ERROR; |
<> | 149:156823d33999 | 253 | } |
<> | 149:156823d33999 | 254 | |
<> | 149:156823d33999 | 255 | /* Check the parameters */ |
<> | 149:156823d33999 | 256 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
<> | 149:156823d33999 | 257 | assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState)); |
<> | 149:156823d33999 | 258 | assert_param(IS_SMARTCARD_PRESCALER(hsc->Init.Prescaler)); |
<> | 149:156823d33999 | 259 | |
<> | 149:156823d33999 | 260 | if(hsc->State == HAL_SMARTCARD_STATE_RESET) |
<> | 149:156823d33999 | 261 | { |
<> | 149:156823d33999 | 262 | /* Allocate lock resource and initialize it */ |
<> | 149:156823d33999 | 263 | hsc->Lock = HAL_UNLOCKED; |
<> | 149:156823d33999 | 264 | |
<> | 149:156823d33999 | 265 | /* Init the low level hardware */ |
<> | 149:156823d33999 | 266 | HAL_SMARTCARD_MspInit(hsc); |
<> | 149:156823d33999 | 267 | } |
<> | 149:156823d33999 | 268 | |
<> | 149:156823d33999 | 269 | hsc->State = HAL_SMARTCARD_STATE_BUSY; |
<> | 149:156823d33999 | 270 | |
<> | 149:156823d33999 | 271 | /* Disable the Peripheral */ |
<> | 149:156823d33999 | 272 | __HAL_SMARTCARD_DISABLE(hsc); |
<> | 149:156823d33999 | 273 | |
<> | 149:156823d33999 | 274 | /* Set the Prescaler */ |
<> | 149:156823d33999 | 275 | MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_PSC, hsc->Init.Prescaler); |
<> | 149:156823d33999 | 276 | |
<> | 149:156823d33999 | 277 | /* Set the Guard Time */ |
<> | 149:156823d33999 | 278 | MODIFY_REG(hsc->Instance->GTPR, USART_GTPR_GT, ((hsc->Init.GuardTime)<<8)); |
<> | 149:156823d33999 | 279 | |
<> | 149:156823d33999 | 280 | /* Set the Smartcard Communication parameters */ |
<> | 149:156823d33999 | 281 | SMARTCARD_SetConfig(hsc); |
<> | 149:156823d33999 | 282 | |
<> | 149:156823d33999 | 283 | /* In SmartCard mode, the following bits must be kept cleared: |
<> | 149:156823d33999 | 284 | - LINEN bit in the USART_CR2 register |
<> | 149:156823d33999 | 285 | - HDSEL and IREN bits in the USART_CR3 register.*/ |
<> | 149:156823d33999 | 286 | CLEAR_BIT(hsc->Instance->CR2, USART_CR2_LINEN); |
<> | 149:156823d33999 | 287 | CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_IREN | USART_CR3_HDSEL)); |
<> | 149:156823d33999 | 288 | |
<> | 149:156823d33999 | 289 | /* Enable the Peripharal */ |
<> | 149:156823d33999 | 290 | __HAL_SMARTCARD_ENABLE(hsc); |
<> | 149:156823d33999 | 291 | |
<> | 149:156823d33999 | 292 | /* Configure the Smartcard NACK state */ |
<> | 149:156823d33999 | 293 | MODIFY_REG(hsc->Instance->CR3, USART_CR3_NACK, hsc->Init.NACKState); |
<> | 149:156823d33999 | 294 | |
<> | 149:156823d33999 | 295 | /* Enable the SC mode by setting the SCEN bit in the CR3 register */ |
<> | 149:156823d33999 | 296 | SET_BIT(hsc->Instance->CR3, USART_CR3_SCEN); |
<> | 149:156823d33999 | 297 | |
<> | 149:156823d33999 | 298 | /* Initialize the SMARTCARD state*/ |
<> | 149:156823d33999 | 299 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 300 | hsc->State= HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 301 | |
<> | 149:156823d33999 | 302 | return HAL_OK; |
<> | 149:156823d33999 | 303 | } |
<> | 149:156823d33999 | 304 | |
<> | 149:156823d33999 | 305 | /** |
<> | 149:156823d33999 | 306 | * @brief DeInitializes the SMARTCARD peripheral |
<> | 149:156823d33999 | 307 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 308 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 309 | * @retval HAL status |
<> | 149:156823d33999 | 310 | */ |
<> | 149:156823d33999 | 311 | HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 312 | { |
<> | 149:156823d33999 | 313 | /* Check the SMARTCARD handle allocation */ |
<> | 149:156823d33999 | 314 | if(hsc == NULL) |
<> | 149:156823d33999 | 315 | { |
<> | 149:156823d33999 | 316 | return HAL_ERROR; |
<> | 149:156823d33999 | 317 | } |
<> | 149:156823d33999 | 318 | |
<> | 149:156823d33999 | 319 | /* Check the parameters */ |
<> | 149:156823d33999 | 320 | assert_param(IS_SMARTCARD_INSTANCE(hsc->Instance)); |
<> | 149:156823d33999 | 321 | |
<> | 149:156823d33999 | 322 | hsc->State = HAL_SMARTCARD_STATE_BUSY; |
<> | 149:156823d33999 | 323 | |
<> | 149:156823d33999 | 324 | /* Disable the Peripheral */ |
<> | 149:156823d33999 | 325 | __HAL_SMARTCARD_DISABLE(hsc); |
<> | 149:156823d33999 | 326 | |
<> | 149:156823d33999 | 327 | hsc->Instance->CR1 = 0x0; |
<> | 149:156823d33999 | 328 | hsc->Instance->CR2 = 0x0; |
<> | 149:156823d33999 | 329 | hsc->Instance->CR3 = 0x0; |
<> | 149:156823d33999 | 330 | hsc->Instance->BRR = 0x0; |
<> | 149:156823d33999 | 331 | hsc->Instance->GTPR = 0x0; |
<> | 149:156823d33999 | 332 | |
<> | 149:156823d33999 | 333 | /* DeInit the low level hardware */ |
<> | 149:156823d33999 | 334 | HAL_SMARTCARD_MspDeInit(hsc); |
<> | 149:156823d33999 | 335 | |
<> | 149:156823d33999 | 336 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 337 | hsc->State = HAL_SMARTCARD_STATE_RESET; |
<> | 149:156823d33999 | 338 | |
<> | 149:156823d33999 | 339 | /* Release Lock */ |
<> | 149:156823d33999 | 340 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 341 | |
<> | 149:156823d33999 | 342 | return HAL_OK; |
<> | 149:156823d33999 | 343 | } |
<> | 149:156823d33999 | 344 | |
<> | 149:156823d33999 | 345 | /** |
<> | 149:156823d33999 | 346 | * @brief SMARTCARD MSP Init. |
<> | 149:156823d33999 | 347 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 348 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 349 | * @retval None |
<> | 149:156823d33999 | 350 | */ |
<> | 149:156823d33999 | 351 | __weak void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 352 | { |
<> | 149:156823d33999 | 353 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 354 | UNUSED(hsc); |
<> | 149:156823d33999 | 355 | |
<> | 149:156823d33999 | 356 | /* NOTE: This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 357 | the HAL_SMARTCARD_MspInit can be implemented in the user file |
<> | 149:156823d33999 | 358 | */ |
<> | 149:156823d33999 | 359 | } |
<> | 149:156823d33999 | 360 | |
<> | 149:156823d33999 | 361 | /** |
<> | 149:156823d33999 | 362 | * @brief SMARTCARD MSP DeInit. |
<> | 149:156823d33999 | 363 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 364 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 365 | * @retval None |
<> | 149:156823d33999 | 366 | */ |
<> | 149:156823d33999 | 367 | __weak void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 368 | { |
<> | 149:156823d33999 | 369 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 370 | UNUSED(hsc); |
<> | 149:156823d33999 | 371 | |
<> | 149:156823d33999 | 372 | /* NOTE: This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 373 | the HAL_SMARTCARD_MspDeInit can be implemented in the user file |
<> | 149:156823d33999 | 374 | */ |
<> | 149:156823d33999 | 375 | } |
<> | 149:156823d33999 | 376 | |
<> | 149:156823d33999 | 377 | /** |
<> | 149:156823d33999 | 378 | * @} |
<> | 149:156823d33999 | 379 | */ |
<> | 149:156823d33999 | 380 | |
<> | 149:156823d33999 | 381 | /** @defgroup SMARTCARD_Exported_Functions_Group2 IO operation functions |
<> | 149:156823d33999 | 382 | * @brief SMARTCARD Transmit and Receive functions |
<> | 149:156823d33999 | 383 | * |
<> | 149:156823d33999 | 384 | @verbatim |
<> | 149:156823d33999 | 385 | ============================================================================== |
<> | 149:156823d33999 | 386 | ##### IO operation functions ##### |
<> | 149:156823d33999 | 387 | ============================================================================== |
<> | 149:156823d33999 | 388 | [..] |
<> | 149:156823d33999 | 389 | This subsection provides a set of functions allowing to manage the SMARTCARD data transfers. |
<> | 149:156823d33999 | 390 | |
<> | 149:156823d33999 | 391 | [..] |
<> | 149:156823d33999 | 392 | (#) Smartcard is a single wire half duplex communication protocol. |
<> | 149:156823d33999 | 393 | The Smartcard interface is designed to support asynchronous protocol Smartcards as |
<> | 149:156823d33999 | 394 | defined in the ISO 7816-3 standard. |
<> | 149:156823d33999 | 395 | (#) The USART should be configured as: |
<> | 149:156823d33999 | 396 | (++) 8 bits plus parity: where M=1 and PCE=1 in the USART_CR1 register |
<> | 149:156823d33999 | 397 | (++) 1.5 stop bits when transmitting and receiving: where STOP=11 in the USART_CR2 register. |
<> | 149:156823d33999 | 398 | |
<> | 149:156823d33999 | 399 | (#) There are two modes of transfer: |
<> | 149:156823d33999 | 400 | (++) Blocking mode: The communication is performed in polling mode. |
<> | 149:156823d33999 | 401 | The HAL status of all data processing is returned by the same function |
<> | 149:156823d33999 | 402 | after finishing transfer. |
<> | 149:156823d33999 | 403 | (++) No-Blocking mode: The communication is performed using Interrupts |
<> | 149:156823d33999 | 404 | or DMA, the relevant API's return the HAL status. |
<> | 149:156823d33999 | 405 | The end of the data processing will be indicated through the |
<> | 149:156823d33999 | 406 | dedicated SMARTCARD IRQ when using Interrupt mode or the DMA IRQ when |
<> | 149:156823d33999 | 407 | using DMA mode. |
<> | 149:156823d33999 | 408 | The HAL_SMARTCARD_TxCpltCallback(), HAL_SMARTCARD_RxCpltCallback() user callbacks |
<> | 149:156823d33999 | 409 | will be executed respectively at the end of the Transmit or Receive process |
<> | 149:156823d33999 | 410 | The HAL_SMARTCARD_ErrorCallback() user callback will be executed when a communication |
<> | 149:156823d33999 | 411 | error is detected. |
<> | 149:156823d33999 | 412 | |
<> | 149:156823d33999 | 413 | (#) Blocking mode APIs are : |
<> | 149:156823d33999 | 414 | (++) HAL_SMARTCARD_Transmit() |
<> | 149:156823d33999 | 415 | (++) HAL_SMARTCARD_Receive() |
<> | 149:156823d33999 | 416 | |
<> | 149:156823d33999 | 417 | (#) Non Blocking mode APIs with Interrupt are : |
<> | 149:156823d33999 | 418 | (++) HAL_SMARTCARD_Transmit_IT() |
<> | 149:156823d33999 | 419 | (++) HAL_SMARTCARD_Receive_IT() |
<> | 149:156823d33999 | 420 | (++) HAL_SMARTCARD_IRQHandler() |
<> | 149:156823d33999 | 421 | |
<> | 149:156823d33999 | 422 | (#) Non Blocking mode functions with DMA are : |
<> | 149:156823d33999 | 423 | (++) HAL_SMARTCARD_Transmit_DMA() |
<> | 149:156823d33999 | 424 | (++) HAL_SMARTCARD_Receive_DMA() |
<> | 149:156823d33999 | 425 | |
<> | 149:156823d33999 | 426 | (#) A set of Transfer Complete Callbacks are provided in non Blocking mode: |
<> | 149:156823d33999 | 427 | (++) HAL_SMARTCARD_TxCpltCallback() |
<> | 149:156823d33999 | 428 | (++) HAL_SMARTCARD_RxCpltCallback() |
<> | 149:156823d33999 | 429 | (++) HAL_SMARTCARD_ErrorCallback() |
<> | 149:156823d33999 | 430 | |
<> | 149:156823d33999 | 431 | @endverbatim |
<> | 149:156823d33999 | 432 | * @{ |
<> | 149:156823d33999 | 433 | */ |
<> | 149:156823d33999 | 434 | |
<> | 149:156823d33999 | 435 | /** |
<> | 149:156823d33999 | 436 | * @brief Sends an amount of data in blocking mode. |
<> | 149:156823d33999 | 437 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 438 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 439 | * @param pData: Pointer to data buffer |
<> | 149:156823d33999 | 440 | * @param Size: Amount of data to be sent |
<> | 149:156823d33999 | 441 | * @param Timeout: Specify timeout value |
<> | 149:156823d33999 | 442 | * @retval HAL status |
<> | 149:156823d33999 | 443 | */ |
<> | 149:156823d33999 | 444 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
<> | 149:156823d33999 | 445 | { |
<> | 149:156823d33999 | 446 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 447 | |
<> | 149:156823d33999 | 448 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 449 | if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_RX)) |
<> | 149:156823d33999 | 450 | { |
<> | 149:156823d33999 | 451 | if((pData == NULL) || (Size == 0)) |
<> | 149:156823d33999 | 452 | { |
<> | 149:156823d33999 | 453 | return HAL_ERROR; |
<> | 149:156823d33999 | 454 | } |
<> | 149:156823d33999 | 455 | |
<> | 149:156823d33999 | 456 | /* Process Locked */ |
<> | 149:156823d33999 | 457 | __HAL_LOCK(hsc); |
<> | 149:156823d33999 | 458 | |
<> | 149:156823d33999 | 459 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 460 | /* Check if a non-blocking receive process is ongoing or not */ |
<> | 149:156823d33999 | 461 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX) |
<> | 149:156823d33999 | 462 | { |
<> | 149:156823d33999 | 463 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
<> | 149:156823d33999 | 464 | } |
<> | 149:156823d33999 | 465 | else |
<> | 149:156823d33999 | 466 | { |
<> | 149:156823d33999 | 467 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 149:156823d33999 | 468 | } |
<> | 149:156823d33999 | 469 | |
<> | 149:156823d33999 | 470 | hsc->TxXferSize = Size; |
<> | 149:156823d33999 | 471 | hsc->TxXferCount = Size; |
<> | 149:156823d33999 | 472 | while(hsc->TxXferCount > 0) |
<> | 149:156823d33999 | 473 | { |
<> | 149:156823d33999 | 474 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TXE, RESET, Timeout) != HAL_OK) |
<> | 149:156823d33999 | 475 | { |
<> | 149:156823d33999 | 476 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 477 | } |
<> | 149:156823d33999 | 478 | WRITE_REG(hsc->Instance->DR, (*pData++ & (uint8_t)0xFF)); |
<> | 149:156823d33999 | 479 | hsc->TxXferCount--; |
<> | 149:156823d33999 | 480 | } |
<> | 149:156823d33999 | 481 | |
<> | 149:156823d33999 | 482 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_TC, RESET, Timeout) != HAL_OK) |
<> | 149:156823d33999 | 483 | { |
<> | 149:156823d33999 | 484 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 485 | } |
<> | 149:156823d33999 | 486 | |
<> | 149:156823d33999 | 487 | /* Check if a non-blocking receive process is ongoing or not */ |
<> | 149:156823d33999 | 488 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
<> | 149:156823d33999 | 489 | { |
<> | 149:156823d33999 | 490 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 149:156823d33999 | 491 | } |
<> | 149:156823d33999 | 492 | else |
<> | 149:156823d33999 | 493 | { |
<> | 149:156823d33999 | 494 | hsc->State = HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 495 | } |
<> | 149:156823d33999 | 496 | /* Process Unlocked */ |
<> | 149:156823d33999 | 497 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 498 | |
<> | 149:156823d33999 | 499 | return HAL_OK; |
<> | 149:156823d33999 | 500 | } |
<> | 149:156823d33999 | 501 | else |
<> | 149:156823d33999 | 502 | { |
<> | 149:156823d33999 | 503 | return HAL_BUSY; |
<> | 149:156823d33999 | 504 | } |
<> | 149:156823d33999 | 505 | } |
<> | 149:156823d33999 | 506 | |
<> | 149:156823d33999 | 507 | /** |
<> | 149:156823d33999 | 508 | * @brief Receive an amount of data in blocking mode. |
<> | 149:156823d33999 | 509 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 510 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 511 | * @param pData: Pointer to data buffer |
<> | 149:156823d33999 | 512 | * @param Size: Amount of data to be received |
<> | 149:156823d33999 | 513 | * @param Timeout: Specify timeout value |
<> | 149:156823d33999 | 514 | * @retval HAL status |
<> | 149:156823d33999 | 515 | */ |
<> | 149:156823d33999 | 516 | HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout) |
<> | 149:156823d33999 | 517 | { |
<> | 149:156823d33999 | 518 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 519 | |
<> | 149:156823d33999 | 520 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 521 | if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX)) |
<> | 149:156823d33999 | 522 | { |
<> | 149:156823d33999 | 523 | if((pData == NULL) || (Size == 0)) |
<> | 149:156823d33999 | 524 | { |
<> | 149:156823d33999 | 525 | return HAL_ERROR; |
<> | 149:156823d33999 | 526 | } |
<> | 149:156823d33999 | 527 | |
<> | 149:156823d33999 | 528 | /* Process Locked */ |
<> | 149:156823d33999 | 529 | __HAL_LOCK(hsc); |
<> | 149:156823d33999 | 530 | |
<> | 149:156823d33999 | 531 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 532 | |
<> | 149:156823d33999 | 533 | /* Check if a non-blocking transmit process is ongoing or not */ |
<> | 149:156823d33999 | 534 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX) |
<> | 149:156823d33999 | 535 | { |
<> | 149:156823d33999 | 536 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
<> | 149:156823d33999 | 537 | } |
<> | 149:156823d33999 | 538 | else |
<> | 149:156823d33999 | 539 | { |
<> | 149:156823d33999 | 540 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 149:156823d33999 | 541 | } |
<> | 149:156823d33999 | 542 | |
<> | 149:156823d33999 | 543 | hsc->RxXferSize = Size; |
<> | 149:156823d33999 | 544 | hsc->RxXferCount = Size; |
<> | 149:156823d33999 | 545 | /* Check the remain data to be received */ |
<> | 149:156823d33999 | 546 | while(hsc->RxXferCount > 0) |
<> | 149:156823d33999 | 547 | { |
<> | 149:156823d33999 | 548 | if(SMARTCARD_WaitOnFlagUntilTimeout(hsc, SMARTCARD_FLAG_RXNE, RESET, Timeout) != HAL_OK) |
<> | 149:156823d33999 | 549 | { |
<> | 149:156823d33999 | 550 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 551 | } |
<> | 149:156823d33999 | 552 | *pData++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0x00FF); |
<> | 149:156823d33999 | 553 | hsc->RxXferCount--; |
<> | 149:156823d33999 | 554 | } |
<> | 149:156823d33999 | 555 | |
<> | 149:156823d33999 | 556 | /* Check if a non-blocking transmit process is ongoing or not */ |
<> | 149:156823d33999 | 557 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
<> | 149:156823d33999 | 558 | { |
<> | 149:156823d33999 | 559 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 149:156823d33999 | 560 | } |
<> | 149:156823d33999 | 561 | else |
<> | 149:156823d33999 | 562 | { |
<> | 149:156823d33999 | 563 | hsc->State = HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 564 | } |
<> | 149:156823d33999 | 565 | |
<> | 149:156823d33999 | 566 | /* Process Unlocked */ |
<> | 149:156823d33999 | 567 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 568 | |
<> | 149:156823d33999 | 569 | return HAL_OK; |
<> | 149:156823d33999 | 570 | } |
<> | 149:156823d33999 | 571 | else |
<> | 149:156823d33999 | 572 | { |
<> | 149:156823d33999 | 573 | return HAL_BUSY; |
<> | 149:156823d33999 | 574 | } |
<> | 149:156823d33999 | 575 | } |
<> | 149:156823d33999 | 576 | |
<> | 149:156823d33999 | 577 | /** |
<> | 149:156823d33999 | 578 | * @brief Sends an amount of data in non-blocking mode. |
<> | 149:156823d33999 | 579 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 580 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 581 | * @param pData: Pointer to data buffer |
<> | 149:156823d33999 | 582 | * @param Size: Amount of data to be sent |
<> | 149:156823d33999 | 583 | * @retval HAL status |
<> | 149:156823d33999 | 584 | */ |
<> | 149:156823d33999 | 585 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
<> | 149:156823d33999 | 586 | { |
<> | 149:156823d33999 | 587 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 588 | |
<> | 149:156823d33999 | 589 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 590 | if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_RX)) |
<> | 149:156823d33999 | 591 | { |
<> | 149:156823d33999 | 592 | if((pData == NULL) || (Size == 0)) |
<> | 149:156823d33999 | 593 | { |
<> | 149:156823d33999 | 594 | return HAL_ERROR; |
<> | 149:156823d33999 | 595 | } |
<> | 149:156823d33999 | 596 | |
<> | 149:156823d33999 | 597 | /* Process Locked */ |
<> | 149:156823d33999 | 598 | __HAL_LOCK(hsc); |
<> | 149:156823d33999 | 599 | |
<> | 149:156823d33999 | 600 | hsc->pTxBuffPtr = pData; |
<> | 149:156823d33999 | 601 | hsc->TxXferSize = Size; |
<> | 149:156823d33999 | 602 | hsc->TxXferCount = Size; |
<> | 149:156823d33999 | 603 | |
<> | 149:156823d33999 | 604 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 605 | /* Check if a non-blocking receive process is ongoing or not */ |
<> | 149:156823d33999 | 606 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX) |
<> | 149:156823d33999 | 607 | { |
<> | 149:156823d33999 | 608 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
<> | 149:156823d33999 | 609 | } |
<> | 149:156823d33999 | 610 | else |
<> | 149:156823d33999 | 611 | { |
<> | 149:156823d33999 | 612 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 149:156823d33999 | 613 | } |
<> | 149:156823d33999 | 614 | |
<> | 149:156823d33999 | 615 | /* Process Unlocked */ |
<> | 149:156823d33999 | 616 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 617 | |
<> | 149:156823d33999 | 618 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 149:156823d33999 | 619 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR); |
<> | 149:156823d33999 | 620 | |
<> | 149:156823d33999 | 621 | /* Enable the SMARTCARD Transmit data register empty Interrupt */ |
<> | 149:156823d33999 | 622 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TXE); |
<> | 149:156823d33999 | 623 | |
<> | 149:156823d33999 | 624 | return HAL_OK; |
<> | 149:156823d33999 | 625 | } |
<> | 149:156823d33999 | 626 | else |
<> | 149:156823d33999 | 627 | { |
<> | 149:156823d33999 | 628 | return HAL_BUSY; |
<> | 149:156823d33999 | 629 | } |
<> | 149:156823d33999 | 630 | } |
<> | 149:156823d33999 | 631 | |
<> | 149:156823d33999 | 632 | /** |
<> | 149:156823d33999 | 633 | * @brief Receives an amount of data in non-blocking mode. |
<> | 149:156823d33999 | 634 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 635 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 636 | * @param pData: Pointer to data buffer |
<> | 149:156823d33999 | 637 | * @param Size: Amount of data to be received |
<> | 149:156823d33999 | 638 | * @retval HAL status |
<> | 149:156823d33999 | 639 | */ |
<> | 149:156823d33999 | 640 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
<> | 149:156823d33999 | 641 | { |
<> | 149:156823d33999 | 642 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 643 | |
<> | 149:156823d33999 | 644 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 645 | if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX)) |
<> | 149:156823d33999 | 646 | { |
<> | 149:156823d33999 | 647 | if((pData == NULL) || (Size == 0)) |
<> | 149:156823d33999 | 648 | { |
<> | 149:156823d33999 | 649 | return HAL_ERROR; |
<> | 149:156823d33999 | 650 | } |
<> | 149:156823d33999 | 651 | |
<> | 149:156823d33999 | 652 | /* Process Locked */ |
<> | 149:156823d33999 | 653 | __HAL_LOCK(hsc); |
<> | 149:156823d33999 | 654 | |
<> | 149:156823d33999 | 655 | hsc->pRxBuffPtr = pData; |
<> | 149:156823d33999 | 656 | hsc->RxXferSize = Size; |
<> | 149:156823d33999 | 657 | hsc->RxXferCount = Size; |
<> | 149:156823d33999 | 658 | |
<> | 149:156823d33999 | 659 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 660 | /* Check if a non-blocking transmit process is ongoing or not */ |
<> | 149:156823d33999 | 661 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX) |
<> | 149:156823d33999 | 662 | { |
<> | 149:156823d33999 | 663 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
<> | 149:156823d33999 | 664 | } |
<> | 149:156823d33999 | 665 | else |
<> | 149:156823d33999 | 666 | { |
<> | 149:156823d33999 | 667 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 149:156823d33999 | 668 | } |
<> | 149:156823d33999 | 669 | |
<> | 149:156823d33999 | 670 | /* Process Unlocked */ |
<> | 149:156823d33999 | 671 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 672 | |
<> | 149:156823d33999 | 673 | /* Enable the SMARTCARD Data Register not empty Interrupt */ |
<> | 149:156823d33999 | 674 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_RXNE); |
<> | 149:156823d33999 | 675 | |
<> | 149:156823d33999 | 676 | /* Enable the SMARTCARD Parity Error Interrupt */ |
<> | 149:156823d33999 | 677 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_PE); |
<> | 149:156823d33999 | 678 | |
<> | 149:156823d33999 | 679 | /* Enable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 149:156823d33999 | 680 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_ERR); |
<> | 149:156823d33999 | 681 | |
<> | 149:156823d33999 | 682 | return HAL_OK; |
<> | 149:156823d33999 | 683 | } |
<> | 149:156823d33999 | 684 | else |
<> | 149:156823d33999 | 685 | { |
<> | 149:156823d33999 | 686 | return HAL_BUSY; |
<> | 149:156823d33999 | 687 | } |
<> | 149:156823d33999 | 688 | } |
<> | 149:156823d33999 | 689 | |
<> | 149:156823d33999 | 690 | /** |
<> | 149:156823d33999 | 691 | * @brief Sends an amount of data in non-blocking mode. |
<> | 149:156823d33999 | 692 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 693 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 694 | * @param pData: Pointer to data buffer |
<> | 149:156823d33999 | 695 | * @param Size: Amount of data to be sent |
<> | 149:156823d33999 | 696 | * @retval HAL status |
<> | 149:156823d33999 | 697 | */ |
<> | 149:156823d33999 | 698 | HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
<> | 149:156823d33999 | 699 | { |
<> | 149:156823d33999 | 700 | uint32_t *tmp = 0; |
<> | 149:156823d33999 | 701 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 702 | |
<> | 149:156823d33999 | 703 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 704 | if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_RX)) |
<> | 149:156823d33999 | 705 | { |
<> | 149:156823d33999 | 706 | if((pData == NULL) || (Size == 0)) |
<> | 149:156823d33999 | 707 | { |
<> | 149:156823d33999 | 708 | return HAL_ERROR; |
<> | 149:156823d33999 | 709 | } |
<> | 149:156823d33999 | 710 | |
<> | 149:156823d33999 | 711 | /* Process Locked */ |
<> | 149:156823d33999 | 712 | __HAL_LOCK(hsc); |
<> | 149:156823d33999 | 713 | |
<> | 149:156823d33999 | 714 | hsc->pTxBuffPtr = pData; |
<> | 149:156823d33999 | 715 | hsc->TxXferSize = Size; |
<> | 149:156823d33999 | 716 | hsc->TxXferCount = Size; |
<> | 149:156823d33999 | 717 | |
<> | 149:156823d33999 | 718 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 719 | /* Check if a non-blocking receive process is ongoing or not */ |
<> | 149:156823d33999 | 720 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_RX) |
<> | 149:156823d33999 | 721 | { |
<> | 149:156823d33999 | 722 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
<> | 149:156823d33999 | 723 | } |
<> | 149:156823d33999 | 724 | else |
<> | 149:156823d33999 | 725 | { |
<> | 149:156823d33999 | 726 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 149:156823d33999 | 727 | } |
<> | 149:156823d33999 | 728 | |
<> | 149:156823d33999 | 729 | /* Set the SMARTCARD DMA transfer complete callback */ |
<> | 149:156823d33999 | 730 | hsc->hdmatx->XferCpltCallback = SMARTCARD_DMATransmitCplt; |
<> | 149:156823d33999 | 731 | |
<> | 149:156823d33999 | 732 | /* Set the DMA error callback */ |
<> | 149:156823d33999 | 733 | hsc->hdmatx->XferErrorCallback = SMARTCARD_DMAError; |
<> | 149:156823d33999 | 734 | |
<> | 149:156823d33999 | 735 | /* Enable the SMARTCARD transmit DMA channel */ |
<> | 149:156823d33999 | 736 | tmp = (uint32_t*)&pData; |
<> | 149:156823d33999 | 737 | HAL_DMA_Start_IT(hsc->hdmatx, *(uint32_t*)tmp, (uint32_t)&hsc->Instance->DR, Size); |
<> | 149:156823d33999 | 738 | |
<> | 149:156823d33999 | 739 | /* Clear the TC flag in the SR register by writing 0 to it */ |
<> | 149:156823d33999 | 740 | __HAL_SMARTCARD_CLEAR_FLAG(hsc, SMARTCARD_FLAG_TC); |
<> | 149:156823d33999 | 741 | |
<> | 149:156823d33999 | 742 | /* Enable the DMA transfer for transmit request by setting the DMAT bit |
<> | 149:156823d33999 | 743 | in the SMARTCARD CR3 register */ |
<> | 149:156823d33999 | 744 | SET_BIT(hsc->Instance->CR3,USART_CR3_DMAT); |
<> | 149:156823d33999 | 745 | |
<> | 149:156823d33999 | 746 | /* Process Unlocked */ |
<> | 149:156823d33999 | 747 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 748 | |
<> | 149:156823d33999 | 749 | return HAL_OK; |
<> | 149:156823d33999 | 750 | } |
<> | 149:156823d33999 | 751 | else |
<> | 149:156823d33999 | 752 | { |
<> | 149:156823d33999 | 753 | return HAL_BUSY; |
<> | 149:156823d33999 | 754 | } |
<> | 149:156823d33999 | 755 | } |
<> | 149:156823d33999 | 756 | |
<> | 149:156823d33999 | 757 | /** |
<> | 149:156823d33999 | 758 | * @brief Receive an amount of data in non-blocking mode. |
<> | 149:156823d33999 | 759 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 760 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 761 | * @param pData: Pointer to data buffer |
<> | 149:156823d33999 | 762 | * @param Size: Amount of data to be received |
<> | 149:156823d33999 | 763 | * @note When the SMARTCARD parity is enabled (PCE = 1) the data received contain the parity bit. |
<> | 149:156823d33999 | 764 | * @retval HAL status |
<> | 149:156823d33999 | 765 | */ |
<> | 149:156823d33999 | 766 | HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size) |
<> | 149:156823d33999 | 767 | { |
<> | 149:156823d33999 | 768 | uint32_t *tmp = 0; |
<> | 149:156823d33999 | 769 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 770 | |
<> | 149:156823d33999 | 771 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 772 | if((tmp_state == HAL_SMARTCARD_STATE_READY) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX)) |
<> | 149:156823d33999 | 773 | { |
<> | 149:156823d33999 | 774 | if((pData == NULL) || (Size == 0)) |
<> | 149:156823d33999 | 775 | { |
<> | 149:156823d33999 | 776 | return HAL_ERROR; |
<> | 149:156823d33999 | 777 | } |
<> | 149:156823d33999 | 778 | |
<> | 149:156823d33999 | 779 | /* Process Locked */ |
<> | 149:156823d33999 | 780 | __HAL_LOCK(hsc); |
<> | 149:156823d33999 | 781 | |
<> | 149:156823d33999 | 782 | hsc->pRxBuffPtr = pData; |
<> | 149:156823d33999 | 783 | hsc->RxXferSize = Size; |
<> | 149:156823d33999 | 784 | |
<> | 149:156823d33999 | 785 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_NONE; |
<> | 149:156823d33999 | 786 | /* Check if a non-blocking transmit process is ongoing or not */ |
<> | 149:156823d33999 | 787 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX) |
<> | 149:156823d33999 | 788 | { |
<> | 149:156823d33999 | 789 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX_RX; |
<> | 149:156823d33999 | 790 | } |
<> | 149:156823d33999 | 791 | else |
<> | 149:156823d33999 | 792 | { |
<> | 149:156823d33999 | 793 | hsc->State = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 149:156823d33999 | 794 | } |
<> | 149:156823d33999 | 795 | |
<> | 149:156823d33999 | 796 | /* Set the SMARTCARD DMA transfer complete callback */ |
<> | 149:156823d33999 | 797 | hsc->hdmarx->XferCpltCallback = SMARTCARD_DMAReceiveCplt; |
<> | 149:156823d33999 | 798 | |
<> | 149:156823d33999 | 799 | /* Set the DMA error callback */ |
<> | 149:156823d33999 | 800 | hsc->hdmarx->XferErrorCallback = SMARTCARD_DMAError; |
<> | 149:156823d33999 | 801 | |
<> | 149:156823d33999 | 802 | /* Enable the DMA channel */ |
<> | 149:156823d33999 | 803 | tmp = (uint32_t*)&pData; |
<> | 149:156823d33999 | 804 | HAL_DMA_Start_IT(hsc->hdmarx, (uint32_t)&hsc->Instance->DR, *(uint32_t*)tmp, Size); |
<> | 149:156823d33999 | 805 | |
<> | 149:156823d33999 | 806 | /* Enable the DMA transfer for the receiver request by setting the DMAR bit |
<> | 149:156823d33999 | 807 | in the SMARTCARD CR3 register */ |
<> | 149:156823d33999 | 808 | SET_BIT(hsc->Instance->CR3,USART_CR3_DMAR); |
<> | 149:156823d33999 | 809 | |
<> | 149:156823d33999 | 810 | /* Process Unlocked */ |
<> | 149:156823d33999 | 811 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 812 | |
<> | 149:156823d33999 | 813 | return HAL_OK; |
<> | 149:156823d33999 | 814 | } |
<> | 149:156823d33999 | 815 | else |
<> | 149:156823d33999 | 816 | { |
<> | 149:156823d33999 | 817 | return HAL_BUSY; |
<> | 149:156823d33999 | 818 | } |
<> | 149:156823d33999 | 819 | } |
<> | 149:156823d33999 | 820 | |
<> | 149:156823d33999 | 821 | /** |
<> | 149:156823d33999 | 822 | * @brief This function handles SMARTCARD interrupt request. |
<> | 149:156823d33999 | 823 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 824 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 825 | * @retval None |
<> | 149:156823d33999 | 826 | */ |
<> | 149:156823d33999 | 827 | void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 828 | { |
<> | 149:156823d33999 | 829 | uint32_t tmp_flag = 0, tmp_it_source = 0; |
<> | 149:156823d33999 | 830 | |
<> | 149:156823d33999 | 831 | tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_PE); |
<> | 149:156823d33999 | 832 | tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_PE); |
<> | 149:156823d33999 | 833 | /* SMARTCARD parity error interrupt occurred -----------------------------------*/ |
<> | 149:156823d33999 | 834 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) |
<> | 149:156823d33999 | 835 | { |
<> | 149:156823d33999 | 836 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_PE; |
<> | 149:156823d33999 | 837 | } |
<> | 149:156823d33999 | 838 | |
<> | 149:156823d33999 | 839 | tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_FE); |
<> | 149:156823d33999 | 840 | tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_ERR); |
<> | 149:156823d33999 | 841 | /* SMARTCARD frame error interrupt occurred ------------------------------------*/ |
<> | 149:156823d33999 | 842 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) |
<> | 149:156823d33999 | 843 | { |
<> | 149:156823d33999 | 844 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_FE; |
<> | 149:156823d33999 | 845 | } |
<> | 149:156823d33999 | 846 | |
<> | 149:156823d33999 | 847 | tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_NE); |
<> | 149:156823d33999 | 848 | /* SMARTCARD noise error interrupt occurred ------------------------------------*/ |
<> | 149:156823d33999 | 849 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) |
<> | 149:156823d33999 | 850 | { |
<> | 149:156823d33999 | 851 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_NE; |
<> | 149:156823d33999 | 852 | } |
<> | 149:156823d33999 | 853 | |
<> | 149:156823d33999 | 854 | tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_ORE); |
<> | 149:156823d33999 | 855 | /* SMARTCARD Over-Run interrupt occurred ---------------------------------------*/ |
<> | 149:156823d33999 | 856 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) |
<> | 149:156823d33999 | 857 | { |
<> | 149:156823d33999 | 858 | hsc->ErrorCode |= HAL_SMARTCARD_ERROR_ORE; |
<> | 149:156823d33999 | 859 | } |
<> | 149:156823d33999 | 860 | |
<> | 149:156823d33999 | 861 | tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_RXNE); |
<> | 149:156823d33999 | 862 | tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_RXNE); |
<> | 149:156823d33999 | 863 | /* SMARTCARD in mode Receiver --------------------------------------------------*/ |
<> | 149:156823d33999 | 864 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) |
<> | 149:156823d33999 | 865 | { |
<> | 149:156823d33999 | 866 | SMARTCARD_Receive_IT(hsc); |
<> | 149:156823d33999 | 867 | } |
<> | 149:156823d33999 | 868 | |
<> | 149:156823d33999 | 869 | tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_TXE); |
<> | 149:156823d33999 | 870 | tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_TXE); |
<> | 149:156823d33999 | 871 | /* SMARTCARD in mode Transmitter -----------------------------------------------*/ |
<> | 149:156823d33999 | 872 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) |
<> | 149:156823d33999 | 873 | { |
<> | 149:156823d33999 | 874 | SMARTCARD_Transmit_IT(hsc); |
<> | 149:156823d33999 | 875 | } |
<> | 149:156823d33999 | 876 | |
<> | 149:156823d33999 | 877 | tmp_flag = __HAL_SMARTCARD_GET_FLAG(hsc, SMARTCARD_FLAG_TC); |
<> | 149:156823d33999 | 878 | tmp_it_source = __HAL_SMARTCARD_GET_IT_SOURCE(hsc, SMARTCARD_IT_TC); |
<> | 149:156823d33999 | 879 | /* SMARTCARD in mode Transmitter (transmission end) ------------------------*/ |
<> | 149:156823d33999 | 880 | if((tmp_flag != RESET) && (tmp_it_source != RESET)) |
<> | 149:156823d33999 | 881 | { |
<> | 149:156823d33999 | 882 | SMARTCARD_EndTransmit_IT(hsc); |
<> | 149:156823d33999 | 883 | } |
<> | 149:156823d33999 | 884 | |
<> | 149:156823d33999 | 885 | /* Call the Error call Back in case of Errors */ |
<> | 149:156823d33999 | 886 | if(hsc->ErrorCode != HAL_SMARTCARD_ERROR_NONE) |
<> | 149:156823d33999 | 887 | { |
<> | 149:156823d33999 | 888 | /* Clear all the error flag at once */ |
<> | 149:156823d33999 | 889 | __HAL_SMARTCARD_CLEAR_PEFLAG(hsc); |
<> | 149:156823d33999 | 890 | |
<> | 149:156823d33999 | 891 | /* Set the SMARTCARD state ready to be able to start again the process */ |
<> | 149:156823d33999 | 892 | hsc->State= HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 893 | HAL_SMARTCARD_ErrorCallback(hsc); |
<> | 149:156823d33999 | 894 | } |
<> | 149:156823d33999 | 895 | } |
<> | 149:156823d33999 | 896 | |
<> | 149:156823d33999 | 897 | /** |
<> | 149:156823d33999 | 898 | * @brief Tx Transfer completed callback. |
<> | 149:156823d33999 | 899 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 900 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 901 | * @retval None |
<> | 149:156823d33999 | 902 | */ |
<> | 149:156823d33999 | 903 | __weak void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 904 | { |
<> | 149:156823d33999 | 905 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 906 | UNUSED(hsc); |
<> | 149:156823d33999 | 907 | |
<> | 149:156823d33999 | 908 | /* NOTE: This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 909 | the HAL_SMARTCARD_TxCpltCallback can be implemented in the user file |
<> | 149:156823d33999 | 910 | */ |
<> | 149:156823d33999 | 911 | } |
<> | 149:156823d33999 | 912 | |
<> | 149:156823d33999 | 913 | /** |
<> | 149:156823d33999 | 914 | * @brief Rx Transfer completed callback. |
<> | 149:156823d33999 | 915 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 916 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 917 | * @retval None |
<> | 149:156823d33999 | 918 | */ |
<> | 149:156823d33999 | 919 | __weak void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 920 | { |
<> | 149:156823d33999 | 921 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 922 | UNUSED(hsc); |
<> | 149:156823d33999 | 923 | |
<> | 149:156823d33999 | 924 | /* NOTE: This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 925 | the HAL_SMARTCARD_RxCpltCallback can be implemented in the user file |
<> | 149:156823d33999 | 926 | */ |
<> | 149:156823d33999 | 927 | } |
<> | 149:156823d33999 | 928 | |
<> | 149:156823d33999 | 929 | /** |
<> | 149:156823d33999 | 930 | * @brief SMARTCARD error callback. |
<> | 149:156823d33999 | 931 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 932 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 933 | * @retval None |
<> | 149:156823d33999 | 934 | */ |
<> | 149:156823d33999 | 935 | __weak void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 936 | { |
<> | 149:156823d33999 | 937 | /* Prevent unused argument(s) compilation warning */ |
<> | 149:156823d33999 | 938 | UNUSED(hsc); |
<> | 149:156823d33999 | 939 | |
<> | 149:156823d33999 | 940 | /* NOTE: This function should not be modified, when the callback is needed, |
<> | 149:156823d33999 | 941 | the HAL_SMARTCARD_ErrorCallback can be implemented in the user file |
<> | 149:156823d33999 | 942 | */ |
<> | 149:156823d33999 | 943 | } |
<> | 149:156823d33999 | 944 | |
<> | 149:156823d33999 | 945 | /** |
<> | 149:156823d33999 | 946 | * @} |
<> | 149:156823d33999 | 947 | */ |
<> | 149:156823d33999 | 948 | |
<> | 149:156823d33999 | 949 | /** @defgroup SMARTCARD_Exported_Functions_Group3 Peripheral State and Errors functions |
<> | 149:156823d33999 | 950 | * @brief SMARTCARD State and Errors functions |
<> | 149:156823d33999 | 951 | * |
<> | 149:156823d33999 | 952 | @verbatim |
<> | 149:156823d33999 | 953 | ============================================================================== |
<> | 149:156823d33999 | 954 | ##### Peripheral State and Errors functions ##### |
<> | 149:156823d33999 | 955 | ============================================================================== |
<> | 149:156823d33999 | 956 | [..] |
<> | 149:156823d33999 | 957 | This subsection provides a set of functions allowing to return the State of SmartCard |
<> | 149:156823d33999 | 958 | communication process and also return Peripheral Errors occurred during communication process |
<> | 149:156823d33999 | 959 | (+) HAL_SMARTCARD_GetState() API can be helpful to check in run-time the state |
<> | 149:156823d33999 | 960 | of the SMARTCARD peripheral. |
<> | 149:156823d33999 | 961 | (+) HAL_SMARTCARD_GetError() check in run-time errors that could be occurred during |
<> | 149:156823d33999 | 962 | communication. |
<> | 149:156823d33999 | 963 | |
<> | 149:156823d33999 | 964 | @endverbatim |
<> | 149:156823d33999 | 965 | * @{ |
<> | 149:156823d33999 | 966 | */ |
<> | 149:156823d33999 | 967 | |
<> | 149:156823d33999 | 968 | /** |
<> | 149:156823d33999 | 969 | * @brief Returns the SMARTCARD state. |
<> | 149:156823d33999 | 970 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 971 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 972 | * @retval HAL state |
<> | 149:156823d33999 | 973 | */ |
<> | 149:156823d33999 | 974 | HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 975 | { |
<> | 149:156823d33999 | 976 | return hsc->State; |
<> | 149:156823d33999 | 977 | } |
<> | 149:156823d33999 | 978 | |
<> | 149:156823d33999 | 979 | /** |
<> | 149:156823d33999 | 980 | * @brief Return the SMARTCARD error code |
<> | 149:156823d33999 | 981 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 982 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 983 | * @retval SMARTCARD Error Code |
<> | 149:156823d33999 | 984 | */ |
<> | 149:156823d33999 | 985 | uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 986 | { |
<> | 149:156823d33999 | 987 | return hsc->ErrorCode; |
<> | 149:156823d33999 | 988 | } |
<> | 149:156823d33999 | 989 | |
<> | 149:156823d33999 | 990 | /** |
<> | 149:156823d33999 | 991 | * @} |
<> | 149:156823d33999 | 992 | */ |
<> | 149:156823d33999 | 993 | |
<> | 149:156823d33999 | 994 | /** |
<> | 149:156823d33999 | 995 | * @} |
<> | 149:156823d33999 | 996 | */ |
<> | 149:156823d33999 | 997 | |
<> | 149:156823d33999 | 998 | /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions |
<> | 149:156823d33999 | 999 | * @brief SMARTCARD Private functions |
<> | 149:156823d33999 | 1000 | * @{ |
<> | 149:156823d33999 | 1001 | */ |
<> | 149:156823d33999 | 1002 | /** |
<> | 149:156823d33999 | 1003 | * @brief DMA SMARTCARD transmit process complete callback. |
<> | 149:156823d33999 | 1004 | * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1005 | * the configuration information for the specified DMA module. |
<> | 149:156823d33999 | 1006 | * @retval None |
<> | 149:156823d33999 | 1007 | */ |
<> | 149:156823d33999 | 1008 | static void SMARTCARD_DMATransmitCplt(DMA_HandleTypeDef *hdma) |
<> | 149:156823d33999 | 1009 | { |
<> | 149:156823d33999 | 1010 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
<> | 149:156823d33999 | 1011 | |
<> | 149:156823d33999 | 1012 | hsc->TxXferCount = 0; |
<> | 149:156823d33999 | 1013 | |
<> | 149:156823d33999 | 1014 | /* Disable the DMA transfer for transmit request by setting the DMAT bit |
<> | 149:156823d33999 | 1015 | in the SMARTCARD CR3 register */ |
<> | 149:156823d33999 | 1016 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAT); |
<> | 149:156823d33999 | 1017 | |
<> | 149:156823d33999 | 1018 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
<> | 149:156823d33999 | 1019 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TC); |
<> | 149:156823d33999 | 1020 | } |
<> | 149:156823d33999 | 1021 | |
<> | 149:156823d33999 | 1022 | /** |
<> | 149:156823d33999 | 1023 | * @brief DMA SMARTCARD receive process complete callback. |
<> | 149:156823d33999 | 1024 | * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1025 | * the configuration information for the specified DMA module. |
<> | 149:156823d33999 | 1026 | * @retval None |
<> | 149:156823d33999 | 1027 | */ |
<> | 149:156823d33999 | 1028 | static void SMARTCARD_DMAReceiveCplt(DMA_HandleTypeDef *hdma) |
<> | 149:156823d33999 | 1029 | { |
<> | 149:156823d33999 | 1030 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
<> | 149:156823d33999 | 1031 | |
<> | 149:156823d33999 | 1032 | hsc->RxXferCount = 0; |
<> | 149:156823d33999 | 1033 | |
<> | 149:156823d33999 | 1034 | /* Disable the DMA transfer for the receiver request by setting the DMAR bit |
<> | 149:156823d33999 | 1035 | in the USART CR3 register */ |
<> | 149:156823d33999 | 1036 | CLEAR_BIT(hsc->Instance->CR3, USART_CR3_DMAR); |
<> | 149:156823d33999 | 1037 | |
<> | 149:156823d33999 | 1038 | /* Check if a non-blocking transmit process is ongoing or not */ |
<> | 149:156823d33999 | 1039 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
<> | 149:156823d33999 | 1040 | { |
<> | 149:156823d33999 | 1041 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 149:156823d33999 | 1042 | } |
<> | 149:156823d33999 | 1043 | else |
<> | 149:156823d33999 | 1044 | { |
<> | 149:156823d33999 | 1045 | hsc->State = HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 1046 | } |
<> | 149:156823d33999 | 1047 | |
<> | 149:156823d33999 | 1048 | HAL_SMARTCARD_RxCpltCallback(hsc); |
<> | 149:156823d33999 | 1049 | } |
<> | 149:156823d33999 | 1050 | |
<> | 149:156823d33999 | 1051 | /** |
<> | 149:156823d33999 | 1052 | * @brief DMA SMARTCARD communication error callback. |
<> | 149:156823d33999 | 1053 | * @param hdma: Pointer to a DMA_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1054 | * the configuration information for the specified DMA module. |
<> | 149:156823d33999 | 1055 | * @retval None |
<> | 149:156823d33999 | 1056 | */ |
<> | 149:156823d33999 | 1057 | static void SMARTCARD_DMAError(DMA_HandleTypeDef *hdma) |
<> | 149:156823d33999 | 1058 | { |
<> | 149:156823d33999 | 1059 | SMARTCARD_HandleTypeDef* hsc = ( SMARTCARD_HandleTypeDef* )((DMA_HandleTypeDef* )hdma)->Parent; |
<> | 149:156823d33999 | 1060 | |
<> | 149:156823d33999 | 1061 | hsc->RxXferCount = 0; |
<> | 149:156823d33999 | 1062 | hsc->TxXferCount = 0; |
<> | 149:156823d33999 | 1063 | hsc->ErrorCode = HAL_SMARTCARD_ERROR_DMA; |
<> | 149:156823d33999 | 1064 | hsc->State= HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 1065 | |
<> | 149:156823d33999 | 1066 | HAL_SMARTCARD_ErrorCallback(hsc); |
<> | 149:156823d33999 | 1067 | } |
<> | 149:156823d33999 | 1068 | |
<> | 149:156823d33999 | 1069 | /** |
<> | 149:156823d33999 | 1070 | * @brief This function handles SMARTCARD Communication Timeout. |
<> | 149:156823d33999 | 1071 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1072 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 1073 | * @param Flag: specifies the SMARTCARD flag to check. |
<> | 149:156823d33999 | 1074 | * @param Status: The new Flag status (SET or RESET). |
<> | 149:156823d33999 | 1075 | * @param Timeout: Timeout duration |
<> | 149:156823d33999 | 1076 | * @retval HAL status |
<> | 149:156823d33999 | 1077 | */ |
<> | 149:156823d33999 | 1078 | static HAL_StatusTypeDef SMARTCARD_WaitOnFlagUntilTimeout(SMARTCARD_HandleTypeDef *hsc, uint32_t Flag, FlagStatus Status, uint32_t Timeout) |
<> | 149:156823d33999 | 1079 | { |
<> | 149:156823d33999 | 1080 | uint32_t tickstart = 0; |
<> | 149:156823d33999 | 1081 | |
<> | 149:156823d33999 | 1082 | /* Get tick */ |
<> | 149:156823d33999 | 1083 | tickstart = HAL_GetTick(); |
<> | 149:156823d33999 | 1084 | |
<> | 149:156823d33999 | 1085 | /* Wait until flag is set */ |
<> | 149:156823d33999 | 1086 | if(Status == RESET) |
<> | 149:156823d33999 | 1087 | { |
<> | 149:156823d33999 | 1088 | while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) == RESET) |
<> | 149:156823d33999 | 1089 | { |
<> | 149:156823d33999 | 1090 | /* Check for the Timeout */ |
<> | 149:156823d33999 | 1091 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 1092 | { |
<> | 149:156823d33999 | 1093 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 1094 | { |
<> | 149:156823d33999 | 1095 | /* Disable TXE and RXNE interrupts for the interrupt process */ |
<> | 149:156823d33999 | 1096 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE); |
<> | 149:156823d33999 | 1097 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE); |
<> | 149:156823d33999 | 1098 | |
<> | 149:156823d33999 | 1099 | hsc->State= HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 1100 | |
<> | 149:156823d33999 | 1101 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1102 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 1103 | |
<> | 149:156823d33999 | 1104 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1105 | } |
<> | 149:156823d33999 | 1106 | } |
<> | 149:156823d33999 | 1107 | } |
<> | 149:156823d33999 | 1108 | } |
<> | 149:156823d33999 | 1109 | else |
<> | 149:156823d33999 | 1110 | { |
<> | 149:156823d33999 | 1111 | while(__HAL_SMARTCARD_GET_FLAG(hsc, Flag) != RESET) |
<> | 149:156823d33999 | 1112 | { |
<> | 149:156823d33999 | 1113 | /* Check for the Timeout */ |
<> | 149:156823d33999 | 1114 | if(Timeout != HAL_MAX_DELAY) |
<> | 149:156823d33999 | 1115 | { |
<> | 149:156823d33999 | 1116 | if((Timeout == 0)||((HAL_GetTick() - tickstart ) > Timeout)) |
<> | 149:156823d33999 | 1117 | { |
<> | 149:156823d33999 | 1118 | /* Disable TXE and RXNE interrupts for the interrupt process */ |
<> | 149:156823d33999 | 1119 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE); |
<> | 149:156823d33999 | 1120 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE); |
<> | 149:156823d33999 | 1121 | |
<> | 149:156823d33999 | 1122 | hsc->State= HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 1123 | |
<> | 149:156823d33999 | 1124 | /* Process Unlocked */ |
<> | 149:156823d33999 | 1125 | __HAL_UNLOCK(hsc); |
<> | 149:156823d33999 | 1126 | |
<> | 149:156823d33999 | 1127 | return HAL_TIMEOUT; |
<> | 149:156823d33999 | 1128 | } |
<> | 149:156823d33999 | 1129 | } |
<> | 149:156823d33999 | 1130 | } |
<> | 149:156823d33999 | 1131 | } |
<> | 149:156823d33999 | 1132 | return HAL_OK; |
<> | 149:156823d33999 | 1133 | } |
<> | 149:156823d33999 | 1134 | |
<> | 149:156823d33999 | 1135 | /** |
<> | 149:156823d33999 | 1136 | * @brief Send an amount of data in non-blocking mode. |
<> | 149:156823d33999 | 1137 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1138 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 1139 | * Function called under interruption only, once |
<> | 149:156823d33999 | 1140 | * interruptions have been enabled by HAL_SMARTCARD_Transmit_IT() |
<> | 149:156823d33999 | 1141 | * @retval HAL status |
<> | 149:156823d33999 | 1142 | */ |
<> | 149:156823d33999 | 1143 | static HAL_StatusTypeDef SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 1144 | { |
<> | 149:156823d33999 | 1145 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 1146 | |
<> | 149:156823d33999 | 1147 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 1148 | if((tmp_state == HAL_SMARTCARD_STATE_BUSY_TX) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX_RX)) |
<> | 149:156823d33999 | 1149 | { |
<> | 149:156823d33999 | 1150 | WRITE_REG(hsc->Instance->DR, (*hsc->pTxBuffPtr++ & (uint8_t)0xFF)); |
<> | 149:156823d33999 | 1151 | |
<> | 149:156823d33999 | 1152 | if(--hsc->TxXferCount == 0) |
<> | 149:156823d33999 | 1153 | { |
<> | 149:156823d33999 | 1154 | /* Disable the SMARTCARD Transmit Data Register Empty Interrupt */ |
<> | 149:156823d33999 | 1155 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_TXE); |
<> | 149:156823d33999 | 1156 | |
<> | 149:156823d33999 | 1157 | /* Enable the SMARTCARD Transmit Complete Interrupt */ |
<> | 149:156823d33999 | 1158 | __HAL_SMARTCARD_ENABLE_IT(hsc, SMARTCARD_IT_TC); |
<> | 149:156823d33999 | 1159 | } |
<> | 149:156823d33999 | 1160 | |
<> | 149:156823d33999 | 1161 | return HAL_OK; |
<> | 149:156823d33999 | 1162 | } |
<> | 149:156823d33999 | 1163 | else |
<> | 149:156823d33999 | 1164 | { |
<> | 149:156823d33999 | 1165 | return HAL_BUSY; |
<> | 149:156823d33999 | 1166 | } |
<> | 149:156823d33999 | 1167 | } |
<> | 149:156823d33999 | 1168 | |
<> | 149:156823d33999 | 1169 | |
<> | 149:156823d33999 | 1170 | /** |
<> | 149:156823d33999 | 1171 | * @brief Wraps up transmission in non blocking mode. |
<> | 149:156823d33999 | 1172 | * @param hsmartcard: pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1173 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 1174 | * @retval HAL status |
<> | 149:156823d33999 | 1175 | */ |
<> | 149:156823d33999 | 1176 | static HAL_StatusTypeDef SMARTCARD_EndTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard) |
<> | 149:156823d33999 | 1177 | { |
<> | 149:156823d33999 | 1178 | /* Disable the SMARTCARD Transmit Complete Interrupt */ |
<> | 149:156823d33999 | 1179 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_TC); |
<> | 149:156823d33999 | 1180 | |
<> | 149:156823d33999 | 1181 | /* Check if a receive process is ongoing or not */ |
<> | 149:156823d33999 | 1182 | if(hsmartcard->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
<> | 149:156823d33999 | 1183 | { |
<> | 149:156823d33999 | 1184 | hsmartcard->State = HAL_SMARTCARD_STATE_BUSY_RX; |
<> | 149:156823d33999 | 1185 | } |
<> | 149:156823d33999 | 1186 | else |
<> | 149:156823d33999 | 1187 | { |
<> | 149:156823d33999 | 1188 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 149:156823d33999 | 1189 | __HAL_SMARTCARD_DISABLE_IT(hsmartcard, SMARTCARD_IT_ERR); |
<> | 149:156823d33999 | 1190 | |
<> | 149:156823d33999 | 1191 | hsmartcard->State = HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 1192 | } |
<> | 149:156823d33999 | 1193 | |
<> | 149:156823d33999 | 1194 | HAL_SMARTCARD_TxCpltCallback(hsmartcard); |
<> | 149:156823d33999 | 1195 | |
<> | 149:156823d33999 | 1196 | return HAL_OK; |
<> | 149:156823d33999 | 1197 | } |
<> | 149:156823d33999 | 1198 | |
<> | 149:156823d33999 | 1199 | |
<> | 149:156823d33999 | 1200 | /** |
<> | 149:156823d33999 | 1201 | * @brief Receive an amount of data in non-blocking mode. |
<> | 149:156823d33999 | 1202 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1203 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 1204 | * @retval HAL status |
<> | 149:156823d33999 | 1205 | */ |
<> | 149:156823d33999 | 1206 | static HAL_StatusTypeDef SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 1207 | { |
<> | 149:156823d33999 | 1208 | uint32_t tmp_state = 0; |
<> | 149:156823d33999 | 1209 | |
<> | 149:156823d33999 | 1210 | tmp_state = hsc->State; |
<> | 149:156823d33999 | 1211 | if((tmp_state == HAL_SMARTCARD_STATE_BUSY_RX) || (tmp_state == HAL_SMARTCARD_STATE_BUSY_TX_RX)) |
<> | 149:156823d33999 | 1212 | { |
<> | 149:156823d33999 | 1213 | *hsc->pRxBuffPtr++ = (uint8_t)(hsc->Instance->DR & (uint8_t)0xFF); |
<> | 149:156823d33999 | 1214 | |
<> | 149:156823d33999 | 1215 | if(--hsc->RxXferCount == 0) |
<> | 149:156823d33999 | 1216 | { |
<> | 149:156823d33999 | 1217 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_RXNE); |
<> | 149:156823d33999 | 1218 | |
<> | 149:156823d33999 | 1219 | /* Disable the SMARTCARD Parity Error Interrupt */ |
<> | 149:156823d33999 | 1220 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_PE); |
<> | 149:156823d33999 | 1221 | |
<> | 149:156823d33999 | 1222 | /* Disable the SMARTCARD Error Interrupt: (Frame error, noise error, overrun error) */ |
<> | 149:156823d33999 | 1223 | __HAL_SMARTCARD_DISABLE_IT(hsc, SMARTCARD_IT_ERR); |
<> | 149:156823d33999 | 1224 | |
<> | 149:156823d33999 | 1225 | /* Check if a non-blocking transmit process is ongoing or not */ |
<> | 149:156823d33999 | 1226 | if(hsc->State == HAL_SMARTCARD_STATE_BUSY_TX_RX) |
<> | 149:156823d33999 | 1227 | { |
<> | 149:156823d33999 | 1228 | hsc->State = HAL_SMARTCARD_STATE_BUSY_TX; |
<> | 149:156823d33999 | 1229 | } |
<> | 149:156823d33999 | 1230 | else |
<> | 149:156823d33999 | 1231 | { |
<> | 149:156823d33999 | 1232 | hsc->State = HAL_SMARTCARD_STATE_READY; |
<> | 149:156823d33999 | 1233 | } |
<> | 149:156823d33999 | 1234 | |
<> | 149:156823d33999 | 1235 | HAL_SMARTCARD_RxCpltCallback(hsc); |
<> | 149:156823d33999 | 1236 | |
<> | 149:156823d33999 | 1237 | return HAL_OK; |
<> | 149:156823d33999 | 1238 | } |
<> | 149:156823d33999 | 1239 | return HAL_OK; |
<> | 149:156823d33999 | 1240 | } |
<> | 149:156823d33999 | 1241 | else |
<> | 149:156823d33999 | 1242 | { |
<> | 149:156823d33999 | 1243 | return HAL_BUSY; |
<> | 149:156823d33999 | 1244 | } |
<> | 149:156823d33999 | 1245 | } |
<> | 149:156823d33999 | 1246 | |
<> | 149:156823d33999 | 1247 | /** |
<> | 149:156823d33999 | 1248 | * @brief Configures the SMARTCARD peripheral. |
<> | 149:156823d33999 | 1249 | * @param hsc: Pointer to a SMARTCARD_HandleTypeDef structure that contains |
<> | 149:156823d33999 | 1250 | * the configuration information for the specified SMARTCARD module. |
<> | 149:156823d33999 | 1251 | * @retval None |
<> | 149:156823d33999 | 1252 | */ |
<> | 149:156823d33999 | 1253 | static void SMARTCARD_SetConfig(SMARTCARD_HandleTypeDef *hsc) |
<> | 149:156823d33999 | 1254 | { |
<> | 149:156823d33999 | 1255 | /* Check the parameters */ |
<> | 149:156823d33999 | 1256 | assert_param(IS_SMARTCARD_POLARITY(hsc->Init.CLKPolarity)); |
<> | 149:156823d33999 | 1257 | assert_param(IS_SMARTCARD_PHASE(hsc->Init.CLKPhase)); |
<> | 149:156823d33999 | 1258 | assert_param(IS_SMARTCARD_LASTBIT(hsc->Init.CLKLastBit)); |
<> | 149:156823d33999 | 1259 | assert_param(IS_SMARTCARD_BAUDRATE(hsc->Init.BaudRate)); |
<> | 149:156823d33999 | 1260 | assert_param(IS_SMARTCARD_WORD_LENGTH(hsc->Init.WordLength)); |
<> | 149:156823d33999 | 1261 | assert_param(IS_SMARTCARD_STOPBITS(hsc->Init.StopBits)); |
<> | 149:156823d33999 | 1262 | assert_param(IS_SMARTCARD_PARITY(hsc->Init.Parity)); |
<> | 149:156823d33999 | 1263 | assert_param(IS_SMARTCARD_MODE(hsc->Init.Mode)); |
<> | 149:156823d33999 | 1264 | assert_param(IS_SMARTCARD_NACK_STATE(hsc->Init.NACKState)); |
<> | 149:156823d33999 | 1265 | |
<> | 149:156823d33999 | 1266 | /* The LBCL, CPOL and CPHA bits have to be selected when both the transmitter and the |
<> | 149:156823d33999 | 1267 | receiver are disabled (TE=RE=0) to ensure that the clock pulses function correctly. */ |
<> | 149:156823d33999 | 1268 | CLEAR_BIT(hsc->Instance->CR1, (uint32_t)(USART_CR1_TE | USART_CR1_RE)); |
<> | 149:156823d33999 | 1269 | |
<> | 149:156823d33999 | 1270 | /*------ SMARTCARD-associated USART registers setting : CR2 Configuration ------*/ |
<> | 149:156823d33999 | 1271 | /* Clear CLKEN, CPOL, CPHA and LBCL bits */ |
<> | 149:156823d33999 | 1272 | /* Configure the SMARTCARD Clock, CPOL, CPHA and LastBit -----------------------*/ |
<> | 149:156823d33999 | 1273 | /* Set CPOL bit according to hsc->Init.CLKPolarity value */ |
<> | 149:156823d33999 | 1274 | /* Set CPHA bit according to hsc->Init.CLKPhase value */ |
<> | 149:156823d33999 | 1275 | /* Set LBCL bit according to hsc->Init.CLKLastBit value */ |
<> | 149:156823d33999 | 1276 | MODIFY_REG(hsc->Instance->CR2, |
<> | 149:156823d33999 | 1277 | ((uint32_t)(USART_CR2_CPHA | USART_CR2_CPOL | USART_CR2_CLKEN | USART_CR2_LBCL)), |
<> | 149:156823d33999 | 1278 | ((uint32_t)(USART_CR2_CLKEN | hsc->Init.CLKPolarity | hsc->Init.CLKPhase| hsc->Init.CLKLastBit)) ); |
<> | 149:156823d33999 | 1279 | |
<> | 149:156823d33999 | 1280 | /* Set Stop Bits: Set STOP[13:12] bits according to hsc->Init.StopBits value */ |
<> | 149:156823d33999 | 1281 | MODIFY_REG(hsc->Instance->CR2, USART_CR2_STOP,(uint32_t)(hsc->Init.StopBits)); |
<> | 149:156823d33999 | 1282 | |
<> | 149:156823d33999 | 1283 | /*------ SMARTCARD-associated USART registers setting : CR1 Configuration ------*/ |
<> | 149:156823d33999 | 1284 | /* Clear M, PCE, PS, TE and RE bits */ |
<> | 149:156823d33999 | 1285 | /* Configure the SMARTCARD Word Length, Parity and mode: |
<> | 149:156823d33999 | 1286 | Set the M according to hsc->Init.WordLength value (forced to 1 as 9B data frame should be selected) |
<> | 149:156823d33999 | 1287 | Set PCE and PS bits according to hsc->Init.Parity value (PCE bit forced to 1 as parity control should always be enabled) |
<> | 149:156823d33999 | 1288 | Set TE and RE bits according to hsc->Init.Mode value */ |
<> | 149:156823d33999 | 1289 | MODIFY_REG(hsc->Instance->CR1, |
<> | 149:156823d33999 | 1290 | ((uint32_t)(USART_CR1_M | USART_CR1_PCE | USART_CR1_PS | USART_CR1_TE | USART_CR1_RE)), |
<> | 149:156823d33999 | 1291 | ((uint32_t)(USART_CR1_M | USART_CR1_PCE | hsc->Init.Parity | hsc->Init.Mode)) ); |
<> | 149:156823d33999 | 1292 | |
<> | 149:156823d33999 | 1293 | /*------ SMARTCARD-associated USART registers setting : CR3 Configuration ------*/ |
<> | 149:156823d33999 | 1294 | /* Clear CTSE and RTSE bits */ |
<> | 149:156823d33999 | 1295 | CLEAR_BIT(hsc->Instance->CR3, (USART_CR3_RTSE | USART_CR3_CTSE)); |
<> | 149:156823d33999 | 1296 | |
<> | 149:156823d33999 | 1297 | /*------ SMARTCARD-associated USART registers setting : BRR Configuration ------*/ |
<> | 149:156823d33999 | 1298 | if(hsc->Instance == USART1) |
<> | 149:156823d33999 | 1299 | { |
<> | 149:156823d33999 | 1300 | hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK2Freq(), hsc->Init.BaudRate); |
<> | 149:156823d33999 | 1301 | } |
<> | 149:156823d33999 | 1302 | else |
<> | 149:156823d33999 | 1303 | { |
<> | 149:156823d33999 | 1304 | hsc->Instance->BRR = SMARTCARD_BRR(HAL_RCC_GetPCLK1Freq(), hsc->Init.BaudRate); |
<> | 149:156823d33999 | 1305 | } |
<> | 149:156823d33999 | 1306 | } |
<> | 149:156823d33999 | 1307 | |
<> | 149:156823d33999 | 1308 | /** |
<> | 149:156823d33999 | 1309 | * @} |
<> | 149:156823d33999 | 1310 | */ |
<> | 149:156823d33999 | 1311 | |
<> | 149:156823d33999 | 1312 | #endif /* HAL_SMARTCARD_MODULE_ENABLED */ |
<> | 149:156823d33999 | 1313 | /** |
<> | 149:156823d33999 | 1314 | * @} |
<> | 149:156823d33999 | 1315 | */ |
<> | 149:156823d33999 | 1316 | |
<> | 149:156823d33999 | 1317 | /** |
<> | 149:156823d33999 | 1318 | * @} |
<> | 149:156823d33999 | 1319 | */ |
<> | 149:156823d33999 | 1320 | |
<> | 149:156823d33999 | 1321 | /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/ |