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