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