source: rtems/c/src/lib/libbsp/arm/stm32f7x/hal/STM32F7xx_HAL_Driver/Inc/stm32f7xx_hal_smartcard.h @ c20847a5

5
Last change on this file since c20847a5 was c20847a5, checked in by Isaac Gutekunst <isaac.gutekunst@…>, on 09/16/15 at 13:16:02

Add STM32F7 HAL Files

These files originated as:

+ STC32CubeF7 V1.1.0 from http://www.st.com/web/en/catalog/tools/PF261909

  • Property mode set to 100644
File size: 38.1 KB
Line 
1/**
2  ******************************************************************************
3  * @file    stm32f7xx_hal_smartcard.h
4  * @author  MCD Application Team
5  * @version V1.0.1
6  * @date    25-June-2015
7  * @brief   Header file of SMARTCARD HAL module.
8  ******************************************************************************
9  * @attention
10  *
11  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
12  *
13  * Redistribution and use in source and binary forms, with or without modification,
14  * are permitted provided that the following conditions are met:
15  *   1. Redistributions of source code must retain the above copyright notice,
16  *      this list of conditions and the following disclaimer.
17  *   2. Redistributions in binary form must reproduce the above copyright notice,
18  *      this list of conditions and the following disclaimer in the documentation
19  *      and/or other materials provided with the distribution.
20  *   3. Neither the name of STMicroelectronics nor the names of its contributors
21  *      may be used to endorse or promote products derived from this software
22  *      without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
25  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
27  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
28  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
30  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
31  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
32  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
33  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34  *
35  ******************************************************************************
36  */
37
38/* Define to prevent recursive inclusion -------------------------------------*/
39#ifndef __STM32F7xx_HAL_SMARTCARD_H
40#define __STM32F7xx_HAL_SMARTCARD_H
41
42#ifdef __cplusplus
43 extern "C" {
44#endif
45
46/* Includes ------------------------------------------------------------------*/
47#include "stm32f7xx_hal_def.h"
48
49/** @addtogroup STM32F7xx_HAL_Driver
50  * @{
51  */
52
53/** @addtogroup SMARTCARD
54  * @{
55  */
56
57/* Exported types ------------------------------------------------------------*/
58/** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
59  * @{
60  */
61
62/**
63  * @brief SMARTCARD Init Structure definition
64  */
65typedef struct
66{
67  uint32_t BaudRate;                  /*!< Configures the SmartCard communication baud rate.
68                                           The baud rate register is computed using the following formula:
69                                              Baud Rate Register = ((PCLKx) / ((hsc->Init.BaudRate))) */
70
71  uint32_t WordLength;                /*!< Specifies the number of data bits transmitted or received in a frame.
72                                           This parameter @ref SMARTCARD_Word_Length can only be set to 9 (8 data + 1 parity bits). */
73
74  uint32_t StopBits;                  /*!< Specifies the number of stop bits @ref SMARTCARD_Stop_Bits.
75                                           Only 1.5 stop bits are authorized in SmartCard mode. */
76
77  uint32_t Parity;                    /*!< Specifies the parity mode.
78                                           This parameter can be a value of @ref SMARTCARD_Parity
79                                           @note The parity is enabled by default (PCE is forced to 1).
80                                                 Since the WordLength is forced to 8 bits + parity, M is
81                                                 forced to 1 and the parity bit is the 9th bit. */
82
83  uint32_t Mode;                      /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
84                                           This parameter can be a value of @ref SMARTCARD_Mode */
85
86  uint32_t CLKPolarity;               /*!< Specifies the steady state of the serial clock.
87                                           This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
88
89  uint32_t CLKPhase;                  /*!< Specifies the clock transition on which the bit capture is made.
90                                           This parameter can be a value of @ref SMARTCARD_Clock_Phase */
91
92  uint32_t CLKLastBit;                /*!< Specifies whether the clock pulse corresponding to the last transmitted
93                                           data bit (MSB) has to be output on the SCLK pin in synchronous mode.
94                                           This parameter can be a value of @ref SMARTCARD_Last_Bit */
95
96  uint32_t OneBitSampling;            /*!< Specifies  whether a single sample or three samples' majority vote is selected.
97                                           Selecting the single sample method increases the receiver tolerance to clock
98                                           deviations. This parameter can be a value of @ref SMARTCARD_OneBit_Sampling */
99
100  uint32_t  Prescaler;                 /*!< Specifies the SmartCard Prescaler */
101
102  uint32_t  GuardTime;                 /*!< Specifies the SmartCard Guard Time */
103
104  uint32_t NACKState;                  /*!< Specifies whether the SmartCard NACK transmission is enabled
105                                            in case of parity error.
106                                            This parameter can be a value of @ref SMARTCARD_NACK_State */
107
108  uint32_t TimeOutEnable;              /*!< Specifies whether the receiver timeout is enabled.
109                                            This parameter can be a value of @ref SMARTCARD_Timeout_Enable*/
110
111  uint32_t TimeOutValue;               /*!< Specifies the receiver time out value in number of baud blocks:
112                                            it is used to implement the Character Wait Time (CWT) and
113                                            Block Wait Time (BWT). It is coded over 24 bits. */
114
115  uint32_t BlockLength;                /*!< Specifies the SmartCard Block Length in T=1 Reception mode.
116                                            This parameter can be any value from 0x0 to 0xFF */
117
118  uint32_t AutoRetryCount;              /*!< Specifies the SmartCard auto-retry count (number of retries in
119                                             receive and transmit mode). When set to 0, retransmission is
120                                             disabled. Otherwise, its maximum value is 7 (before signalling
121                                             an error) */
122
123}SMARTCARD_InitTypeDef;
124
125/**
126  * @brief  SMARTCARD advanced features initalization structure definition
127  */
128typedef struct
129{
130  uint32_t AdvFeatureInit;            /*!< Specifies which advanced SMARTCARD features is initialized. Several
131                                           advanced features may be initialized at the same time. This parameter
132                                           can be a value of @ref SMARTCARD_Advanced_Features_Initialization_Type */
133
134  uint32_t TxPinLevelInvert;          /*!< Specifies whether the TX pin active level is inverted.
135                                           This parameter can be a value of @ref SMARTCARD_Tx_Inv  */
136
137  uint32_t RxPinLevelInvert;          /*!< Specifies whether the RX pin active level is inverted.
138                                           This parameter can be a value of @ref SMARTCARD_Rx_Inv  */
139
140  uint32_t DataInvert;                /*!< Specifies whether data are inverted (positive/direct logic
141                                           vs negative/inverted logic).
142                                           This parameter can be a value of @ref SMARTCARD_Data_Inv */
143
144  uint32_t Swap;                      /*!< Specifies whether TX and RX pins are swapped.
145                                           This parameter can be a value of @ref SMARTCARD_Rx_Tx_Swap */
146
147  uint32_t OverrunDisable;            /*!< Specifies whether the reception overrun detection is disabled.
148                                           This parameter can be a value of @ref SMARTCARD_Overrun_Disable */
149
150  uint32_t DMADisableonRxError;       /*!< Specifies whether the DMA is disabled in case of reception error.
151                                           This parameter can be a value of @ref SMARTCARD_DMA_Disable_on_Rx_Error */
152
153  uint32_t MSBFirst;                  /*!< Specifies whether MSB is sent first on UART line.
154                                           This parameter can be a value of @ref SMARTCARD_MSB_First */
155}SMARTCARD_AdvFeatureInitTypeDef;
156
157/**
158  * @brief HAL State structures definition
159  */
160typedef enum
161{
162  HAL_SMARTCARD_STATE_RESET             = 0x00,    /*!< Peripheral is not yet Initialized */
163  HAL_SMARTCARD_STATE_READY             = 0x01,    /*!< Peripheral Initialized and ready for use */
164  HAL_SMARTCARD_STATE_BUSY              = 0x02,    /*!< an internal process is ongoing */
165  HAL_SMARTCARD_STATE_BUSY_TX           = 0x12,    /*!< Data Transmission process is ongoing */
166  HAL_SMARTCARD_STATE_BUSY_RX           = 0x22,    /*!< Data Reception process is ongoing */
167  HAL_SMARTCARD_STATE_BUSY_TX_RX        = 0x32,    /*!< Data Transmission and Reception process is ongoing */
168  HAL_SMARTCARD_STATE_TIMEOUT           = 0x03,    /*!< Timeout state */
169  HAL_SMARTCARD_STATE_ERROR             = 0x04     /*!< Error */
170}HAL_SMARTCARD_StateTypeDef;
171
172
173/**
174  * @brief  SMARTCARD clock sources definition
175  */
176typedef enum
177{
178  SMARTCARD_CLOCKSOURCE_PCLK1      = 0x00,    /*!< PCLK1 clock source  */
179  SMARTCARD_CLOCKSOURCE_PCLK2      = 0x01,    /*!< PCLK2 clock source  */
180  SMARTCARD_CLOCKSOURCE_HSI        = 0x02,    /*!< HSI clock source    */
181  SMARTCARD_CLOCKSOURCE_SYSCLK     = 0x04,    /*!< SYSCLK clock source */
182  SMARTCARD_CLOCKSOURCE_LSE        = 0x08     /*!< LSE clock source    */
183}SMARTCARD_ClockSourceTypeDef;
184
185/**
186  * @brief  SMARTCARD handle Structure definition
187  */
188typedef struct
189{
190  USART_TypeDef                       *Instance;        /* USART registers base address                          */
191
192  SMARTCARD_InitTypeDef               Init;             /* SmartCard communication parameters                    */
193
194  SMARTCARD_AdvFeatureInitTypeDef     AdvancedInit;     /* SmartCard advanced features initialization parameters */
195
196  uint8_t                             *pTxBuffPtr;      /* Pointer to SmartCard Tx transfer Buffer            */
197
198  uint16_t                            TxXferSize;       /* SmartCard Tx Transfer size                         */
199
200  uint16_t                            TxXferCount;      /* SmartCard Tx Transfer Counter                      */
201
202  uint8_t                             *pRxBuffPtr;      /* Pointer to SmartCard Rx transfer Buffer        */
203
204  uint16_t                            RxXferSize;       /* SmartCard Rx Transfer size                     */
205
206  uint16_t                            RxXferCount;      /* SmartCard Rx Transfer Counter                  */
207
208  DMA_HandleTypeDef                   *hdmatx;          /* SmartCard Tx DMA Handle parameters             */
209
210  DMA_HandleTypeDef                   *hdmarx;          /* SmartCard Rx DMA Handle parameters             */
211
212  HAL_LockTypeDef                     Lock;             /* Locking object                                 */
213
214  __IO HAL_SMARTCARD_StateTypeDef     State;            /* SmartCard communication state                  */
215
216  __IO uint32_t                       ErrorCode;        /* SmartCard Error code                           */
217
218}SMARTCARD_HandleTypeDef;
219
220/**
221  * @}
222  */
223/* Exported constants --------------------------------------------------------*/
224/** @defgroup SMARTCARD_Exported_Constants  SMARTCARD Exported constants
225  * @{
226  */
227/** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
228  * @brief    SMARTCARD Error Code
229  * @{
230  */
231#define HAL_SMARTCARD_ERROR_NONE      ((uint32_t)0x00)    /*!< No error                */
232#define HAL_SMARTCARD_ERROR_PE        ((uint32_t)0x01)    /*!< Parity error            */
233#define HAL_SMARTCARD_ERROR_NE        ((uint32_t)0x02)    /*!< Noise error             */
234#define HAL_SMARTCARD_ERROR_FE        ((uint32_t)0x04)    /*!< frame error             */
235#define HAL_SMARTCARD_ERROR_ORE       ((uint32_t)0x08)    /*!< Overrun error           */
236#define HAL_SMARTCARD_ERROR_DMA       ((uint32_t)0x10)    /*!< DMA transfer error      */
237#define HAL_SMARTCARD_ERROR_RTO       ((uint32_t)0x20)    /*!< Receiver TimeOut error  */
238/**
239  * @}
240  */
241
242/** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
243  * @{
244  */
245#define SMARTCARD_WORDLENGTH_9B                  ((uint32_t)USART_CR1_M_0)
246/**
247  * @}
248  */
249
250/** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
251  * @{
252  */
253#define SMARTCARD_STOPBITS_1_5                   ((uint32_t)(USART_CR2_STOP))
254/**
255  * @}
256  */
257
258/** @defgroup SMARTCARD_Parity SMARTCARD Parity
259  * @{
260  */
261#define SMARTCARD_PARITY_EVEN                    ((uint32_t)USART_CR1_PCE)
262#define SMARTCARD_PARITY_ODD                     ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
263/**
264  * @}
265  */
266
267/** @defgroup SMARTCARD_Mode SMARTCARD Mode
268  * @{
269  */
270#define SMARTCARD_MODE_RX                        ((uint32_t)USART_CR1_RE)
271#define SMARTCARD_MODE_TX                        ((uint32_t)USART_CR1_TE)
272#define SMARTCARD_MODE_TX_RX                     ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
273/**
274  * @}
275  */
276
277/** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
278  * @{
279  */
280#define SMARTCARD_POLARITY_LOW                   ((uint32_t)0x0000)
281#define SMARTCARD_POLARITY_HIGH                  ((uint32_t)USART_CR2_CPOL)
282/**
283  * @}
284  */
285
286/** @defgroup SMARTCARD_Clock_Phase  SMARTCARD Clock Phase
287  * @{
288  */
289#define SMARTCARD_PHASE_1EDGE                    ((uint32_t)0x0000)
290#define SMARTCARD_PHASE_2EDGE                    ((uint32_t)USART_CR2_CPHA)
291/**
292  * @}
293  */
294
295/** @defgroup SMARTCARD_Last_Bit  SMARTCARD Last Bit
296  * @{
297  */
298#define SMARTCARD_LASTBIT_DISABLE                ((uint32_t)0x0000)
299#define SMARTCARD_LASTBIT_ENABLE                 ((uint32_t)USART_CR2_LBCL)
300/**
301  * @}
302  */
303
304/** @defgroup SMARTCARD_OneBit_Sampling SMARTCARD OneBit Sampling
305  * @{
306  */
307#define SMARTCARD_ONE_BIT_SAMPLE_DISABLE   ((uint32_t)0x0000)
308#define SMARTCARD_ONE_BIT_SAMPLE_ENABLE    ((uint32_t)USART_CR3_ONEBIT)
309/**
310  * @}
311  */
312
313
314/** @defgroup SMARTCARD_NACK_State  SMARTCARD NACK State
315  * @{
316  */
317#define SMARTCARD_NACK_ENABLE           ((uint32_t)USART_CR3_NACK)
318#define SMARTCARD_NACK_DISABLE          ((uint32_t)0x0000)
319/**
320  * @}
321  */
322
323/** @defgroup SMARTCARD_Timeout_Enable SMARTCARD Timeout Enable
324  * @{
325  */
326#define SMARTCARD_TIMEOUT_DISABLE      ((uint32_t)0x00000000)
327#define SMARTCARD_TIMEOUT_ENABLE       ((uint32_t)USART_CR2_RTOEN)
328/**
329  * @}
330  */
331
332/** @defgroup SMARTCARD_DMA_Requests   SMARTCARD DMA requests
333  * @{
334  */
335
336#define SMARTCARD_DMAREQ_TX                    ((uint32_t)USART_CR3_DMAT)
337#define SMARTCARD_DMAREQ_RX                    ((uint32_t)USART_CR3_DMAR)
338
339/**
340  * @}
341  */
342
343/** @defgroup SMARTCARD_Advanced_Features_Initialization_Type SMARTCARD Advanced Features Initialization Type
344  * @{
345  */
346#define SMARTCARD_ADVFEATURE_NO_INIT                 ((uint32_t)0x00000000)
347#define SMARTCARD_ADVFEATURE_TXINVERT_INIT           ((uint32_t)0x00000001)
348#define SMARTCARD_ADVFEATURE_RXINVERT_INIT           ((uint32_t)0x00000002)
349#define SMARTCARD_ADVFEATURE_DATAINVERT_INIT         ((uint32_t)0x00000004)
350#define SMARTCARD_ADVFEATURE_SWAP_INIT               ((uint32_t)0x00000008)
351#define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT   ((uint32_t)0x00000010)
352#define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT  ((uint32_t)0x00000020)
353#define SMARTCARD_ADVFEATURE_MSBFIRST_INIT           ((uint32_t)0x00000080)
354/**
355  * @}
356  */
357
358/** @defgroup SMARTCARD_Tx_Inv SMARTCARD Tx Inv
359  * @{
360  */
361#define SMARTCARD_ADVFEATURE_TXINV_DISABLE   ((uint32_t)0x00000000)
362#define SMARTCARD_ADVFEATURE_TXINV_ENABLE    ((uint32_t)USART_CR2_TXINV)
363/**
364  * @}
365  */
366
367/** @defgroup SMARTCARD_Rx_Inv SMARTCARD Rx Inv
368  * @{
369  */
370#define SMARTCARD_ADVFEATURE_RXINV_DISABLE   ((uint32_t)0x00000000)
371#define SMARTCARD_ADVFEATURE_RXINV_ENABLE    ((uint32_t)USART_CR2_RXINV)
372/**
373  * @}
374  */
375
376/** @defgroup SMARTCARD_Data_Inv SMARTCARD Data Inv
377  * @{
378  */
379#define SMARTCARD_ADVFEATURE_DATAINV_DISABLE     ((uint32_t)0x00000000)
380#define SMARTCARD_ADVFEATURE_DATAINV_ENABLE      ((uint32_t)USART_CR2_DATAINV)
381/**
382  * @}
383  */
384
385/** @defgroup SMARTCARD_Rx_Tx_Swap SMARTCARD Rx Tx Swap
386  * @{
387  */
388#define SMARTCARD_ADVFEATURE_SWAP_DISABLE   ((uint32_t)0x00000000)
389#define SMARTCARD_ADVFEATURE_SWAP_ENABLE    ((uint32_t)USART_CR2_SWAP)
390/**
391  * @}
392  */
393
394/** @defgroup SMARTCARD_Overrun_Disable SMARTCARD Overrun Disable
395  * @{
396  */
397#define SMARTCARD_ADVFEATURE_OVERRUN_ENABLE   ((uint32_t)0x00000000)
398#define SMARTCARD_ADVFEATURE_OVERRUN_DISABLE  ((uint32_t)USART_CR3_OVRDIS)
399/**
400  * @}
401  */
402
403/** @defgroup SMARTCARD_DMA_Disable_on_Rx_Error SMARTCARD DMA Disable on Rx Error
404  * @{
405  */
406#define SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR       ((uint32_t)0x00000000)
407#define SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR      ((uint32_t)USART_CR3_DDRE)
408/**
409  * @}
410  */
411
412/** @defgroup SMARTCARD_MSB_First SMARTCARD MSB First
413  * @{
414  */
415#define SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE      ((uint32_t)0x00000000)
416#define SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE       ((uint32_t)USART_CR2_MSBFIRST)
417/**
418  * @}
419  */
420
421/** @defgroup SmartCard_Flags SMARTCARD Flags
422  *        Elements values convention: 0xXXXX
423  *           - 0xXXXX  : Flag mask in the ISR register
424  * @{
425  */
426#define SMARTCARD_FLAG_REACK                     ((uint32_t)0x00400000)
427#define SMARTCARD_FLAG_TEACK                     ((uint32_t)0x00200000)
428#define SMARTCARD_FLAG_BUSY                      ((uint32_t)0x00010000)
429#define SMARTCARD_FLAG_EOBF                      ((uint32_t)0x00001000)
430#define SMARTCARD_FLAG_RTOF                      ((uint32_t)0x00000800)
431#define SMARTCARD_FLAG_TXE                       ((uint32_t)0x00000080)
432#define SMARTCARD_FLAG_TC                        ((uint32_t)0x00000040)
433#define SMARTCARD_FLAG_RXNE                      ((uint32_t)0x00000020)
434#define SMARTCARD_FLAG_IDLE                      ((uint32_t)0x00000010)
435#define SMARTCARD_FLAG_ORE                       ((uint32_t)0x00000008)
436#define SMARTCARD_FLAG_NE                        ((uint32_t)0x00000004)
437#define SMARTCARD_FLAG_FE                        ((uint32_t)0x00000002)
438#define SMARTCARD_FLAG_PE                        ((uint32_t)0x00000001)
439/**
440  * @}
441  */
442
443/** @defgroup SMARTCARD_Interrupt_definition SMARTCARD Interrupt definition
444  *        Elements values convention: 0000ZZZZ0XXYYYYYb
445  *           - YYYYY  : Interrupt source position in the XX register (5bits)
446  *           - XX  : Interrupt source register (2bits)
447  *                 - 01: CR1 register
448  *                 - 10: CR2 register
449  *                 - 11: CR3 register
450  *           - ZZZZ  : Flag position in the ISR register(4bits)
451  * @{
452  */
453
454#define SMARTCARD_IT_PE                          ((uint16_t)0x0028)
455#define SMARTCARD_IT_TXE                         ((uint16_t)0x0727)
456#define SMARTCARD_IT_TC                          ((uint16_t)0x0626)
457#define SMARTCARD_IT_RXNE                        ((uint16_t)0x0525)
458#define SMARTCARD_IT_IDLE                        ((uint16_t)0x0424)
459#define SMARTCARD_IT_ERR                         ((uint16_t)0x0060)
460#define SMARTCARD_IT_ORE                         ((uint16_t)0x0300)
461#define SMARTCARD_IT_NE                          ((uint16_t)0x0200)
462#define SMARTCARD_IT_FE                          ((uint16_t)0x0100)
463
464#define SMARTCARD_IT_EOB                         ((uint16_t)0x0C3B)
465#define SMARTCARD_IT_RTO                         ((uint16_t)0x0B3A)
466/**
467  * @}
468  */
469
470
471/** @defgroup SMARTCARD_IT_CLEAR_Flags SMARTCARD IT CLEAR Flags
472  * @{
473  */
474#define SMARTCARD_CLEAR_PEF                       USART_ICR_PECF            /*!< Parity Error Clear Flag */
475#define SMARTCARD_CLEAR_FEF                       USART_ICR_FECF            /*!< Framing Error Clear Flag */
476#define SMARTCARD_CLEAR_NEF                       USART_ICR_NCF             /*!< Noise detected Clear Flag */
477#define SMARTCARD_CLEAR_OREF                      USART_ICR_ORECF           /*!< OverRun Error Clear Flag */
478#define SMARTCARD_CLEAR_IDLEF                     USART_ICR_IDLECF          /*!< Idle line detected clear Flag */
479#define SMARTCARD_CLEAR_TCF                       USART_ICR_TCCF            /*!< Transmission Complete Clear Flag */
480#define SMARTCARD_CLEAR_RTOF                      USART_ICR_RTOCF           /*!< Receiver Time Out Clear Flag */
481#define SMARTCARD_CLEAR_EOBF                      USART_ICR_EOBCF           /*!< End Of Block Clear Flag */
482/**
483  * @}
484  */
485
486/** @defgroup SMARTCARD_Request_Parameters SMARTCARD Request Parameters
487  * @{
488  */
489#define SMARTCARD_RXDATA_FLUSH_REQUEST        ((uint32_t)USART_RQR_RXFRQ)        /*!< Receive Data flush Request */
490#define SMARTCARD_TXDATA_FLUSH_REQUEST        ((uint32_t)USART_RQR_TXFRQ)        /*!< Transmit data flush Request */
491/**
492  * @}
493  */
494
495
496/** @defgroup SMARTCARD_CR3_SCAR_CNT_LSB_POS SMARTCARD CR3 SCAR CNT LSB POS
497  * @{
498  */
499#define SMARTCARD_CR3_SCARCNT_LSB_POS            ((uint32_t) 17)
500/**
501  * @}
502  */
503
504/** @defgroup SMARTCARD_GTPR_GT_LSBPOS SMARTCARD GTPR GT LSBPOS
505  * @{
506  */
507#define SMARTCARD_GTPR_GT_LSB_POS            ((uint32_t) 8)
508/**
509  * @}
510  */
511
512/** @defgroup SMARTCARD_RTOR_BLEN_LSBPOS SMARTCARD RTOR BLEN LSBPOS
513  * @{
514  */
515#define SMARTCARD_RTOR_BLEN_LSB_POS          ((uint32_t) 24)
516/**
517  * @}
518  */
519
520/** @defgroup SMARTCARD_Interruption_Mask SMARTCARD Interruption Mask
521  * @{
522  */
523#define SMARTCARD_IT_MASK  ((uint16_t)0x001F)
524/**
525  * @}
526  */
527
528/**
529  * @}
530  */
531
532/* Exported macro ------------------------------------------------------------*/
533/** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
534  * @{
535  */
536
537/** @brief Reset SMARTCARD handle state
538  * @param  __HANDLE__: specifies the SMARTCARD Handle.
539  *         The Handle Instance which can be USART1 or USART2
540  * @retval None
541  */
542#define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMARTCARD_STATE_RESET)
543
544/** @brief  Flush the Smartcard DR register
545  * @param  __HANDLE__: specifies the SMARTCARD Handle.
546  *         The Handle Instance which can be USART1 or USART2.
547  * @retval None
548  */
549#define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) (__HAL_SMARTCARD_SEND_REQ((__HANDLE__), SMARTCARD_RXDATA_FLUSH_REQUEST))
550
551/** @brief  Checks whether the specified Smartcard flag is set or not.
552  * @param  __HANDLE__: specifies the SMARTCARD Handle.
553  *         The Handle Instance which can be USART1 or USART2.
554  * @param  __FLAG__: specifies the flag to check.
555  *        This parameter can be one of the following values:
556  *            @arg SMARTCARD_FLAG_REACK: Receive enable acknowledge flag
557  *            @arg SMARTCARD_FLAG_TEACK: Transmit enable acknowledge flag
558  *            @arg SMARTCARD_FLAG_BUSY:  Busy flag
559  *            @arg SMARTCARD_FLAG_EOBF:  End of block flag
560  *            @arg SMARTCARD_FLAG_RTOF:  Receiver timeout flag
561  *            @arg SMARTCARD_FLAG_TXE:   Transmit data register empty flag
562  *            @arg SMARTCARD_FLAG_TC:    Transmission Complete flag
563  *            @arg SMARTCARD_FLAG_RXNE:  Receive data register not empty flag
564  *            @arg SMARTCARD_FLAG_ORE:   OverRun Error flag
565  *            @arg SMARTCARD_FLAG_NE:    Noise Error flag
566  *            @arg SMARTCARD_FLAG_FE:    Framing Error flag
567  *            @arg SMARTCARD_FLAG_PE:    Parity Error flag
568  * @retval The new state of __FLAG__ (TRUE or FALSE).
569  */
570#define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
571
572/** @brief  Enables the specified SmartCard interrupt.
573  * @param  __HANDLE__: specifies the SMARTCARD Handle.
574  *         The Handle Instance which can be USART1 or USART2.
575  * @param  __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
576  *          This parameter can be one of the following values:
577  *            @arg SMARTCARD_IT_EOBF: End Of Block interrupt
578  *            @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
579  *            @arg SMARTCARD_IT_TXE:  Transmit Data Register empty interrupt
580  *            @arg SMARTCARD_IT_TC:   Transmission complete interrupt
581  *            @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
582  *            @arg SMARTCARD_IT_PE:   Parity Error interrupt
583  *            @arg SMARTCARD_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
584  * @retval None
585  */
586#define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__)   (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
587                                                        ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
588                                                        ((__HANDLE__)->Instance->CR3 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
589/** @brief  Disables the specified SmartCard interrupt.
590  * @param  __HANDLE__: specifies the SMARTCARD Handle.
591  *         The Handle Instance which can be USART1 or USART2.
592  * @param  __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
593  *          This parameter can be one of the following values:
594  *            @arg SMARTCARD_IT_EOBF: End Of Block interrupt
595  *            @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
596  *            @arg SMARTCARD_IT_TXE:  Transmit Data Register empty interrupt
597  *            @arg SMARTCARD_IT_TC:   Transmission complete interrupt
598  *            @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
599  *            @arg SMARTCARD_IT_PE:   Parity Error interrupt
600  *            @arg SMARTCARD_IT_ERR:  Error interrupt(Frame error, noise error, overrun error)
601  * @retval None
602  */
603#define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__)  (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
604                                                        ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
605                                                        ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
606
607/** @brief  Checks whether the specified SmartCard interrupt has occurred or not.
608  * @param  __HANDLE__: specifies the SMARTCARD Handle.
609  *         The Handle Instance which can be USART1 or USART2.
610  * @param  __IT__: specifies the SMARTCARD interrupt to check.
611  *          This parameter can be one of the following values:
612  *            @arg SMARTCARD_IT_EOBF: End Of Block interrupt
613  *            @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
614  *            @arg SMARTCARD_IT_TXE:  Transmit Data Register empty interrupt
615  *            @arg SMARTCARD_IT_TC:   Transmission complete interrupt
616  *            @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
617  *            @arg SMARTCARD_IT_ORE:  OverRun Error interrupt
618  *            @arg SMARTCARD_IT_NE:   Noise Error interrupt
619  *            @arg SMARTCARD_IT_FE:   Framing Error interrupt
620  *            @arg SMARTCARD_IT_PE:   Parity Error interrupt
621  * @retval The new state of __IT__ (TRUE or FALSE).
622  */
623#define __HAL_SMARTCARD_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
624
625/** @brief  Checks whether the specified SmartCard interrupt interrupt source is enabled.
626  * @param  __HANDLE__: specifies the SMARTCARD Handle.
627  *         The Handle Instance which can be USART1 or USART2.
628  * @param  __IT__: specifies the SMARTCARD interrupt source to check.
629  *          This parameter can be one of the following values:
630  *            @arg SMARTCARD_IT_EOBF: End Of Block interrupt
631  *            @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
632  *            @arg SMARTCARD_IT_TXE:  Transmit Data Register empty interrupt
633  *            @arg SMARTCARD_IT_TC:   Transmission complete interrupt
634  *            @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
635  *            @arg SMARTCARD_IT_ORE:  OverRun Error interrupt
636  *            @arg SMARTCARD_IT_NE:   Noise Error interrupt
637  *            @arg SMARTCARD_IT_FE:   Framing Error interrupt
638  *            @arg SMARTCARD_IT_PE:   Parity Error interrupt
639  * @retval The new state of __IT__ (TRUE or FALSE).
640  */
641#define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
642                                                               (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << \
643                                                               (((uint16_t)(__IT__)) & SMARTCARD_IT_MASK)))
644
645
646/** @brief  Clears the specified SMARTCARD ISR flag, in setting the proper ICR register flag.
647  * @param  __HANDLE__: specifies the SMARTCARD Handle.
648  *         The Handle Instance which can be USART1 or USART2.
649  * @param  __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
650  *                       to clear the corresponding interrupt
651  *          This parameter can be one of the following values:
652  *            @arg USART_CLEAR_PEF: Parity Error Clear Flag
653  *            @arg USART_CLEAR_FEF: Framing Error Clear Flag
654  *            @arg USART_CLEAR_NEF: Noise detected Clear Flag
655  *            @arg USART_CLEAR_OREF: OverRun Error Clear Flag
656  *            @arg USART_CLEAR_TCF: Transmission Complete Clear Flag
657  *            @arg USART_CLEAR_RTOF: Receiver Time Out Clear Flag
658  *            @arg USART_CLEAR_EOBF: End Of Block Clear Flag
659  * @retval None
660  */
661#define __HAL_SMARTCARD_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
662
663/** @brief  Set a specific SMARTCARD request flag.
664  * @param  __HANDLE__: specifies the SMARTCARD Handle.
665  *         The Handle Instance which can be USART1 or USART2.
666  * @param  __REQ__: specifies the request flag to set
667  *          This parameter can be one of the following values:
668  *            @arg SMARTCARD_RXDATA_FLUSH_REQUEST: Receive Data flush Request
669  *            @arg SMARTCARD_TXDATA_FLUSH_REQUEST: Transmit data flush Request
670  *
671  * @retval None
672  */
673#define __HAL_SMARTCARD_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
674
675/** @brief  Enable the USART associated to the SMARTCARD Handle
676  * @param  __HANDLE__: specifies the SMARTCARD Handle.
677  *         The Handle Instance which can be USART1 or USART2.
678  * @retval None
679  */
680#define __HAL_SMARTCARD_ENABLE(__HANDLE__)               ( (__HANDLE__)->Instance->CR1 |=  USART_CR1_UE)
681
682/** @brief  Disable the USART associated to the SMARTCARD Handle
683  * @param  __HANDLE__: specifies the SMARTCARD Handle.
684  *         The Handle Instance which can be USART1 or USART2.
685  * @retval None
686  */
687#define __HAL_SMARTCARD_DISABLE(__HANDLE__)              ( (__HANDLE__)->Instance->CR1 &=  ~USART_CR1_UE)
688
689/** @brief  Macros to enable or disable the SmartCard DMA request.
690  * @param  __HANDLE__: specifies the SMARTCARD Handle.
691  *         The Handle Instance which can be USART1 or USART2.
692  * @param  __REQUEST__: specifies the SmartCard DMA request.
693  *          This parameter can be one of the following values:
694  *            @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
695  *            @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
696  */
697#define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__)    ((__HANDLE__)->Instance->CR3 |=  (__REQUEST__))
698#define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__)   ((__HANDLE__)->Instance->CR3 &=  ~(__REQUEST__))
699/**
700  * @}
701  */
702
703/* Include SMARTCARD HAL Extension module */
704#include "stm32f7xx_hal_smartcard_ex.h"
705/* Exported functions --------------------------------------------------------*/
706/** @addtogroup SMARTCARD_Exported_Functions
707  * @{
708  */
709
710/** @addtogroup SMARTCARD_Exported_Functions_Group1
711  * @{
712  */
713/* Initialization/de-initialization functions  **********************************/
714HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
715HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
716void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
717void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
718/**
719  * @}
720  */
721
722/** @addtogroup SMARTCARD_Exported_Functions_Group2
723  * @{
724  */
725/* IO operation functions *******************************************************/
726HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
727HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
728HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
729HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
730HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
731HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
732void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
733void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
734void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
735void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
736/**
737  * @}
738  */
739
740/** @addtogroup SMARTCARD_Exported_Functions_Group3
741  * @{
742  */
743/* Peripheral State functions  **************************************************/
744HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
745uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
746
747/**
748  * @}
749  */
750
751/**
752  * @}
753  */
754/* Private types -------------------------------------------------------------*/
755/* Private variables ---------------------------------------------------------*/
756/* Private constants ---------------------------------------------------------*/
757/** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
758  * @{
759  */
760
761#define IS_SMARTCARD_WORD_LENGTH(__LENGTH__) ((__LENGTH__) == SMARTCARD_WORDLENGTH_9B)
762#define IS_SMARTCARD_STOPBITS(__STOPBITS__) ((__STOPBITS__) == SMARTCARD_STOPBITS_1_5)
763#define IS_SMARTCARD_PARITY(__PARITY__) (((__PARITY__) == SMARTCARD_PARITY_EVEN) || \
764                                         ((__PARITY__) == SMARTCARD_PARITY_ODD))
765#define IS_SMARTCARD_MODE(__MODE__) ((((__MODE__) & (uint32_t)0xFFF3) == 0x00) && ((__MODE__) != (uint32_t)0x00))
766#define IS_SMARTCARD_POLARITY(__CPOL__) (((__CPOL__) == SMARTCARD_POLARITY_LOW) || ((__CPOL__) == SMARTCARD_POLARITY_HIGH))
767#define IS_SMARTCARD_PHASE(__CPHA__) (((__CPHA__) == SMARTCARD_PHASE_1EDGE) || ((__CPHA__) == SMARTCARD_PHASE_2EDGE))
768#define IS_SMARTCARD_LASTBIT(__LASTBIT__) (((__LASTBIT__) == SMARTCARD_LASTBIT_DISABLE) || \
769                                           ((__LASTBIT__) == SMARTCARD_LASTBIT_ENABLE))
770#define IS_SMARTCARD_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_DISABLE) || \
771                                                  ((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_ENABLE))
772#define IS_SMARTCARD_NACK(__NACK__) (((__NACK__) == SMARTCARD_NACK_ENABLE) || \
773                                     ((__NACK__) == SMARTCARD_NACK_DISABLE))
774#define IS_SMARTCARD_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == SMARTCARD_TIMEOUT_DISABLE) || \
775                                           ((__TIMEOUT__) == SMARTCARD_TIMEOUT_ENABLE))
776#define IS_SMARTCARD_ADVFEATURE_INIT(INIT)           ((INIT) <= (SMARTCARD_ADVFEATURE_NO_INIT | \
777                                                            SMARTCARD_ADVFEATURE_TXINVERT_INIT | \
778                                                            SMARTCARD_ADVFEATURE_RXINVERT_INIT | \
779                                                            SMARTCARD_ADVFEATURE_DATAINVERT_INIT | \
780                                                            SMARTCARD_ADVFEATURE_SWAP_INIT | \
781                                                            SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
782                                                            SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT   | \
783                                                            SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
784#define IS_SMARTCARD_ADVFEATURE_TXINV(TXINV) (((TXINV) == SMARTCARD_ADVFEATURE_TXINV_DISABLE) || \
785                                         ((TXINV) == SMARTCARD_ADVFEATURE_TXINV_ENABLE))
786#define IS_SMARTCARD_ADVFEATURE_RXINV(RXINV) (((RXINV) == SMARTCARD_ADVFEATURE_RXINV_DISABLE) || \
787                                         ((RXINV) == SMARTCARD_ADVFEATURE_RXINV_ENABLE))
788#define IS_SMARTCARD_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_DISABLE) || \
789                                             ((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_ENABLE))
790#define IS_SMARTCARD_ADVFEATURE_SWAP(SWAP) (((SWAP) == SMARTCARD_ADVFEATURE_SWAP_DISABLE) || \
791                                       ((SWAP) == SMARTCARD_ADVFEATURE_SWAP_ENABLE))
792#define IS_SMARTCARD_OVERRUN(OVERRUN)         (((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_ENABLE) || \
793                                          ((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_DISABLE))
794#define IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(DMA)      (((DMA) == SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR) || \
795                                                   ((DMA) == SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR))
796#define IS_SMARTCARD_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4500001)
797#define IS_SMARTCARD_BLOCKLENGTH(__LENGTH__) ((__LENGTH__) <= 0xFF)
798#define IS_SMARTCARD_TIMEOUT_VALUE(__TIMEOUTVALUE__)    ((__TIMEOUTVALUE__) <= 0xFFFFFF)
799#define IS_SMARTCARD_AUTORETRY_COUNT(__COUNT__)         ((__COUNT__) <= 0x7)
800#define IS_SMARTCARD_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE) || \
801                                               ((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE))
802#define IS_SMARTCARD_REQUEST_PARAMETER(PARAM) (((PARAM) == SMARTCARD_RXDATA_FLUSH_REQUEST) || \
803                                               ((PARAM) == SMARTCARD_TXDATA_FLUSH_REQUEST))
804
805
806/**
807  * @}
808  */
809
810/* Private functions ---------------------------------------------------------*/
811/** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
812  * @{
813  */
814
815/**
816  * @}
817  */
818
819/**
820  * @}
821  */
822
823/**
824  * @}
825  */
826
827#ifdef __cplusplus
828}
829#endif
830
831#endif /* __STM32F7xx_HAL_SMARTCARD_H */
832
833/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Note: See TracBrowser for help on using the repository browser.