1 /**
2   ******************************************************************************
3   * @file    stm32f0xx_hal_smartcard_ex.h
4   * @author  MCD Application Team
5   * @brief   Header file of SMARTCARD HAL Extended module.
6   ******************************************************************************
7   * @attention
8   *
9   * Copyright (c) 2016 STMicroelectronics.
10   * All rights reserved.
11   *
12   * This software is licensed under terms that can be found in the LICENSE file
13   * in the root directory of this software component.
14   * If no LICENSE file comes with this software, it is provided AS-IS.
15   *
16   ******************************************************************************
17   */
18 
19 /* Define to prevent recursive inclusion -------------------------------------*/
20 #ifndef STM32F0xx_HAL_SMARTCARD_EX_H
21 #define STM32F0xx_HAL_SMARTCARD_EX_H
22 
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 #if !defined(STM32F030x6) && !defined(STM32F030x8) && !defined(STM32F070x6) \
27  && !defined(STM32F070xB) && !defined(STM32F030xC)
28 /* Includes ------------------------------------------------------------------*/
29 #include "stm32f0xx_hal_def.h"
30 
31 /** @addtogroup STM32F0xx_HAL_Driver
32   * @{
33   */
34 
35 /** @addtogroup SMARTCARDEx
36   * @{
37   */
38 
39 /* Exported types ------------------------------------------------------------*/
40 /* Exported constants --------------------------------------------------------*/
41 
42 /** @addtogroup SMARTCARDEx_Exported_Constants  SMARTCARD Extended Exported Constants
43   * @{
44   */
45 
46 /** @defgroup SMARTCARDEx_Transmission_Completion_Indication SMARTCARD Transmission Completion Indication
47   * @{
48   */
49 #if defined(USART_TCBGT_SUPPORT)
50 #define SMARTCARD_TCBGT      SMARTCARD_IT_TCBGT /*!< SMARTCARD transmission complete before guard time */
51 #endif /* USART_TCBGT_SUPPORT */
52 #define SMARTCARD_TC         SMARTCARD_IT_TC    /*!< SMARTCARD transmission complete (flag raised when guard time has elapsed) */
53 /**
54   * @}
55   */
56 
57 /** @defgroup SMARTCARDEx_Advanced_Features_Initialization_Type SMARTCARD advanced feature initialization type
58   * @{
59   */
60 #define SMARTCARD_ADVFEATURE_NO_INIT                 0x00000000U    /*!< No advanced feature initialization                  */
61 #define SMARTCARD_ADVFEATURE_TXINVERT_INIT           0x00000001U    /*!< TX pin active level inversion                       */
62 #define SMARTCARD_ADVFEATURE_RXINVERT_INIT           0x00000002U    /*!< RX pin active level inversion                       */
63 #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT         0x00000004U    /*!< Binary data inversion                               */
64 #define SMARTCARD_ADVFEATURE_SWAP_INIT               0x00000008U    /*!< TX/RX pins swap                                     */
65 #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT   0x00000010U    /*!< RX overrun disable                                  */
66 #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT  0x00000020U    /*!< DMA disable on Reception Error                      */
67 #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT           0x00000080U    /*!< Most significant bit sent/received first            */
68 #if defined(USART_TCBGT_SUPPORT)
69 #define SMARTCARD_ADVFEATURE_TXCOMPLETION            0x00000100U    /*!< TX completion indication before of after guard time */
70 #endif /* USART_TCBGT_SUPPORT */
71 /**
72   * @}
73   */
74 
75 /** @defgroup SMARTCARDEx_Flags SMARTCARD Flags
76   *        Elements values convention: 0xXXXX
77   *           - 0xXXXX  : Flag mask in the ISR register
78   * @{
79   */
80 #if defined(USART_TCBGT_SUPPORT)
81 #define SMARTCARD_FLAG_TCBGT          USART_ISR_TCBGT         /*!< SMARTCARD transmission complete before guard time completion */
82 #endif /* USART_TCBGT_SUPPORT */
83 #define SMARTCARD_FLAG_REACK          USART_ISR_REACK         /*!< SMARTCARD receive enable acknowledge flag  */
84 #define SMARTCARD_FLAG_TEACK          USART_ISR_TEACK         /*!< SMARTCARD transmit enable acknowledge flag */
85 #define SMARTCARD_FLAG_BUSY           USART_ISR_BUSY          /*!< SMARTCARD busy flag                        */
86 #define SMARTCARD_FLAG_EOBF           USART_ISR_EOBF          /*!< SMARTCARD end of block flag                */
87 #define SMARTCARD_FLAG_RTOF           USART_ISR_RTOF          /*!< SMARTCARD receiver timeout flag            */
88 #define SMARTCARD_FLAG_TXE            USART_ISR_TXE           /*!< SMARTCARD transmit data register empty     */
89 #define SMARTCARD_FLAG_TC             USART_ISR_TC            /*!< SMARTCARD transmission complete            */
90 #define SMARTCARD_FLAG_RXNE           USART_ISR_RXNE          /*!< SMARTCARD read data register not empty     */
91 #define SMARTCARD_FLAG_IDLE           USART_ISR_IDLE          /*!< SMARTCARD idle line detection              */
92 #define SMARTCARD_FLAG_ORE            USART_ISR_ORE           /*!< SMARTCARD overrun error                    */
93 #define SMARTCARD_FLAG_NE             USART_ISR_NE            /*!< SMARTCARD noise error                      */
94 #define SMARTCARD_FLAG_FE             USART_ISR_FE            /*!< SMARTCARD frame error                      */
95 #define SMARTCARD_FLAG_PE             USART_ISR_PE            /*!< SMARTCARD parity error                     */
96 /**
97   * @}
98   */
99 
100 /** @defgroup SMARTCARDEx_Interrupt_definition SMARTCARD Interrupts Definition
101   *        Elements values convention: 000ZZZZZ0XXYYYYYb
102   *           - YYYYY  : Interrupt source position in the XX register (5 bits)
103   *           - XX  : Interrupt source register (2 bits)
104   *                 - 01: CR1 register
105   *                 - 10: CR2 register
106   *                 - 11: CR3 register
107   *           - ZZZZZ  : Flag position in the ISR register(5 bits)
108   * @{
109   */
110 #define SMARTCARD_IT_PE                     0x0028U           /*!< SMARTCARD parity error interruption                 */
111 #define SMARTCARD_IT_TXE                    0x0727U           /*!< SMARTCARD transmit data register empty interruption */
112 #define SMARTCARD_IT_TC                     0x0626U           /*!< SMARTCARD transmission complete interruption        */
113 #define SMARTCARD_IT_RXNE                   0x0525U           /*!< SMARTCARD read data register not empty interruption */
114 #define SMARTCARD_IT_IDLE                   0x0424U           /*!< SMARTCARD idle line detection interruption          */
115 
116 #define SMARTCARD_IT_ERR                    0x0060U           /*!< SMARTCARD error interruption         */
117 #define SMARTCARD_IT_ORE                    0x0300U           /*!< SMARTCARD overrun error interruption */
118 #define SMARTCARD_IT_NE                     0x0200U           /*!< SMARTCARD noise error interruption   */
119 #define SMARTCARD_IT_FE                     0x0100U           /*!< SMARTCARD frame error interruption   */
120 
121 #define SMARTCARD_IT_EOB                    0x0C3BU           /*!< SMARTCARD end of block interruption     */
122 #define SMARTCARD_IT_RTO                    0x0B3AU           /*!< SMARTCARD receiver timeout interruption */
123 #if defined(USART_TCBGT_SUPPORT)
124 #define SMARTCARD_IT_TCBGT                  0x1978U           /*!< SMARTCARD transmission complete before guard time completion interruption */
125 #endif /* USART_TCBGT_SUPPORT */
126 
127 /**
128   * @}
129   */
130 
131 /** @defgroup SMARTCARDEx_IT_CLEAR_Flags SMARTCARD Interruption Clear Flags
132   * @{
133   */
134 #define SMARTCARD_CLEAR_PEF                 USART_ICR_PECF    /*!< SMARTCARD parity error clear flag          */
135 #define SMARTCARD_CLEAR_FEF                 USART_ICR_FECF    /*!< SMARTCARD framing error clear flag         */
136 #define SMARTCARD_CLEAR_NEF                 USART_ICR_NCF     /*!< SMARTCARD noise error detected clear flag  */
137 #define SMARTCARD_CLEAR_OREF                USART_ICR_ORECF   /*!< SMARTCARD overrun error clear flag         */
138 #define SMARTCARD_CLEAR_IDLEF               USART_ICR_IDLECF  /*!< SMARTCARD idle line detected clear flag    */
139 #define SMARTCARD_CLEAR_TCF                 USART_ICR_TCCF    /*!< SMARTCARD transmission complete clear flag */
140 #if defined(USART_TCBGT_SUPPORT)
141 #define SMARTCARD_CLEAR_TCBGTF              USART_ICR_TCBGTCF /*!< SMARTCARD transmission complete before guard time completion clear flag */
142 #endif /* USART_TCBGT_SUPPORT */
143 #define SMARTCARD_CLEAR_RTOF                USART_ICR_RTOCF   /*!< SMARTCARD receiver time out clear flag     */
144 #define SMARTCARD_CLEAR_EOBF                USART_ICR_EOBCF   /*!< SMARTCARD end of block clear flag          */
145 /**
146   * @}
147   */
148 
149 /**
150   * @}
151   */
152 /* Exported macros -----------------------------------------------------------*/
153 /* Private macros ------------------------------------------------------------*/
154 /** @defgroup SMARTCARDEx_Private_Macros SMARTCARD Extended Private Macros
155   * @{
156   */
157 
158 /** @brief  Report the SMARTCARD clock source.
159   * @param  __HANDLE__ specifies the SMARTCARD Handle.
160   * @param  __CLOCKSOURCE__ output variable.
161   * @retval the SMARTCARD clocking source, written in __CLOCKSOURCE__.
162   */
163 #if defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx)
164 #define SMARTCARD_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)   \
165   do {                                                         \
166     switch(__HAL_RCC_GET_USART1_SOURCE())                      \
167     {                                                          \
168       case RCC_USART1CLKSOURCE_PCLK1:                          \
169         (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;       \
170         break;                                                 \
171       case RCC_USART1CLKSOURCE_HSI:                            \
172         (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;         \
173         break;                                                 \
174       case RCC_USART1CLKSOURCE_SYSCLK:                         \
175         (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;      \
176         break;                                                 \
177       case RCC_USART1CLKSOURCE_LSE:                            \
178         (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;         \
179         break;                                                 \
180       default:                                                 \
181         (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED;   \
182         break;                                                 \
183     }                                                          \
184   } while(0)
185 #elif defined (STM32F030x8) || defined (STM32F070x6) ||  defined (STM32F042x6) || defined (STM32F048xx) \
186    || defined (STM32F051x8) || defined (STM32F058xx)
187 #define SMARTCARD_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)   \
188   do {                                                         \
189     if((__HANDLE__)->Instance == USART1)                       \
190     {                                                          \
191       switch(__HAL_RCC_GET_USART1_SOURCE())                    \
192       {                                                        \
193         case RCC_USART1CLKSOURCE_PCLK1:                        \
194           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
195           break;                                               \
196         case RCC_USART1CLKSOURCE_HSI:                          \
197           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
198           break;                                               \
199         case RCC_USART1CLKSOURCE_SYSCLK:                       \
200           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
201           break;                                               \
202         case RCC_USART1CLKSOURCE_LSE:                          \
203           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
204           break;                                               \
205         default:                                               \
206           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
207           break;                                               \
208       }                                                        \
209     }                                                          \
210     else if((__HANDLE__)->Instance == USART2)                  \
211     {                                                          \
212       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
213     }                                                          \
214     else                                                       \
215     {                                                          \
216       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED;     \
217     }                                                          \
218   } while(0)
219 #elif defined (STM32F070xB)
220 #define SMARTCARD_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)   \
221   do {                                                         \
222     if((__HANDLE__)->Instance == USART1)                       \
223     {                                                          \
224       switch(__HAL_RCC_GET_USART1_SOURCE())                    \
225       {                                                        \
226         case RCC_USART1CLKSOURCE_PCLK1:                        \
227           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
228           break;                                               \
229         case RCC_USART1CLKSOURCE_HSI:                          \
230           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
231           break;                                               \
232         case RCC_USART1CLKSOURCE_SYSCLK:                       \
233           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
234           break;                                               \
235         case RCC_USART1CLKSOURCE_LSE:                          \
236           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
237           break;                                               \
238         default:                                               \
239           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
240           break;                                               \
241       }                                                        \
242     }                                                          \
243     else if((__HANDLE__)->Instance == USART2)                  \
244     {                                                          \
245       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
246     }                                                          \
247     else if((__HANDLE__)->Instance == USART3)                  \
248     {                                                          \
249       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
250     }                                                          \
251     else if((__HANDLE__)->Instance == USART4)                  \
252     {                                                          \
253       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
254     }                                                          \
255     else                                                       \
256     {                                                          \
257       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED;     \
258     }                                                          \
259   } while(0)
260 #elif defined(STM32F071xB) || defined(STM32F072xB) || defined(STM32F078xx)
261 #define SMARTCARD_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)   \
262   do {                                                         \
263     if((__HANDLE__)->Instance == USART1)                       \
264     {                                                          \
265       switch(__HAL_RCC_GET_USART1_SOURCE())                    \
266       {                                                        \
267         case RCC_USART1CLKSOURCE_PCLK1:                        \
268           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
269           break;                                               \
270         case RCC_USART1CLKSOURCE_HSI:                          \
271           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
272           break;                                               \
273         case RCC_USART1CLKSOURCE_SYSCLK:                       \
274           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
275           break;                                               \
276         case RCC_USART1CLKSOURCE_LSE:                          \
277           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
278           break;                                               \
279         default:                                               \
280           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
281           break;                                               \
282       }                                                        \
283     }                                                          \
284     else if((__HANDLE__)->Instance == USART2)                  \
285     {                                                          \
286       switch(__HAL_RCC_GET_USART2_SOURCE())                    \
287       {                                                        \
288         case RCC_USART2CLKSOURCE_PCLK1:                        \
289           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
290           break;                                               \
291         case RCC_USART2CLKSOURCE_HSI:                          \
292           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
293           break;                                               \
294         case RCC_USART2CLKSOURCE_SYSCLK:                       \
295           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
296           break;                                               \
297         case RCC_USART2CLKSOURCE_LSE:                          \
298           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
299           break;                                               \
300         default:                                               \
301           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
302           break;                                               \
303       }                                                        \
304     }                                                          \
305     else if((__HANDLE__)->Instance == USART3)                  \
306     {                                                          \
307       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
308     }                                                          \
309     else if((__HANDLE__)->Instance == USART4)                  \
310     {                                                          \
311       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
312     }                                                          \
313     else                                                       \
314     {                                                          \
315       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED;     \
316     }                                                          \
317   } while(0)
318 #elif defined(STM32F091xC) || defined (STM32F098xx)
319 #define SMARTCARD_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)   \
320   do {                                                         \
321     if((__HANDLE__)->Instance == USART1)                       \
322     {                                                          \
323       switch(__HAL_RCC_GET_USART1_SOURCE())                    \
324       {                                                        \
325         case RCC_USART1CLKSOURCE_PCLK1:                        \
326           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
327           break;                                               \
328         case RCC_USART1CLKSOURCE_HSI:                          \
329           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
330           break;                                               \
331         case RCC_USART1CLKSOURCE_SYSCLK:                       \
332           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
333           break;                                               \
334         case RCC_USART1CLKSOURCE_LSE:                          \
335           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
336           break;                                               \
337         default:                                               \
338           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
339           break;                                               \
340       }                                                        \
341     }                                                          \
342     else if((__HANDLE__)->Instance == USART2)                  \
343     {                                                          \
344       switch(__HAL_RCC_GET_USART2_SOURCE())                    \
345       {                                                        \
346         case RCC_USART2CLKSOURCE_PCLK1:                        \
347           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
348           break;                                               \
349         case RCC_USART2CLKSOURCE_HSI:                          \
350           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
351           break;                                               \
352         case RCC_USART2CLKSOURCE_SYSCLK:                       \
353           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
354           break;                                               \
355         case RCC_USART2CLKSOURCE_LSE:                          \
356           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
357           break;                                               \
358         default:                                               \
359           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
360           break;                                               \
361       }                                                        \
362     }                                                          \
363     else if((__HANDLE__)->Instance == USART3)                  \
364     {                                                          \
365       switch(__HAL_RCC_GET_USART3_SOURCE())                    \
366       {                                                        \
367         case RCC_USART3CLKSOURCE_PCLK1:                        \
368           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
369           break;                                               \
370         case RCC_USART3CLKSOURCE_HSI:                          \
371           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
372           break;                                               \
373         case RCC_USART3CLKSOURCE_SYSCLK:                       \
374           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
375           break;                                               \
376         case RCC_USART3CLKSOURCE_LSE:                          \
377           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
378           break;                                               \
379         default:                                               \
380           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
381           break;                                               \
382       }                                                        \
383     }                                                          \
384     else if((__HANDLE__)->Instance == USART4)                  \
385     {                                                          \
386       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
387     }                                                          \
388     else if((__HANDLE__)->Instance == USART5)                  \
389     {                                                          \
390       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
391     }                                                          \
392     else if((__HANDLE__)->Instance == USART6)                  \
393     {                                                          \
394       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
395     }                                                          \
396     else if((__HANDLE__)->Instance == USART7)                  \
397     {                                                          \
398       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
399     }                                                          \
400     else if((__HANDLE__)->Instance == USART8)                  \
401     {                                                          \
402       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
403     }                                                          \
404     else                                                       \
405     {                                                          \
406       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED;     \
407     }                                                          \
408   } while(0)
409 #elif defined(STM32F030xC)
410 #define SMARTCARD_GETCLOCKSOURCE(__HANDLE__,__CLOCKSOURCE__)   \
411   do {                                                         \
412     if((__HANDLE__)->Instance == USART1)                       \
413     {                                                          \
414       switch(__HAL_RCC_GET_USART1_SOURCE())                    \
415       {                                                        \
416         case RCC_USART1CLKSOURCE_PCLK1:                        \
417           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;     \
418           break;                                               \
419         case RCC_USART1CLKSOURCE_HSI:                          \
420           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_HSI;       \
421           break;                                               \
422         case RCC_USART1CLKSOURCE_SYSCLK:                       \
423           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_SYSCLK;    \
424           break;                                               \
425         case RCC_USART1CLKSOURCE_LSE:                          \
426           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_LSE;       \
427           break;                                               \
428         default:                                               \
429           (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED; \
430           break;                                               \
431       }                                                        \
432     }                                                          \
433     else if((__HANDLE__)->Instance == USART2)                  \
434     {                                                          \
435       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
436     }                                                          \
437     else if((__HANDLE__)->Instance == USART3)                  \
438     {                                                          \
439       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
440     }                                                          \
441     else if((__HANDLE__)->Instance == USART4)                  \
442     {                                                          \
443       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
444     }                                                          \
445     else if((__HANDLE__)->Instance == USART5)                  \
446     {                                                          \
447       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
448     }                                                          \
449     else if((__HANDLE__)->Instance == USART6)                  \
450     {                                                          \
451       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_PCLK1;         \
452     }                                                          \
453     else                                                       \
454     {                                                          \
455       (__CLOCKSOURCE__) = SMARTCARD_CLOCKSOURCE_UNDEFINED;     \
456     }                                                          \
457   } while(0)
458 #endif /* defined(STM32F030x6) || defined(STM32F031x6) || defined(STM32F038xx) */
459 
460 /** @brief  Set the Transmission Completion flag
461   * @param  __HANDLE__ specifies the SMARTCARD Handle.
462   * @note  If TCBGT (Transmission Complete Before Guard Time) flag is not available or if
463   *        AdvancedInit.TxCompletionIndication is not already filled, the latter is forced
464   *        to SMARTCARD_TC (transmission completion indication when guard time has elapsed).
465   * @retval None
466   */
467 #if defined(USART_TCBGT_SUPPORT)
468 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__)                                                \
469   do {                                                                                                       \
470     if (HAL_IS_BIT_CLR((__HANDLE__)->AdvancedInit.AdvFeatureInit, SMARTCARD_ADVFEATURE_TXCOMPLETION))        \
471     {                                                                                                        \
472       (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC;                                      \
473     }                                                                                                        \
474     else                                                                                                     \
475     {                                                                                                        \
476       assert_param(IS_SMARTCARD_TRANSMISSION_COMPLETION((__HANDLE__)->AdvancedInit.TxCompletionIndication)); \
477     }                                                                                                        \
478   } while(0U)
479 #else
480 #define SMARTCARD_TRANSMISSION_COMPLETION_SETTING(__HANDLE__)         \
481   do {                                                                \
482     (__HANDLE__)->AdvancedInit.TxCompletionIndication = SMARTCARD_TC; \
483   } while(0U)
484 #endif /* USART_TCBGT_SUPPORT */
485 
486 /** @brief  Return the transmission completion flag.
487   * @param  __HANDLE__ specifies the SMARTCARD Handle.
488   * @note  Based on AdvancedInit.TxCompletionIndication setting, return TC or TCBGT flag.
489   *        When TCBGT flag (Transmission Complete Before Guard Time) is not available, TC flag is
490   *        reported.
491   * @retval Transmission completion flag
492   */
493 #if defined(USART_TCBGT_SUPPORT)
494 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__)  \
495   (((__HANDLE__)->AdvancedInit.TxCompletionIndication == SMARTCARD_TC) ? (SMARTCARD_FLAG_TC) :  (SMARTCARD_FLAG_TCBGT))
496 #else
497 #define SMARTCARD_TRANSMISSION_COMPLETION_FLAG(__HANDLE__)    (SMARTCARD_FLAG_TC)
498 #endif /* USART_TCBGT_SUPPORT */
499 
500 
501 /** @brief Ensure that SMARTCARD frame transmission completion used flag is valid.
502   * @param __TXCOMPLETE__ SMARTCARD frame transmission completion used flag.
503   * @retval SET (__TXCOMPLETE__ is valid) or RESET (__TXCOMPLETE__ is invalid)
504   */
505 #if defined(USART_TCBGT_SUPPORT)
506 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) (((__TXCOMPLETE__) == SMARTCARD_TCBGT) || \
507                                                               ((__TXCOMPLETE__) == SMARTCARD_TC))
508 #else
509 #define IS_SMARTCARD_TRANSMISSION_COMPLETION(__TXCOMPLETE__) ((__TXCOMPLETE__) == SMARTCARD_TC)
510 #endif /* USART_TCBGT_SUPPORT */
511 
512 /**
513   * @}
514   */
515 
516 /* Exported functions --------------------------------------------------------*/
517 /** @addtogroup SMARTCARDEx_Exported_Functions
518   * @{
519   */
520 
521 /* Initialization and de-initialization functions  ****************************/
522 /* IO operation methods *******************************************************/
523 
524 /** @addtogroup SMARTCARDEx_Exported_Functions_Group1
525   * @{
526   */
527 
528 /* Peripheral Control functions ***********************************************/
529 void              HAL_SMARTCARDEx_BlockLength_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint8_t BlockLength);
530 void              HAL_SMARTCARDEx_TimeOut_Config(SMARTCARD_HandleTypeDef *hsmartcard, uint32_t TimeOutValue);
531 HAL_StatusTypeDef HAL_SMARTCARDEx_EnableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
532 HAL_StatusTypeDef HAL_SMARTCARDEx_DisableReceiverTimeOut(SMARTCARD_HandleTypeDef *hsmartcard);
533 
534 /**
535   * @}
536   */
537 
538 /* Exported functions --------------------------------------------------------*/
539 /** @addtogroup SMARTCARDEx_Exported_Functions_Group2
540   * @{
541   */
542 
543 /* IO operation functions *****************************************************/
544 
545 /**
546   * @}
547   */
548 
549 
550 /**
551   * @}
552   */
553 
554 /* Private functions ---------------------------------------------------------*/
555 
556 /**
557   * @}
558   */
559 
560 /**
561   * @}
562   */
563 #endif /* !STM32F030x6 && !STM32F030x8 && !STM32F070x6 && !STM32F070xB && !STM32F030xC */
564 #ifdef __cplusplus
565 }
566 #endif
567 
568 #endif /* STM32F0xx_HAL_SMARTCARD_EX_H */
569 
570