1 /**
2   ******************************************************************************
3   * @file    stm32l0xx_hal_smartcard.h
4   * @author  MCD Application Team
5   * @brief   Header file of SMARTCARD HAL module.
6   ******************************************************************************
7   * @attention
8   *
9   * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
10   *
11   * Redistribution and use in source and binary forms, with or without modification,
12   * are permitted provided that the following conditions are met:
13   *   1. Redistributions of source code must retain the above copyright notice,
14   *      this list of conditions and the following disclaimer.
15   *   2. Redistributions in binary form must reproduce the above copyright notice,
16   *      this list of conditions and the following disclaimer in the documentation
17   *      and/or other materials provided with the distribution.
18   *   3. Neither the name of STMicroelectronics nor the names of its contributors
19   *      may be used to endorse or promote products derived from this software
20   *      without specific prior written permission.
21   *
22   * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
23   * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
25   * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
26   * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27   * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
28   * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29   * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30   * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31   * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   *
33   ******************************************************************************
34   */
35 
36 /* Define to prevent recursive inclusion -------------------------------------*/
37 #ifndef __STM32L0xx_HAL_SMARTCARD_H
38 #define __STM32L0xx_HAL_SMARTCARD_H
39 
40 #ifdef __cplusplus
41  extern "C" {
42 #endif
43 
44 /* Includes ------------------------------------------------------------------*/
45 #include "stm32l0xx_hal_def.h"
46 
47 /** @addtogroup STM32L0xx_HAL_Driver
48   * @{
49   */
50 
51 /** @addtogroup SMARTCARD
52   * @{
53   */
54 
55 /* Exported types ------------------------------------------------------------*/
56 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
57   * @{
58   */
59 
60 /**
61   * @brief SMARTCARD Init Structure definition
62   */
63 typedef struct
64 {
65   uint32_t BaudRate;                  /*!< Configures the SmartCard communication baud rate.
66                                            The baud rate register is computed using the following formula:
67                                               Baud Rate Register = ((PCLKx) / ((hsmartcard->Init.BaudRate))) */
68 
69   uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
70                                            This parameter @ref SMARTCARD_Word_Length can only be set to 9 (8 data + 1 parity bits). */
71 
72   uint32_t StopBits;                  /*!< Specifies the number of stop bits.
73                                            This parameter can be a value of @ref SMARTCARD_Stop_Bits. */
74 
75   uint16_t Parity;                    /*!< Specifies the parity mode.
76                                            This parameter can be a value of @ref SMARTCARD_Parity
77                                            @note The parity is enabled by default (PCE is forced to 1).
78                                                  Since the WordLength is forced to 8 bits + parity, M is
79                                                  forced to 1 and the parity bit is the 9th bit. */
80 
81   uint16_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
82                                            This parameter can be a value of @ref SMARTCARD_Mode */
83 
84   uint16_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
85                                            This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
86 
87   uint16_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
88                                            This parameter can be a value of @ref SMARTCARD_Clock_Phase */
89 
90   uint16_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
91                                            data bit (MSB) has to be output on the SCLK pin in synchronous mode.
92                                            This parameter can be a value of @ref SMARTCARD_Last_Bit */
93 
94   uint16_t OneBitSampling;            /*!< Specifies whether a single sample or three samples' majority vote is selected.
95                                            Selecting the single sample method increases the receiver tolerance to clock
96                                            deviations. This parameter can be a value of @ref SMARTCARD_OneBit_Sampling. */
97 
98   uint8_t  Prescaler;                 /*!< Specifies the SmartCard Prescaler. */
99 
100   uint8_t  GuardTime;                 /*!< Specifies the SmartCard Guard Time applied after stop bits. */
101 
102   uint16_t NACKEnable;                /*!< Specifies whether the SmartCard NACK transmission is enabled
103                                            in case of parity error.
104                                            This parameter can be a value of @ref SMARTCARD_NACK_Enable */
105 
106   uint32_t TimeOutEnable;             /*!< Specifies whether the receiver timeout is enabled.
107                                             This parameter can be a value of @ref SMARTCARD_Timeout_Enable*/
108 
109   uint32_t TimeOutValue;              /*!< Specifies the receiver time out value in number of baud blocks:
110                                            it is used to implement the Character Wait Time (CWT) and
111                                            Block Wait Time (BWT). It is coded over 24 bits. */
112 
113   uint8_t BlockLength;                /*!< Specifies the SmartCard Block Length in T=1 Reception mode.
114                                            This parameter can be any value from 0x0 to 0xFF */
115 
116   uint8_t AutoRetryCount;             /*!< Specifies the SmartCard auto-retry count (number of retries in
117                                             receive and transmit mode). When set to 0, retransmission is
118                                             disabled. Otherwise, its maximum value is 7 (before signalling
119                                             an error) */
120 
121 }SMARTCARD_InitTypeDef;
122 
123 /**
124   * @brief  SMARTCARD advanced features initalization structure definition
125   */
126 typedef struct
127 {
128   uint32_t AdvFeatureInit;            /*!< Specifies which advanced SMARTCARD features is initialized. Several
129                                            advanced features may be initialized at the same time. This parameter
130                                            can be a value of @ref SMARTCARD_Advanced_Features_Initialization_Type */
131 
132   uint32_t TxPinLevelInvert;          /*!< Specifies whether the TX pin active level is inverted.
133                                            This parameter can be a value of @ref SMARTCARD_Tx_Inv  */
134 
135   uint32_t RxPinLevelInvert;          /*!< Specifies whether the RX pin active level is inverted.
136                                            This parameter can be a value of @ref SMARTCARD_Rx_Inv  */
137 
138   uint32_t DataInvert;                /*!< Specifies whether data are inverted (positive/direct logic
139                                            vs negative/inverted logic).
140                                            This parameter can be a value of @ref SMARTCARD_Data_Inv */
141 
142   uint32_t Swap;                      /*!< Specifies whether TX and RX pins are swapped.
143                                            This parameter can be a value of @ref SMARTCARD_Rx_Tx_Swap */
144 
145   uint32_t OverrunDisable;            /*!< Specifies whether the reception overrun detection is disabled.
146                                            This parameter can be a value of @ref SMARTCARD_Overrun_Disable */
147 
148   uint32_t DMADisableonRxError;       /*!< Specifies whether the DMA is disabled in case of reception error.
149                                            This parameter can be a value of @ref SMARTCARD_DMA_Disable_on_Rx_Error */
150 
151   uint32_t MSBFirst;                  /*!< Specifies whether MSB is sent first on UART line.
152                                            This parameter can be a value of @ref SMARTCARD_MSB_First */
153 }SMARTCARD_AdvFeatureInitTypeDef;
154 
155 /**
156   * @brief HAL SMARTCARD State structures definition
157   * @note  HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState.
158   *        - gState contains SMARTCARD state information related to global Handle management
159   *          and also information related to Tx operations.
160   *          gState value coding follow below described bitmap :
161   *          b7-b6  Error information
162   *             00 : No Error
163   *             01 : (Not Used)
164   *             10 : Timeout
165   *             11 : Error
166   *          b5     IP initilisation status
167   *             0  : Reset (IP not initialized)
168   *             1  : Init done (IP not initialized. HAL SMARTCARD Init function already called)
169   *          b4-b3  (not used)
170   *             xx : Should be set to 00
171   *          b2     Intrinsic process state
172   *             0  : Ready
173   *             1  : Busy (IP busy with some configuration or internal operations)
174   *          b1     (not used)
175   *             x  : Should be set to 0
176   *          b0     Tx state
177   *             0  : Ready (no Tx operation ongoing)
178   *             1  : Busy (Tx operation ongoing)
179   *        - RxState contains information related to Rx operations.
180   *          RxState value coding follow below described bitmap :
181   *          b7-b6  (not used)
182   *             xx : Should be set to 00
183   *          b5     IP initilisation status
184   *             0  : Reset (IP not initialized)
185   *             1  : Init done (IP not initialized)
186   *          b4-b2  (not used)
187   *            xxx : Should be set to 000
188   *          b1     Rx state
189   *             0  : Ready (no Rx operation ongoing)
190   *             1  : Busy (Rx operation ongoing)
191   *          b0     (not used)
192   *             x  : Should be set to 0.
193   */
194 typedef enum
195 {
196   HAL_SMARTCARD_STATE_RESET             = 0x00U,   /*!< Peripheral is not initialized
197                                                         Value is allowed for gState and RxState */
198   HAL_SMARTCARD_STATE_READY             = 0x20U,   /*!< Peripheral Initialized and ready for use
199                                                         Value is allowed for gState and RxState */
200   HAL_SMARTCARD_STATE_BUSY              = 0x24U,   /*!< an internal process is ongoing
201                                                         Value is allowed for gState only */
202   HAL_SMARTCARD_STATE_BUSY_TX           = 0x21U,   /*!< Data Transmission process is ongoing
203                                                         Value is allowed for gState only */
204   HAL_SMARTCARD_STATE_BUSY_RX           = 0x22U,   /*!< Data Reception process is ongoing
205                                                         Value is allowed for RxState only */
206   HAL_SMARTCARD_STATE_BUSY_TX_RX        = 0x23U,   /*!< Data Transmission and Reception process is ongoing
207                                                         Not to be used for neither gState nor RxState.
208                                                         Value is result of combination (Or) between gState and RxState values */
209   HAL_SMARTCARD_STATE_TIMEOUT           = 0xA0U,   /*!< Timeout state
210                                                         Value is allowed for gState only */
211   HAL_SMARTCARD_STATE_ERROR             = 0xE0U    /*!< Error
212                                                         Value is allowed for gState only */
213 }HAL_SMARTCARD_StateTypeDef;
214 
215 /**
216   * @brief  HAL SMARTCARD Error Code structure definition
217   */
218 typedef enum
219 {
220   HAL_SMARTCARD_ERROR_NONE      = 0x00,    /*!< No error                */
221   HAL_SMARTCARD_ERROR_PE        = 0x01,    /*!< Parity error            */
222   HAL_SMARTCARD_ERROR_NE        = 0x02,    /*!< Noise error             */
223   HAL_SMARTCARD_ERROR_FE        = 0x04,    /*!< frame error             */
224   HAL_SMARTCARD_ERROR_ORE       = 0x08,    /*!< Overrun error           */
225   HAL_SMARTCARD_ERROR_DMA       = 0x10,    /*!< DMA transfer error      */
226   HAL_SMARTCARD_ERROR_RTO       = 0x20     /*!< Receiver TimeOut error  */
227 }HAL_SMARTCARD_ErrorTypeDef;
228 
229 /**
230   * @brief  SMARTCARD handle Structure definition
231   */
232 typedef struct
233 {
234   USART_TypeDef                   *Instance;        /*!< USART registers base address                          */
235 
236   SMARTCARD_InitTypeDef           Init;             /*!< SmartCard communication parameters                    */
237 
238   SMARTCARD_AdvFeatureInitTypeDef AdvancedInit;     /*!< SmartCard advanced features initialization parameters */
239 
240   uint8_t                         *pTxBuffPtr;      /*!< Pointer to SmartCard Tx transfer Buffer               */
241 
242   uint16_t                        TxXferSize;       /*!< SmartCard Tx Transfer size                            */
243 
244   __IO uint16_t                   TxXferCount;      /*!< SmartCard Tx Transfer Counter                         */
245 
246   uint8_t                         *pRxBuffPtr;      /*!< Pointer to SmartCard Rx transfer Buffer               */
247 
248   uint16_t                        RxXferSize;       /*!< SmartCard Rx Transfer size                            */
249 
250   __IO uint16_t                   RxXferCount;      /*!< SmartCard Rx Transfer Counter                         */
251 
252   DMA_HandleTypeDef               *hdmatx;          /*!< SmartCard Tx DMA Handle parameters                    */
253 
254   DMA_HandleTypeDef               *hdmarx;          /*!< SmartCard Rx DMA Handle parameters                    */
255 
256   HAL_LockTypeDef                 Lock;             /*!< Locking object                                        */
257 
258   __IO HAL_SMARTCARD_StateTypeDef    gState;        /*!< SmartCard state information related to global Handle management
259                                                          and also related to Tx operations.
260                                                          This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
261 
262   __IO HAL_SMARTCARD_StateTypeDef    RxState;       /*!< SmartCard state information related to Rx operations.
263                                                          This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
264 
265   __IO uint32_t                   ErrorCode;        /*!< SmartCard Error code                                  */
266 
267 }SMARTCARD_HandleTypeDef;
268 
269 /**
270   * @brief  SMARTCARD clock sources
271   */
272 typedef enum
273 {
274   SMARTCARD_CLOCKSOURCE_PCLK1     = 0x00U, /*!< PCLK1 clock source     */
275   SMARTCARD_CLOCKSOURCE_PCLK2     = 0x01U, /*!< PCLK2 clock source     */
276   SMARTCARD_CLOCKSOURCE_HSI       = 0x02U, /*!< HSI clock source       */
277   SMARTCARD_CLOCKSOURCE_SYSCLK    = 0x04U, /*!< SYSCLK clock source    */
278   SMARTCARD_CLOCKSOURCE_LSE       = 0x08U, /*!< LSE clock source       */
279   SMARTCARD_CLOCKSOURCE_UNDEFINED = 0x10U  /*!< undefined clock source */
280 }SMARTCARD_ClockSourceTypeDef;
281 
282 /**
283   * @}
284   */
285 
286 /* Exported constants --------------------------------------------------------*/
287 /** @defgroup SMARTCARD_Exported_Constants  SMARTCARD Exported Constants
288   * @{
289   */
290 
291 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
292   * @{
293   */
294 #define SMARTCARD_WORDLENGTH_9B             ((uint32_t)USART_CR1_M0)              /*!< SMARTCARD frame length */
295 /**
296   * @}
297   */
298 
299 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
300   * @{
301   */
302 #define SMARTCARD_STOPBITS_0_5              ((uint32_t)USART_CR2_STOP_0)                      /*!< SMARTCARD frame with 0.5 stop bit  */
303 #define SMARTCARD_STOPBITS_1_5              ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1)) /*!< SMARTCARD frame with 1.5 stop bits */
304 /**
305   * @}
306   */
307 
308 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
309   * @{
310   */
311 #define SMARTCARD_PARITY_EVEN               ((uint32_t)USART_CR1_PCE)                  /*!< SMARTCARD frame even parity */
312 #define SMARTCARD_PARITY_ODD                ((uint32_t)(USART_CR1_PCE | USART_CR1_PS)) /*!< SMARTCARD frame odd parity  */
313 /**
314   * @}
315   */
316 
317 /** @defgroup SMARTCARD_Mode SMARTCARD Transfer Mode
318   * @{
319   */
320 #define SMARTCARD_MODE_RX                   ((uint32_t)USART_CR1_RE)                  /*!< SMARTCARD RX mode        */
321 #define SMARTCARD_MODE_TX                   ((uint32_t)USART_CR1_TE)                  /*!< SMARTCARD TX mode        */
322 #define SMARTCARD_MODE_TX_RX                ((uint32_t)(USART_CR1_TE |USART_CR1_RE))  /*!< SMARTCARD RX and TX mode */
323 /**
324   * @}
325   */
326 
327 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
328   * @{
329   */
330 #define SMARTCARD_POLARITY_LOW              ((uint32_t)0x00000000)                   /*!< SMARTCARD frame low polarity  */
331 #define SMARTCARD_POLARITY_HIGH             ((uint32_t)USART_CR2_CPOL)               /*!< SMARTCARD frame high polarity */
332 /**
333   * @}
334   */
335 
336 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
337   * @{
338   */
339 #define SMARTCARD_PHASE_1EDGE               ((uint32_t)0x00000000)                  /*!< SMARTCARD frame phase on first clock transition  */
340 #define SMARTCARD_PHASE_2EDGE               ((uint32_t)USART_CR2_CPHA)              /*!< SMARTCARD frame phase on second clock transition */
341 /**
342   * @}
343   */
344 
345 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
346   * @{
347   */
348 #define SMARTCARD_LASTBIT_DISABLE           ((uint32_t)0x00000000)                 /*!< SMARTCARD frame last data bit clock pulse not output to SCLK pin */
349 #define SMARTCARD_LASTBIT_ENABLE            ((uint32_t)USART_CR2_LBCL)             /*!< SMARTCARD frame last data bit clock pulse output to SCLK pin     */
350 /**
351   * @}
352   */
353 
354 /** @defgroup SMARTCARD_OneBit_Sampling SMARTCARD One Bit Sampling Method
355   * @{
356   */
357 #define SMARTCARD_ONE_BIT_SAMPLE_DISABLE    ((uint32_t)0x00000000)                 /*!< SMARTCARD frame one-bit sample disabled */
358 #define SMARTCARD_ONE_BIT_SAMPLE_ENABLE     ((uint32_t)USART_CR3_ONEBIT)           /*!< SMARTCARD frame one-bit sample enabled  */
359 /**
360   * @}
361   */
362 
363 
364 /** @defgroup SMARTCARD_NACK_Enable SMARTCARD NACK Enable
365   * @{
366   */
367 #define SMARTCARD_NACK_ENABLE               ((uint32_t)USART_CR3_NACK)            /*!< SMARTCARD NACK transmission disabled */
368 #define SMARTCARD_NACK_DISABLE              ((uint32_t)0x00000000)                /*!< SMARTCARD NACK transmission enabled  */
369 /**
370   * @}
371   */
372 
373 /** @defgroup SMARTCARD_Timeout_Enable SMARTCARD Timeout Enable
374   * @{
375   */
376 #define SMARTCARD_TIMEOUT_DISABLE           ((uint32_t)0x00000000)                /*!< SMARTCARD receiver timeout disabled */
377 #define SMARTCARD_TIMEOUT_ENABLE            ((uint32_t)USART_CR2_RTOEN)           /*!< SMARTCARD receiver timeout enabled  */
378 /**
379   * @}
380   */
381 
382 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA Requests
383   * @{
384   */
385 
386 #define SMARTCARD_DMAREQ_TX                    ((uint32_t)USART_CR3_DMAT)
387 #define SMARTCARD_DMAREQ_RX                    ((uint32_t)USART_CR3_DMAR)
388 /**
389   * @}
390   */
391 
392 /** @defgroup SMARTCARD_Advanced_Features_Initialization_Type SMARTCARD Advanced Features Initialization
393   * @{
394   */
395 #define SMARTCARD_ADVFEATURE_NO_INIT                 ((uint32_t)0x00000000U)
396 #define SMARTCARD_ADVFEATURE_TXINVERT_INIT           ((uint32_t)0x00000001U)
397 #define SMARTCARD_ADVFEATURE_RXINVERT_INIT           ((uint32_t)0x00000002U)
398 #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT         ((uint32_t)0x00000004U)
399 #define SMARTCARD_ADVFEATURE_SWAP_INIT               ((uint32_t)0x00000008U)
400 #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT   ((uint32_t)0x00000010U)
401 #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT  ((uint32_t)0x00000020U)
402 #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT           ((uint32_t)0x00000080U)
403 /**
404   * @}
405   */
406 
407 /** @defgroup SMARTCARD_Tx_Inv SMARTCARD advanced feature TX pin active level inversion
408   * @{
409   */
410 #define SMARTCARD_ADVFEATURE_TXINV_DISABLE  ((uint32_t)0x00000000U)               /*!< TX pin active level inversion disable */
411 #define SMARTCARD_ADVFEATURE_TXINV_ENABLE   ((uint32_t)USART_CR2_TXINV)           /*!< TX pin active level inversion enable  */
412 /**
413   * @}
414   */
415 
416 /** @defgroup SMARTCARD_Rx_Inv SMARTCARD advanced feature RX pin active level inversion
417   * @{
418   */
419 #define SMARTCARD_ADVFEATURE_RXINV_DISABLE  ((uint32_t)0x00000000U)               /*!< RX pin active level inversion disable */
420 #define SMARTCARD_ADVFEATURE_RXINV_ENABLE   ((uint32_t)USART_CR2_RXINV)           /*!< RX pin active level inversion enable  */
421 /**
422   * @}
423   */
424 
425 /** @defgroup SMARTCARD_Data_Inv SMARTCARD advanced feature Binary Data inversion
426   * @{
427   */
428 #define SMARTCARD_ADVFEATURE_DATAINV_DISABLE  ((uint32_t)0x00000000U)             /*!< Binary data inversion disable */
429 #define SMARTCARD_ADVFEATURE_DATAINV_ENABLE   ((uint32_t)USART_CR2_DATAINV)       /*!< Binary data inversion enable  */
430 /**
431   * @}
432   */
433 
434 /** @defgroup SMARTCARD_Rx_Tx_Swap SMARTCARD advanced feature RX TX pins swap
435   * @{
436   */
437 #define SMARTCARD_ADVFEATURE_SWAP_DISABLE   ((uint32_t)0x00000000U)               /*!< TX/RX pins swap disable */
438 #define SMARTCARD_ADVFEATURE_SWAP_ENABLE    ((uint32_t)USART_CR2_SWAP)            /*!< TX/RX pins swap enable  */
439 /**
440   * @}
441   */
442 
443 /** @defgroup SMARTCARD_Overrun_Disable SMARTCARD advanced feature Overrun Disable
444   * @{
445   */
446 #define SMARTCARD_ADVFEATURE_OVERRUN_ENABLE   ((uint32_t)0x00000000U)             /*!< RX overrun enable  */
447 #define SMARTCARD_ADVFEATURE_OVERRUN_DISABLE  ((uint32_t)USART_CR3_OVRDIS)        /*!< RX overrun disable */
448 /**
449   * @}
450   */
451 
452 /** @defgroup SMARTCARD_DMA_Disable_on_Rx_Error SMARTCARD advanced feature DMA Disable on Rx Error
453   * @{
454   */
455 #define SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR   ((uint32_t)0x00000000U)        /*!< DMA enable on Reception Error  */
456 #define SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR  ((uint32_t)USART_CR3_DDRE)     /*!< DMA disable on Reception Error */
457 /**
458   * @}
459   */
460 
461 /** @defgroup SMARTCARD_MSB_First   SMARTCARD advanced feature MSB first
462   * @{
463   */
464 #define SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE      ((uint32_t)0x00000000U)          /*!< Most significant bit sent/received first disable */
465 #define SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE       ((uint32_t)USART_CR2_MSBFIRST)   /*!< Most significant bit sent/received first enable  */
466 /**
467   * @}
468   */
469 
470 /** @defgroup SMARTCARD_Request_Parameters SMARTCARD Request Parameters
471   * @{
472   */
473 #define SMARTCARD_RXDATA_FLUSH_REQUEST      ((uint16_t)USART_RQR_RXFRQ)        /*!< Receive data flush request */
474 #define SMARTCARD_TXDATA_FLUSH_REQUEST      ((uint16_t)USART_RQR_TXFRQ)        /*!< Transmit data flush request */
475 /**
476   * @}
477   */
478 
479 
480 /** @defgroup SMARTCARD_Flags SMARTCARD Flags
481   *        Elements values convention: 0xXXXX
482   *           - 0xXXXX  : Flag mask in the ISR register
483   * @{
484   */
485 #define SMARTCARD_FLAG_REACK          USART_ISR_REACK      /*!< SMARTCARD receive enable acknowledge flag  */
486 #define SMARTCARD_FLAG_TEACK          USART_ISR_TEACK      /*!< SMARTCARD transmit enable acknowledge flag */
487 #define SMARTCARD_FLAG_BUSY           USART_ISR_BUSY       /*!< SMARTCARD busy flag                        */
488 #define SMARTCARD_FLAG_EOBF           USART_ISR_EOBF       /*!< SMARTCARD end of block flag                */
489 #define SMARTCARD_FLAG_RTOF           USART_ISR_RTOF       /*!< SMARTCARD receiver timeout flag            */
490 #define SMARTCARD_FLAG_TXE            USART_ISR_TXE        /*!< SMARTCARD transmit data register empty     */
491 #define SMARTCARD_FLAG_TC             USART_ISR_TC         /*!< SMARTCARD transmission complete            */
492 #define SMARTCARD_FLAG_RXNE           USART_ISR_RXNE       /*!< SMARTCARD read data register not empty     */
493 #define SMARTCARD_FLAG_IDLE           USART_ISR_IDLE       /*!< SMARTCARD idle line detection              */
494 #define SMARTCARD_FLAG_ORE            USART_ISR_ORE        /*!< SMARTCARD overrun error                    */
495 #define SMARTCARD_FLAG_NE             USART_ISR_NE         /*!< SMARTCARD noise error                      */
496 #define SMARTCARD_FLAG_FE             USART_ISR_FE         /*!< SMARTCARD frame error                      */
497 #define SMARTCARD_FLAG_PE             USART_ISR_PE         /*!< SMARTCARD parity error                     */
498 
499 /**
500   * @}
501   */
502 
503 /** @defgroup SMARTCARD_Interrupt_definition SMARTCARD Interrupt definition
504   *        Elements values convention: 0000ZZZZ0XXYYYYYb
505   *           - YYYYY  : Interrupt source position in the XX register (5bits)
506   *           - XX  : Interrupt source register (2bits)
507   *                 - 01: CR1 register
508   *                 - 10: CR2 register
509   *                 - 11: CR3 register
510   *           - ZZZZ  : Flag position in the ISR register(4bits)
511   * @{
512   */
513 
514 #define SMARTCARD_IT_PE                          ((uint16_t)0x0028U)    /*!< SMARTCARD parity error interruption                 */
515 #define SMARTCARD_IT_TXE                         ((uint16_t)0x0727U)    /*!< SMARTCARD transmit data register empty interruption */
516 #define SMARTCARD_IT_TC                          ((uint16_t)0x0626U)    /*!< SMARTCARD transmission complete interruption        */
517 #define SMARTCARD_IT_RXNE                        ((uint16_t)0x0525U)    /*!< SMARTCARD read data register not empty interruption */
518 #define SMARTCARD_IT_IDLE                        ((uint16_t)0x0424U)    /*!< SMARTCARD idle line detection interruption          */
519 
520 #define SMARTCARD_IT_ERR                         ((uint16_t)0x0060U)    /*!< SMARTCARD error interruption         */
521 #define SMARTCARD_IT_ORE                         ((uint16_t)0x0300U)    /*!< SMARTCARD overrun error interruption */
522 #define SMARTCARD_IT_NE                          ((uint16_t)0x0200U)    /*!< SMARTCARD noise error interruption   */
523 #define SMARTCARD_IT_FE                          ((uint16_t)0x0100U)    /*!< SMARTCARD frame error interruption   */
524 
525 #define SMARTCARD_IT_EOB                         ((uint16_t)0x0C3BU)    /*!< SMARTCARD end of block interruption     */
526 #define SMARTCARD_IT_RTO                         ((uint16_t)0x0B3AU)    /*!< SMARTCARD receiver timeout interruption */
527 /**
528   * @}
529   */
530 
531 
532 /** @defgroup SMARTCARD_IT_CLEAR_Flags SMARTCARD IT CLEAR Flags
533   * @{
534   */
535 #define SMARTCARD_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag */
536 #define SMARTCARD_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag */
537 #define SMARTCARD_CLEAR_NEF                       USART_ICR_NCF             /*!< Noise detected Clear Flag */
538 #define SMARTCARD_CLEAR_OREF                      USART_ICR_ORECF           /*!< OverRun Error Clear Flag */
539 #define SMARTCARD_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< IDLE line detected Clear Flag */
540 #define SMARTCARD_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag */
541 #define SMARTCARD_CLEAR_RTOF                      USART_ICR_RTOCF           /*!< Receiver Time Out Clear Flag */
542 #define SMARTCARD_CLEAR_EOBF                      USART_ICR_EOBCF           /*!< End Of Block Clear Flag */
543 /**
544   * @}
545   */
546 
547 /** @defgroup SMARTCARD_CR3_SCARCNT_LSB_POS SMARTCARD auto retry counter LSB position in CR3 register
548   * @{
549   */
550 #define SMARTCARD_CR3_SCARCNT_LSB_POS       ((uint32_t) 17U)   /*!< SMARTCARD auto retry counter LSB position in CR3 register */
551 /**
552   * @}
553   */
554 
555 /** @defgroup SMARTCARD_GTPR_GT_LSB_POS SMARTCARD guard time value LSB position in GTPR register
556   * @{
557   */
558 #define SMARTCARD_GTPR_GT_LSB_POS           ((uint32_t) 8U)   /*!<  SMARTCARD guard time value LSB position in GTPR register */
559 /**
560   * @}
561   */
562 
563 /** @defgroup SMARTCARD_RTOR_BLEN_LSB_POS SMARTCARD block length LSB position in RTOR register
564   * @{
565   */
566 #define SMARTCARD_RTOR_BLEN_LSB_POS         ((uint32_t) 24U)  /*!< SMARTCARD block length LSB position in RTOR register */
567 /**
568   * @}
569   */
570 
571 /** @defgroup SMARTCARD_Interruption_Mask SMARTCARD interruptions flags mask
572   * @{
573   */
574 #define SMARTCARD_IT_MASK               ((uint16_t)0x001FU)   /*!< SMARTCARD interruptions flags mask */
575 /**
576   * @}
577   */
578 
579 /**
580   * @}
581   */
582 
583 /* Exported macros -----------------------------------------------------------*/
584 /** @defgroup SMARTCARD_Exported_Macros  SMARTCARD Exported Macros
585   * @{
586   */
587 
588 /** @brief  Reset SMARTCARD handle states.
589   * @param  __HANDLE__: SMARTCARD handle.
590   * @retval None
591   */
592 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__)  do{                                                       \
593                                                            (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET;      \
594                                                            (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET;     \
595                                                           } while(0)
596 
597 /** @brief  Flush the Smartcard Data registers.
598   * @param  __HANDLE__: specifies the SMARTCARD Handle.
599   * @retval None
600   */
601 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__)                                 \
602     do{                                                                              \
603       SET_BIT((__HANDLE__)->Instance->RQR, SMARTCARD_RXDATA_FLUSH_REQUEST); \
604       SET_BIT((__HANDLE__)->Instance->RQR, SMARTCARD_TXDATA_FLUSH_REQUEST); \
605       } while(0)
606 
607 /** @brief  Clear the specified SMARTCARD pending flag.
608   * @param  __HANDLE__: specifies the SMARTCARD Handle.
609   * @param  __FLAG__: specifies the flag to check.
610   *          This parameter can be any combination of the following values:
611   *            @arg @ref SMARTCARD_CLEAR_PEF    Parity error clear flag
612   *            @arg @ref SMARTCARD_CLEAR_FEF    Framing error clear flag
613   *            @arg @ref SMARTCARD_CLEAR_NEF    Noise detected clear flag
614   *            @arg @ref SMARTCARD_CLEAR_OREF   OverRun error clear flag
615   *            @arg @ref SMARTCARD_CLEAR_IDLEF  Idle line detected clear flag
616   *            @arg @ref SMARTCARD_CLEAR_TCF    Transmission complete clear flag
617   *            @arg @ref SMARTCARD_CLEAR_RTOF   Receiver timeout clear flag
618   *            @arg @ref SMARTCARD_CLEAR_EOBF   End of block clear flag
619   * @retval None
620   */
621 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->ICR = (__FLAG__))
622 
623 /** @brief  Clear the SMARTCARD PE pending flag.
624   * @param  __HANDLE__: specifies the SMARTCARD Handle.
625   * @retval None
626   */
627 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_PEF)
628 
629 
630 /** @brief  Clear the SMARTCARD FE pending flag.
631   * @param  __HANDLE__: specifies the SMARTCARD Handle.
632   * @retval None
633   */
634 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_FEF)
635 
636 /** @brief  Clear the SMARTCARD NE pending flag.
637   * @param  __HANDLE__: specifies the SMARTCARD Handle.
638   * @retval None
639   */
640 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_NEF)
641 
642 /** @brief  Clear the SMARTCARD ORE pending flag.
643   * @param  __HANDLE__: specifies the SMARTCARD Handle.
644   * @retval None
645   */
646 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_OREF)
647 
648 /** @brief  Clear the SMARTCARD IDLE pending flag.
649   * @param  __HANDLE__: specifies the SMARTCARD Handle.
650   * @retval None
651   */
652 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__)   __HAL_SMARTCARD_CLEAR_FLAG((__HANDLE__), SMARTCARD_CLEAR_IDLEF)
653 
654 /** @brief  Check whether the specified Smartcard flag is set or not.
655   * @param  __HANDLE__: specifies the SMARTCARD Handle.
656   * @param  __FLAG__: specifies the flag to check.
657   *        This parameter can be one of the following values:
658   *            @arg @ref SMARTCARD_FLAG_REACK Receive enable acknowledge flag
659   *            @arg @ref SMARTCARD_FLAG_TEACK Transmit enable acknowledge flag
660   *            @arg @ref SMARTCARD_FLAG_BUSY  Busy flag
661   *            @arg @ref SMARTCARD_FLAG_EOBF  End of block flag
662   *            @arg @ref SMARTCARD_FLAG_RTOF  Receiver timeout flag
663   *            @arg @ref SMARTCARD_FLAG_TXE   Transmit data register empty flag
664   *            @arg @ref SMARTCARD_FLAG_TC    Transmission complete flag
665   *            @arg @ref SMARTCARD_FLAG_RXNE  Receive data register not empty flag
666   *            @arg @ref SMARTCARD_FLAG_IDLE  Idle line detection flag
667   *            @arg @ref SMARTCARD_FLAG_ORE   Overrun error flag
668   *            @arg @ref SMARTCARD_FLAG_NE    Noise error flag
669   *            @arg @ref SMARTCARD_FLAG_FE    Framing error flag
670   *            @arg @ref SMARTCARD_FLAG_PE    Parity error flag
671   * @retval The new state of __FLAG__ (TRUE or FALSE).
672   */
673 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
674 
675 
676 /** @brief  Enable the specified SmartCard interrupt.
677   * @param  __HANDLE__: specifies the SMARTCARD Handle.
678   * @param  __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
679   *          This parameter can be one of the following values:
680   *            @arg @ref SMARTCARD_IT_EOB   End of block interrupt
681   *            @arg @ref SMARTCARD_IT_RTO   Receive timeout interrupt
682   *            @arg @ref SMARTCARD_IT_TXE   Transmit data register empty interrupt
683   *            @arg @ref SMARTCARD_IT_TC    Transmission complete interrupt
684   *            @arg @ref SMARTCARD_IT_RXNE  Receive data register not empty interrupt
685   *            @arg @ref SMARTCARD_IT_IDLE  Idle line detection interrupt
686   *            @arg @ref SMARTCARD_IT_PE    Parity error interrupt
687   *            @arg @ref SMARTCARD_IT_ERR   Error interrupt(frame error, noise error, overrun error)
688   * @retval None
689   */
690 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
691                                                                 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
692                                                                 ((__HANDLE__)->Instance->CR3 |= (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
693 
694 /** @brief  Disable the specified SmartCard interrupt.
695   * @param  __HANDLE__: specifies the SMARTCARD Handle.
696   * @param  __INTERRUPT__: specifies the SMARTCARD interrupt to disable.
697   *          This parameter can be one of the following values:
698   *            @arg @ref SMARTCARD_IT_EOB   End of block interrupt
699   *            @arg @ref SMARTCARD_IT_RTO   Receive timeout interrupt
700   *            @arg @ref SMARTCARD_IT_TXE   Transmit data register empty interrupt
701   *            @arg @ref SMARTCARD_IT_TC    Transmission complete interrupt
702   *            @arg @ref SMARTCARD_IT_RXNE  Receive data register not empty interrupt
703   *            @arg @ref SMARTCARD_IT_IDLE  Idle line detection interrupt
704   *            @arg @ref SMARTCARD_IT_PE    Parity error interrupt
705   *            @arg @ref SMARTCARD_IT_ERR   Error interrupt(frame error, noise error, overrun error)
706   * @retval None
707   */
708 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
709                                                                 ((((uint8_t)(__INTERRUPT__)) >> 5U) == 2U)? ((__HANDLE__)->Instance->CR2 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
710                                                                 ((__HANDLE__)->Instance->CR3 &= ~ (1U << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
711 
712 
713 /** @brief  Check whether the specified SmartCard interrupt has occurred or not.
714   * @param  __HANDLE__: specifies the SMARTCARD Handle.
715   * @param  __IT__: specifies the SMARTCARD interrupt to check.
716   *          This parameter can be one of the following values:
717   *            @arg @ref SMARTCARD_IT_EOB   End of block interrupt
718   *            @arg @ref SMARTCARD_IT_RTO   Receive timeout interrupt
719   *            @arg @ref SMARTCARD_IT_TXE   Transmit data register empty interrupt
720   *            @arg @ref SMARTCARD_IT_TC    Transmission complete interrupt
721   *            @arg @ref SMARTCARD_IT_RXNE  Receive data register not empty interrupt
722   *            @arg @ref SMARTCARD_IT_IDLE  Idle line detection interrupt
723   *            @arg @ref SMARTCARD_IT_ORE   Overrun error interrupt
724   *            @arg @ref SMARTCARD_IT_NE    Noise error interrupt
725   *            @arg @ref SMARTCARD_IT_FE    Framing error interrupt
726   *            @arg @ref SMARTCARD_IT_PE    Parity error interrupt
727   * @retval The new state of __IT__ (TRUE or FALSE).
728   */
729 #define __HAL_SMARTCARD_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1U << ((__IT__)>> 0x08U)))
730 
731 /** @brief  Check whether the specified SmartCard interrupt source is enabled or not.
732   * @param  __HANDLE__: specifies the SMARTCARD Handle.
733   * @param  __IT__: specifies the SMARTCARD interrupt source to check.
734   *          This parameter can be one of the following values:
735   *            @arg @ref SMARTCARD_IT_EOB   End of block interrupt
736   *            @arg @ref SMARTCARD_IT_RTO   Receive timeout interrupt
737   *            @arg @ref SMARTCARD_IT_TXE   Transmit data register empty interrupt
738   *            @arg @ref SMARTCARD_IT_TC    Transmission complete interrupt
739   *            @arg @ref SMARTCARD_IT_RXNE  Receive data register not empty interrupt
740   *            @arg @ref SMARTCARD_IT_IDLE  Idle line detection interrupt
741   *            @arg @ref SMARTCARD_IT_ERR   Framing, overrun or noise error interrupt
742   *            @arg @ref SMARTCARD_IT_PE    Parity error interrupt
743   * @retval The new state of __IT__ (TRUE or FALSE).
744   */
745 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5U) == 1U)? (__HANDLE__)->Instance->CR1 : \
746                                                            (((((uint8_t)(__IT__)) >> 5U) == 2U)? (__HANDLE__)->Instance->CR2 : \
747                                                            (__HANDLE__)->Instance->CR3)) & ((uint32_t)1U << (((uint16_t)(__IT__)) & SMARTCARD_IT_MASK)))
748 
749 
750 /** @brief  Clear the specified SMARTCARD ISR flag, in setting the proper ICR register flag.
751   * @param  __HANDLE__: specifies the SMARTCARD Handle.
752   * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
753   *                       to clear the corresponding interrupt.
754   *          This parameter can be one of the following values:
755   *            @arg @ref SMARTCARD_CLEAR_PEF    Parity error clear flag
756   *            @arg @ref SMARTCARD_CLEAR_FEF    Framing error clear flag
757   *            @arg @ref SMARTCARD_CLEAR_NEF    Noise detected clear flag
758   *            @arg @ref SMARTCARD_CLEAR_OREF   OverRun error clear flag
759   *            @arg @ref SMARTCARD_CLEAR_IDLEF  Idle line detection clear flag
760   *            @arg @ref SMARTCARD_CLEAR_TCF    Transmission complete clear flag
761   *            @arg @ref SMARTCARD_CLEAR_RTOF   Receiver timeout clear flag
762   *            @arg @ref SMARTCARD_CLEAR_EOBF   End of block clear flag
763   * @retval None
764   */
765 #define __HAL_SMARTCARD_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
766 
767 /** @brief  Set a specific SMARTCARD request flag.
768   * @param  __HANDLE__: specifies the SMARTCARD Handle.
769   * @param  __REQ__: specifies the request flag to set
770   *          This parameter can be one of the following values:
771   *            @arg @ref SMARTCARD_RXDATA_FLUSH_REQUEST Receive data flush Request
772   *            @arg @ref SMARTCARD_TXDATA_FLUSH_REQUEST Transmit data flush Request
773   *
774   * @retval None
775   */
776 #define __HAL_SMARTCARD_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint16_t)(__REQ__))
777 
778 /** @brief  Enable the SMARTCARD one bit sample method.
779   * @param  __HANDLE__: specifies the SMARTCARD Handle.
780   * @retval None
781   */
782 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
783 
784 /** @brief  Disable the SMARTCARD one bit sample method.
785   * @param  __HANDLE__: specifies the SMARTCARD Handle.
786   * @retval None
787   */
788 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint32_t)~((uint32_t)USART_CR3_ONEBIT))
789 
790 /** @brief  Enable the USART associated to the SMARTCARD Handle.
791   * @param  __HANDLE__: specifies the SMARTCARD Handle.
792   * @retval None
793   */
794 #define __HAL_SMARTCARD_ENABLE(__HANDLE__)               ((__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
795 
796 /** @brief  Disable the USART associated to the SMARTCARD Handle
797   * @param  __HANDLE__: specifies the SMARTCARD Handle.
798   * @retval None
799   */
800 #define __HAL_SMARTCARD_DISABLE(__HANDLE__)              ((__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
801 
802 /** @brief  Macros to enable or disable the SmartCard DMA request.
803   * @param  __HANDLE__: specifies the SMARTCARD Handle.
804   *         The Handle Instance which can be USART1 or USART2.
805   * @param  __REQUEST__: specifies the SmartCard DMA request.
806   *          This parameter can be one of the following values:
807   *            @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
808   *            @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
809   */
810 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__)    ((__HANDLE__)->Instance->CR3 |=  (__REQUEST__))
811 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__)   ((__HANDLE__)->Instance->CR3 &=  ~(__REQUEST__))
812 
813 /**
814   * @}
815   */
816 
817 /* Private macros -------------------------------------------------------------*/
818 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
819   * @{
820   */
821 
822 /** @brief  Check the Baud rate range.
823   * @note   The maximum Baud Rate is derived from the maximum clock on L0 (i.e. 32 MHz)
824   *         divided by the oversampling used on the SMARTCARD (i.e. 16).
825   * @param  __BAUDRATE__: Baud rate set by the configuration function.
826   * @retval Test result (TRUE or FALSE)
827   */
828 #define IS_SMARTCARD_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 2000001U)
829 
830 /** @brief  Check the block length range.
831   * @note   The maximum SMARTCARD block length is 0xFF.
832   * @param  __LENGTH__: block length.
833   * @retval Test result (TRUE or FALSE)
834   */
835 #define IS_SMARTCARD_BLOCKLENGTH(__LENGTH__) ((__LENGTH__) <= 0xFFU)
836 
837 /** @brief  Check the receiver timeout value.
838   * @note   The maximum SMARTCARD receiver timeout value is 0xFFFFFF.
839   * @param  __TIMEOUTVALUE__: receiver timeout value.
840   * @retval Test result (TRUE or FALSE)
841   */
842 #define IS_SMARTCARD_TIMEOUT_VALUE(__TIMEOUTVALUE__)    ((__TIMEOUTVALUE__) <= 0xFFFFFFU)
843 
844 /** @brief  Check the SMARTCARD autoretry counter value.
845   * @note   The maximum number of retransmissions is 0x7.
846   * @param  __COUNT__: number of retransmissions.
847   * @retval Test result (TRUE or FALSE)
848   */
849 #define IS_SMARTCARD_AUTORETRY_COUNT(__COUNT__)         ((__COUNT__) <= 0x7U)
850 
851 /**
852   * @brief Ensure that SMARTCARD frame length is valid.
853   * @param __LENGTH__: SMARTCARD frame length.
854   * @retval SET (__LENGTH__ is valid) or RESET (__LENGTH__ is invalid)
855   */
856 #define IS_SMARTCARD_WORD_LENGTH(__LENGTH__) ((__LENGTH__) == SMARTCARD_WORDLENGTH_9B)
857 
858 /**
859   * @brief Ensure that SMARTCARD frame number of stop bits is valid.
860   * @param __STOPBITS__: SMARTCARD frame number of stop bits.
861   * @retval SET (__STOPBITS__ is valid) or RESET (__STOPBITS__ is invalid)
862   */
863 #define IS_SMARTCARD_STOPBITS(__STOPBITS__) (((__STOPBITS__) == SMARTCARD_STOPBITS_0_5) ||\
864                                              ((__STOPBITS__) == SMARTCARD_STOPBITS_1_5))
865 
866 /**
867   * @brief Ensure that SMARTCARD frame parity is valid.
868   * @param __PARITY__: SMARTCARD frame parity.
869   * @retval SET (__PARITY__ is valid) or RESET (__PARITY__ is invalid)
870   */
871 #define IS_SMARTCARD_PARITY(__PARITY__) (((__PARITY__) == SMARTCARD_PARITY_EVEN) || \
872                                          ((__PARITY__) == SMARTCARD_PARITY_ODD))
873 
874 /**
875   * @brief Ensure that SMARTCARD communication mode is valid.
876   * @param __MODE__: SMARTCARD communication mode.
877   * @retval SET (__MODE__ is valid) or RESET (__MODE__ is invalid)
878   */
879 #define IS_SMARTCARD_MODE(__MODE__) ((((__MODE__) & (uint16_t)0xFFF3) == 0x00) && ((__MODE__) != (uint16_t)0x00))
880 
881 /**
882   * @brief Ensure that SMARTCARD frame polarity is valid.
883   * @param __CPOL__: SMARTCARD frame polarity.
884   * @retval SET (__CPOL__ is valid) or RESET (__CPOL__ is invalid)
885   */
886 #define IS_SMARTCARD_POLARITY(__CPOL__) (((__CPOL__) == SMARTCARD_POLARITY_LOW) || ((__CPOL__) == SMARTCARD_POLARITY_HIGH))
887 
888 /**
889   * @brief Ensure that SMARTCARD frame phase is valid.
890   * @param __CPHA__: SMARTCARD frame phase.
891   * @retval SET (__CPHA__ is valid) or RESET (__CPHA__ is invalid)
892   */
893 #define IS_SMARTCARD_PHASE(__CPHA__) (((__CPHA__) == SMARTCARD_PHASE_1EDGE) || ((__CPHA__) == SMARTCARD_PHASE_2EDGE))
894 
895 /**
896   * @brief Ensure that SMARTCARD frame last bit clock pulse setting is valid.
897   * @param __LASTBIT__: SMARTCARD frame last bit clock pulse setting.
898   * @retval SET (__LASTBIT__ is valid) or RESET (__LASTBIT__ is invalid)
899   */
900 #define IS_SMARTCARD_LASTBIT(__LASTBIT__) (((__LASTBIT__) == SMARTCARD_LASTBIT_DISABLE) || \
901                                            ((__LASTBIT__) == SMARTCARD_LASTBIT_ENABLE))
902 
903 /**
904   * @brief Ensure that SMARTCARD frame sampling is valid.
905   * @param __ONEBIT__: SMARTCARD frame sampling.
906   * @retval SET (__ONEBIT__ is valid) or RESET (__ONEBIT__ is invalid)
907   */
908 #define IS_SMARTCARD_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_DISABLE) || \
909                                                  ((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_ENABLE))
910 
911 /**
912   * @brief Ensure that SMARTCARD NACK transmission setting is valid.
913   * @param __NACK__: SMARTCARD NACK transmission setting.
914   * @retval SET (__NACK__ is valid) or RESET (__NACK__ is invalid)
915   */
916 #define IS_SMARTCARD_NACK(__NACK__) (((__NACK__) == SMARTCARD_NACK_ENABLE) || \
917                                      ((__NACK__) == SMARTCARD_NACK_DISABLE))
918 
919 /**
920   * @brief Ensure that SMARTCARD receiver timeout setting is valid.
921   * @param __TIMEOUT__: SMARTCARD receiver timeout setting.
922   * @retval SET (__TIMEOUT__ is valid) or RESET (__TIMEOUT__ is invalid)
923   */
924 #define IS_SMARTCARD_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == SMARTCARD_TIMEOUT_DISABLE) || \
925                                            ((__TIMEOUT__) == SMARTCARD_TIMEOUT_ENABLE))
926 
927 /**
928   * @brief Ensure that SMARTCARD advanced features initialization is valid.
929   * @param __INIT__: SMARTCARD advanced features initialization.
930   * @retval SET (__INIT__ is valid) or RESET (__INIT__ is invalid)
931   */
932 #define IS_SMARTCARD_ADVFEATURE_INIT(__INIT__) ((__INIT__) <= (SMARTCARD_ADVFEATURE_NO_INIT                | \
933                                                                SMARTCARD_ADVFEATURE_TXINVERT_INIT          | \
934                                                                SMARTCARD_ADVFEATURE_RXINVERT_INIT          | \
935                                                                SMARTCARD_ADVFEATURE_DATAINVERT_INIT        | \
936                                                                SMARTCARD_ADVFEATURE_SWAP_INIT              | \
937                                                                SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT  | \
938                                                                SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT | \
939                                                                SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
940 
941 /**
942   * @brief Ensure that SMARTCARD frame TX inversion setting is valid.
943   * @param __TXINV__: SMARTCARD frame TX inversion setting.
944   * @retval SET (__TXINV__ is valid) or RESET (__TXINV__ is invalid)
945   */
946 #define IS_SMARTCARD_ADVFEATURE_TXINV(__TXINV__) (((__TXINV__) == SMARTCARD_ADVFEATURE_TXINV_DISABLE) || \
947                                                   ((__TXINV__) == SMARTCARD_ADVFEATURE_TXINV_ENABLE))
948 
949 /**
950   * @brief Ensure that SMARTCARD frame RX inversion setting is valid.
951   * @param __RXINV__: SMARTCARD frame RX inversion setting.
952   * @retval SET (__RXINV__ is valid) or RESET (__RXINV__ is invalid)
953   */
954 #define IS_SMARTCARD_ADVFEATURE_RXINV(__RXINV__) (((__RXINV__) == SMARTCARD_ADVFEATURE_RXINV_DISABLE) || \
955                                                   ((__RXINV__) == SMARTCARD_ADVFEATURE_RXINV_ENABLE))
956 
957 /**
958   * @brief Ensure that SMARTCARD frame data inversion setting is valid.
959   * @param __DATAINV__: SMARTCARD frame data inversion setting.
960   * @retval SET (__DATAINV__ is valid) or RESET (__DATAINV__ is invalid)
961   */
962 #define IS_SMARTCARD_ADVFEATURE_DATAINV(__DATAINV__) (((__DATAINV__) == SMARTCARD_ADVFEATURE_DATAINV_DISABLE) || \
963                                                       ((__DATAINV__) == SMARTCARD_ADVFEATURE_DATAINV_ENABLE))
964 
965 /**
966   * @brief Ensure that SMARTCARD frame RX/TX pins swap setting is valid.
967   * @param __SWAP__: SMARTCARD frame RX/TX pins swap setting.
968   * @retval SET (__SWAP__ is valid) or RESET (__SWAP__ is invalid)
969   */
970 #define IS_SMARTCARD_ADVFEATURE_SWAP(__SWAP__) (((__SWAP__) == SMARTCARD_ADVFEATURE_SWAP_DISABLE) || \
971                                                 ((__SWAP__) == SMARTCARD_ADVFEATURE_SWAP_ENABLE))
972 
973 /**
974   * @brief Ensure that SMARTCARD frame overrun setting is valid.
975   * @param __OVERRUN__: SMARTCARD frame overrun setting.
976   * @retval SET (__OVERRUN__ is valid) or RESET (__OVERRUN__ is invalid)
977   */
978 #define IS_SMARTCARD_OVERRUN(__OVERRUN__) (((__OVERRUN__) == SMARTCARD_ADVFEATURE_OVERRUN_ENABLE) || \
979                                            ((__OVERRUN__) == SMARTCARD_ADVFEATURE_OVERRUN_DISABLE))
980 
981 /**
982   * @brief Ensure that SMARTCARD DMA enabling or disabling on error setting is valid.
983   * @param __DMA__: SMARTCARD DMA enabling or disabling on error setting.
984   * @retval SET (__DMA__ is valid) or RESET (__DMA__ is invalid)
985   */
986 #define IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(__DMA__) (((__DMA__) == SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR) || \
987                                                        ((__DMA__) == SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR))
988 
989 /**
990   * @brief Ensure that SMARTCARD frame MSB first setting is valid.
991   * @param __MSBFIRST__: SMARTCARD frame MSB first setting.
992   * @retval SET (__MSBFIRST__ is valid) or RESET (__MSBFIRST__ is invalid)
993   */
994 #define IS_SMARTCARD_ADVFEATURE_MSBFIRST(__MSBFIRST__) (((__MSBFIRST__) == SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE) || \
995                                                         ((__MSBFIRST__) == SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE))
996 
997 /**
998   * @brief Ensure that SMARTCARD request parameter is valid.
999   * @param __PARAM__: SMARTCARD request parameter.
1000   * @retval SET (__PARAM__ is valid) or RESET (__PARAM__ is invalid)
1001   */
1002 #define IS_SMARTCARD_REQUEST_PARAMETER(__PARAM__) (((__PARAM__) == SMARTCARD_RXDATA_FLUSH_REQUEST) || \
1003                                                    ((__PARAM__) == SMARTCARD_TXDATA_FLUSH_REQUEST))
1004 
1005 /**
1006   * @}
1007   */
1008 
1009 /* Include SMARTCARD HAL Extended module */
1010 #include "stm32l0xx_hal_smartcard_ex.h"
1011 
1012 
1013 /* Exported functions --------------------------------------------------------*/
1014 /** @addtogroup SMARTCARD_Exported_Functions
1015   * @{
1016   */
1017 
1018 /* Initialization and de-initialization functions  ****************************/
1019 /** @addtogroup SMARTCARD_Exported_Functions_Group1
1020   * @{
1021   */
1022 
1023 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsmartcard);
1024 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsmartcard);
1025 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsmartcard);
1026 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsmartcard);
1027 
1028 /**
1029   * @}
1030   */
1031 
1032 /* IO operation functions *****************************************************/
1033 /** @addtogroup SMARTCARD_Exported_Functions_Group2
1034   * @{
1035   */
1036 
1037 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
1038 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size, uint32_t Timeout);
1039 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
1040 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
1041 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
1042 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t *pData, uint16_t Size);
1043 /* Transfer Abort functions */
1044 HAL_StatusTypeDef HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef *hsmartcard);
1045 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef *hsmartcard);
1046 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef *hsmartcard);
1047 HAL_StatusTypeDef HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef *hsmartcard);
1048 HAL_StatusTypeDef HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef *hsmartcard);
1049 HAL_StatusTypeDef HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef *hsmartcard);
1050 
1051 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsmartcard);
1052 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
1053 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsmartcard);
1054 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsmartcard);
1055 void HAL_SMARTCARD_AbortCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard);
1056 void HAL_SMARTCARD_AbortTransmitCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard);
1057 void HAL_SMARTCARD_AbortReceiveCpltCallback (SMARTCARD_HandleTypeDef *hsmartcard);
1058 
1059 /**
1060   * @}
1061   */
1062 
1063 /* Peripheral Control functions ***********************************************/
1064 /* Peripheral State and Error functions ***************************************/
1065 /** @addtogroup SMARTCARD_Exported_Functions_Group4
1066   * @{
1067   */
1068 
1069 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsmartcard);
1070 uint32_t                   HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsmartcard);
1071 
1072 /**
1073   * @}
1074   */
1075 
1076 /**
1077   * @}
1078   */
1079 
1080 /**
1081   * @}
1082   */
1083 
1084 /**
1085   * @}
1086   */
1087 
1088 #ifdef __cplusplus
1089 }
1090 #endif
1091 
1092 #endif /* __STM32L0xx_HAL_SMARTCARD_H */
1093 
1094 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
1095 
1096