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