2 ******************************************************************************
\r
3 * @file stm32f7xx_hal_smartcard.h
\r
4 * @author MCD Application Team
\r
6 * @date 24-March-2015
\r
7 * @brief Header file of SMARTCARD HAL module.
\r
8 ******************************************************************************
\r
11 * <h2><center>© COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
\r
13 * Redistribution and use in source and binary forms, with or without modification,
\r
14 * are permitted provided that the following conditions are met:
\r
15 * 1. Redistributions of source code must retain the above copyright notice,
\r
16 * this list of conditions and the following disclaimer.
\r
17 * 2. Redistributions in binary form must reproduce the above copyright notice,
\r
18 * this list of conditions and the following disclaimer in the documentation
\r
19 * and/or other materials provided with the distribution.
\r
20 * 3. Neither the name of STMicroelectronics nor the names of its contributors
\r
21 * may be used to endorse or promote products derived from this software
\r
22 * without specific prior written permission.
\r
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
\r
25 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
\r
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
\r
27 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
\r
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
\r
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
\r
30 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
\r
31 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
\r
32 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
\r
33 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
\r
35 ******************************************************************************
\r
38 /* Define to prevent recursive inclusion -------------------------------------*/
\r
39 #ifndef __STM32F7xx_HAL_SMARTCARD_H
\r
40 #define __STM32F7xx_HAL_SMARTCARD_H
\r
46 /* Includes ------------------------------------------------------------------*/
\r
47 #include "stm32f7xx_hal_def.h"
\r
49 /** @addtogroup STM32F7xx_HAL_Driver
\r
53 /** @addtogroup SMARTCARD
\r
57 /* Exported types ------------------------------------------------------------*/
\r
58 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
\r
63 * @brief SMARTCARD Init Structure definition
\r
67 uint32_t BaudRate; /*!< Configures the SmartCard communication baud rate.
\r
68 The baud rate register is computed using the following formula:
\r
69 Baud Rate Register = ((PCLKx) / ((hsc->Init.BaudRate))) */
\r
71 uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
\r
72 This parameter @ref SMARTCARD_Word_Length can only be set to 9 (8 data + 1 parity bits). */
\r
74 uint32_t StopBits; /*!< Specifies the number of stop bits @ref SMARTCARD_Stop_Bits.
\r
75 Only 1.5 stop bits are authorized in SmartCard mode. */
\r
77 uint32_t Parity; /*!< Specifies the parity mode.
\r
78 This parameter can be a value of @ref SMARTCARD_Parity
\r
79 @note The parity is enabled by default (PCE is forced to 1).
\r
80 Since the WordLength is forced to 8 bits + parity, M is
\r
81 forced to 1 and the parity bit is the 9th bit. */
\r
83 uint32_t Mode; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
\r
84 This parameter can be a value of @ref SMARTCARD_Mode */
\r
86 uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
\r
87 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
\r
89 uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
\r
90 This parameter can be a value of @ref SMARTCARD_Clock_Phase */
\r
92 uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
\r
93 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
\r
94 This parameter can be a value of @ref SMARTCARD_Last_Bit */
\r
96 uint32_t OneBitSampling; /*!< Specifies whether a single sample or three samples' majority vote is selected.
\r
97 Selecting the single sample method increases the receiver tolerance to clock
\r
98 deviations. This parameter can be a value of @ref SMARTCARD_OneBit_Sampling */
\r
100 uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler */
\r
102 uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time */
\r
104 uint32_t NACKState; /*!< Specifies whether the SmartCard NACK transmission is enabled
\r
105 in case of parity error.
\r
106 This parameter can be a value of @ref SmartCard_NACK_State */
\r
108 uint32_t TimeOutEnable; /*!< Specifies whether the receiver timeout is enabled.
\r
109 This parameter can be a value of @ref SMARTCARD_Timeout_Enable*/
\r
111 uint32_t TimeOutValue; /*!< Specifies the receiver time out value in number of baud blocks:
\r
112 it is used to implement the Character Wait Time (CWT) and
\r
113 Block Wait Time (BWT). It is coded over 24 bits. */
\r
115 uint32_t BlockLength; /*!< Specifies the SmartCard Block Length in T=1 Reception mode.
\r
116 This parameter can be any value from 0x0 to 0xFF */
\r
118 uint32_t AutoRetryCount; /*!< Specifies the SmartCard auto-retry count (number of retries in
\r
119 receive and transmit mode). When set to 0, retransmission is
\r
120 disabled. Otherwise, its maximum value is 7 (before signalling
\r
123 }SMARTCARD_InitTypeDef;
\r
126 * @brief SMARTCARD advanced features initalization structure definition
\r
130 uint32_t AdvFeatureInit; /*!< Specifies which advanced SMARTCARD features is initialized. Several
\r
131 advanced features may be initialized at the same time. This parameter
\r
132 can be a value of @ref SMARTCARD_Advanced_Features_Initialization_Type */
\r
134 uint32_t TxPinLevelInvert; /*!< Specifies whether the TX pin active level is inverted.
\r
135 This parameter can be a value of @ref SMARTCARD_Tx_Inv */
\r
137 uint32_t RxPinLevelInvert; /*!< Specifies whether the RX pin active level is inverted.
\r
138 This parameter can be a value of @ref SMARTCARD_Rx_Inv */
\r
140 uint32_t DataInvert; /*!< Specifies whether data are inverted (positive/direct logic
\r
141 vs negative/inverted logic).
\r
142 This parameter can be a value of @ref SMARTCARD_Data_Inv */
\r
144 uint32_t Swap; /*!< Specifies whether TX and RX pins are swapped.
\r
145 This parameter can be a value of @ref SMARTCARD_Rx_Tx_Swap */
\r
147 uint32_t OverrunDisable; /*!< Specifies whether the reception overrun detection is disabled.
\r
148 This parameter can be a value of @ref SMARTCARD_Overrun_Disable */
\r
150 uint32_t DMADisableonRxError; /*!< Specifies whether the DMA is disabled in case of reception error.
\r
151 This parameter can be a value of @ref SMARTCARD_DMA_Disable_on_Rx_Error */
\r
153 uint32_t MSBFirst; /*!< Specifies whether MSB is sent first on UART line.
\r
154 This parameter can be a value of @ref SMARTCARD_MSB_First */
\r
155 }SMARTCARD_AdvFeatureInitTypeDef;
\r
158 * @brief HAL State structures definition
\r
162 HAL_SMARTCARD_STATE_RESET = 0x00, /*!< Peripheral is not yet Initialized */
\r
163 HAL_SMARTCARD_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
\r
164 HAL_SMARTCARD_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
\r
165 HAL_SMARTCARD_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
\r
166 HAL_SMARTCARD_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
\r
167 HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
\r
168 HAL_SMARTCARD_STATE_TIMEOUT = 0x03, /*!< Timeout state */
\r
169 HAL_SMARTCARD_STATE_ERROR = 0x04 /*!< Error */
\r
170 }HAL_SMARTCARD_StateTypeDef;
\r
174 * @brief SMARTCARD clock sources definition
\r
178 SMARTCARD_CLOCKSOURCE_PCLK1 = 0x00, /*!< PCLK1 clock source */
\r
179 SMARTCARD_CLOCKSOURCE_PCLK2 = 0x01, /*!< PCLK2 clock source */
\r
180 SMARTCARD_CLOCKSOURCE_HSI = 0x02, /*!< HSI clock source */
\r
181 SMARTCARD_CLOCKSOURCE_SYSCLK = 0x04, /*!< SYSCLK clock source */
\r
182 SMARTCARD_CLOCKSOURCE_LSE = 0x08 /*!< LSE clock source */
\r
183 }SMARTCARD_ClockSourceTypeDef;
\r
186 * @brief SMARTCARD handle Structure definition
\r
190 USART_TypeDef *Instance; /* USART registers base address */
\r
192 SMARTCARD_InitTypeDef Init; /* SmartCard communication parameters */
\r
194 SMARTCARD_AdvFeatureInitTypeDef AdvancedInit; /* SmartCard advanced features initialization parameters */
\r
196 uint8_t *pTxBuffPtr; /* Pointer to SmartCard Tx transfer Buffer */
\r
198 uint16_t TxXferSize; /* SmartCard Tx Transfer size */
\r
200 uint16_t TxXferCount; /* SmartCard Tx Transfer Counter */
\r
202 uint8_t *pRxBuffPtr; /* Pointer to SmartCard Rx transfer Buffer */
\r
204 uint16_t RxXferSize; /* SmartCard Rx Transfer size */
\r
206 uint16_t RxXferCount; /* SmartCard Rx Transfer Counter */
\r
208 DMA_HandleTypeDef *hdmatx; /* SmartCard Tx DMA Handle parameters */
\r
210 DMA_HandleTypeDef *hdmarx; /* SmartCard Rx DMA Handle parameters */
\r
212 HAL_LockTypeDef Lock; /* Locking object */
\r
214 __IO HAL_SMARTCARD_StateTypeDef State; /* SmartCard communication state */
\r
216 __IO uint32_t ErrorCode; /* SmartCard Error code */
\r
218 }SMARTCARD_HandleTypeDef;
\r
223 /* Exported constants --------------------------------------------------------*/
\r
224 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants
\r
227 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
\r
228 * @brief SMARTCARD Error Code
\r
231 #define HAL_SMARTCARD_ERROR_NONE ((uint32_t)0x00) /*!< No error */
\r
232 #define HAL_SMARTCARD_ERROR_PE ((uint32_t)0x01) /*!< Parity error */
\r
233 #define HAL_SMARTCARD_ERROR_NE ((uint32_t)0x02) /*!< Noise error */
\r
234 #define HAL_SMARTCARD_ERROR_FE ((uint32_t)0x04) /*!< frame error */
\r
235 #define HAL_SMARTCARD_ERROR_ORE ((uint32_t)0x08) /*!< Overrun error */
\r
236 #define HAL_SMARTCARD_ERROR_DMA ((uint32_t)0x10) /*!< DMA transfer error */
\r
237 #define HAL_SMARTCARD_ERROR_RTO ((uint32_t)0x20) /*!< Receiver TimeOut error */
\r
242 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
\r
245 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M_0)
\r
250 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
\r
253 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP))
\r
258 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
\r
261 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
\r
262 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
\r
267 /** @defgroup SMARTCARD_Mode SMARTCARD Mode
\r
270 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
\r
271 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
\r
272 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
\r
277 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
\r
280 #define SMARTCARD_POLARITY_LOW ((uint32_t)0x0000)
\r
281 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
\r
286 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
\r
289 #define SMARTCARD_PHASE_1EDGE ((uint32_t)0x0000)
\r
290 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
\r
295 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
\r
298 #define SMARTCARD_LASTBIT_DISABLE ((uint32_t)0x0000)
\r
299 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
\r
304 /** @defgroup SMARTCARD_OneBit_Sampling SMARTCARD OneBit Sampling
\r
307 #define SMARTCARD_ONE_BIT_SAMPLE_DISABLE ((uint32_t)0x0000)
\r
308 #define SMARTCARD_ONE_BIT_SAMPLE_ENABLE ((uint32_t)USART_CR3_ONEBIT)
\r
314 /** @defgroup SmartCard_NACK_State SMARTCARD NACK State
\r
317 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
\r
318 #define SMARTCARD_NACK_DISABLE ((uint32_t)0x0000)
\r
323 /** @defgroup SMARTCARD_Timeout_Enable SMARTCARD Timeout Enable
\r
326 #define SMARTCARD_TIMEOUT_DISABLE ((uint32_t)0x00000000)
\r
327 #define SMARTCARD_TIMEOUT_ENABLE ((uint32_t)USART_CR2_RTOEN)
\r
332 /** @defgroup SmartCard_DMA_Requests SMARTCARD DMA requests
\r
336 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
\r
337 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
\r
343 /** @defgroup SMARTCARD_Advanced_Features_Initialization_Type SMARTCARD Advanced Features Initialization Type
\r
346 #define SMARTCARD_ADVFEATURE_NO_INIT ((uint32_t)0x00000000)
\r
347 #define SMARTCARD_ADVFEATURE_TXINVERT_INIT ((uint32_t)0x00000001)
\r
348 #define SMARTCARD_ADVFEATURE_RXINVERT_INIT ((uint32_t)0x00000002)
\r
349 #define SMARTCARD_ADVFEATURE_DATAINVERT_INIT ((uint32_t)0x00000004)
\r
350 #define SMARTCARD_ADVFEATURE_SWAP_INIT ((uint32_t)0x00000008)
\r
351 #define SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT ((uint32_t)0x00000010)
\r
352 #define SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT ((uint32_t)0x00000020)
\r
353 #define SMARTCARD_ADVFEATURE_MSBFIRST_INIT ((uint32_t)0x00000080)
\r
358 /** @defgroup SMARTCARD_Tx_Inv SMARTCARD Tx Inv
\r
361 #define SMARTCARD_ADVFEATURE_TXINV_DISABLE ((uint32_t)0x00000000)
\r
362 #define SMARTCARD_ADVFEATURE_TXINV_ENABLE ((uint32_t)USART_CR2_TXINV)
\r
367 /** @defgroup SMARTCARD_Rx_Inv SMARTCARD Rx Inv
\r
370 #define SMARTCARD_ADVFEATURE_RXINV_DISABLE ((uint32_t)0x00000000)
\r
371 #define SMARTCARD_ADVFEATURE_RXINV_ENABLE ((uint32_t)USART_CR2_RXINV)
\r
376 /** @defgroup SMARTCARD_Data_Inv SMARTCARD Data Inv
\r
379 #define SMARTCARD_ADVFEATURE_DATAINV_DISABLE ((uint32_t)0x00000000)
\r
380 #define SMARTCARD_ADVFEATURE_DATAINV_ENABLE ((uint32_t)USART_CR2_DATAINV)
\r
385 /** @defgroup SMARTCARD_Rx_Tx_Swap SMARTCARD Rx Tx Swap
\r
388 #define SMARTCARD_ADVFEATURE_SWAP_DISABLE ((uint32_t)0x00000000)
\r
389 #define SMARTCARD_ADVFEATURE_SWAP_ENABLE ((uint32_t)USART_CR2_SWAP)
\r
394 /** @defgroup SMARTCARD_Overrun_Disable SMARTCARD Overrun Disable
\r
397 #define SMARTCARD_ADVFEATURE_OVERRUN_ENABLE ((uint32_t)0x00000000)
\r
398 #define SMARTCARD_ADVFEATURE_OVERRUN_DISABLE ((uint32_t)USART_CR3_OVRDIS)
\r
403 /** @defgroup SMARTCARD_DMA_Disable_on_Rx_Error SMARTCARD DMA Disable on Rx Error
\r
406 #define SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR ((uint32_t)0x00000000)
\r
407 #define SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR ((uint32_t)USART_CR3_DDRE)
\r
412 /** @defgroup SMARTCARD_MSB_First SMARTCARD MSB First
\r
415 #define SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE ((uint32_t)0x00000000)
\r
416 #define SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE ((uint32_t)USART_CR2_MSBFIRST)
\r
421 /** @defgroup SmartCard_Flags SMARTCARD Flags
\r
422 * Elements values convention: 0xXXXX
\r
423 * - 0xXXXX : Flag mask in the ISR register
\r
426 #define SMARTCARD_FLAG_REACK ((uint32_t)0x00400000)
\r
427 #define SMARTCARD_FLAG_TEACK ((uint32_t)0x00200000)
\r
428 #define SMARTCARD_FLAG_BUSY ((uint32_t)0x00010000)
\r
429 #define SMARTCARD_FLAG_EOBF ((uint32_t)0x00001000)
\r
430 #define SMARTCARD_FLAG_RTOF ((uint32_t)0x00000800)
\r
431 #define SMARTCARD_FLAG_TXE ((uint32_t)0x00000080)
\r
432 #define SMARTCARD_FLAG_TC ((uint32_t)0x00000040)
\r
433 #define SMARTCARD_FLAG_RXNE ((uint32_t)0x00000020)
\r
434 #define SMARTCARD_FLAG_ORE ((uint32_t)0x00000008)
\r
435 #define SMARTCARD_FLAG_NE ((uint32_t)0x00000004)
\r
436 #define SMARTCARD_FLAG_FE ((uint32_t)0x00000002)
\r
437 #define SMARTCARD_FLAG_PE ((uint32_t)0x00000001)
\r
442 /** @defgroup SMARTCARD_Interrupt_definition SMARTCARD Interrupt definition
\r
443 * Elements values convention: 0000ZZZZ0XXYYYYYb
\r
444 * - YYYYY : Interrupt source position in the XX register (5bits)
\r
445 * - XX : Interrupt source register (2bits)
\r
446 * - 01: CR1 register
\r
447 * - 10: CR2 register
\r
448 * - 11: CR3 register
\r
449 * - ZZZZ : Flag position in the ISR register(4bits)
\r
453 #define SMARTCARD_IT_PE ((uint16_t)0x0028)
\r
454 #define SMARTCARD_IT_TXE ((uint16_t)0x0727)
\r
455 #define SMARTCARD_IT_TC ((uint16_t)0x0626)
\r
456 #define SMARTCARD_IT_RXNE ((uint16_t)0x0525)
\r
458 #define SMARTCARD_IT_ERR ((uint16_t)0x0060)
\r
459 #define SMARTCARD_IT_ORE ((uint16_t)0x0300)
\r
460 #define SMARTCARD_IT_NE ((uint16_t)0x0200)
\r
461 #define SMARTCARD_IT_FE ((uint16_t)0x0100)
\r
463 #define SMARTCARD_IT_EOB ((uint16_t)0x0C3B)
\r
464 #define SMARTCARD_IT_RTO ((uint16_t)0x0B3A)
\r
470 /** @defgroup SMARTCARD_IT_CLEAR_Flags SMARTCARD IT CLEAR Flags
\r
473 #define SMARTCARD_CLEAR_PEF USART_ICR_PECF /*!< Parity Error Clear Flag */
\r
474 #define SMARTCARD_CLEAR_FEF USART_ICR_FECF /*!< Framing Error Clear Flag */
\r
475 #define SMARTCARD_CLEAR_NEF USART_ICR_NCF /*!< Noise detected Clear Flag */
\r
476 #define SMARTCARD_CLEAR_OREF USART_ICR_ORECF /*!< OverRun Error Clear Flag */
\r
477 #define SMARTCARD_CLEAR_TCF USART_ICR_TCCF /*!< Transmission Complete Clear Flag */
\r
478 #define SMARTCARD_CLEAR_RTOF USART_ICR_RTOCF /*!< Receiver Time Out Clear Flag */
\r
479 #define SMARTCARD_CLEAR_EOBF USART_ICR_EOBCF /*!< End Of Block Clear Flag */
\r
484 /** @defgroup SMARTCARD_Request_Parameters SMARTCARD Request Parameters
\r
487 #define SMARTCARD_RXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_RXFRQ) /*!< Receive Data flush Request */
\r
488 #define SMARTCARD_TXDATA_FLUSH_REQUEST ((uint32_t)USART_RQR_TXFRQ) /*!< Transmit data flush Request */
\r
494 /** @defgroup SMARTCARD_CR3_SCAR_CNT_LSB_POS SMARTCARD CR3 SCAR CNT LSB POS
\r
497 #define SMARTCARD_CR3_SCARCNT_LSB_POS ((uint32_t) 17)
\r
502 /** @defgroup SMARTCARD_GTPR_GT_LSBPOS SMARTCARD GTPR GT LSBPOS
\r
505 #define SMARTCARD_GTPR_GT_LSB_POS ((uint32_t) 8)
\r
510 /** @defgroup SMARTCARD_RTOR_BLEN_LSBPOS SMARTCARD RTOR BLEN LSBPOS
\r
513 #define SMARTCARD_RTOR_BLEN_LSB_POS ((uint32_t) 24)
\r
518 /** @defgroup SMARTCARD_Interruption_Mask SMARTCARD Interruption Mask
\r
521 #define SMARTCARD_IT_MASK ((uint16_t)0x001F)
\r
530 /* Exported macro ------------------------------------------------------------*/
\r
531 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
\r
535 /** @brief Reset SMARTCARD handle state
\r
536 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
537 * The Handle Instance which can be USART1 or USART2
\r
540 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMARTCARD_STATE_RESET)
\r
542 /** @brief Flush the Smartcard DR register
\r
543 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
544 * The Handle Instance which can be USART1 or USART2.
\r
547 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) (__HAL_SMARTCARD_SEND_REQ((__HANDLE__), SMARTCARD_RXDATA_FLUSH_REQUEST))
\r
549 /** @brief Checks whether the specified Smartcard flag is set or not.
\r
550 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
551 * The Handle Instance which can be USART1 or USART2.
\r
552 * @param __FLAG__: specifies the flag to check.
\r
553 * This parameter can be one of the following values:
\r
554 * @arg SMARTCARD_FLAG_REACK: Receive enable acknowledge flag
\r
555 * @arg SMARTCARD_FLAG_TEACK: Transmit enable acknowledge flag
\r
556 * @arg SMARTCARD_FLAG_BUSY: Busy flag
\r
557 * @arg SMARTCARD_FLAG_EOBF: End of block flag
\r
558 * @arg SMARTCARD_FLAG_RTOF: Receiver timeout flag
\r
559 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
\r
560 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
\r
561 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
\r
562 * @arg SMARTCARD_FLAG_ORE: OverRun Error flag
\r
563 * @arg SMARTCARD_FLAG_NE: Noise Error flag
\r
564 * @arg SMARTCARD_FLAG_FE: Framing Error flag
\r
565 * @arg SMARTCARD_FLAG_PE: Parity Error flag
\r
566 * @retval The new state of __FLAG__ (TRUE or FALSE).
\r
568 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->ISR & (__FLAG__)) == (__FLAG__))
\r
570 /** @brief Enables the specified SmartCard interrupt.
\r
571 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
572 * The Handle Instance which can be USART1 or USART2.
\r
573 * @param __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
\r
574 * This parameter can be one of the following values:
\r
575 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
\r
576 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
\r
577 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
\r
578 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
\r
579 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
\r
580 * @arg SMARTCARD_IT_PE: Parity Error interrupt
\r
581 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
\r
584 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
\r
585 ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
\r
586 ((__HANDLE__)->Instance->CR3 |= (1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
\r
587 /** @brief Disables the specified SmartCard interrupt.
\r
588 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
589 * The Handle Instance which can be USART1 or USART2.
\r
590 * @param __INTERRUPT__: specifies the SMARTCARD interrupt to enable.
\r
591 * This parameter can be one of the following values:
\r
592 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
\r
593 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
\r
594 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
\r
595 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
\r
596 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
\r
597 * @arg SMARTCARD_IT_PE: Parity Error interrupt
\r
598 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
\r
601 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) (((((uint8_t)(__INTERRUPT__)) >> 5) == 1)? ((__HANDLE__)->Instance->CR1 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
\r
602 ((((uint8_t)(__INTERRUPT__)) >> 5) == 2)? ((__HANDLE__)->Instance->CR2 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))): \
\r
603 ((__HANDLE__)->Instance->CR3 &= ~ ((uint32_t)1 << ((__INTERRUPT__) & SMARTCARD_IT_MASK))))
\r
605 /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
\r
606 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
607 * The Handle Instance which can be USART1 or USART2.
\r
608 * @param __IT__: specifies the SMARTCARD interrupt to check.
\r
609 * This parameter can be one of the following values:
\r
610 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
\r
611 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
\r
612 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
\r
613 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
\r
614 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
\r
615 * @arg SMARTCARD_IT_ORE: OverRun Error interrupt
\r
616 * @arg SMARTCARD_IT_NE: Noise Error interrupt
\r
617 * @arg SMARTCARD_IT_FE: Framing Error interrupt
\r
618 * @arg SMARTCARD_IT_PE: Parity Error interrupt
\r
619 * @retval The new state of __IT__ (TRUE or FALSE).
\r
621 #define __HAL_SMARTCARD_GET_IT(__HANDLE__, __IT__) ((__HANDLE__)->Instance->ISR & ((uint32_t)1 << ((__IT__)>> 0x08)))
\r
623 /** @brief Checks whether the specified SmartCard interrupt interrupt source is enabled.
\r
624 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
625 * The Handle Instance which can be USART1 or USART2.
\r
626 * @param __IT__: specifies the SMARTCARD interrupt source to check.
\r
627 * This parameter can be one of the following values:
\r
628 * @arg SMARTCARD_IT_EOBF: End Of Block interrupt
\r
629 * @arg SMARTCARD_IT_RTOF: Receive TimeOut interrupt
\r
630 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
\r
631 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
\r
632 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
\r
633 * @arg SMARTCARD_IT_ORE: OverRun Error interrupt
\r
634 * @arg SMARTCARD_IT_NE: Noise Error interrupt
\r
635 * @arg SMARTCARD_IT_FE: Framing Error interrupt
\r
636 * @arg SMARTCARD_IT_PE: Parity Error interrupt
\r
637 * @retval The new state of __IT__ (TRUE or FALSE).
\r
639 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) ((((((uint8_t)(__IT__)) >> 5) == 1)? (__HANDLE__)->Instance->CR1:(((((uint8_t)(__IT__)) >> 5) == 2)? \
\r
640 (__HANDLE__)->Instance->CR2 : (__HANDLE__)->Instance->CR3)) & ((uint32_t)1 << \
\r
641 (((uint16_t)(__IT__)) & SMARTCARD_IT_MASK)))
\r
644 /** @brief Clears the specified SMARTCARD ISR flag, in setting the proper ICR register flag.
\r
645 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
646 * The Handle Instance which can be USART1 or USART2.
\r
647 * @param __IT_CLEAR__: specifies the interrupt clear register flag that needs to be set
\r
648 * to clear the corresponding interrupt
\r
649 * This parameter can be one of the following values:
\r
650 * @arg USART_CLEAR_PEF: Parity Error Clear Flag
\r
651 * @arg USART_CLEAR_FEF: Framing Error Clear Flag
\r
652 * @arg USART_CLEAR_NEF: Noise detected Clear Flag
\r
653 * @arg USART_CLEAR_OREF: OverRun Error Clear Flag
\r
654 * @arg USART_CLEAR_TCF: Transmission Complete Clear Flag
\r
655 * @arg USART_CLEAR_RTOF: Receiver Time Out Clear Flag
\r
656 * @arg USART_CLEAR_EOBF: End Of Block Clear Flag
\r
659 #define __HAL_SMARTCARD_CLEAR_IT(__HANDLE__, __IT_CLEAR__) ((__HANDLE__)->Instance->ICR = (uint32_t)(__IT_CLEAR__))
\r
661 /** @brief Set a specific SMARTCARD request flag.
\r
662 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
663 * The Handle Instance which can be USART1 or USART2.
\r
664 * @param __REQ__: specifies the request flag to set
\r
665 * This parameter can be one of the following values:
\r
666 * @arg SMARTCARD_RXDATA_FLUSH_REQUEST: Receive Data flush Request
\r
667 * @arg SMARTCARD_TXDATA_FLUSH_REQUEST: Transmit data flush Request
\r
671 #define __HAL_SMARTCARD_SEND_REQ(__HANDLE__, __REQ__) ((__HANDLE__)->Instance->RQR |= (uint32_t)(__REQ__))
\r
673 /** @brief Enable the USART associated to the SMARTCARD Handle
\r
674 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
675 * The Handle Instance which can be USART1 or USART2.
\r
678 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
\r
680 /** @brief Disable the USART associated to the SMARTCARD Handle
\r
681 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
682 * The Handle Instance which can be USART1 or USART2.
\r
685 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ( (__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
\r
687 /** @brief Macros to enable or disable the SmartCard DMA request.
\r
688 * @param __HANDLE__: specifies the SMARTCARD Handle.
\r
689 * The Handle Instance which can be USART1 or USART2.
\r
690 * @param __REQUEST__: specifies the SmartCard DMA request.
\r
691 * This parameter can be one of the following values:
\r
692 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
\r
693 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
\r
695 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
\r
696 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
\r
701 /* Include SMARTCARD HAL Extension module */
\r
702 #include "stm32f7xx_hal_smartcard_ex.h"
\r
703 /* Exported functions --------------------------------------------------------*/
\r
704 /** @addtogroup SMARTCARD_Exported_Functions
\r
708 /** @addtogroup SMARTCARD_Exported_Functions_Group1
\r
711 /* Initialization/de-initialization functions **********************************/
\r
712 HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
\r
713 HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
\r
714 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
\r
715 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
\r
720 /** @addtogroup SMARTCARD_Exported_Functions_Group2
\r
723 /* IO operation functions *******************************************************/
\r
724 HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
\r
725 HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
\r
726 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
\r
727 HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
\r
728 HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
\r
729 HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
\r
730 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
\r
731 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
\r
732 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
\r
733 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
\r
738 /** @addtogroup SMARTCARD_Exported_Functions_Group3
\r
741 /* Peripheral State functions **************************************************/
\r
742 HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
\r
743 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
\r
752 /* Private types -------------------------------------------------------------*/
\r
753 /* Private variables ---------------------------------------------------------*/
\r
754 /* Private constants ---------------------------------------------------------*/
\r
755 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
\r
759 #define IS_SMARTCARD_WORD_LENGTH(__LENGTH__) ((__LENGTH__) == SMARTCARD_WORDLENGTH_9B)
\r
760 #define IS_SMARTCARD_STOPBITS(__STOPBITS__) ((__STOPBITS__) == SMARTCARD_STOPBITS_1_5)
\r
761 #define IS_SMARTCARD_PARITY(__PARITY__) (((__PARITY__) == SMARTCARD_PARITY_EVEN) || \
\r
762 ((__PARITY__) == SMARTCARD_PARITY_ODD))
\r
763 #define IS_SMARTCARD_MODE(__MODE__) ((((__MODE__) & (uint32_t)0xFFF3) == 0x00) && ((__MODE__) != (uint32_t)0x00))
\r
764 #define IS_SMARTCARD_POLARITY(__CPOL__) (((__CPOL__) == SMARTCARD_POLARITY_LOW) || ((__CPOL__) == SMARTCARD_POLARITY_HIGH))
\r
765 #define IS_SMARTCARD_PHASE(__CPHA__) (((__CPHA__) == SMARTCARD_PHASE_1EDGE) || ((__CPHA__) == SMARTCARD_PHASE_2EDGE))
\r
766 #define IS_SMARTCARD_LASTBIT(__LASTBIT__) (((__LASTBIT__) == SMARTCARD_LASTBIT_DISABLE) || \
\r
767 ((__LASTBIT__) == SMARTCARD_LASTBIT_ENABLE))
\r
768 #define IS_SMARTCARD_ONE_BIT_SAMPLE(__ONEBIT__) (((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_DISABLE) || \
\r
769 ((__ONEBIT__) == SMARTCARD_ONE_BIT_SAMPLE_ENABLE))
\r
770 #define IS_SMARTCARD_NACK(__NACK__) (((__NACK__) == SMARTCARD_NACK_ENABLE) || \
\r
771 ((__NACK__) == SMARTCARD_NACK_DISABLE))
\r
772 #define IS_SMARTCARD_TIMEOUT(__TIMEOUT__) (((__TIMEOUT__) == SMARTCARD_TIMEOUT_DISABLE) || \
\r
773 ((__TIMEOUT__) == SMARTCARD_TIMEOUT_ENABLE))
\r
774 #define IS_SMARTCARD_ADVFEATURE_INIT(INIT) ((INIT) <= (SMARTCARD_ADVFEATURE_NO_INIT | \
\r
775 SMARTCARD_ADVFEATURE_TXINVERT_INIT | \
\r
776 SMARTCARD_ADVFEATURE_RXINVERT_INIT | \
\r
777 SMARTCARD_ADVFEATURE_DATAINVERT_INIT | \
\r
778 SMARTCARD_ADVFEATURE_SWAP_INIT | \
\r
779 SMARTCARD_ADVFEATURE_RXOVERRUNDISABLE_INIT | \
\r
780 SMARTCARD_ADVFEATURE_DMADISABLEONERROR_INIT | \
\r
781 SMARTCARD_ADVFEATURE_MSBFIRST_INIT))
\r
782 #define IS_SMARTCARD_ADVFEATURE_TXINV(TXINV) (((TXINV) == SMARTCARD_ADVFEATURE_TXINV_DISABLE) || \
\r
783 ((TXINV) == SMARTCARD_ADVFEATURE_TXINV_ENABLE))
\r
784 #define IS_SMARTCARD_ADVFEATURE_RXINV(RXINV) (((RXINV) == SMARTCARD_ADVFEATURE_RXINV_DISABLE) || \
\r
785 ((RXINV) == SMARTCARD_ADVFEATURE_RXINV_ENABLE))
\r
786 #define IS_SMARTCARD_ADVFEATURE_DATAINV(DATAINV) (((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_DISABLE) || \
\r
787 ((DATAINV) == SMARTCARD_ADVFEATURE_DATAINV_ENABLE))
\r
788 #define IS_SMARTCARD_ADVFEATURE_SWAP(SWAP) (((SWAP) == SMARTCARD_ADVFEATURE_SWAP_DISABLE) || \
\r
789 ((SWAP) == SMARTCARD_ADVFEATURE_SWAP_ENABLE))
\r
790 #define IS_SMARTCARD_OVERRUN(OVERRUN) (((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_ENABLE) || \
\r
791 ((OVERRUN) == SMARTCARD_ADVFEATURE_OVERRUN_DISABLE))
\r
792 #define IS_SMARTCARD_ADVFEATURE_DMAONRXERROR(DMA) (((DMA) == SMARTCARD_ADVFEATURE_DMA_ENABLEONRXERROR) || \
\r
793 ((DMA) == SMARTCARD_ADVFEATURE_DMA_DISABLEONRXERROR))
\r
794 #define IS_SMARTCARD_BAUDRATE(__BAUDRATE__) ((__BAUDRATE__) < 4500001)
\r
795 #define IS_SMARTCARD_BLOCKLENGTH(__LENGTH__) ((__LENGTH__) <= 0xFF)
\r
796 #define IS_SMARTCARD_TIMEOUT_VALUE(__TIMEOUTVALUE__) ((__TIMEOUTVALUE__) <= 0xFFFFFF)
\r
797 #define IS_SMARTCARD_AUTORETRY_COUNT(__COUNT__) ((__COUNT__) <= 0x7)
\r
798 #define IS_SMARTCARD_ADVFEATURE_MSBFIRST(MSBFIRST) (((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_DISABLE) || \
\r
799 ((MSBFIRST) == SMARTCARD_ADVFEATURE_MSBFIRST_ENABLE))
\r
800 #define IS_SMARTCARD_REQUEST_PARAMETER(PARAM) (((PARAM) == SMARTCARD_RXDATA_FLUSH_REQUEST) || \
\r
801 ((PARAM) == SMARTCARD_TXDATA_FLUSH_REQUEST))
\r
808 /* Private functions ---------------------------------------------------------*/
\r
809 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
\r
829 #endif /* __STM32F7xx_HAL_SMARTCARD_H */
\r
831 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
\r