mbed library sources

Dependents:   Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more

Superseded

This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.

Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.

If you are looking for a stable and tested release, please import one of the official mbed library releases:

Import librarymbed

The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Committer:
mbed_official
Date:
Mon Sep 28 10:45:10 2015 +0100
Revision:
630:825f75ca301e
Parent:
441:d2c15dda23c1
Synchronized with git revision 54fbe4144faf309c37205a5d39fa665daa919f10

Full URL: https://github.com/mbedmicro/mbed/commit/54fbe4144faf309c37205a5d39fa665daa919f10/

NUCLEO_F031K6 : Add new target

Who changed what in which revision?

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