001

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ganlikun 0:13413ea9a877 1 /**
ganlikun 0:13413ea9a877 2 ******************************************************************************
ganlikun 0:13413ea9a877 3 * @file stm32f4xx_hal_smartcard.h
ganlikun 0:13413ea9a877 4 * @author MCD Application Team
ganlikun 0:13413ea9a877 5 * @version V1.7.1
ganlikun 0:13413ea9a877 6 * @date 14-April-2017
ganlikun 0:13413ea9a877 7 * @brief Header file of SMARTCARD HAL module.
ganlikun 0:13413ea9a877 8 ******************************************************************************
ganlikun 0:13413ea9a877 9 * @attention
ganlikun 0:13413ea9a877 10 *
ganlikun 0:13413ea9a877 11 * <h2><center>&copy; COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
ganlikun 0:13413ea9a877 12 *
ganlikun 0:13413ea9a877 13 * Redistribution and use in source and binary forms, with or without modification,
ganlikun 0:13413ea9a877 14 * are permitted provided that the following conditions are met:
ganlikun 0:13413ea9a877 15 * 1. Redistributions of source code must retain the above copyright notice,
ganlikun 0:13413ea9a877 16 * this list of conditions and the following disclaimer.
ganlikun 0:13413ea9a877 17 * 2. Redistributions in binary form must reproduce the above copyright notice,
ganlikun 0:13413ea9a877 18 * this list of conditions and the following disclaimer in the documentation
ganlikun 0:13413ea9a877 19 * and/or other materials provided with the distribution.
ganlikun 0:13413ea9a877 20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
ganlikun 0:13413ea9a877 21 * may be used to endorse or promote products derived from this software
ganlikun 0:13413ea9a877 22 * without specific prior written permission.
ganlikun 0:13413ea9a877 23 *
ganlikun 0:13413ea9a877 24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
ganlikun 0:13413ea9a877 25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
ganlikun 0:13413ea9a877 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
ganlikun 0:13413ea9a877 27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
ganlikun 0:13413ea9a877 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
ganlikun 0:13413ea9a877 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
ganlikun 0:13413ea9a877 30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
ganlikun 0:13413ea9a877 31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
ganlikun 0:13413ea9a877 32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
ganlikun 0:13413ea9a877 33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
ganlikun 0:13413ea9a877 34 *
ganlikun 0:13413ea9a877 35 ******************************************************************************
ganlikun 0:13413ea9a877 36 */
ganlikun 0:13413ea9a877 37
ganlikun 0:13413ea9a877 38 /* Define to prevent recursive inclusion -------------------------------------*/
ganlikun 0:13413ea9a877 39 #ifndef __STM32F4xx_HAL_SMARTCARD_H
ganlikun 0:13413ea9a877 40 #define __STM32F4xx_HAL_SMARTCARD_H
ganlikun 0:13413ea9a877 41
ganlikun 0:13413ea9a877 42 #ifdef __cplusplus
ganlikun 0:13413ea9a877 43 extern "C" {
ganlikun 0:13413ea9a877 44 #endif
ganlikun 0:13413ea9a877 45
ganlikun 0:13413ea9a877 46 /* Includes ------------------------------------------------------------------*/
ganlikun 0:13413ea9a877 47 #include "stm32f4xx_hal_def.h"
ganlikun 0:13413ea9a877 48
ganlikun 0:13413ea9a877 49 /** @addtogroup STM32F4xx_HAL_Driver
ganlikun 0:13413ea9a877 50 * @{
ganlikun 0:13413ea9a877 51 */
ganlikun 0:13413ea9a877 52
ganlikun 0:13413ea9a877 53 /** @addtogroup SMARTCARD
ganlikun 0:13413ea9a877 54 * @{
ganlikun 0:13413ea9a877 55 */
ganlikun 0:13413ea9a877 56
ganlikun 0:13413ea9a877 57 /* Exported types ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 58 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
ganlikun 0:13413ea9a877 59 * @{
ganlikun 0:13413ea9a877 60 */
ganlikun 0:13413ea9a877 61
ganlikun 0:13413ea9a877 62 /**
ganlikun 0:13413ea9a877 63 * @brief SMARTCARD Init Structure definition
ganlikun 0:13413ea9a877 64 */
ganlikun 0:13413ea9a877 65 typedef struct
ganlikun 0:13413ea9a877 66 {
ganlikun 0:13413ea9a877 67 uint32_t BaudRate; /*!< This member configures the SmartCard communication baud rate.
ganlikun 0:13413ea9a877 68 The baud rate is computed using the following formula:
ganlikun 0:13413ea9a877 69 - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
ganlikun 0:13413ea9a877 70 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
ganlikun 0:13413ea9a877 71
ganlikun 0:13413ea9a877 72 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
ganlikun 0:13413ea9a877 73 This parameter can be a value of @ref SMARTCARD_Word_Length */
ganlikun 0:13413ea9a877 74
ganlikun 0:13413ea9a877 75 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
ganlikun 0:13413ea9a877 76 This parameter can be a value of @ref SMARTCARD_Stop_Bits */
ganlikun 0:13413ea9a877 77
ganlikun 0:13413ea9a877 78 uint32_t Parity; /*!< Specifies the parity mode.
ganlikun 0:13413ea9a877 79 This parameter can be a value of @ref SMARTCARD_Parity
ganlikun 0:13413ea9a877 80 @note When parity is enabled, the computed parity is inserted
ganlikun 0:13413ea9a877 81 at the MSB position of the transmitted data (9th bit when
ganlikun 0:13413ea9a877 82 the word length is set to 9 data bits; 8th bit when the
ganlikun 0:13413ea9a877 83 word length is set to 8 data bits).*/
ganlikun 0:13413ea9a877 84
ganlikun 0:13413ea9a877 85 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
ganlikun 0:13413ea9a877 86 This parameter can be a value of @ref SMARTCARD_Mode */
ganlikun 0:13413ea9a877 87
ganlikun 0:13413ea9a877 88 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
ganlikun 0:13413ea9a877 89 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
ganlikun 0:13413ea9a877 90
ganlikun 0:13413ea9a877 91 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
ganlikun 0:13413ea9a877 92 This parameter can be a value of @ref SMARTCARD_Clock_Phase */
ganlikun 0:13413ea9a877 93
ganlikun 0:13413ea9a877 94 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
ganlikun 0:13413ea9a877 95 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
ganlikun 0:13413ea9a877 96 This parameter can be a value of @ref SMARTCARD_Last_Bit */
ganlikun 0:13413ea9a877 97
ganlikun 0:13413ea9a877 98 uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler value used for dividing the system clock
ganlikun 0:13413ea9a877 99 to provide the smartcard clock. The value given in the register (5 significant bits)
ganlikun 0:13413ea9a877 100 is multiplied by 2 to give the division factor of the source clock frequency.
ganlikun 0:13413ea9a877 101 This parameter can be a value of @ref SMARTCARD_Prescaler */
ganlikun 0:13413ea9a877 102
ganlikun 0:13413ea9a877 103 uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time value in terms of number of baud clocks */
ganlikun 0:13413ea9a877 104
ganlikun 0:13413ea9a877 105 uint32_t NACKState; /*!< Specifies the SmartCard NACK Transmission state.
ganlikun 0:13413ea9a877 106 This parameter can be a value of @ref SMARTCARD_NACK_State */
ganlikun 0:13413ea9a877 107 }SMARTCARD_InitTypeDef;
ganlikun 0:13413ea9a877 108
ganlikun 0:13413ea9a877 109 /**
ganlikun 0:13413ea9a877 110 * @brief HAL SMARTCARD State structures definition
ganlikun 0:13413ea9a877 111 * @note HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState.
ganlikun 0:13413ea9a877 112 * - gState contains SMARTCARD state information related to global Handle management
ganlikun 0:13413ea9a877 113 * and also information related to Tx operations.
ganlikun 0:13413ea9a877 114 * gState value coding follow below described bitmap :
ganlikun 0:13413ea9a877 115 * b7-b6 Error information
ganlikun 0:13413ea9a877 116 * 00 : No Error
ganlikun 0:13413ea9a877 117 * 01 : (Not Used)
ganlikun 0:13413ea9a877 118 * 10 : Timeout
ganlikun 0:13413ea9a877 119 * 11 : Error
ganlikun 0:13413ea9a877 120 * b5 IP initilisation status
ganlikun 0:13413ea9a877 121 * 0 : Reset (IP not initialized)
ganlikun 0:13413ea9a877 122 * 1 : Init done (IP not initialized. HAL SMARTCARD Init function already called)
ganlikun 0:13413ea9a877 123 * b4-b3 (not used)
ganlikun 0:13413ea9a877 124 * xx : Should be set to 00
ganlikun 0:13413ea9a877 125 * b2 Intrinsic process state
ganlikun 0:13413ea9a877 126 * 0 : Ready
ganlikun 0:13413ea9a877 127 * 1 : Busy (IP busy with some configuration or internal operations)
ganlikun 0:13413ea9a877 128 * b1 (not used)
ganlikun 0:13413ea9a877 129 * x : Should be set to 0
ganlikun 0:13413ea9a877 130 * b0 Tx state
ganlikun 0:13413ea9a877 131 * 0 : Ready (no Tx operation ongoing)
ganlikun 0:13413ea9a877 132 * 1 : Busy (Tx operation ongoing)
ganlikun 0:13413ea9a877 133 * - RxState contains information related to Rx operations.
ganlikun 0:13413ea9a877 134 * RxState value coding follow below described bitmap :
ganlikun 0:13413ea9a877 135 * b7-b6 (not used)
ganlikun 0:13413ea9a877 136 * xx : Should be set to 00
ganlikun 0:13413ea9a877 137 * b5 IP initilisation status
ganlikun 0:13413ea9a877 138 * 0 : Reset (IP not initialized)
ganlikun 0:13413ea9a877 139 * 1 : Init done (IP not initialized)
ganlikun 0:13413ea9a877 140 * b4-b2 (not used)
ganlikun 0:13413ea9a877 141 * xxx : Should be set to 000
ganlikun 0:13413ea9a877 142 * b1 Rx state
ganlikun 0:13413ea9a877 143 * 0 : Ready (no Rx operation ongoing)
ganlikun 0:13413ea9a877 144 * 1 : Busy (Rx operation ongoing)
ganlikun 0:13413ea9a877 145 * b0 (not used)
ganlikun 0:13413ea9a877 146 * x : Should be set to 0.
ganlikun 0:13413ea9a877 147 */
ganlikun 0:13413ea9a877 148 typedef enum
ganlikun 0:13413ea9a877 149 {
ganlikun 0:13413ea9a877 150 HAL_SMARTCARD_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized
ganlikun 0:13413ea9a877 151 Value is allowed for gState and RxState */
ganlikun 0:13413ea9a877 152 HAL_SMARTCARD_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use
ganlikun 0:13413ea9a877 153 Value is allowed for gState and RxState */
ganlikun 0:13413ea9a877 154 HAL_SMARTCARD_STATE_BUSY = 0x24U, /*!< an internal process is ongoing
ganlikun 0:13413ea9a877 155 Value is allowed for gState only */
ganlikun 0:13413ea9a877 156 HAL_SMARTCARD_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing
ganlikun 0:13413ea9a877 157 Value is allowed for gState only */
ganlikun 0:13413ea9a877 158 HAL_SMARTCARD_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing
ganlikun 0:13413ea9a877 159 Value is allowed for RxState only */
ganlikun 0:13413ea9a877 160 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing
ganlikun 0:13413ea9a877 161 Not to be used for neither gState nor RxState.
ganlikun 0:13413ea9a877 162 Value is result of combination (Or) between gState and RxState values */
ganlikun 0:13413ea9a877 163 HAL_SMARTCARD_STATE_TIMEOUT = 0xA0U, /*!< Timeout state
ganlikun 0:13413ea9a877 164 Value is allowed for gState only */
ganlikun 0:13413ea9a877 165 HAL_SMARTCARD_STATE_ERROR = 0xE0U /*!< Error
ganlikun 0:13413ea9a877 166 Value is allowed for gState only */
ganlikun 0:13413ea9a877 167 }HAL_SMARTCARD_StateTypeDef;
ganlikun 0:13413ea9a877 168
ganlikun 0:13413ea9a877 169 /**
ganlikun 0:13413ea9a877 170 * @brief SMARTCARD handle Structure definition
ganlikun 0:13413ea9a877 171 */
ganlikun 0:13413ea9a877 172 typedef struct
ganlikun 0:13413ea9a877 173 {
ganlikun 0:13413ea9a877 174 USART_TypeDef *Instance; /* USART registers base address */
ganlikun 0:13413ea9a877 175
ganlikun 0:13413ea9a877 176 SMARTCARD_InitTypeDef Init; /* SmartCard communication parameters */
ganlikun 0:13413ea9a877 177
ganlikun 0:13413ea9a877 178 uint8_t *pTxBuffPtr; /* Pointer to SmartCard Tx transfer Buffer */
ganlikun 0:13413ea9a877 179
ganlikun 0:13413ea9a877 180 uint16_t TxXferSize; /* SmartCard Tx Transfer size */
ganlikun 0:13413ea9a877 181
ganlikun 0:13413ea9a877 182 __IO uint16_t TxXferCount; /* SmartCard Tx Transfer Counter */
ganlikun 0:13413ea9a877 183
ganlikun 0:13413ea9a877 184 uint8_t *pRxBuffPtr; /* Pointer to SmartCard Rx transfer Buffer */
ganlikun 0:13413ea9a877 185
ganlikun 0:13413ea9a877 186 uint16_t RxXferSize; /* SmartCard Rx Transfer size */
ganlikun 0:13413ea9a877 187
ganlikun 0:13413ea9a877 188 __IO uint16_t RxXferCount; /* SmartCard Rx Transfer Counter */
ganlikun 0:13413ea9a877 189
ganlikun 0:13413ea9a877 190 DMA_HandleTypeDef *hdmatx; /* SmartCard Tx DMA Handle parameters */
ganlikun 0:13413ea9a877 191
ganlikun 0:13413ea9a877 192 DMA_HandleTypeDef *hdmarx; /* SmartCard Rx DMA Handle parameters */
ganlikun 0:13413ea9a877 193
ganlikun 0:13413ea9a877 194 HAL_LockTypeDef Lock; /* Locking object */
ganlikun 0:13413ea9a877 195
ganlikun 0:13413ea9a877 196 __IO HAL_SMARTCARD_StateTypeDef gState; /* SmartCard state information related to global Handle management
ganlikun 0:13413ea9a877 197 and also related to Tx operations.
ganlikun 0:13413ea9a877 198 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
ganlikun 0:13413ea9a877 199
ganlikun 0:13413ea9a877 200 __IO HAL_SMARTCARD_StateTypeDef RxState; /* SmartCard state information related to Rx operations.
ganlikun 0:13413ea9a877 201 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
ganlikun 0:13413ea9a877 202
ganlikun 0:13413ea9a877 203 __IO uint32_t ErrorCode; /* SmartCard Error code */
ganlikun 0:13413ea9a877 204
ganlikun 0:13413ea9a877 205 }SMARTCARD_HandleTypeDef;
ganlikun 0:13413ea9a877 206
ganlikun 0:13413ea9a877 207 /**
ganlikun 0:13413ea9a877 208 * @}
ganlikun 0:13413ea9a877 209 */
ganlikun 0:13413ea9a877 210
ganlikun 0:13413ea9a877 211 /* Exported constants --------------------------------------------------------*/
ganlikun 0:13413ea9a877 212 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants
ganlikun 0:13413ea9a877 213 * @{
ganlikun 0:13413ea9a877 214 */
ganlikun 0:13413ea9a877 215 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
ganlikun 0:13413ea9a877 216 * @brief SMARTCARD Error Code
ganlikun 0:13413ea9a877 217 * @{
ganlikun 0:13413ea9a877 218 */
ganlikun 0:13413ea9a877 219 #define HAL_SMARTCARD_ERROR_NONE 0x00000000U /*!< No error */
ganlikun 0:13413ea9a877 220 #define HAL_SMARTCARD_ERROR_PE 0x00000001U /*!< Parity error */
ganlikun 0:13413ea9a877 221 #define HAL_SMARTCARD_ERROR_NE 0x00000002U /*!< Noise error */
ganlikun 0:13413ea9a877 222 #define HAL_SMARTCARD_ERROR_FE 0x00000004U /*!< Frame error */
ganlikun 0:13413ea9a877 223 #define HAL_SMARTCARD_ERROR_ORE 0x00000008U /*!< Overrun error */
ganlikun 0:13413ea9a877 224 #define HAL_SMARTCARD_ERROR_DMA 0x00000010U /*!< DMA transfer error */
ganlikun 0:13413ea9a877 225 /**
ganlikun 0:13413ea9a877 226 * @}
ganlikun 0:13413ea9a877 227 */
ganlikun 0:13413ea9a877 228
ganlikun 0:13413ea9a877 229 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
ganlikun 0:13413ea9a877 230 * @{
ganlikun 0:13413ea9a877 231 */
ganlikun 0:13413ea9a877 232 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
ganlikun 0:13413ea9a877 233 /**
ganlikun 0:13413ea9a877 234 * @}
ganlikun 0:13413ea9a877 235 */
ganlikun 0:13413ea9a877 236
ganlikun 0:13413ea9a877 237 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
ganlikun 0:13413ea9a877 238 * @{
ganlikun 0:13413ea9a877 239 */
ganlikun 0:13413ea9a877 240 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
ganlikun 0:13413ea9a877 241 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
ganlikun 0:13413ea9a877 242 /**
ganlikun 0:13413ea9a877 243 * @}
ganlikun 0:13413ea9a877 244 */
ganlikun 0:13413ea9a877 245
ganlikun 0:13413ea9a877 246 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
ganlikun 0:13413ea9a877 247 * @{
ganlikun 0:13413ea9a877 248 */
ganlikun 0:13413ea9a877 249 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
ganlikun 0:13413ea9a877 250 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
ganlikun 0:13413ea9a877 251 /**
ganlikun 0:13413ea9a877 252 * @}
ganlikun 0:13413ea9a877 253 */
ganlikun 0:13413ea9a877 254
ganlikun 0:13413ea9a877 255 /** @defgroup SMARTCARD_Mode SMARTCARD Mode
ganlikun 0:13413ea9a877 256 * @{
ganlikun 0:13413ea9a877 257 */
ganlikun 0:13413ea9a877 258 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
ganlikun 0:13413ea9a877 259 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
ganlikun 0:13413ea9a877 260 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
ganlikun 0:13413ea9a877 261 /**
ganlikun 0:13413ea9a877 262 * @}
ganlikun 0:13413ea9a877 263 */
ganlikun 0:13413ea9a877 264
ganlikun 0:13413ea9a877 265 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
ganlikun 0:13413ea9a877 266 * @{
ganlikun 0:13413ea9a877 267 */
ganlikun 0:13413ea9a877 268 #define SMARTCARD_POLARITY_LOW 0x00000000U
ganlikun 0:13413ea9a877 269 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
ganlikun 0:13413ea9a877 270 /**
ganlikun 0:13413ea9a877 271 * @}
ganlikun 0:13413ea9a877 272 */
ganlikun 0:13413ea9a877 273
ganlikun 0:13413ea9a877 274 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
ganlikun 0:13413ea9a877 275 * @{
ganlikun 0:13413ea9a877 276 */
ganlikun 0:13413ea9a877 277 #define SMARTCARD_PHASE_1EDGE 0x00000000U
ganlikun 0:13413ea9a877 278 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
ganlikun 0:13413ea9a877 279 /**
ganlikun 0:13413ea9a877 280 * @}
ganlikun 0:13413ea9a877 281 */
ganlikun 0:13413ea9a877 282
ganlikun 0:13413ea9a877 283 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
ganlikun 0:13413ea9a877 284 * @{
ganlikun 0:13413ea9a877 285 */
ganlikun 0:13413ea9a877 286 #define SMARTCARD_LASTBIT_DISABLE 0x00000000U
ganlikun 0:13413ea9a877 287 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
ganlikun 0:13413ea9a877 288 /**
ganlikun 0:13413ea9a877 289 * @}
ganlikun 0:13413ea9a877 290 */
ganlikun 0:13413ea9a877 291
ganlikun 0:13413ea9a877 292 /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State
ganlikun 0:13413ea9a877 293 * @{
ganlikun 0:13413ea9a877 294 */
ganlikun 0:13413ea9a877 295 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
ganlikun 0:13413ea9a877 296 #define SMARTCARD_NACK_DISABLE 0x00000000U
ganlikun 0:13413ea9a877 297 /**
ganlikun 0:13413ea9a877 298 * @}
ganlikun 0:13413ea9a877 299 */
ganlikun 0:13413ea9a877 300
ganlikun 0:13413ea9a877 301 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests
ganlikun 0:13413ea9a877 302 * @{
ganlikun 0:13413ea9a877 303 */
ganlikun 0:13413ea9a877 304 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
ganlikun 0:13413ea9a877 305 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
ganlikun 0:13413ea9a877 306 /**
ganlikun 0:13413ea9a877 307 * @}
ganlikun 0:13413ea9a877 308 */
ganlikun 0:13413ea9a877 309
ganlikun 0:13413ea9a877 310 /** @defgroup SMARTCARD_Prescaler SMARTCARD Prescaler
ganlikun 0:13413ea9a877 311 * @{
ganlikun 0:13413ea9a877 312 */
ganlikun 0:13413ea9a877 313 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 0x00000001U /*!< SYSCLK divided by 2 */
ganlikun 0:13413ea9a877 314 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 0x00000002U /*!< SYSCLK divided by 4 */
ganlikun 0:13413ea9a877 315 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 0x00000003U /*!< SYSCLK divided by 6 */
ganlikun 0:13413ea9a877 316 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 0x00000004U /*!< SYSCLK divided by 8 */
ganlikun 0:13413ea9a877 317 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 0x00000005U /*!< SYSCLK divided by 10 */
ganlikun 0:13413ea9a877 318 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 0x00000006U /*!< SYSCLK divided by 12 */
ganlikun 0:13413ea9a877 319 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 0x00000007U /*!< SYSCLK divided by 14 */
ganlikun 0:13413ea9a877 320 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 0x00000008U /*!< SYSCLK divided by 16 */
ganlikun 0:13413ea9a877 321 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 0x00000009U /*!< SYSCLK divided by 18 */
ganlikun 0:13413ea9a877 322 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 0x0000000AU /*!< SYSCLK divided by 20 */
ganlikun 0:13413ea9a877 323 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 0x0000000BU /*!< SYSCLK divided by 22 */
ganlikun 0:13413ea9a877 324 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 0x0000000CU /*!< SYSCLK divided by 24 */
ganlikun 0:13413ea9a877 325 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 0x0000000DU /*!< SYSCLK divided by 26 */
ganlikun 0:13413ea9a877 326 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 0x0000000EU /*!< SYSCLK divided by 28 */
ganlikun 0:13413ea9a877 327 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 0x0000000FU /*!< SYSCLK divided by 30 */
ganlikun 0:13413ea9a877 328 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 0x00000010U /*!< SYSCLK divided by 32 */
ganlikun 0:13413ea9a877 329 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 0x00000011U /*!< SYSCLK divided by 34 */
ganlikun 0:13413ea9a877 330 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 0x00000012U /*!< SYSCLK divided by 36 */
ganlikun 0:13413ea9a877 331 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 0x00000013U /*!< SYSCLK divided by 38 */
ganlikun 0:13413ea9a877 332 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 0x00000014U /*!< SYSCLK divided by 40 */
ganlikun 0:13413ea9a877 333 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 0x00000015U /*!< SYSCLK divided by 42 */
ganlikun 0:13413ea9a877 334 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 0x00000016U /*!< SYSCLK divided by 44 */
ganlikun 0:13413ea9a877 335 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 0x00000017U /*!< SYSCLK divided by 46 */
ganlikun 0:13413ea9a877 336 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 0x00000018U /*!< SYSCLK divided by 48 */
ganlikun 0:13413ea9a877 337 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 0x00000019U /*!< SYSCLK divided by 50 */
ganlikun 0:13413ea9a877 338 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 0x0000001AU /*!< SYSCLK divided by 52 */
ganlikun 0:13413ea9a877 339 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 0x0000001BU /*!< SYSCLK divided by 54 */
ganlikun 0:13413ea9a877 340 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 0x0000001CU /*!< SYSCLK divided by 56 */
ganlikun 0:13413ea9a877 341 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 0x0000001DU /*!< SYSCLK divided by 58 */
ganlikun 0:13413ea9a877 342 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 0x0000001EU /*!< SYSCLK divided by 60 */
ganlikun 0:13413ea9a877 343 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 0x0000001FU /*!< SYSCLK divided by 62 */
ganlikun 0:13413ea9a877 344 /**
ganlikun 0:13413ea9a877 345 * @}
ganlikun 0:13413ea9a877 346 */
ganlikun 0:13413ea9a877 347
ganlikun 0:13413ea9a877 348 /** @defgroup SmartCard_Flags SMARTCARD Flags
ganlikun 0:13413ea9a877 349 * Elements values convention: 0xXXXX
ganlikun 0:13413ea9a877 350 * - 0xXXXX : Flag mask in the SR register
ganlikun 0:13413ea9a877 351 * @{
ganlikun 0:13413ea9a877 352 */
ganlikun 0:13413ea9a877 353 #define SMARTCARD_FLAG_TXE 0x00000080U
ganlikun 0:13413ea9a877 354 #define SMARTCARD_FLAG_TC 0x00000040U
ganlikun 0:13413ea9a877 355 #define SMARTCARD_FLAG_RXNE 0x00000020U
ganlikun 0:13413ea9a877 356 #define SMARTCARD_FLAG_IDLE 0x00000010U
ganlikun 0:13413ea9a877 357 #define SMARTCARD_FLAG_ORE 0x00000008U
ganlikun 0:13413ea9a877 358 #define SMARTCARD_FLAG_NE 0x00000004U
ganlikun 0:13413ea9a877 359 #define SMARTCARD_FLAG_FE 0x00000002U
ganlikun 0:13413ea9a877 360 #define SMARTCARD_FLAG_PE 0x00000001U
ganlikun 0:13413ea9a877 361 /**
ganlikun 0:13413ea9a877 362 * @}
ganlikun 0:13413ea9a877 363 */
ganlikun 0:13413ea9a877 364
ganlikun 0:13413ea9a877 365 /** @defgroup SmartCard_Interrupt_definition SMARTCARD Interrupts Definition
ganlikun 0:13413ea9a877 366 * Elements values convention: 0xY000XXXX
ganlikun 0:13413ea9a877 367 * - XXXX : Interrupt mask in the XX register
ganlikun 0:13413ea9a877 368 * - Y : Interrupt source register (2bits)
ganlikun 0:13413ea9a877 369 * - 01: CR1 register
ganlikun 0:13413ea9a877 370 * - 10: CR3 register
ganlikun 0:13413ea9a877 371 * @{
ganlikun 0:13413ea9a877 372 */
ganlikun 0:13413ea9a877 373 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
ganlikun 0:13413ea9a877 374 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
ganlikun 0:13413ea9a877 375 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
ganlikun 0:13413ea9a877 376 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
ganlikun 0:13413ea9a877 377 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
ganlikun 0:13413ea9a877 378 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE))
ganlikun 0:13413ea9a877 379 /**
ganlikun 0:13413ea9a877 380 * @}
ganlikun 0:13413ea9a877 381 */
ganlikun 0:13413ea9a877 382
ganlikun 0:13413ea9a877 383 /**
ganlikun 0:13413ea9a877 384 * @}
ganlikun 0:13413ea9a877 385 */
ganlikun 0:13413ea9a877 386
ganlikun 0:13413ea9a877 387 /* Exported macro ------------------------------------------------------------*/
ganlikun 0:13413ea9a877 388 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
ganlikun 0:13413ea9a877 389 * @{
ganlikun 0:13413ea9a877 390 */
ganlikun 0:13413ea9a877 391
ganlikun 0:13413ea9a877 392 /** @brief Reset SMARTCARD handle gstate & RxState
ganlikun 0:13413ea9a877 393 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 394 * @retval None
ganlikun 0:13413ea9a877 395 */
ganlikun 0:13413ea9a877 396 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
ganlikun 0:13413ea9a877 397 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
ganlikun 0:13413ea9a877 398 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
ganlikun 0:13413ea9a877 399 } while(0U)
ganlikun 0:13413ea9a877 400
ganlikun 0:13413ea9a877 401 /** @brief Flushs the Smartcard DR register
ganlikun 0:13413ea9a877 402 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 403 */
ganlikun 0:13413ea9a877 404 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
ganlikun 0:13413ea9a877 405
ganlikun 0:13413ea9a877 406 /** @brief Checks whether the specified Smartcard flag is set or not.
ganlikun 0:13413ea9a877 407 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 408 * @param __FLAG__: specifies the flag to check.
ganlikun 0:13413ea9a877 409 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 410 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
ganlikun 0:13413ea9a877 411 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
ganlikun 0:13413ea9a877 412 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
ganlikun 0:13413ea9a877 413 * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag
ganlikun 0:13413ea9a877 414 * @arg SMARTCARD_FLAG_ORE: Overrun Error flag
ganlikun 0:13413ea9a877 415 * @arg SMARTCARD_FLAG_NE: Noise Error flag
ganlikun 0:13413ea9a877 416 * @arg SMARTCARD_FLAG_FE: Framing Error flag
ganlikun 0:13413ea9a877 417 * @arg SMARTCARD_FLAG_PE: Parity Error flag
ganlikun 0:13413ea9a877 418 * @retval The new state of __FLAG__ (TRUE or FALSE).
ganlikun 0:13413ea9a877 419 */
ganlikun 0:13413ea9a877 420 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
ganlikun 0:13413ea9a877 421
ganlikun 0:13413ea9a877 422 /** @brief Clears the specified Smartcard pending flags.
ganlikun 0:13413ea9a877 423 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 424 * @param __FLAG__: specifies the flag to check.
ganlikun 0:13413ea9a877 425 * This parameter can be any combination of the following values:
ganlikun 0:13413ea9a877 426 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag.
ganlikun 0:13413ea9a877 427 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag.
ganlikun 0:13413ea9a877 428 *
ganlikun 0:13413ea9a877 429 * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (Overrun
ganlikun 0:13413ea9a877 430 * error) flags are cleared by software sequence: a read operation to
ganlikun 0:13413ea9a877 431 * USART_SR register followed by a read operation to USART_DR register.
ganlikun 0:13413ea9a877 432 * @note RXNE flag can be also cleared by a read to the USART_DR register.
ganlikun 0:13413ea9a877 433 * @note TC flag can be also cleared by software sequence: a read operation to
ganlikun 0:13413ea9a877 434 * USART_SR register followed by a write operation to USART_DR register.
ganlikun 0:13413ea9a877 435 * @note TXE flag is cleared only by a write to the USART_DR register.
ganlikun 0:13413ea9a877 436 */
ganlikun 0:13413ea9a877 437 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
ganlikun 0:13413ea9a877 438
ganlikun 0:13413ea9a877 439 /** @brief Clear the SMARTCARD PE pending flag.
ganlikun 0:13413ea9a877 440 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:13413ea9a877 441 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
ganlikun 0:13413ea9a877 442 * SMARTCARD peripheral.
ganlikun 0:13413ea9a877 443 * @retval None
ganlikun 0:13413ea9a877 444 */
ganlikun 0:13413ea9a877 445 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \
ganlikun 0:13413ea9a877 446 do{ \
ganlikun 0:13413ea9a877 447 __IO uint32_t tmpreg = 0x00U; \
ganlikun 0:13413ea9a877 448 tmpreg = (__HANDLE__)->Instance->SR; \
ganlikun 0:13413ea9a877 449 tmpreg = (__HANDLE__)->Instance->DR; \
ganlikun 0:13413ea9a877 450 UNUSED(tmpreg); \
ganlikun 0:13413ea9a877 451 } while(0U)
ganlikun 0:13413ea9a877 452
ganlikun 0:13413ea9a877 453 /** @brief Clear the SMARTCARD FE pending flag.
ganlikun 0:13413ea9a877 454 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:13413ea9a877 455 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
ganlikun 0:13413ea9a877 456 * SMARTCARD peripheral.
ganlikun 0:13413ea9a877 457 * @retval None
ganlikun 0:13413ea9a877 458 */
ganlikun 0:13413ea9a877 459 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:13413ea9a877 460
ganlikun 0:13413ea9a877 461 /** @brief Clear the SMARTCARD NE pending flag.
ganlikun 0:13413ea9a877 462 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:13413ea9a877 463 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
ganlikun 0:13413ea9a877 464 * SMARTCARD peripheral.
ganlikun 0:13413ea9a877 465 * @retval None
ganlikun 0:13413ea9a877 466 */
ganlikun 0:13413ea9a877 467 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:13413ea9a877 468
ganlikun 0:13413ea9a877 469 /** @brief Clear the SMARTCARD ORE pending flag.
ganlikun 0:13413ea9a877 470 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:13413ea9a877 471 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
ganlikun 0:13413ea9a877 472 * SMARTCARD peripheral.
ganlikun 0:13413ea9a877 473 * @retval None
ganlikun 0:13413ea9a877 474 */
ganlikun 0:13413ea9a877 475 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:13413ea9a877 476
ganlikun 0:13413ea9a877 477 /** @brief Clear the SMARTCARD IDLE pending flag.
ganlikun 0:13413ea9a877 478 * @param __HANDLE__: specifies the USART Handle.
ganlikun 0:13413ea9a877 479 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
ganlikun 0:13413ea9a877 480 * SMARTCARD peripheral.
ganlikun 0:13413ea9a877 481 * @retval None
ganlikun 0:13413ea9a877 482 */
ganlikun 0:13413ea9a877 483 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
ganlikun 0:13413ea9a877 484
ganlikun 0:13413ea9a877 485 /** @brief Enables or disables the specified SmartCard interrupts.
ganlikun 0:13413ea9a877 486 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 487 * @param __INTERRUPT__: specifies the SMARTCARD interrupt source to check.
ganlikun 0:13413ea9a877 488 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 489 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
ganlikun 0:13413ea9a877 490 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
ganlikun 0:13413ea9a877 491 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
ganlikun 0:13413ea9a877 492 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
ganlikun 0:13413ea9a877 493 * @arg SMARTCARD_IT_PE: Parity Error interrupt
ganlikun 0:13413ea9a877 494 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
ganlikun 0:13413ea9a877 495 */
ganlikun 0:13413ea9a877 496 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
ganlikun 0:13413ea9a877 497 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
ganlikun 0:13413ea9a877 498 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
ganlikun 0:13413ea9a877 499 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
ganlikun 0:13413ea9a877 500
ganlikun 0:13413ea9a877 501 /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
ganlikun 0:13413ea9a877 502 * @param __HANDLE__: specifies the SmartCard Handle.
ganlikun 0:13413ea9a877 503 * @param __IT__: specifies the SMARTCARD interrupt source to check.
ganlikun 0:13413ea9a877 504 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 505 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
ganlikun 0:13413ea9a877 506 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
ganlikun 0:13413ea9a877 507 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
ganlikun 0:13413ea9a877 508 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
ganlikun 0:13413ea9a877 509 * @arg SMARTCARD_IT_ERR: Error interrupt
ganlikun 0:13413ea9a877 510 * @arg SMARTCARD_IT_PE: Parity Error interrupt
ganlikun 0:13413ea9a877 511 * @retval The new state of __IT__ (TRUE or FALSE).
ganlikun 0:13413ea9a877 512 */
ganlikun 0:13413ea9a877 513 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
ganlikun 0:13413ea9a877 514
ganlikun 0:13413ea9a877 515 /** @brief Macro to enable the SMARTCARD's one bit sample method
ganlikun 0:13413ea9a877 516 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 517 * @retval None
ganlikun 0:13413ea9a877 518 */
ganlikun 0:13413ea9a877 519 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
ganlikun 0:13413ea9a877 520
ganlikun 0:13413ea9a877 521 /** @brief Macro to disable the SMARTCARD's one bit sample method
ganlikun 0:13413ea9a877 522 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 523 * @retval None
ganlikun 0:13413ea9a877 524 */
ganlikun 0:13413ea9a877 525 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
ganlikun 0:13413ea9a877 526
ganlikun 0:13413ea9a877 527 /** @brief Enable the USART associated to the SMARTCARD Handle
ganlikun 0:13413ea9a877 528 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 529 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
ganlikun 0:13413ea9a877 530 * @retval None
ganlikun 0:13413ea9a877 531 */
ganlikun 0:13413ea9a877 532 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
ganlikun 0:13413ea9a877 533
ganlikun 0:13413ea9a877 534 /** @brief Disable the USART associated to the SMARTCARD Handle
ganlikun 0:13413ea9a877 535 * @param __HANDLE__: specifies the SMARTCARD Handle.
ganlikun 0:13413ea9a877 536 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
ganlikun 0:13413ea9a877 537 * @retval None
ganlikun 0:13413ea9a877 538 */
ganlikun 0:13413ea9a877 539 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
ganlikun 0:13413ea9a877 540
ganlikun 0:13413ea9a877 541 /** @brief Macros to enable or disable the SmartCard DMA request.
ganlikun 0:13413ea9a877 542 * @param __HANDLE__: specifies the SmartCard Handle.
ganlikun 0:13413ea9a877 543 * @param __REQUEST__: specifies the SmartCard DMA request.
ganlikun 0:13413ea9a877 544 * This parameter can be one of the following values:
ganlikun 0:13413ea9a877 545 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
ganlikun 0:13413ea9a877 546 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
ganlikun 0:13413ea9a877 547 */
ganlikun 0:13413ea9a877 548 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
ganlikun 0:13413ea9a877 549 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
ganlikun 0:13413ea9a877 550
ganlikun 0:13413ea9a877 551 /**
ganlikun 0:13413ea9a877 552 * @}
ganlikun 0:13413ea9a877 553 */
ganlikun 0:13413ea9a877 554
ganlikun 0:13413ea9a877 555 /* Exported functions --------------------------------------------------------*/
ganlikun 0:13413ea9a877 556 /** @addtogroup SMARTCARD_Exported_Functions
ganlikun 0:13413ea9a877 557 * @{
ganlikun 0:13413ea9a877 558 */
ganlikun 0:13413ea9a877 559
ganlikun 0:13413ea9a877 560 /** @addtogroup SMARTCARD_Exported_Functions_Group1
ganlikun 0:13413ea9a877 561 * @{
ganlikun 0:13413ea9a877 562 */
ganlikun 0:13413ea9a877 563 /* Initialization/de-initialization functions **********************************/
ganlikun 0:13413ea9a877 564 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 565 HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 566 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 567 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 568 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 569 /**
ganlikun 0:13413ea9a877 570 * @}
ganlikun 0:13413ea9a877 571 */
ganlikun 0:13413ea9a877 572
ganlikun 0:13413ea9a877 573 /** @addtogroup SMARTCARD_Exported_Functions_Group2
ganlikun 0:13413ea9a877 574 * @{
ganlikun 0:13413ea9a877 575 */
ganlikun 0:13413ea9a877 576 /* IO operation functions *******************************************************/
ganlikun 0:13413ea9a877 577 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
ganlikun 0:13413ea9a877 578 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
ganlikun 0:13413ea9a877 579 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
ganlikun 0:13413ea9a877 580 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
ganlikun 0:13413ea9a877 581 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
ganlikun 0:13413ea9a877 582 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
ganlikun 0:13413ea9a877 583 /* Transfer Abort functions */
ganlikun 0:13413ea9a877 584 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 585 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 586 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 587 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 588 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 589 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 590
ganlikun 0:13413ea9a877 591 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 592 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 593 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 594 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 595 void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 596 void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 597 void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 598 /**
ganlikun 0:13413ea9a877 599 * @}
ganlikun 0:13413ea9a877 600 */
ganlikun 0:13413ea9a877 601
ganlikun 0:13413ea9a877 602 /** @addtogroup SMARTCARD_Exported_Functions_Group3
ganlikun 0:13413ea9a877 603 * @{
ganlikun 0:13413ea9a877 604 */
ganlikun 0:13413ea9a877 605 /* Peripheral State functions **************************************************/
ganlikun 0:13413ea9a877 606 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 607 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
ganlikun 0:13413ea9a877 608
ganlikun 0:13413ea9a877 609 /**
ganlikun 0:13413ea9a877 610 * @}
ganlikun 0:13413ea9a877 611 */
ganlikun 0:13413ea9a877 612
ganlikun 0:13413ea9a877 613 /**
ganlikun 0:13413ea9a877 614 * @}
ganlikun 0:13413ea9a877 615 */
ganlikun 0:13413ea9a877 616 /* Private types -------------------------------------------------------------*/
ganlikun 0:13413ea9a877 617 /* Private variables ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 618 /* Private constants ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 619 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
ganlikun 0:13413ea9a877 620 * @{
ganlikun 0:13413ea9a877 621 */
ganlikun 0:13413ea9a877 622
ganlikun 0:13413ea9a877 623 /** @brief SMARTCARD interruptions flag mask
ganlikun 0:13413ea9a877 624 *
ganlikun 0:13413ea9a877 625 */
ganlikun 0:13413ea9a877 626 #define SMARTCARD_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
ganlikun 0:13413ea9a877 627 USART_CR1_IDLEIE | USART_CR3_EIE )
ganlikun 0:13413ea9a877 628
ganlikun 0:13413ea9a877 629 #define SMARTCARD_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_)))
ganlikun 0:13413ea9a877 630 #define SMARTCARD_DIVMANT(_PCLK_, _BAUD_) (SMARTCARD_DIV((_PCLK_), (_BAUD_))/100U)
ganlikun 0:13413ea9a877 631 #define SMARTCARD_DIVFRAQ(_PCLK_, _BAUD_) (((SMARTCARD_DIV((_PCLK_), (_BAUD_)) - (SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
ganlikun 0:13413ea9a877 632 /* SMARTCARD BRR = mantissa + overflow + fraction
ganlikun 0:13413ea9a877 633 = (SMARTCARD DIVMANT << 4) + (SMARTCARD DIVFRAQ & 0xF0) + (SMARTCARD DIVFRAQ & 0x0FU) */
ganlikun 0:13413ea9a877 634 #define SMARTCARD_BRR(_PCLK_, _BAUD_) (((SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
ganlikun 0:13413ea9a877 635 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
ganlikun 0:13413ea9a877 636 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
ganlikun 0:13413ea9a877 637
ganlikun 0:13413ea9a877 638 #define SMARTCARD_CR1_REG_INDEX 1U
ganlikun 0:13413ea9a877 639 #define SMARTCARD_CR3_REG_INDEX 3U
ganlikun 0:13413ea9a877 640 /**
ganlikun 0:13413ea9a877 641 * @}
ganlikun 0:13413ea9a877 642 */
ganlikun 0:13413ea9a877 643
ganlikun 0:13413ea9a877 644 /* Private macros --------------------------------------------------------*/
ganlikun 0:13413ea9a877 645 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
ganlikun 0:13413ea9a877 646 * @{
ganlikun 0:13413ea9a877 647 */
ganlikun 0:13413ea9a877 648 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B)
ganlikun 0:13413ea9a877 649 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
ganlikun 0:13413ea9a877 650 ((STOPBITS) == SMARTCARD_STOPBITS_1_5))
ganlikun 0:13413ea9a877 651 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \
ganlikun 0:13413ea9a877 652 ((PARITY) == SMARTCARD_PARITY_ODD))
ganlikun 0:13413ea9a877 653 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x000000U))
ganlikun 0:13413ea9a877 654 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
ganlikun 0:13413ea9a877 655 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
ganlikun 0:13413ea9a877 656 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
ganlikun 0:13413ea9a877 657 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
ganlikun 0:13413ea9a877 658 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \
ganlikun 0:13413ea9a877 659 ((NACK) == SMARTCARD_NACK_DISABLE))
ganlikun 0:13413ea9a877 660 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
ganlikun 0:13413ea9a877 661 /**
ganlikun 0:13413ea9a877 662 * @}
ganlikun 0:13413ea9a877 663 */
ganlikun 0:13413ea9a877 664
ganlikun 0:13413ea9a877 665 /* Private functions ---------------------------------------------------------*/
ganlikun 0:13413ea9a877 666 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
ganlikun 0:13413ea9a877 667 * @{
ganlikun 0:13413ea9a877 668 */
ganlikun 0:13413ea9a877 669
ganlikun 0:13413ea9a877 670 /**
ganlikun 0:13413ea9a877 671 * @}
ganlikun 0:13413ea9a877 672 */
ganlikun 0:13413ea9a877 673
ganlikun 0:13413ea9a877 674 /**
ganlikun 0:13413ea9a877 675 * @}
ganlikun 0:13413ea9a877 676 */
ganlikun 0:13413ea9a877 677
ganlikun 0:13413ea9a877 678 /**
ganlikun 0:13413ea9a877 679 * @}
ganlikun 0:13413ea9a877 680 */
ganlikun 0:13413ea9a877 681 #ifdef __cplusplus
ganlikun 0:13413ea9a877 682 }
ganlikun 0:13413ea9a877 683 #endif
ganlikun 0:13413ea9a877 684
ganlikun 0:13413ea9a877 685 #endif /* __STM32F4xx_HAL_SMARTCARD_H */
ganlikun 0:13413ea9a877 686
ganlikun 0:13413ea9a877 687 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
ganlikun 0:13413ea9a877 688