STM32F103xB HAL User Manual
|
00001 /** 00002 ****************************************************************************** 00003 * @file stm32f1xx_hal_smartcard.h 00004 * @author MCD Application Team 00005 * @brief Header file of SMARTCARD HAL module. 00006 ****************************************************************************** 00007 * @attention 00008 * 00009 * <h2><center>© Copyright (c) 2016 STMicroelectronics. 00010 * All rights reserved.</center></h2> 00011 * 00012 * This software component is licensed by ST under BSD 3-Clause license, 00013 * the "License"; You may not use this file except in compliance with the 00014 * License. You may obtain a copy of the License at: 00015 * opensource.org/licenses/BSD-3-Clause 00016 * 00017 ****************************************************************************** 00018 */ 00019 00020 /* Define to prevent recursive inclusion -------------------------------------*/ 00021 #ifndef __STM32F1xx_HAL_SMARTCARD_H 00022 #define __STM32F1xx_HAL_SMARTCARD_H 00023 00024 #ifdef __cplusplus 00025 extern "C" { 00026 #endif 00027 00028 /* Includes ------------------------------------------------------------------*/ 00029 #include "stm32f1xx_hal_def.h" 00030 00031 /** @addtogroup STM32F1xx_HAL_Driver 00032 * @{ 00033 */ 00034 00035 /** @addtogroup SMARTCARD 00036 * @{ 00037 */ 00038 00039 /* Exported types ------------------------------------------------------------*/ 00040 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types 00041 * @{ 00042 */ 00043 00044 /** 00045 * @brief SMARTCARD Init Structure definition 00046 */ 00047 typedef struct 00048 { 00049 uint32_t BaudRate; /*!< This member configures the SmartCard communication baud rate. 00050 The baud rate is computed using the following formula: 00051 - IntegerDivider = ((PCLKx) / (16 * (hsc->Init.BaudRate))) 00052 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 16) + 0.5 */ 00053 00054 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame. 00055 This parameter can be a value of @ref SMARTCARD_Word_Length */ 00056 00057 uint32_t StopBits; /*!< Specifies the number of stop bits transmitted. 00058 This parameter can be a value of @ref SMARTCARD_Stop_Bits */ 00059 00060 uint32_t Parity; /*!< Specifies the parity mode. 00061 This parameter can be a value of @ref SMARTCARD_Parity 00062 @note When parity is enabled, the computed parity is inserted 00063 at the MSB position of the transmitted data (9th bit when 00064 the word length is set to 9 data bits; 8th bit when the 00065 word length is set to 8 data bits).*/ 00066 00067 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled. 00068 This parameter can be a value of @ref SMARTCARD_Mode */ 00069 00070 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock. 00071 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */ 00072 00073 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made. 00074 This parameter can be a value of @ref SMARTCARD_Clock_Phase */ 00075 00076 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted 00077 data bit (MSB) has to be output on the SCLK pin in synchronous mode. 00078 This parameter can be a value of @ref SMARTCARD_Last_Bit */ 00079 00080 uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler value used for dividing the system clock 00081 to provide the smartcard clock. The value given in the register (5 significant bits) 00082 is multiplied by 2 to give the division factor of the source clock frequency. 00083 This parameter can be a value of @ref SMARTCARD_Prescaler */ 00084 00085 uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time value in terms of number of baud clocks */ 00086 00087 uint32_t NACKState; /*!< Specifies the SmartCard NACK Transmission state. 00088 This parameter can be a value of @ref SMARTCARD_NACK_State */ 00089 }SMARTCARD_InitTypeDef; 00090 00091 /** 00092 * @brief HAL SMARTCARD State structures definition 00093 * @note HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState. 00094 * - gState contains SMARTCARD state information related to global Handle management 00095 * and also information related to Tx operations. 00096 * gState value coding follow below described bitmap : 00097 * b7-b6 Error information 00098 * 00 : No Error 00099 * 01 : (Not Used) 00100 * 10 : Timeout 00101 * 11 : Error 00102 * b5 IP initialization status 00103 * 0 : Reset (IP not initialized) 00104 * 1 : Init done (IP initialized. HAL SMARTCARD Init function already called) 00105 * b4-b3 (not used) 00106 * xx : Should be set to 00 00107 * b2 Intrinsic process state 00108 * 0 : Ready 00109 * 1 : Busy (IP busy with some configuration or internal operations) 00110 * b1 (not used) 00111 * x : Should be set to 0 00112 * b0 Tx state 00113 * 0 : Ready (no Tx operation ongoing) 00114 * 1 : Busy (Tx operation ongoing) 00115 * - RxState contains information related to Rx operations. 00116 * RxState value coding follow below described bitmap : 00117 * b7-b6 (not used) 00118 * xx : Should be set to 00 00119 * b5 IP initialization status 00120 * 0 : Reset (IP not initialized) 00121 * 1 : Init done (IP initialized) 00122 * b4-b2 (not used) 00123 * xxx : Should be set to 000 00124 * b1 Rx state 00125 * 0 : Ready (no Rx operation ongoing) 00126 * 1 : Busy (Rx operation ongoing) 00127 * b0 (not used) 00128 * x : Should be set to 0. 00129 */ 00130 typedef enum 00131 { 00132 HAL_SMARTCARD_STATE_RESET = 0x00U, /*!< Peripheral is not yet Initialized 00133 Value is allowed for gState and RxState */ 00134 HAL_SMARTCARD_STATE_READY = 0x20U, /*!< Peripheral Initialized and ready for use 00135 Value is allowed for gState and RxState */ 00136 HAL_SMARTCARD_STATE_BUSY = 0x24U, /*!< an internal process is ongoing 00137 Value is allowed for gState only */ 00138 HAL_SMARTCARD_STATE_BUSY_TX = 0x21U, /*!< Data Transmission process is ongoing 00139 Value is allowed for gState only */ 00140 HAL_SMARTCARD_STATE_BUSY_RX = 0x22U, /*!< Data Reception process is ongoing 00141 Value is allowed for RxState only */ 00142 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x23U, /*!< Data Transmission and Reception process is ongoing 00143 Not to be used for neither gState nor RxState. 00144 Value is result of combination (Or) between gState and RxState values */ 00145 HAL_SMARTCARD_STATE_TIMEOUT = 0xA0U, /*!< Timeout state 00146 Value is allowed for gState only */ 00147 HAL_SMARTCARD_STATE_ERROR = 0xE0U /*!< Error 00148 Value is allowed for gState only */ 00149 }HAL_SMARTCARD_StateTypeDef; 00150 00151 /** 00152 * @brief SMARTCARD handle Structure definition 00153 */ 00154 typedef struct __SMARTCARD_HandleTypeDef 00155 { 00156 USART_TypeDef *Instance; /*!< USART registers base address */ 00157 00158 SMARTCARD_InitTypeDef Init; /*!< SmartCard communication parameters */ 00159 00160 uint8_t *pTxBuffPtr; /*!< Pointer to SmartCard Tx transfer Buffer */ 00161 00162 uint16_t TxXferSize; /*!< SmartCard Tx Transfer size */ 00163 00164 __IO uint16_t TxXferCount; /*!< SmartCard Tx Transfer Counter */ 00165 00166 uint8_t *pRxBuffPtr; /*!< Pointer to SmartCard Rx transfer Buffer */ 00167 00168 uint16_t RxXferSize; /*!< SmartCard Rx Transfer size */ 00169 00170 __IO uint16_t RxXferCount; /*!< SmartCard Rx Transfer Counter */ 00171 00172 DMA_HandleTypeDef *hdmatx; /*!< SmartCard Tx DMA Handle parameters */ 00173 00174 DMA_HandleTypeDef *hdmarx; /*!< SmartCard Rx DMA Handle parameters */ 00175 00176 HAL_LockTypeDef Lock; /*!< Locking object */ 00177 00178 __IO HAL_SMARTCARD_StateTypeDef gState; /*!< SmartCard state information related to global Handle management 00179 and also related to Tx operations. 00180 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */ 00181 00182 __IO HAL_SMARTCARD_StateTypeDef RxState; /*!< SmartCard state information related to Rx operations. 00183 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */ 00184 00185 __IO uint32_t ErrorCode; /*!< SmartCard Error code */ 00186 00187 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) 00188 void (* TxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Tx Complete Callback */ 00189 00190 void (* RxCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Rx Complete Callback */ 00191 00192 void (* ErrorCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Error Callback */ 00193 00194 void (* AbortCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Abort Complete Callback */ 00195 00196 void (* AbortTransmitCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Abort Transmit Complete Callback */ 00197 00198 void (* AbortReceiveCpltCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Abort Receive Complete Callback */ 00199 00200 void (* MspInitCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Msp Init callback */ 00201 00202 void (* MspDeInitCallback)(struct __SMARTCARD_HandleTypeDef *hsc); /*!< SMARTCARD Msp DeInit callback */ 00203 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ 00204 00205 } SMARTCARD_HandleTypeDef; 00206 00207 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) 00208 /** 00209 * @brief HAL SMARTCARD Callback ID enumeration definition 00210 */ 00211 typedef enum 00212 { 00213 HAL_SMARTCARD_TX_COMPLETE_CB_ID = 0x00U, /*!< SMARTCARD Tx Complete Callback ID */ 00214 HAL_SMARTCARD_RX_COMPLETE_CB_ID = 0x01U, /*!< SMARTCARD Rx Complete Callback ID */ 00215 HAL_SMARTCARD_ERROR_CB_ID = 0x02U, /*!< SMARTCARD Error Callback ID */ 00216 HAL_SMARTCARD_ABORT_COMPLETE_CB_ID = 0x03U, /*!< SMARTCARD Abort Complete Callback ID */ 00217 HAL_SMARTCARD_ABORT_TRANSMIT_COMPLETE_CB_ID = 0x04U, /*!< SMARTCARD Abort Transmit Complete Callback ID */ 00218 HAL_SMARTCARD_ABORT_RECEIVE_COMPLETE_CB_ID = 0x05U, /*!< SMARTCARD Abort Receive Complete Callback ID */ 00219 00220 HAL_SMARTCARD_MSPINIT_CB_ID = 0x08U, /*!< SMARTCARD MspInit callback ID */ 00221 HAL_SMARTCARD_MSPDEINIT_CB_ID = 0x09U /*!< SMARTCARD MspDeInit callback ID */ 00222 00223 } HAL_SMARTCARD_CallbackIDTypeDef; 00224 00225 /** 00226 * @brief HAL SMARTCARD Callback pointer definition 00227 */ 00228 typedef void (*pSMARTCARD_CallbackTypeDef)(SMARTCARD_HandleTypeDef *hsc); /*!< pointer to an SMARTCARD callback function */ 00229 00230 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ 00231 00232 /** 00233 * @} 00234 */ 00235 00236 /* Exported constants --------------------------------------------------------*/ 00237 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants 00238 * @{ 00239 */ 00240 00241 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code 00242 * @{ 00243 */ 00244 #define HAL_SMARTCARD_ERROR_NONE 0x00000000U /*!< No error */ 00245 #define HAL_SMARTCARD_ERROR_PE 0x00000001U /*!< Parity error */ 00246 #define HAL_SMARTCARD_ERROR_NE 0x00000002U /*!< Noise error */ 00247 #define HAL_SMARTCARD_ERROR_FE 0x00000004U /*!< Frame error */ 00248 #define HAL_SMARTCARD_ERROR_ORE 0x00000008U /*!< Overrun error */ 00249 #define HAL_SMARTCARD_ERROR_DMA 0x00000010U /*!< DMA transfer error */ 00250 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) 00251 #define HAL_SMARTCARD_ERROR_INVALID_CALLBACK 0x00000020U /*!< Invalid Callback error */ 00252 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ 00253 /** 00254 * @} 00255 */ 00256 00257 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length 00258 * @{ 00259 */ 00260 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M) 00261 /** 00262 * @} 00263 */ 00264 00265 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits 00266 * @{ 00267 */ 00268 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0) 00269 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) 00270 /** 00271 * @} 00272 */ 00273 00274 /** @defgroup SMARTCARD_Parity SMARTCARD Parity 00275 * @{ 00276 */ 00277 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE) 00278 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) 00279 /** 00280 * @} 00281 */ 00282 00283 /** @defgroup SMARTCARD_Mode SMARTCARD Mode 00284 * @{ 00285 */ 00286 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE) 00287 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE) 00288 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE)) 00289 /** 00290 * @} 00291 */ 00292 00293 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity 00294 * @{ 00295 */ 00296 #define SMARTCARD_POLARITY_LOW 0x00000000U 00297 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL) 00298 /** 00299 * @} 00300 */ 00301 00302 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase 00303 * @{ 00304 */ 00305 #define SMARTCARD_PHASE_1EDGE 0x00000000U 00306 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA) 00307 /** 00308 * @} 00309 */ 00310 00311 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit 00312 * @{ 00313 */ 00314 #define SMARTCARD_LASTBIT_DISABLE 0x00000000U 00315 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL) 00316 /** 00317 * @} 00318 */ 00319 00320 /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State 00321 * @{ 00322 */ 00323 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK) 00324 #define SMARTCARD_NACK_DISABLE 0x00000000U 00325 /** 00326 * @} 00327 */ 00328 00329 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests 00330 * @{ 00331 */ 00332 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT) 00333 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR) 00334 /** 00335 * @} 00336 */ 00337 00338 /** @defgroup SMARTCARD_Prescaler SMARTCARD Prescaler 00339 * @{ 00340 */ 00341 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 0x00000001U /*!< SYSCLK divided by 2 */ 00342 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 0x00000002U /*!< SYSCLK divided by 4 */ 00343 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 0x00000003U /*!< SYSCLK divided by 6 */ 00344 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 0x00000004U /*!< SYSCLK divided by 8 */ 00345 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 0x00000005U /*!< SYSCLK divided by 10 */ 00346 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 0x00000006U /*!< SYSCLK divided by 12 */ 00347 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 0x00000007U /*!< SYSCLK divided by 14 */ 00348 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 0x00000008U /*!< SYSCLK divided by 16 */ 00349 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 0x00000009U /*!< SYSCLK divided by 18 */ 00350 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 0x0000000AU /*!< SYSCLK divided by 20 */ 00351 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 0x0000000BU /*!< SYSCLK divided by 22 */ 00352 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 0x0000000CU /*!< SYSCLK divided by 24 */ 00353 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 0x0000000DU /*!< SYSCLK divided by 26 */ 00354 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 0x0000000EU /*!< SYSCLK divided by 28 */ 00355 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 0x0000000FU /*!< SYSCLK divided by 30 */ 00356 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 0x00000010U /*!< SYSCLK divided by 32 */ 00357 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 0x00000011U /*!< SYSCLK divided by 34 */ 00358 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 0x00000012U /*!< SYSCLK divided by 36 */ 00359 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 0x00000013U /*!< SYSCLK divided by 38 */ 00360 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 0x00000014U /*!< SYSCLK divided by 40 */ 00361 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 0x00000015U /*!< SYSCLK divided by 42 */ 00362 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 0x00000016U /*!< SYSCLK divided by 44 */ 00363 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 0x00000017U /*!< SYSCLK divided by 46 */ 00364 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 0x00000018U /*!< SYSCLK divided by 48 */ 00365 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 0x00000019U /*!< SYSCLK divided by 50 */ 00366 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 0x0000001AU /*!< SYSCLK divided by 52 */ 00367 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 0x0000001BU /*!< SYSCLK divided by 54 */ 00368 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 0x0000001CU /*!< SYSCLK divided by 56 */ 00369 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 0x0000001DU /*!< SYSCLK divided by 58 */ 00370 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 0x0000001EU /*!< SYSCLK divided by 60 */ 00371 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 0x0000001FU /*!< SYSCLK divided by 62 */ 00372 /** 00373 * @} 00374 */ 00375 00376 /** @defgroup SmartCard_Flags SMARTCARD Flags 00377 * Elements values convention: 0xXXXX 00378 * - 0xXXXX : Flag mask in the SR register 00379 * @{ 00380 */ 00381 #define SMARTCARD_FLAG_TXE ((uint32_t)USART_SR_TXE) 00382 #define SMARTCARD_FLAG_TC ((uint32_t)USART_SR_TC) 00383 #define SMARTCARD_FLAG_RXNE ((uint32_t)USART_SR_RXNE) 00384 #define SMARTCARD_FLAG_IDLE ((uint32_t)USART_SR_IDLE) 00385 #define SMARTCARD_FLAG_ORE ((uint32_t)USART_SR_ORE) 00386 #define SMARTCARD_FLAG_NE ((uint32_t)USART_SR_NE) 00387 #define SMARTCARD_FLAG_FE ((uint32_t)USART_SR_FE) 00388 #define SMARTCARD_FLAG_PE ((uint32_t)USART_SR_PE) 00389 /** 00390 * @} 00391 */ 00392 00393 /** @defgroup SmartCard_Interrupt_definition SMARTCARD Interrupts Definition 00394 * Elements values convention: 0xY000XXXX 00395 * - XXXX : Interrupt mask in the Y register 00396 * - Y : Interrupt source register (2bits) 00397 * - 01: CR1 register 00398 * - 11: CR3 register 00399 * @{ 00400 */ 00401 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE)) 00402 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE)) 00403 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE)) 00404 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE)) 00405 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE)) 00406 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE)) 00407 /** 00408 * @} 00409 */ 00410 00411 /** 00412 * @} 00413 */ 00414 00415 /* Exported macro ------------------------------------------------------------*/ 00416 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros 00417 * @{ 00418 */ 00419 00420 /** @brief Reset SMARTCARD handle gstate & RxState 00421 * @param __HANDLE__ specifies the SMARTCARD Handle. 00422 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00423 * @retval None 00424 */ 00425 #if USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1 00426 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \ 00427 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \ 00428 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \ 00429 (__HANDLE__)->MspInitCallback = NULL; \ 00430 (__HANDLE__)->MspDeInitCallback = NULL; \ 00431 } while(0U) 00432 #else 00433 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \ 00434 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \ 00435 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \ 00436 } while(0U) 00437 #endif /*USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ 00438 00439 /** @brief Flush the Smartcard DR register 00440 * @param __HANDLE__ specifies the SMARTCARD Handle. 00441 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00442 * @retval None 00443 */ 00444 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR) 00445 00446 /** @brief Check whether the specified Smartcard flag is set or not. 00447 * @param __HANDLE__ specifies the SMARTCARD Handle. 00448 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00449 * @param __FLAG__ specifies the flag to check. 00450 * This parameter can be one of the following values: 00451 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag 00452 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag 00453 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag 00454 * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag 00455 * @arg SMARTCARD_FLAG_ORE: Overrun Error flag 00456 * @arg SMARTCARD_FLAG_NE: Noise Error flag 00457 * @arg SMARTCARD_FLAG_FE: Framing Error flag 00458 * @arg SMARTCARD_FLAG_PE: Parity Error flag 00459 * @retval The new state of __FLAG__ (TRUE or FALSE). 00460 */ 00461 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__)) 00462 00463 /** @brief Clear the specified Smartcard pending flags. 00464 * @param __HANDLE__ specifies the SMARTCARD Handle. 00465 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00466 * @param __FLAG__ specifies the flag to check. 00467 * This parameter can be any combination of the following values: 00468 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag. 00469 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag. 00470 * 00471 * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (Overrun 00472 * error) flags are cleared by software sequence: a read operation to 00473 * USART_SR register followed by a read operation to USART_DR register. 00474 * @note RXNE flag can be also cleared by a read to the USART_DR register. 00475 * @note TC flag can be also cleared by software sequence: a read operation to 00476 * USART_SR register followed by a write operation to USART_DR register. 00477 * @note TXE flag is cleared only by a write to the USART_DR register. 00478 * @retval None 00479 */ 00480 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__)) 00481 00482 /** @brief Clear the SMARTCARD PE pending flag. 00483 * @param __HANDLE__ specifies the USART Handle. 00484 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00485 * @retval None 00486 */ 00487 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \ 00488 do{ \ 00489 __IO uint32_t tmpreg = 0x00U; \ 00490 tmpreg = (__HANDLE__)->Instance->SR; \ 00491 tmpreg = (__HANDLE__)->Instance->DR; \ 00492 UNUSED(tmpreg); \ 00493 } while(0U) 00494 00495 /** @brief Clear the SMARTCARD FE pending flag. 00496 * @param __HANDLE__ specifies the USART Handle. 00497 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00498 * @retval None 00499 */ 00500 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) 00501 00502 /** @brief Clear the SMARTCARD NE pending flag. 00503 * @param __HANDLE__ specifies the USART Handle. 00504 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00505 * @retval None 00506 */ 00507 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) 00508 00509 /** @brief Clear the SMARTCARD ORE pending flag. 00510 * @param __HANDLE__ specifies the USART Handle. 00511 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00512 * @retval None 00513 */ 00514 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) 00515 00516 /** @brief Clear the SMARTCARD IDLE pending flag. 00517 * @param __HANDLE__ specifies the USART Handle. 00518 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00519 * @retval None 00520 */ 00521 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) 00522 00523 /** @brief Enable the specified SmartCard interrupt. 00524 * @param __HANDLE__ specifies the SMARTCARD Handle. 00525 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00526 * @param __INTERRUPT__ specifies the SMARTCARD interrupt to enable. 00527 * This parameter can be one of the following values: 00528 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt 00529 * @arg SMARTCARD_IT_TC: Transmission complete interrupt 00530 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt 00531 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt 00532 * @arg SMARTCARD_IT_PE: Parity Error interrupt 00533 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 00534 * @retval None 00535 */ 00536 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \ 00537 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK))) 00538 00539 /** @brief Disable the specified SmartCard interrupt. 00540 * @param __HANDLE__ specifies the SMARTCARD Handle. 00541 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00542 * @param __INTERRUPT__ specifies the SMARTCARD interrupt to disable. 00543 * This parameter can be one of the following values: 00544 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt 00545 * @arg SMARTCARD_IT_TC: Transmission complete interrupt 00546 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt 00547 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt 00548 * @arg SMARTCARD_IT_PE: Parity Error interrupt 00549 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error) 00550 * @retval None 00551 */ 00552 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \ 00553 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK))) 00554 00555 /** @brief Checks whether the specified SmartCard interrupt has occurred or not. 00556 * @param __HANDLE__ specifies the SmartCard Handle. 00557 * @param __IT__ specifies the SMARTCARD interrupt source to check. 00558 * This parameter can be one of the following values: 00559 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt 00560 * @arg SMARTCARD_IT_TC: Transmission complete interrupt 00561 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt 00562 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt 00563 * @arg SMARTCARD_IT_ERR: Error interrupt 00564 * @arg SMARTCARD_IT_PE: Parity Error interrupt 00565 * @retval The new state of __IT__ (TRUE or FALSE). 00566 */ 00567 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == SMARTCARD_CR1_REG_INDEX)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK)) 00568 00569 /** @brief Enable the USART associated to the SMARTCARD Handle 00570 * @param __HANDLE__ specifies the SMARTCARD Handle. 00571 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00572 * @retval None 00573 */ 00574 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE) 00575 00576 /** @brief Disable the USART associated to the SMARTCARD Handle 00577 * @param __HANDLE__ specifies the SMARTCARD Handle. 00578 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device). 00579 * @retval None 00580 */ 00581 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE) 00582 00583 /** @brief Macros to enable the SmartCard DMA request. 00584 * @param __HANDLE__ specifies the SmartCard Handle. 00585 * @param __REQUEST__ specifies the SmartCard DMA request. 00586 * This parameter can be one of the following values: 00587 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request 00588 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request 00589 * @retval None 00590 */ 00591 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__)) 00592 00593 /** @brief Macros to disable the SmartCard DMA request. 00594 * @param __HANDLE__ specifies the SmartCard Handle. 00595 * @param __REQUEST__ specifies the SmartCard DMA request. 00596 * This parameter can be one of the following values: 00597 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request 00598 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request 00599 * @retval None 00600 */ 00601 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__)) 00602 00603 /** 00604 * @} 00605 */ 00606 00607 /* Exported functions --------------------------------------------------------*/ 00608 /** @addtogroup SMARTCARD_Exported_Functions 00609 * @{ 00610 */ 00611 00612 /** @addtogroup SMARTCARD_Exported_Functions_Group1 00613 * @{ 00614 */ 00615 /* Initialization/de-initialization functions **********************************/ 00616 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc); 00617 HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc); 00618 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc); 00619 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc); 00620 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc); 00621 #if (USE_HAL_SMARTCARD_REGISTER_CALLBACKS == 1) 00622 /* Callbacks Register/UnRegister functions ***********************************/ 00623 HAL_StatusTypeDef HAL_SMARTCARD_RegisterCallback(SMARTCARD_HandleTypeDef *hsc, HAL_SMARTCARD_CallbackIDTypeDef CallbackID, pSMARTCARD_CallbackTypeDef pCallback); 00624 HAL_StatusTypeDef HAL_SMARTCARD_UnRegisterCallback(SMARTCARD_HandleTypeDef *hsc, HAL_SMARTCARD_CallbackIDTypeDef CallbackID); 00625 #endif /* USE_HAL_SMARTCARD_REGISTER_CALLBACKS */ 00626 /** 00627 * @} 00628 */ 00629 00630 /** @addtogroup SMARTCARD_Exported_Functions_Group2 00631 * @{ 00632 */ 00633 /* IO operation functions *******************************************************/ 00634 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00635 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout); 00636 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); 00637 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); 00638 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); 00639 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size); 00640 /* Transfer Abort functions */ 00641 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsc); 00642 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsc); 00643 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsc); 00644 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsc); 00645 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsc); 00646 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsc); 00647 00648 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc); 00649 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc); 00650 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc); 00651 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc); 00652 void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef *hsc); 00653 void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef *hsc); 00654 void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef *hsc); 00655 /** 00656 * @} 00657 */ 00658 00659 /** @addtogroup SMARTCARD_Exported_Functions_Group3 00660 * @{ 00661 */ 00662 /* Peripheral State functions **************************************************/ 00663 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc); 00664 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc); 00665 /** 00666 * @} 00667 */ 00668 00669 /** 00670 * @} 00671 */ 00672 /* Private types -------------------------------------------------------------*/ 00673 /* Private variables ---------------------------------------------------------*/ 00674 /* Private constants ---------------------------------------------------------*/ 00675 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants 00676 * @{ 00677 */ 00678 00679 /** @brief SMARTCARD interruptions flag mask 00680 * 00681 */ 00682 #define SMARTCARD_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \ 00683 USART_CR1_IDLEIE | USART_CR3_EIE ) 00684 00685 #define SMARTCARD_CR1_REG_INDEX 1U 00686 #define SMARTCARD_CR3_REG_INDEX 3U 00687 /** 00688 * @} 00689 */ 00690 00691 /* Private macros --------------------------------------------------------*/ 00692 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros 00693 * @{ 00694 */ 00695 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B) 00696 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \ 00697 ((STOPBITS) == SMARTCARD_STOPBITS_1_5)) 00698 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \ 00699 ((PARITY) == SMARTCARD_PARITY_ODD)) 00700 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x000000U)) 00701 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH)) 00702 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE)) 00703 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \ 00704 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE)) 00705 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \ 00706 ((NACK) == SMARTCARD_NACK_DISABLE)) 00707 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 4500001U) 00708 00709 #define SMARTCARD_DIV(__PCLK__, __BAUD__) (((__PCLK__)*25U)/(4U*(__BAUD__))) 00710 #define SMARTCARD_DIVMANT(__PCLK__, __BAUD__) (SMARTCARD_DIV((__PCLK__), (__BAUD__))/100U) 00711 #define SMARTCARD_DIVFRAQ(__PCLK__, __BAUD__) ((((SMARTCARD_DIV((__PCLK__), (__BAUD__)) - (SMARTCARD_DIVMANT((__PCLK__), (__BAUD__)) * 100U)) * 16U) + 50U) / 100U) 00712 /* SMARTCARD BRR = mantissa + overflow + fraction 00713 = (SMARTCARD DIVMANT << 4) + (SMARTCARD DIVFRAQ & 0xF0) + (SMARTCARD DIVFRAQ & 0x0FU) */ 00714 #define SMARTCARD_BRR(__PCLK__, __BAUD__) (((SMARTCARD_DIVMANT((__PCLK__), (__BAUD__)) << 4U) + \ 00715 (SMARTCARD_DIVFRAQ((__PCLK__), (__BAUD__)) & 0xF0U)) + \ 00716 (SMARTCARD_DIVFRAQ((__PCLK__), (__BAUD__)) & 0x0FU)) 00717 00718 /** 00719 * @} 00720 */ 00721 00722 /* Private functions ---------------------------------------------------------*/ 00723 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions 00724 * @{ 00725 */ 00726 00727 /** 00728 * @} 00729 */ 00730 00731 /** 00732 * @} 00733 */ 00734 00735 /** 00736 * @} 00737 */ 00738 00739 #ifdef __cplusplus 00740 } 00741 #endif 00742 00743 #endif /* __STM32F1xx_HAL_SMARTCARD_H */ 00744 00745 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/