L4 HAL Drivers

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers stm32l4xx_hal_smartcard.h Source File

stm32l4xx_hal_smartcard.h

Go to the documentation of this file.
00001 /**
00002   ******************************************************************************
00003   * @file    stm32l4xx_hal_smartcard.h
00004   * @author  MCD Application Team
00005   * @version V1.1.0
00006   * @date    16-September-2015
00007   * @brief   Header file of SMARTCARD HAL module.
00008   ******************************************************************************
00009   * @attention
00010   *
00011   * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012   *
00013   * Redistribution and use in source and binary forms, with or without modification,
00014   * are permitted provided that the following conditions are met:
00015   *   1. Redistributions of source code must retain the above copyright notice,
00016   *      this list of conditions and the following disclaimer.
00017   *   2. Redistributions in binary form must reproduce the above copyright notice,
00018   *      this list of conditions and the following disclaimer in the documentation
00019   *      and/or other materials provided with the distribution.
00020   *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021   *      may be used to endorse or promote products derived from this software
00022   *      without specific prior written permission.
00023   *
00024   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034   *
00035   ******************************************************************************
00036   */
00037 
00038 /* Define to prevent recursive inclusion -------------------------------------*/
00039 #ifndef __STM32L4xx_HAL_SMARTCARD_H
00040 #define __STM32L4xx_HAL_SMARTCARD_H
00041 
00042 #ifdef __cplusplus
00043  extern "C" {
00044 #endif
00045 
00046 /* Includes ------------------------------------------------------------------*/
00047 #include "stm32l4xx_hal_def.h"
00048 
00049 /** @addtogroup STM32L4xx_HAL_Driver
00050   * @{
00051   */
00052 
00053 /** @addtogroup SMARTCARD
00054   * @{
00055   */
00056 
00057 /* Exported types ------------------------------------------------------------*/
00058 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
00059   * @{
00060   */
00061 
00062 /**
00063   * @brief SMARTCARD Init Structure definition
00064   */
00065 typedef struct
00066 {
00067   uint32_t BaudRate;                  /*!< Configures the SmartCard communication baud rate.
00068                                            The baud rate register is computed using the following formula:
00069                                               Baud Rate Register = ((PCLKx) / ((hsmartcard->Init.BaudRate))) */
00070 
00071   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
00072                                            This parameter @ref SMARTCARD_Word_Length can only be set to 9 (8 data + 1 parity bits). */
00073 
00074   uint32_t StopBits;                  /*!< Specifies the number of stop bits @ref SMARTCARD_Stop_Bits.
00075                                            Only 1.5 stop bits are authorized in SmartCard mode. */
00076 
00077   uint16_t Parity;                    /*!< Specifies the parity mode.
00078                                            This parameter can be a value of @ref SMARTCARD_Parity
00079                                            @note The parity is enabled by default (PCE is forced to 1).
00080                                                  Since the WordLength is forced to 8 bits + parity, M is
00081                                                  forced to 1 and the parity bit is the 9th bit. */
00082 
00083   uint16_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   uint16_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
00087                                            This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
00088 
00089   uint16_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   uint16_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   uint16_t OneBitSampling;            /*!< Specifies whether a single sample or three samples' majority vote is selected.
00097                                            Selecting the single sample method increases the receiver tolerance to clock
00098                                            deviations. This parameter can be a value of @ref SMARTCARD_OneBit_Sampling. */
00099 
00100   uint8_t  Prescaler;                 /*!< Specifies the SmartCard Prescaler */
00101 
00102   uint8_t  GuardTime;                 /*!< Specifies the SmartCard Guard Time */
00103 
00104   uint16_t NACKEnable;                /*!< Specifies whether the SmartCard NACK transmission is enabled
00105                                            in case of parity error.
00106                                            This parameter can be a value of @ref SMARTCARD_NACK_Enable */
00107 
00108   uint32_t TimeOutEnable;             /*!< Specifies whether the receiver timeout is enabled.
00109                                             This parameter can be a value of @ref SMARTCARD_Timeout_Enable*/
00110 
00111   uint32_t TimeOutValue;              /*!< Specifies the receiver time out value in number of baud blocks:
00112                                            it is used to implement the Character Wait Time (CWT) and
00113                                            Block Wait Time (BWT). It is coded over 24 bits. */
00114 
00115   uint8_t BlockLength;                /*!< Specifies the SmartCard Block Length in T=1 Reception mode.
00116                                            This parameter can be any value from 0x0 to 0xFF */
00117 
00118   uint8_t AutoRetryCount;             /*!< Specifies the SmartCard auto-retry count (number of retries in
00119                                             receive and transmit mode). When set to 0, retransmission is
00120                                             disabled. Otherwise, its maximum value is 7 (before signalling
00121                                             an error) */
00122 
00123 }SMARTCARD_InitTypeDef;
00124 
00125 /**
00126   * @brief  SMARTCARD advanced features initalization structure definition
00127   */
00128 typedef struct
00129 {
00130   uint32_t AdvFeatureInit;            /*!< Specifies which advanced SMARTCARD features is initialized. Several
00131                                            advanced features may be initialized at the same time. This parameter
00132                                            can be a value of @ref SMARTCARD_Advanced_Features_Initialization_Type */
00133 
00134   uint32_t TxPinLevelInvert;          /*!< Specifies whether the TX pin active level is inverted.
00135                                            This parameter can be a value of @ref SMARTCARD_Tx_Inv  */
00136 
00137   uint32_t RxPinLevelInvert;          /*!< Specifies whether the RX pin active level is inverted.
00138                                            This parameter can be a value of @ref SMARTCARD_Rx_Inv  */
00139 
00140   uint32_t DataInvert;                /*!< Specifies whether data are inverted (positive/direct logic
00141                                            vs negative/inverted logic).
00142                                            This parameter can be a value of @ref SMARTCARD_Data_Inv */
00143 
00144   uint32_t Swap;                      /*!< Specifies whether TX and RX pins are swapped.
00145                                            This parameter can be a value of @ref SMARTCARD_Rx_Tx_Swap */
00146 
00147   uint32_t OverrunDisable;            /*!< Specifies whether the reception overrun detection is disabled.
00148                                            This parameter can be a value of @ref SMARTCARD_Overrun_Disable */
00149 
00150   uint32_t DMADisableonRxError;       /*!< Specifies whether the DMA is disabled in case of reception error.
00151                                            This parameter can be a value of @ref SMARTCARD_DMA_Disable_on_Rx_Error */
00152 
00153   uint32_t MSBFirst;                  /*!< Specifies whether MSB is sent first on UART line.
00154                                            This parameter can be a value of @ref SMARTCARD_MSB_First */
00155 }SMARTCARD_AdvFeatureInitTypeDef;
00156 
00157 /**
00158   * @brief HAL State structures definition
00159   */
00160 typedef enum
00161 {
00162   HAL_SMARTCARD_STATE_RESET             = 0x00,    /*!< Peripheral is not initialized                      */
00163   HAL_SMARTCARD_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use           */
00164   HAL_SMARTCARD_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing                     */
00165   HAL_SMARTCARD_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing               */
00166   HAL_SMARTCARD_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing                  */
00167   HAL_SMARTCARD_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission and Reception process is ongoing */
00168   HAL_SMARTCARD_STATE_TIMEOUT           = 0x03,    /*!< Timeout state                                      */
00169   HAL_SMARTCARD_STATE_ERROR             = 0x04     /*!< Error                                              */
00170 }HAL_SMARTCARD_StateTypeDef;
00171 
00172 /**
00173   * @brief  HAL SMARTCARD Error Code structure definition
00174   */
00175 typedef enum
00176 {
00177   HAL_SMARTCARD_ERROR_NONE      = 0x00,    /*!< No error                */
00178   HAL_SMARTCARD_ERROR_PE        = 0x01,    /*!< Parity error            */
00179   HAL_SMARTCARD_ERROR_NE        = 0x02,    /*!< Noise error             */
00180   HAL_SMARTCARD_ERROR_FE        = 0x04,    /*!< frame error             */
00181   HAL_SMARTCARD_ERROR_ORE       = 0x08,    /*!< Overrun error           */
00182   HAL_SMARTCARD_ERROR_DMA       = 0x10,    /*!< DMA transfer error      */
00183   HAL_SMARTCARD_ERROR_RTO       = 0x20     /*!< Receiver TimeOut error  */
00184 }HAL_SMARTCARD_ErrorTypeDef;
00185 
00186 /**
00187   * @brief  SMARTCARD handle Structure definition
00188   */
00189 typedef struct
00190 {
00191   USART_TypeDef                   *Instance;        /*!< USART registers base address                          */
00192 
00193   SMARTCARD_InitTypeDef           Init;             /*!< SmartCard communication parameters                    */
00194 
00195   SMARTCARD_AdvFeatureInitTypeDef AdvancedInit;     /*!< SmartCard advanced features initialization parameters */
00196 
00197   uint8_t                         *pTxBuffPtr;      /*!< Pointer to SmartCard Tx transfer Buffer               */
00198 
00199   uint16_t                        TxXferSize;       /*!< SmartCard Tx Transfer size                            */
00200 
00201   uint16_t                        TxXferCount;      /*!< SmartCard Tx Transfer Counter                         */
00202 
00203   uint8_t                         *pRxBuffPtr;      /*!< Pointer to SmartCard Rx transfer Buffer               */
00204 
00205   uint16_t                        RxXferSize;       /*!< SmartCard Rx Transfer size                            */
00206 
00207   uint16_t                        RxXferCount;      /*!< SmartCard Rx Transfer Counter                         */
00208 
00209   DMA_HandleTypeDef               *hdmatx;          /*!< SmartCard Tx DMA Handle parameters                    */
00210 
00211   DMA_HandleTypeDef               *hdmarx;          /*!< SmartCard Rx DMA Handle parameters                    */
00212 
00213   HAL_LockTypeDef                 Lock;             /*!< Locking object                                        */
00214 
00215   HAL_SMARTCARD_StateTypeDef      State;            /*!< SmartCard communication state                         */
00216 
00217   uint32_t                        ErrorCode;        /*!< SmartCard Error code                                  */
00218 
00219 }SMARTCARD_HandleTypeDef;
00220 
00221 /**
00222   * @brief  SMARTCARD clock sources
00223   */
00224 typedef enum
00225 {
00226   SMARTCARD_CLOCKSOURCE_PCLK1     = 0x00, /*!< PCLK1 clock source     */
00227   SMARTCARD_CLOCKSOURCE_PCLK2     = 0x01, /*!< PCLK2 clock source     */
00228   SMARTCARD_CLOCKSOURCE_HSI       = 0x02, /*!< HSI clock source       */
00229   SMARTCARD_CLOCKSOURCE_SYSCLK    = 0x04, /*!< SYSCLK clock source    */
00230   SMARTCARD_CLOCKSOURCE_LSE       = 0x08, /*!< LSE clock source       */
00231   SMARTCARD_CLOCKSOURCE_UNDEFINED = 0x10  /*!< undefined clock source */
00232 }SMARTCARD_ClockSourceTypeDef;
00233 
00234 /**
00235   * @}
00236   */
00237 
00238 /* Exported constants --------------------------------------------------------*/
00239 /** @defgroup SMARTCARD_Exported_Constants  SMARTCARD Exported Constants
00240   * @{
00241   */
00242 
00243 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
00244   * @{
00245   */
00246 #define SMARTCARD_WORDLENGTH_9B             ((uint32_t)USART_CR1_M0)     /*!< SMARTCARD frame length */
00247 /**
00248   * @}
00249   */
00250 
00251 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
00252   * @{
00253   */
00254 #define SMARTCARD_STOPBITS_1_5              ((uint32_t)(USART_CR2_STOP)) /*!< SMARTCARD frame numer of stop bits */
00255 /**
00256   * @}
00257   */
00258 
00259 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
00260   * @{
00261   */
00262 #define SMARTCARD_PARITY_EVEN               ((uint32_t)USART_CR1_PCE)                  /*!< SMARTCARD frame even parity */
00263 #define SMARTCARD_PARITY_ODD                ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< SMARTCARD frame odd parity  */
00264 /**
00265   * @}
00266   */
00267 
00268 /** @defgroup SMARTCARD_Mode SMARTCARD Transfer Mode
00269   * @{
00270   */
00271 #define SMARTCARD_MODE_RX                   ((uint32_t)USART_CR1_RE)                  /*!< SMARTCARD RX mode        */
00272 #define SMARTCARD_MODE_TX                   ((uint32_t)USART_CR1_TE)                  /*!< SMARTCARD TX mode        */
00273 #define SMARTCARD_MODE_TX_RX                ((uint32_t)(USART_CR1_TE |USART_CR1_RE))  /*!< SMARTCARD RX and TX mode */
00274 /**
00275   * @}
00276   */
00277 
00278 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
00279   * @{
00280   */
00281 #define SMARTCARD_POLARITY_LOW              ((uint32_t)0x00000000)                   /*!< SMARTCARD frame low polarity  */
00282 #define SMARTCARD_POLARITY_HIGH             ((uint32_t)USART_CR2_CPOL)               /*!< SMARTCARD frame high polarity */
00283 /**
00284   * @}
00285   */
00286 
00287 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
00288   * @{
00289   */
00290 #define SMARTCARD_PHASE_1EDGE               ((uint32_t)0x00000000)                  /*!< SMARTCARD frame phase on first clock transition  */
00291 #define SMARTCARD_PHASE_2EDGE               ((uint32_t)USART_CR2_CPHA)              /*!< SMARTCARD frame phase on second clock transition */
00292 /**
00293   * @}
00294   */
00295 
00296 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
00297   * @{
00298   */
00299 #define SMARTCARD_LASTBIT_DISABLE           ((uint32_t)0x00000000)                 /*!< SMARTCARD frame last data bit clock pulse not output to SCLK pin */
00300 #define SMARTCARD_LASTBIT_ENABLE            ((uint32_t)USART_CR2_LBCL)             /*!< SMARTCARD frame last data bit clock pulse output to SCLK pin     */
00301 /**
00302   * @}
00303   */
00304 
00305 /** @defgroup SMARTCARD_OneBit_Sampling SMARTCARD One Bit Sampling Method
00306   * @{
00307   */
00308 #define SMARTCARD_ONE_BIT_SAMPLE_DISABLE    ((uint32_t)0x00000000)                 /*!< SMARTCARD frame one-bit sample disabled */
00309 #define SMARTCARD_ONE_BIT_SAMPLE_ENABLE     ((uint32_t)USART_CR3_ONEBIT)           /*!< SMARTCARD frame one-bit sample enabled  */
00310 /**
00311   * @}
00312   */
00313 
00314 
00315 /** @defgroup SMARTCARD_NACK_Enable SMARTCARD NACK Enable
00316   * @{
00317   */
00318 #define SMARTCARD_NACK_ENABLE               ((uint32_t)USART_CR3_NACK)            /*!< SMARTCARD NACK transmission disabled */
00319 #define SMARTCARD_NACK_DISABLE              ((uint32_t)0x00000000)                /*!< SMARTCARD NACK transmission enabled  */
00320 /**
00321   * @}
00322   */
00323 
00324 /** @defgroup SMARTCARD_Timeout_Enable SMARTCARD Timeout Enable
00325   * @{
00326   */
00327 #define SMARTCARD_TIMEOUT_DISABLE           ((uint32_t)0x00000000)                /*!< SMARTCARD receiver timeout disabled */
00328 #define SMARTCARD_TIMEOUT_ENABLE            ((uint32_t)USART_CR2_RTOEN)           /*!< SMARTCARD receiver timeout enabled  */
00329 /**
00330   * @}
00331   */
00332 
00333 /** @defgroup SMARTCARD_Advanced_Features_Initialization_Type SMARTCARD advanced feature initialization type
00334   * @{
00335   */
00336 #define SMARTCARD_ADVFEATURE_NO_INIT                 ((uint32_t)0x00000000)      /*!< No advanced feature initialization       */ 
00337 #define SMARTCARD_ADVFEATURE_TXINVERT_INIT           ((uint32_t)0x00000001)      /*!< TX pin active level inversion            */
00338 #define SMARTCARD_ADVFEATURE_RXINVERT_INIT           ((uint32_t)0x00000002)      /*!< RX pin active level inversion            */
00339 #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT         ((uint32_t)0x00000004)      /*!< Binary data inversion                    */
00340 #define SMARTCARD_ADVFEATURE_SWAP_INIT               ((uint32_t)0x00000008)      /*!< TX/RX pins swap                          */
00341 #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT   ((uint32_t)0x00000010)      /*!< RX overrun disable                       */
00342 #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT  ((uint32_t)0x00000020)      /*!< DMA disable on Reception Error           */
00343 #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT           ((uint32_t)0x00000080)      /*!< Most significant bit sent/received first */
00344 /**
00345   * @}
00346   */
00347 
00348 /** @defgroup SMARTCARD_Tx_Inv SMARTCARD advanced feature TX pin active level inversion
00349   * @{
00350   */
00351 #define SMARTCARD_ADVFEATURE_TXINV_DISABLE  ((uint32_t)0x00000000)                /*!< TX pin active level inversion disable */
00352 #define SMARTCARD_ADVFEATURE_TXINV_ENABLE   ((uint32_t)USART_CR2_TXINV)           /*!< TX pin active level inversion enable  */
00353 /**
00354   * @}
00355   */
00356 
00357 /** @defgroup SMARTCARD_Rx_Inv SMARTCARD advanced feature RX pin active level inversion
00358   * @{
00359   */
00360 #define SMARTCARD_ADVFEATURE_RXINV_DISABLE  ((uint32_t)0x00000000)                /*!< RX pin active level inversion disable */
00361 #define SMARTCARD_ADVFEATURE_RXINV_ENABLE   ((uint32_t)USART_CR2_RXINV)           /*!< RX pin active level inversion enable  */
00362 /**
00363   * @}
00364   */
00365 
00366 /** @defgroup SMARTCARD_Data_Inv SMARTCARD advanced feature Binary Data inversion
00367   * @{
00368   */
00369 #define SMARTCARD_ADVFEATURE_DATAINV_DISABLE  ((uint32_t)0x00000000)              /*!< Binary data inversion disable */
00370 #define SMARTCARD_ADVFEATURE_DATAINV_ENABLE   ((uint32_t)USART_CR2_DATAINV)       /*!< Binary data inversion enable  */
00371 /**
00372   * @}
00373   */
00374 
00375 /** @defgroup SMARTCARD_Rx_Tx_Swap SMARTCARD advanced feature RX TX pins swap
00376   * @{
00377   */
00378 #define SMARTCARD_ADVFEATURE_SWAP_DISABLE   ((uint32_t)0x00000000)                /*!< TX/RX pins swap disable */
00379 #define SMARTCARD_ADVFEATURE_SWAP_ENABLE    ((uint32_t)USART_CR2_SWAP)            /*!< TX/RX pins swap enable  */
00380 /**
00381   * @}
00382   */
00383 
00384 /** @defgroup SMARTCARD_Overrun_Disable SMARTCARD advanced feature Overrun Disable
00385   * @{
00386   */
00387 #define SMARTCARD_ADVFEATURE_OVERRUN_ENABLE   ((uint32_t)0x00000000)              /*!< RX overrun enable  */
00388 #define SMARTCARD_ADVFEATURE_OVERRUN_DISABLE  ((uint32_t)USART_CR3_OVRDIS)        /*!< RX overrun disable */
00389 /**
00390   * @}
00391   */
00392 
00393 /** @defgroup SMARTCARD_DMA_Disable_on_Rx_Error SMARTCARD advanced feature DMA Disable on Rx Error
00394   * @{
00395   */
00396 #define SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR   ((uint32_t)0x00000000)         /*!< DMA enable on Reception Error  */
00397 #define SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR  ((uint32_t)USART_CR3_DDRE)     /*!< DMA disable on Reception Error */
00398 /**
00399   * @}
00400   */
00401 
00402 /** @defgroup SMARTCARD_MSB_First   SMARTCARD advanced feature MSB first
00403   * @{
00404   */
00405 #define SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE      ((uint32_t)0x00000000)           /*!< Most significant bit sent/received first disable */
00406 #define SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE       ((uint32_t)USART_CR2_MSBFIRST)   /*!< Most significant bit sent/received first enable  */
00407 /**
00408   * @}
00409   */
00410 
00411 /** @defgroup SMARTCARD_Request_Parameters SMARTCARD Request Parameters
00412   * @{
00413   */
00414 #define SMARTCARD_RXDATA_FLUSH_REQUEST      ((uint16_t)USART_RQR_RXFRQ)        /*!< Receive data flush request */
00415 #define SMARTCARD_TXDATA_FLUSH_REQUEST      ((uint16_t)USART_RQR_TXFRQ)        /*!< Transmit data flush request */
00416 /**
00417   * @}
00418   */
00419 
00420 /** @defgroup SmartCard_Flags SMARTCARD Flags
00421   *        Elements values convention: 0xXXXX
00422   *           - 0xXXXX  : Flag mask in the ISR register
00423   * @{
00424   */
00425 #define SMARTCARD_FLAG_REACK          USART_ISR_REACK      /*!< SMARTCARD receive enable acknowledge flag  */
00426 #define SMARTCARD_FLAG_TEACK          USART_ISR_TEACK      /*!< SMARTCARD transmit enable acknowledge flag */
00427 #define SMARTCARD_FLAG_BUSY           USART_ISR_BUSY       /*!< SMARTCARD busy flag                        */
00428 #define SMARTCARD_FLAG_EOBF           USART_ISR_EOBF       /*!< SMARTCARD end of block flag                */
00429 #define SMARTCARD_FLAG_RTOF           USART_ISR_RTOF       /*!< SMARTCARD receiver timeout flag            */
00430 #define SMARTCARD_FLAG_TXE            USART_ISR_TXE        /*!< SMARTCARD transmit data register empty     */
00431 #define SMARTCARD_FLAG_TC             USART_ISR_TC         /*!< SMARTCARD transmission complete            */
00432 #define SMARTCARD_FLAG_RXNE           USART_ISR_RXNE       /*!< SMARTCARD read data register not empty     */
00433 #define SMARTCARD_FLAG_IDLE           USART_ISR_IDLE       /*!< SMARTCARD idle line detection              */
00434 #define SMARTCARD_FLAG_ORE            USART_ISR_ORE        /*!< SMARTCARD overrun error                    */
00435 #define SMARTCARD_FLAG_NE             USART_ISR_NE         /*!< SMARTCARD noise error                      */
00436 #define SMARTCARD_FLAG_FE             USART_ISR_FE         /*!< SMARTCARD frame error                      */
00437 #define SMARTCARD_FLAG_PE             USART_ISR_PE         /*!< SMARTCARD parity error                     */
00438 /**
00439   * @}
00440   */
00441 
00442 /** @defgroup SMARTCARD_Interrupt_definition SMARTCARD Interrupts Definition
00443   *        Elements values convention: 0000ZZZZ0XXYYYYYb
00444   *           - YYYYY  : Interrupt source position in the XX register (5bits)
00445   *           - XX  : Interrupt source register (2bits)
00446   *                 - 01: CR1 register
00447   *                 - 10: CR2 register
00448   *                 - 11: CR3 register
00449   *           - ZZZZ  : Flag position in the ISR register(4bits)
00450   * @{
00451   */
00452 
00453 #define SMARTCARD_IT_PE                     ((uint16_t)0x0028)        /*!< SMARTCARD parity error interruption                 */
00454 #define SMARTCARD_IT_TXE                    ((uint16_t)0x0727)        /*!< SMARTCARD transmit data register empty interruption */
00455 #define SMARTCARD_IT_TC                     ((uint16_t)0x0626)        /*!< SMARTCARD transmission complete interruption        */
00456 #define SMARTCARD_IT_RXNE                   ((uint16_t)0x0525)        /*!< SMARTCARD read data register not empty interruption */
00457 #define SMARTCARD_IT_IDLE                   ((uint16_t)0x0424)        /*!< SMARTCARD idle line detection interruption          */                                                                      
00458 
00459 #define SMARTCARD_IT_ERR                    ((uint16_t)0x0060)        /*!< SMARTCARD error interruption         */
00460 #define SMARTCARD_IT_ORE                    ((uint16_t)0x0300)        /*!< SMARTCARD overrun error interruption */
00461 #define SMARTCARD_IT_NE                     ((uint16_t)0x0200)        /*!< SMARTCARD noise error interruption   */
00462 #define SMARTCARD_IT_FE                     ((uint16_t)0x0100)        /*!< SMARTCARD frame error interruption   */
00463 
00464 #define SMARTCARD_IT_EOB                    ((uint16_t)0x0C3B)        /*!< SMARTCARD end of block interruption     */ 
00465 #define SMARTCARD_IT_RTO                    ((uint16_t)0x0B3A)        /*!< SMARTCARD receiver timeout interruption */
00466 /**
00467   * @}
00468   */
00469 
00470 
00471 /** @defgroup SMARTCARD_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags
00472   * @{
00473   */
00474 #define SMARTCARD_CLEAR_PEF                 USART_ICR_PECF   /*!< Parity Error Clear Flag          */
00475 #define SMARTCARD_CLEAR_FEF                 USART_ICR_FECF   /*!< Framing Error Clear Flag         */
00476 #define SMARTCARD_CLEAR_NEF                 USART_ICR_NCF    /*!< Noise detected Clear Flag        */
00477 #define SMARTCARD_CLEAR_OREF                USART_ICR_ORECF  /*!< OverRun Error Clear Flag         */
00478 #define SMARTCARD_CLEAR_IDLEF               USART_ICR_IDLECF /*!< Idle line detected clear flag    */
00479 #define SMARTCARD_CLEAR_TCF                 USART_ICR_TCCF   /*!< Transmission Complete Clear Flag */
00480 #define SMARTCARD_CLEAR_RTOF                USART_ICR_RTOCF  /*!< Receiver Time Out Clear Flag     */
00481 #define SMARTCARD_CLEAR_EOBF                USART_ICR_EOBCF  /*!< End Of Block Clear Flag          */
00482 /**
00483   * @}
00484   */
00485 
00486 /** @defgroup SMARTCARD_CR3_SCARCNT_LSB_POS SMARTCARD auto retry counter LSB position in CR3 register
00487   * @{
00488   */
00489 #define SMARTCARD_CR3_SCARCNT_LSB_POS       ((uint32_t) 17)   /*!< SMARTCARD auto retry counter LSB position in CR3 register */
00490 /**
00491   * @}
00492   */
00493 
00494 /** @defgroup SMARTCARD_GTPR_GT_LSB_POS SMARTCARD guard time value LSB position in GTPR register
00495   * @{
00496   */
00497 #define SMARTCARD_GTPR_GT_LSB_POS           ((uint32_t) 8)   /*!<  SMARTCARD guard time value LSB position in GTPR register */
00498 /**
00499   * @}
00500   */
00501 
00502 /** @defgroup SMARTCARD_RTOR_BLEN_LSB_POS SMARTCARD block length LSB position in RTOR register
00503   * @{
00504   */
00505 #define SMARTCARD_RTOR_BLEN_LSB_POS         ((uint32_t) 24)  /*!< SMARTCARD block length LSB position in RTOR register */
00506 /**
00507   * @}
00508   */
00509 
00510 /** @defgroup SMARTCARD_Interruption_Mask SMARTCARD interruptions flags mask
00511   * @{
00512   */
00513 #define SMARTCARD_IT_MASK                   ((uint16_t)0x001F)   /*!< SMARTCARD interruptions flags mask */
00514 /**
00515   * @}
00516   */
00517 
00518 /**
00519   * @}
00520   */
00521 
00522 /* Exported macros -----------------------------------------------------------*/
00523 /** @defgroup SMARTCARD_Exported_Macros  SMARTCARD Exported Macros
00524   * @{
00525   */
00526 
00527 /** @brief  Reset SMARTCARD handle state.
00528   * @param  __HANDLE__: SMARTCARD handle.
00529   * @retval None
00530   */
00531 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMARTCARD_STATE_RESET)
00532 
00533 /** @brief  Flush the Smartcard Data registers.
00534   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00535   * @retval None
00536   */
00537 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__)                                 \
00538     do{                                                                              \
00539       SET_BIT((__HANDLE__)->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST); \
00540       SET_BIT((__HANDLE__)->Instance->RQR, SMARTCARD_TXDATA_FLUSH_REQUEST); \
00541       } while(0)
00542 
00543 /** @brief  Clear the specified SMARTCARD pending flag.
00544   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00545   * @param  __FLAG__: specifies the flag to check.
00546   *          This parameter can be any combination of the following values:
00547   *            @arg SMARTCARD_CLEAR_PEF:    Parity error clear flag
00548   *            @arg SMARTCARD_CLEAR_FEF:    Framing error clear flag
00549   *            @arg SMARTCARD_CLEAR_NEF:    Noise detected clear flag
00550   *            @arg SMARTCARD_CLEAR_OREF:   OverRun error clear flag
00551   *            @arg SMARTCARD_CLEAR_IDLEF:  Idle line detected clear flag
00552   *            @arg SMARTCARD_CLEAR_TCF:    Transmission complete clear flag
00553   *            @arg SMARTCARD_CLEAR_RTOF:   Receiver timeout clear flag
00554   *            @arg SMARTCARD_CLEAR_EOBF:   End of block clear flag
00555   * @retval None
00556   */
00557 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
00558 
00559 /** @brief  Clear the SMARTCARD PE pending flag.
00560   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00561   * @retval None
00562   */
00563 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_PEF)
00564 
00565 
00566 /** @brief  Clear the SMARTCARD FE pending flag.
00567   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00568   * @retval None
00569   */
00570 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_FEF)
00571 
00572 /** @brief  Clear the SMARTCARD NE pending flag.
00573   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00574   * @retval None
00575   */
00576 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_NEF)
00577 
00578 /** @brief  Clear the SMARTCARD ORE pending flag.
00579   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00580   * @retval None
00581   */
00582 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_OREF)
00583 
00584 /** @brief  Clear the SMARTCARD IDLE pending flag.
00585   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00586   * @retval None
00587   */
00588 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_IDLEF)
00589 
00590 /** @brief  Check whether the specified Smartcard flag is set or not.
00591   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00592   * @param  __FLAG__: specifies the flag to check.
00593   *        This parameter can be one of the following values:
00594   *            @arg SMARTCARD_FLAG_REACK: Receive enable acknowledge flag
00595   *            @arg SMARTCARD_FLAG_TEACK: Transmit enable acknowledge flag
00596   *            @arg SMARTCARD_FLAG_BUSY:  Busy flag
00597   *            @arg SMARTCARD_FLAG_EOBF:  End of block flag
00598   *            @arg SMARTCARD_FLAG_RTOF:  Receiver timeout flag
00599   *            @arg SMARTCARD_FLAG_TXE:   Transmit data register empty flag
00600   *            @arg SMARTCARD_FLAG_TC:    Transmission complete flag
00601   *            @arg SMARTCARD_FLAG_RXNE:  Receive data register not empty flag
00602   *            @arg SMARTCARD_FLAG_IDLE:  Idle line detection flag  
00603   *            @arg SMARTCARD_FLAG_ORE:   Overrun error flag
00604   *            @arg SMARTCARD_FLAG_NE:    Noise error flag
00605   *            @arg SMARTCARD_FLAG_FE:    Framing error flag
00606   *            @arg SMARTCARD_FLAG_PE:    Parity error flag
00607   * @retval The new state of __FLAG__ (TRUE or FALSE).
00608   */
00609 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
00610 
00611 
00612 /** @brief  Enable the specified SmartCard interrupt.
00613   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00614   * @param  __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
00615   *          This parameter can be one of the following values:
00616   *            @arg SMARTCARD_IT_EOB:   End of block interrupt
00617   *            @arg SMARTCARD_IT_RTO:   Receive timeout interrupt
00618   *            @arg SMARTCARD_IT_TXE:   Transmit data register empty interrupt
00619   *            @arg SMARTCARD_IT_TC:    Transmission complete interrupt
00620   *            @arg SMARTCARD_IT_RXNE:  Receive data register not empty interrupt
00621   *            @arg SMARTCARD_IT_IDLE:  Idle line detection interrupt  
00622   *            @arg SMARTCARD_IT_PE:    Parity error interrupt
00623   *            @arg SMARTCARD_IT_ERR:   Error interrupt(frame error, noise error, overrun error)
00624   * @retval None
00625   */
00626 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
00627                                                                 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
00628                                                                 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
00629 
00630 /** @brief  Disable the specified SmartCard interrupt.
00631   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00632   * @param  __INTERRUPT__: specifies the SMARTCARD interrupt to disable.
00633   *          This parameter can be one of the following values:
00634   *            @arg SMARTCARD_IT_EOB:   End of block interrupt
00635   *            @arg SMARTCARD_IT_RTO:   Receive timeout interrupt
00636   *            @arg SMARTCARD_IT_TXE:   Transmit data register empty interrupt
00637   *            @arg SMARTCARD_IT_TC:    Transmission complete interrupt
00638   *            @arg SMARTCARD_IT_RXNE:  Receive data register not empty interrupt
00639   *            @arg SMARTCARD_IT_IDLE:  Idle line detection interrupt   
00640   *            @arg SMARTCARD_IT_PE:    Parity error interrupt
00641   *            @arg SMARTCARD_IT_ERR:   Error interrupt(frame error, noise error, overrun error)
00642   * @retval None
00643   */
00644 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
00645                                                                 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
00646                                                                 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
00647 
00648 
00649 /** @brief  Check whether the specified SmartCard interrupt has occurred or not.
00650   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00651   * @param  __IT__: specifies the SMARTCARD interrupt to check.
00652   *          This parameter can be one of the following values:
00653   *            @arg SMARTCARD_IT_EOB:   End of block interrupt
00654   *            @arg SMARTCARD_IT_RTO:   Receive timeout interrupt
00655   *            @arg SMARTCARD_IT_TXE:   Transmit data register empty interrupt
00656   *            @arg SMARTCARD_IT_TC:    Transmission complete interrupt
00657   *            @arg SMARTCARD_IT_RXNE:  Receive data register not empty interrupt
00658   *            @arg SMARTCARD_IT_IDLE:  Idle line detection interrupt  
00659   *            @arg SMARTCARD_IT_ORE:   Overrun error interrupt
00660   *            @arg SMARTCARD_IT_NE:    Noise error interrupt
00661   *            @arg SMARTCARD_IT_FE:    Framing error interrupt
00662   *            @arg SMARTCARD_IT_PE:    Parity error interrupt
00663   * @retval The new state of __IT__ (TRUE or FALSE).
00664   */
00665 #define __HAL_SMARTCARD_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
00666 
00667 /** @brief  Check whether the specified SmartCard interrupt source is enabled or not.
00668   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00669   * @param  __IT__: specifies the SMARTCARD interrupt source to check.
00670   *          This parameter can be one of the following values:
00671   *            @arg SMARTCARD_IT_EOB:   End of block interrupt
00672   *            @arg SMARTCARD_IT_RTO:   Receive timeout interrupt
00673   *            @arg SMARTCARD_IT_TXE:   Transmit data register empty interrupt
00674   *            @arg SMARTCARD_IT_TC:    Transmission complete interrupt
00675   *            @arg SMARTCARD_IT_RXNE:  Receive data register not empty interrupt
00676   *            @arg SMARTCARD_IT_IDLE:  Idle line detection interrupt  
00677   *            @arg SMARTCARD_IT_ORE:   Overrun error interrupt
00678   *            @arg SMARTCARD_IT_NE:    Noise error interrupt
00679   *            @arg SMARTCARD_IT_FE:    Framing error interrupt
00680   *            @arg SMARTCARD_IT_PE:    Parity error interrupt
00681   * @retval The new state of __IT__ (TRUE or FALSE).
00682   */
00683 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1)? (__HANDLE__)->Instance->CR1 : \
00684                                                            (((((uint8_t)(__IT__)) >> 5U) == 2)? (__HANDLE__)->Instance->CR2 : \
00685                                                            (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << (((uint16_t)(__IT__)) & SMARTCARD_IT_MASK)))
00686 
00687 
00688 /** @brief  Clear the specified SMARTCARD ISR flag, in setting the proper ICR register flag.
00689   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00690   * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
00691   *                       to clear the corresponding interrupt.
00692   *          This parameter can be one of the following values:
00693   *            @arg SMARTCARD_CLEAR_PEF:    Parity error clear flag
00694   *            @arg SMARTCARD_CLEAR_FEF:    Framing error clear flag
00695   *            @arg SMARTCARD_CLEAR_NEF:    Noise detected clear flag
00696   *            @arg SMARTCARD_CLEAR_OREF:   OverRun error clear flag
00697   *            @arg SMARTCARD_CLEAR_IDLEF:  Idle line detection clear flag    
00698   *            @arg SMARTCARD_CLEAR_TCF:    Transmission complete clear flag
00699   *            @arg SMARTCARD_CLEAR_RTOF:   Receiver timeout clear flag
00700   *            @arg SMARTCARD_CLEAR_EOBF:   End of block clear flag
00701   * @retval None
00702   */
00703 #define __HAL_SMARTCARD_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR |= (uint32_t)(__IT_CLEAR__))
00704 
00705 /** @brief  Set a specific SMARTCARD request flag.
00706   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00707   * @param  __REQ__: specifies the request flag to set
00708   *          This parameter can be one of the following values:
00709   *            @arg SMARTCARD_RXDATA_FLUSH_REQUEST: Receive data flush Request
00710   *            @arg SMARTCARD_TXDATA_FLUSH_REQUEST: Transmit data flush Request
00711   *
00712   * @retval None
00713   */
00714 #define __HAL_SMARTCARD_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
00715 
00716 /** @brief  Enable the SMARTCARD one bit sample method.
00717   * @param  __HANDLE__: specifies the SMARTCARD Handle.  
00718   * @retval None
00719   */     
00720 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
00721 
00722 /** @brief  Disable the SMARTCARD one bit sample method.
00723   * @param  __HANDLE__: specifies the SMARTCARD Handle.  
00724   * @retval None
00725   */      
00726 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
00727 
00728 /** @brief  Enable the USART associated to the SMARTCARD Handle.
00729   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00730   * @retval None
00731   */
00732 #define __HAL_SMARTCARD_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
00733 
00734 /** @brief  Disable the USART associated to the SMARTCARD Handle
00735   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00736   * @retval None
00737   */
00738 #define __HAL_SMARTCARD_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
00739 
00740 /**
00741   * @}
00742   */
00743 
00744 /* Private macros -------------------------------------------------------------*/
00745 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
00746   * @{
00747   */
00748 
00749 /** @brief  Report the SMARTCARD clock source.
00750   * @param  __HANDLE__: specifies the SMARTCARD Handle.
00751   * @param  __CLOCKSOURCE__: output variable.
00752   * @retval the SMARTCARD clocking source, written in __CLOCKSOURCE__.
00753   */
00754 #define SMARTCARD_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)   \
00755   do {                                                         \
00756     if((__HANDLE__)->Instance == USART1)                       \
00757     {                                                          \
00758        switch(__HAL_RCC_GET_USART1_SOURCE())                   \
00759        {                                                       \
00760         case RCC_USART1CLKSOURCE_PCLK2:                        \
00761           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK2;     \
00762           break;                                               \
00763         case RCC_USART1CLKSOURCE_HSI:                          \
00764           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
00765           break;                                               \
00766         case RCC_USART1CLKSOURCE_SYSCLK:                       \
00767           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
00768           break;                                               \
00769         case RCC_USART1CLKSOURCE_LSE:                          \
00770           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
00771           break;                                               \
00772         default:                                               \
00773           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
00774           break;                                               \
00775        }                                                       \
00776     }                                                          \
00777     else if((__HANDLE__)->Instance == USART2)                  \
00778     {                                                          \
00779        switch(__HAL_RCC_GET_USART2_SOURCE())                   \
00780        {                                                       \
00781         case RCC_USART2CLKSOURCE_PCLK1:                        \
00782           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
00783           break;                                               \
00784         case RCC_USART2CLKSOURCE_HSI:                          \
00785           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
00786           break;                                               \
00787         case RCC_USART2CLKSOURCE_SYSCLK:                       \
00788           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
00789           break;                                               \
00790         case RCC_USART2CLKSOURCE_LSE:                          \
00791           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
00792           break;                                               \
00793         default:                                               \
00794           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
00795           break;                                               \
00796        }                                                       \
00797     }                                                          \
00798     else if((__HANDLE__)->Instance == USART3)                  \
00799     {                                                          \
00800        switch(__HAL_RCC_GET_USART3_SOURCE())                   \
00801        {                                                       \
00802         case RCC_USART3CLKSOURCE_PCLK1:                        \
00803           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
00804           break;                                               \
00805         case RCC_USART3CLKSOURCE_HSI:                          \
00806           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
00807           break;                                               \
00808         case RCC_USART3CLKSOURCE_SYSCLK:                       \
00809           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
00810           break;                                               \
00811         case RCC_USART3CLKSOURCE_LSE:                          \
00812           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
00813           break;                                               \
00814         default:                                               \
00815           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
00816           break;                                               \
00817        }                                                       \
00818     }                                                          \
00819   } while(0)
00820 
00821 /** @brief  Check the Baud rate range. 
00822   * @note   The maximum Baud Rate is derived from the maximum clock on L4 (80 MHz)
00823   *         divided by the oversampling used on the SMARTCARD (i.e. 16).
00824   * @param  __BAUDRATE__: Baud rate set by the configuration function.
00825   * @retval Test result (TRUE or FALSE)
00826   */
00827 #define IS_SMARTCARD_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 5000001)
00828 
00829 /** @brief  Check the block length range.
00830   * @note   The maximum SMARTCARD block length is 0xFF.
00831   * @param  __LENGTH__: block length.
00832   * @retval Test result (TRUE or FALSE)
00833   */
00834 #define IS_SMARTCARD_BLOCKLENGTH(__LENGTH__) ((__LENGTH__) <= 0xFF)
00835 
00836 /** @brief  Check the receiver timeout value. 
00837   * @note   The maximum SMARTCARD receiver timeout value is 0xFFFFFF.
00838   * @param  __TIMEOUTVALUE__: receiver timeout value.
00839   * @retval Test result (TRUE or FALSE)
00840   */
00841 #define IS_SMARTCARD_TIMEOUT_VALUE(__TIMEOUTVALUE__)    ((__TIMEOUTVALUE__) <= 0xFFFFFF)
00842 
00843 /** @brief  Check the SMARTCARD autoretry counter value. 
00844   * @note   The maximum number of retransmissions is 0x7.
00845   * @param  __COUNT__: number of retransmissions.
00846   * @retval Test result (TRUE or FALSE)
00847   */
00848 #define IS_SMARTCARD_AUTORETRY_COUNT(__COUNT__)         ((__COUNT__) <= 0x7)
00849 
00850 /**
00851   * @brief Ensure that SMARTCARD frame length is valid.
00852   * @param __LENGTH__: SMARTCARD frame length. 
00853   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
00854   */ 
00855 #define IS_SMARTCARD_WORD_LENGTH(__LENGTH__) ((__LENGTH__) == SMARTCARD_WORDLENGTH_9B)
00856 
00857 /**
00858   * @brief Ensure that SMARTCARD frame number of stop bits is valid.
00859   * @param __STOPBITS__: SMARTCARD frame number of stop bits. 
00860   * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
00861   */ 
00862 #define IS_SMARTCARD_STOPBITS(__STOPBITS__) ((__STOPBITS__) == SMARTCARD_STOPBITS_1_5)
00863 
00864 /**
00865   * @brief Ensure that SMARTCARD frame parity is valid.
00866   * @param __PARITY__: SMARTCARD frame parity. 
00867   * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
00868   */ 
00869 #define IS_SMARTCARD_PARITY(__PARITY__) (((__PARITY__) == SMARTCARD_PARITY_EVEN) || \
00870                                          ((__PARITY__) == SMARTCARD_PARITY_ODD))
00871 
00872 /**
00873   * @brief Ensure that SMARTCARD communication mode is valid.
00874   * @param __MODE__: SMARTCARD communication mode. 
00875   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
00876   */ 
00877 #define IS_SMARTCARD_MODE(__MODE__) ((((__MODE__) & (uint16_t)0xFFF3) == 0x00) && ((__MODE__) != (uint16_t)0x00))
00878 
00879 /**
00880   * @brief Ensure that SMARTCARD frame polarity is valid.
00881   * @param __CPOL__: SMARTCARD frame polarity. 
00882   * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
00883   */ 
00884 #define IS_SMARTCARD_POLARITY(__CPOL__) (((__CPOL__) == SMARTCARD_POLARITY_LOW) || ((__CPOL__) == SMARTCARD_POLARITY_HIGH))
00885 
00886 /**
00887   * @brief Ensure that SMARTCARD frame phase is valid.
00888   * @param __CPHA__: SMARTCARD frame phase. 
00889   * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
00890   */
00891 #define IS_SMARTCARD_PHASE(__CPHA__) (((__CPHA__) == SMARTCARD_PHASE_1EDGE) || ((__CPHA__) == SMARTCARD_PHASE_2EDGE))
00892 
00893 /**
00894   * @brief Ensure that SMARTCARD frame last bit clock pulse setting is valid.
00895   * @param __LASTBIT__: SMARTCARD frame last bit clock pulse setting. 
00896   * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
00897   */
00898 #define IS_SMARTCARD_LASTBIT(__LASTBIT__) (((__LASTBIT__) == SMARTCARD_LASTBIT_DISABLE) || \
00899                                            ((__LASTBIT__) == SMARTCARD_LASTBIT_ENABLE))
00900 
00901 /**
00902   * @brief Ensure that SMARTCARD frame sampling is valid.
00903   * @param __ONEBIT__: SMARTCARD frame sampling. 
00904   * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
00905   */
00906 #define IS_SMARTCARD_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_DISABLE) || \
00907                                                  ((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_ENABLE))
00908 
00909 /**
00910   * @brief Ensure that SMARTCARD NACK transmission setting is valid.
00911   * @param __NACK__: SMARTCARD NACK transmission setting. 
00912   * @retval SET (__NACK__ is valid) or RESET (__NACK__ is invalid)
00913   */
00914 #define IS_SMARTCARD_NACK(__NACK__) (((__NACK__) == SMARTCARD_NACK_ENABLE) || \
00915                                      ((__NACK__) == SMARTCARD_NACK_DISABLE))
00916 
00917 /**
00918   * @brief Ensure that SMARTCARD receiver timeout setting is valid.
00919   * @param __TIMEOUT__: SMARTCARD receiver timeout setting. 
00920   * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
00921   */
00922 #define IS_SMARTCARD_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == SMARTCARD_TIMEOUT_DISABLE) || \
00923                                            ((__TIMEOUT__) == SMARTCARD_TIMEOUT_ENABLE))
00924 
00925 /**
00926   * @brief Ensure that SMARTCARD advanced features initialization is valid.
00927   * @param __INIT__: SMARTCARD advanced features initialization. 
00928   * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
00929   */
00930 #define IS_SMARTCARD_ADVFEATURE_INIT(__INIT__) ((__INIT__) <= (SMARTCARD_ADVFEATURE_NO_INIT                | \
00931                                                                SMARTCARD_ADVFEATURE_TXINVERT_INIT          | \
00932                                                                SMARTCARD_ADVFEATURE_RXINVERT_INIT          | \
00933                                                                SMARTCARD_ADVFEATURE_DATAINVERT_INIT        | \
00934                                                                SMARTCARD_ADVFEATURE_SWAP_INIT              | \
00935                                                                SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT  | \
00936                                                                SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT | \
00937                                                                SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
00938 
00939 /**
00940   * @brief Ensure that SMARTCARD frame TX inversion setting is valid.
00941   * @param __TXINV__: SMARTCARD frame TX inversion setting. 
00942   * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
00943   */
00944 #define IS_SMARTCARD_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == SMARTCARD_ADVFEATURE_TXINV_DISABLE) || \
00945                                                   ((__TXINV__) == SMARTCARD_ADVFEATURE_TXINV_ENABLE))
00946 
00947 /**
00948   * @brief Ensure that SMARTCARD frame RX inversion setting is valid.
00949   * @param __RXINV__: SMARTCARD frame RX inversion setting. 
00950   * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
00951   */
00952 #define IS_SMARTCARD_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == SMARTCARD_ADVFEATURE_RXINV_DISABLE) || \
00953                                                   ((__RXINV__) == SMARTCARD_ADVFEATURE_RXINV_ENABLE))
00954 
00955 /**
00956   * @brief Ensure that SMARTCARD frame data inversion setting is valid.
00957   * @param __DATAINV__: SMARTCARD frame data inversion setting. 
00958   * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
00959   */
00960 #define IS_SMARTCARD_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == SMARTCARD_ADVFEATURE_DATAINV_DISABLE) || \
00961                                                       ((__DATAINV__) == SMARTCARD_ADVFEATURE_DATAINV_ENABLE))
00962 
00963 /**
00964   * @brief Ensure that SMARTCARD frame RX/TX pins swap setting is valid.
00965   * @param __SWAP__: SMARTCARD frame RX/TX pins swap setting. 
00966   * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
00967   */
00968 #define IS_SMARTCARD_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == SMARTCARD_ADVFEATURE_SWAP_DISABLE) || \
00969                                                 ((__SWAP__) == SMARTCARD_ADVFEATURE_SWAP_ENABLE))
00970 
00971 /**
00972   * @brief Ensure that SMARTCARD frame overrun setting is valid.
00973   * @param __OVERRUN__: SMARTCARD frame overrun setting. 
00974   * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
00975   */
00976 #define IS_SMARTCARD_OVERRUN(__OVERRUN__) (((__OVERRUN__) == SMARTCARD_ADVFEATURE_OVERRUN_ENABLE) || \
00977                                            ((__OVERRUN__) == SMARTCARD_ADVFEATURE_OVERRUN_DISABLE))
00978 
00979 /**
00980   * @brief Ensure that SMARTCARD DMA enabling or disabling on error setting is valid.
00981   * @param __DMA__: SMARTCARD DMA enabling or disabling on error setting. 
00982   * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
00983   */
00984 #define IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(__DMA__) (((__DMA__) == SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR) || \
00985                                                        ((__DMA__) == SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR))
00986 
00987 /**
00988   * @brief Ensure that SMARTCARD frame MSB first setting is valid.
00989   * @param __MSBFIRST__: SMARTCARD frame MSB first setting. 
00990   * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
00991   */
00992 #define IS_SMARTCARD_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE) || \
00993                                                         ((__MSBFIRST__) == SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE))
00994 
00995 /**
00996   * @brief Ensure that SMARTCARD request parameter is valid.
00997   * @param __PARAM__: SMARTCARD request parameter. 
00998   * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
00999   */
01000 #define IS_SMARTCARD_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == SMARTCARD_RXDATA_FLUSH_REQUEST) || \
01001                                                    ((__PARAM__) == SMARTCARD_TXDATA_FLUSH_REQUEST))
01002 
01003 /**
01004   * @}
01005   */
01006 
01007 /* Include SMARTCARD HAL Extended module */
01008 #include "stm32l4xx_hal_smartcard_ex.h"
01009 
01010 
01011 /* Exported functions --------------------------------------------------------*/
01012 /** @addtogroup SMARTCARD_Exported_Functions
01013   * @{
01014   */
01015 
01016 /* Initialization and de-initialization functions  ****************************/
01017 /** @addtogroup SMARTCARD_Exported_Functions_Group1
01018   * @{
01019   */
01020 
01021 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsmartcard);
01022 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard);
01023 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard);
01024 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard);
01025 
01026 /**
01027   * @}
01028   */
01029 
01030 /* IO operation functions *****************************************************/
01031 /** @addtogroup SMARTCARD_Exported_Functions_Group2
01032   * @{
01033   */
01034 
01035 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
01036 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
01037 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
01038 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
01039 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
01040 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
01041 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard);
01042 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
01043 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
01044 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard);
01045 
01046 /**
01047   * @}
01048   */
01049 
01050 /* Peripheral Control functions ***********************************************/
01051 /* Peripheral State and Error functions ***************************************/
01052 /** @addtogroup SMARTCARD_Exported_Functions_Group4
01053   * @{
01054   */
01055 
01056 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsmartcard);
01057 uint32_t                   HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsmartcard);
01058 
01059 /**
01060   * @}
01061   */
01062 
01063 /**
01064   * @}
01065   */
01066 
01067 /**
01068   * @}
01069   */
01070 
01071 /**
01072   * @}
01073   */
01074 
01075 #ifdef __cplusplus
01076 }
01077 #endif
01078 
01079 #endif /* __STM32L4xx_HAL_SMARTCARD_H */
01080 
01081 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
01082