2 ******************************************************************************
3 * @file stm32f4xx_hal_smartcard.h
4 * @author MCD Application Team
7 * @brief Header file of SMARTCARD HAL module.
8 ******************************************************************************
11 * <h2><center>© COPYRIGHT(c) 2017 STMicroelectronics</center></h2>
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.
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.
35 ******************************************************************************
38 /* Define to prevent recursive inclusion -------------------------------------*/
39 #ifndef __STM32F4xx_HAL_SMARTCARD_H
40 #define __STM32F4xx_HAL_SMARTCARD_H
46 /* Includes ------------------------------------------------------------------*/
47 #include "stm32f4xx_hal_def.h"
49 /** @addtogroup STM32F4xx_HAL_Driver
53 /** @addtogroup SMARTCARD
57 /* Exported types ------------------------------------------------------------*/
58 /** @defgroup SMARTCARD_Exported_Types SMARTCARD Exported Types
63 * @brief SMARTCARD Init Structure definition
67 uint32_t BaudRate
; /*!< This member configures the SmartCard communication baud rate.
68 The baud rate is computed using the following formula:
69 - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
70 - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
72 uint32_t WordLength
; /*!< Specifies the number of data bits transmitted or received in a frame.
73 This parameter can be a value of @ref SMARTCARD_Word_Length */
75 uint32_t StopBits
; /*!< Specifies the number of stop bits transmitted.
76 This parameter can be a value of @ref SMARTCARD_Stop_Bits */
78 uint32_t Parity
; /*!< Specifies the parity mode.
79 This parameter can be a value of @ref SMARTCARD_Parity
80 @note When parity is enabled, the computed parity is inserted
81 at the MSB position of the transmitted data (9th bit when
82 the word length is set to 9 data bits; 8th bit when the
83 word length is set to 8 data bits).*/
85 uint32_t Mode
; /*!< Specifies whether the Receive or Transmit mode is enabled or disabled.
86 This parameter can be a value of @ref SMARTCARD_Mode */
88 uint32_t CLKPolarity
; /*!< Specifies the steady state of the serial clock.
89 This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
91 uint32_t CLKPhase
; /*!< Specifies the clock transition on which the bit capture is made.
92 This parameter can be a value of @ref SMARTCARD_Clock_Phase */
94 uint32_t CLKLastBit
; /*!< Specifies whether the clock pulse corresponding to the last transmitted
95 data bit (MSB) has to be output on the SCLK pin in synchronous mode.
96 This parameter can be a value of @ref SMARTCARD_Last_Bit */
98 uint32_t Prescaler
; /*!< Specifies the SmartCard Prescaler value used for dividing the system clock
99 to provide the smartcard clock. The value given in the register (5 significant bits)
100 is multiplied by 2 to give the division factor of the source clock frequency.
101 This parameter can be a value of @ref SMARTCARD_Prescaler */
103 uint32_t GuardTime
; /*!< Specifies the SmartCard Guard Time value in terms of number of baud clocks */
105 uint32_t NACKState
; /*!< Specifies the SmartCard NACK Transmission state.
106 This parameter can be a value of @ref SMARTCARD_NACK_State */
107 }SMARTCARD_InitTypeDef
;
110 * @brief HAL SMARTCARD State structures definition
111 * @note HAL SMARTCARD State value is a combination of 2 different substates: gState and RxState.
112 * - gState contains SMARTCARD state information related to global Handle management
113 * and also information related to Tx operations.
114 * gState value coding follow below described bitmap :
115 * b7-b6 Error information
120 * b5 IP initilisation status
121 * 0 : Reset (IP not initialized)
122 * 1 : Init done (IP not initialized. HAL SMARTCARD Init function already called)
124 * xx : Should be set to 00
125 * b2 Intrinsic process state
127 * 1 : Busy (IP busy with some configuration or internal operations)
129 * x : Should be set to 0
131 * 0 : Ready (no Tx operation ongoing)
132 * 1 : Busy (Tx operation ongoing)
133 * - RxState contains information related to Rx operations.
134 * RxState value coding follow below described bitmap :
136 * xx : Should be set to 00
137 * b5 IP initilisation status
138 * 0 : Reset (IP not initialized)
139 * 1 : Init done (IP not initialized)
141 * xxx : Should be set to 000
143 * 0 : Ready (no Rx operation ongoing)
144 * 1 : Busy (Rx operation ongoing)
146 * x : Should be set to 0.
150 HAL_SMARTCARD_STATE_RESET
= 0x00U
, /*!< Peripheral is not yet Initialized
151 Value is allowed for gState and RxState */
152 HAL_SMARTCARD_STATE_READY
= 0x20U
, /*!< Peripheral Initialized and ready for use
153 Value is allowed for gState and RxState */
154 HAL_SMARTCARD_STATE_BUSY
= 0x24U
, /*!< an internal process is ongoing
155 Value is allowed for gState only */
156 HAL_SMARTCARD_STATE_BUSY_TX
= 0x21U
, /*!< Data Transmission process is ongoing
157 Value is allowed for gState only */
158 HAL_SMARTCARD_STATE_BUSY_RX
= 0x22U
, /*!< Data Reception process is ongoing
159 Value is allowed for RxState only */
160 HAL_SMARTCARD_STATE_BUSY_TX_RX
= 0x23U
, /*!< Data Transmission and Reception process is ongoing
161 Not to be used for neither gState nor RxState.
162 Value is result of combination (Or) between gState and RxState values */
163 HAL_SMARTCARD_STATE_TIMEOUT
= 0xA0U
, /*!< Timeout state
164 Value is allowed for gState only */
165 HAL_SMARTCARD_STATE_ERROR
= 0xE0U
/*!< Error
166 Value is allowed for gState only */
167 }HAL_SMARTCARD_StateTypeDef
;
170 * @brief SMARTCARD handle Structure definition
174 USART_TypeDef
*Instance
; /* USART registers base address */
176 SMARTCARD_InitTypeDef Init
; /* SmartCard communication parameters */
178 uint8_t *pTxBuffPtr
; /* Pointer to SmartCard Tx transfer Buffer */
180 uint16_t TxXferSize
; /* SmartCard Tx Transfer size */
182 __IO
uint16_t TxXferCount
; /* SmartCard Tx Transfer Counter */
184 uint8_t *pRxBuffPtr
; /* Pointer to SmartCard Rx transfer Buffer */
186 uint16_t RxXferSize
; /* SmartCard Rx Transfer size */
188 __IO
uint16_t RxXferCount
; /* SmartCard Rx Transfer Counter */
190 DMA_HandleTypeDef
*hdmatx
; /* SmartCard Tx DMA Handle parameters */
192 DMA_HandleTypeDef
*hdmarx
; /* SmartCard Rx DMA Handle parameters */
194 HAL_LockTypeDef Lock
; /* Locking object */
196 __IO HAL_SMARTCARD_StateTypeDef gState
; /* SmartCard state information related to global Handle management
197 and also related to Tx operations.
198 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
200 __IO HAL_SMARTCARD_StateTypeDef RxState
; /* SmartCard state information related to Rx operations.
201 This parameter can be a value of @ref HAL_SMARTCARD_StateTypeDef */
203 __IO
uint32_t ErrorCode
; /* SmartCard Error code */
205 }SMARTCARD_HandleTypeDef
;
211 /* Exported constants --------------------------------------------------------*/
212 /** @defgroup SMARTCARD_Exported_Constants SMARTCARD Exported constants
215 /** @defgroup SMARTCARD_Error_Code SMARTCARD Error Code
216 * @brief SMARTCARD Error Code
219 #define HAL_SMARTCARD_ERROR_NONE 0x00000000U /*!< No error */
220 #define HAL_SMARTCARD_ERROR_PE 0x00000001U /*!< Parity error */
221 #define HAL_SMARTCARD_ERROR_NE 0x00000002U /*!< Noise error */
222 #define HAL_SMARTCARD_ERROR_FE 0x00000004U /*!< Frame error */
223 #define HAL_SMARTCARD_ERROR_ORE 0x00000008U /*!< Overrun error */
224 #define HAL_SMARTCARD_ERROR_DMA 0x00000010U /*!< DMA transfer error */
229 /** @defgroup SMARTCARD_Word_Length SMARTCARD Word Length
232 #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
237 /** @defgroup SMARTCARD_Stop_Bits SMARTCARD Number of Stop Bits
240 #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
241 #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
246 /** @defgroup SMARTCARD_Parity SMARTCARD Parity
249 #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
250 #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
255 /** @defgroup SMARTCARD_Mode SMARTCARD Mode
258 #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
259 #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
260 #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
265 /** @defgroup SMARTCARD_Clock_Polarity SMARTCARD Clock Polarity
268 #define SMARTCARD_POLARITY_LOW 0x00000000U
269 #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
274 /** @defgroup SMARTCARD_Clock_Phase SMARTCARD Clock Phase
277 #define SMARTCARD_PHASE_1EDGE 0x00000000U
278 #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
283 /** @defgroup SMARTCARD_Last_Bit SMARTCARD Last Bit
286 #define SMARTCARD_LASTBIT_DISABLE 0x00000000U
287 #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
292 /** @defgroup SMARTCARD_NACK_State SMARTCARD NACK State
295 #define SMARTCARD_NACK_ENABLE ((uint32_t)USART_CR3_NACK)
296 #define SMARTCARD_NACK_DISABLE 0x00000000U
301 /** @defgroup SMARTCARD_DMA_Requests SMARTCARD DMA requests
304 #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
305 #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
310 /** @defgroup SMARTCARD_Prescaler SMARTCARD Prescaler
313 #define SMARTCARD_PRESCALER_SYSCLK_DIV2 0x00000001U /*!< SYSCLK divided by 2 */
314 #define SMARTCARD_PRESCALER_SYSCLK_DIV4 0x00000002U /*!< SYSCLK divided by 4 */
315 #define SMARTCARD_PRESCALER_SYSCLK_DIV6 0x00000003U /*!< SYSCLK divided by 6 */
316 #define SMARTCARD_PRESCALER_SYSCLK_DIV8 0x00000004U /*!< SYSCLK divided by 8 */
317 #define SMARTCARD_PRESCALER_SYSCLK_DIV10 0x00000005U /*!< SYSCLK divided by 10 */
318 #define SMARTCARD_PRESCALER_SYSCLK_DIV12 0x00000006U /*!< SYSCLK divided by 12 */
319 #define SMARTCARD_PRESCALER_SYSCLK_DIV14 0x00000007U /*!< SYSCLK divided by 14 */
320 #define SMARTCARD_PRESCALER_SYSCLK_DIV16 0x00000008U /*!< SYSCLK divided by 16 */
321 #define SMARTCARD_PRESCALER_SYSCLK_DIV18 0x00000009U /*!< SYSCLK divided by 18 */
322 #define SMARTCARD_PRESCALER_SYSCLK_DIV20 0x0000000AU /*!< SYSCLK divided by 20 */
323 #define SMARTCARD_PRESCALER_SYSCLK_DIV22 0x0000000BU /*!< SYSCLK divided by 22 */
324 #define SMARTCARD_PRESCALER_SYSCLK_DIV24 0x0000000CU /*!< SYSCLK divided by 24 */
325 #define SMARTCARD_PRESCALER_SYSCLK_DIV26 0x0000000DU /*!< SYSCLK divided by 26 */
326 #define SMARTCARD_PRESCALER_SYSCLK_DIV28 0x0000000EU /*!< SYSCLK divided by 28 */
327 #define SMARTCARD_PRESCALER_SYSCLK_DIV30 0x0000000FU /*!< SYSCLK divided by 30 */
328 #define SMARTCARD_PRESCALER_SYSCLK_DIV32 0x00000010U /*!< SYSCLK divided by 32 */
329 #define SMARTCARD_PRESCALER_SYSCLK_DIV34 0x00000011U /*!< SYSCLK divided by 34 */
330 #define SMARTCARD_PRESCALER_SYSCLK_DIV36 0x00000012U /*!< SYSCLK divided by 36 */
331 #define SMARTCARD_PRESCALER_SYSCLK_DIV38 0x00000013U /*!< SYSCLK divided by 38 */
332 #define SMARTCARD_PRESCALER_SYSCLK_DIV40 0x00000014U /*!< SYSCLK divided by 40 */
333 #define SMARTCARD_PRESCALER_SYSCLK_DIV42 0x00000015U /*!< SYSCLK divided by 42 */
334 #define SMARTCARD_PRESCALER_SYSCLK_DIV44 0x00000016U /*!< SYSCLK divided by 44 */
335 #define SMARTCARD_PRESCALER_SYSCLK_DIV46 0x00000017U /*!< SYSCLK divided by 46 */
336 #define SMARTCARD_PRESCALER_SYSCLK_DIV48 0x00000018U /*!< SYSCLK divided by 48 */
337 #define SMARTCARD_PRESCALER_SYSCLK_DIV50 0x00000019U /*!< SYSCLK divided by 50 */
338 #define SMARTCARD_PRESCALER_SYSCLK_DIV52 0x0000001AU /*!< SYSCLK divided by 52 */
339 #define SMARTCARD_PRESCALER_SYSCLK_DIV54 0x0000001BU /*!< SYSCLK divided by 54 */
340 #define SMARTCARD_PRESCALER_SYSCLK_DIV56 0x0000001CU /*!< SYSCLK divided by 56 */
341 #define SMARTCARD_PRESCALER_SYSCLK_DIV58 0x0000001DU /*!< SYSCLK divided by 58 */
342 #define SMARTCARD_PRESCALER_SYSCLK_DIV60 0x0000001EU /*!< SYSCLK divided by 60 */
343 #define SMARTCARD_PRESCALER_SYSCLK_DIV62 0x0000001FU /*!< SYSCLK divided by 62 */
348 /** @defgroup SmartCard_Flags SMARTCARD Flags
349 * Elements values convention: 0xXXXX
350 * - 0xXXXX : Flag mask in the SR register
353 #define SMARTCARD_FLAG_TXE 0x00000080U
354 #define SMARTCARD_FLAG_TC 0x00000040U
355 #define SMARTCARD_FLAG_RXNE 0x00000020U
356 #define SMARTCARD_FLAG_IDLE 0x00000010U
357 #define SMARTCARD_FLAG_ORE 0x00000008U
358 #define SMARTCARD_FLAG_NE 0x00000004U
359 #define SMARTCARD_FLAG_FE 0x00000002U
360 #define SMARTCARD_FLAG_PE 0x00000001U
365 /** @defgroup SmartCard_Interrupt_definition SMARTCARD Interrupts Definition
366 * Elements values convention: 0xY000XXXX
367 * - XXXX : Interrupt mask in the XX register
368 * - Y : Interrupt source register (2bits)
373 #define SMARTCARD_IT_PE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_PEIE))
374 #define SMARTCARD_IT_TXE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TXEIE))
375 #define SMARTCARD_IT_TC ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_TCIE))
376 #define SMARTCARD_IT_RXNE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_RXNEIE))
377 #define SMARTCARD_IT_IDLE ((uint32_t)(SMARTCARD_CR1_REG_INDEX << 28U | USART_CR1_IDLEIE))
378 #define SMARTCARD_IT_ERR ((uint32_t)(SMARTCARD_CR3_REG_INDEX << 28U | USART_CR3_EIE))
387 /* Exported macro ------------------------------------------------------------*/
388 /** @defgroup SMARTCARD_Exported_Macros SMARTCARD Exported Macros
392 /** @brief Reset SMARTCARD handle gstate & RxState
393 * @param __HANDLE__: specifies the SMARTCARD Handle.
396 #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) do{ \
397 (__HANDLE__)->gState = HAL_SMARTCARD_STATE_RESET; \
398 (__HANDLE__)->RxState = HAL_SMARTCARD_STATE_RESET; \
401 /** @brief Flushs the Smartcard DR register
402 * @param __HANDLE__: specifies the SMARTCARD Handle.
404 #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
406 /** @brief Checks whether the specified Smartcard flag is set or not.
407 * @param __HANDLE__: specifies the SMARTCARD Handle.
408 * @param __FLAG__: specifies the flag to check.
409 * This parameter can be one of the following values:
410 * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
411 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
412 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
413 * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag
414 * @arg SMARTCARD_FLAG_ORE: Overrun Error flag
415 * @arg SMARTCARD_FLAG_NE: Noise Error flag
416 * @arg SMARTCARD_FLAG_FE: Framing Error flag
417 * @arg SMARTCARD_FLAG_PE: Parity Error flag
418 * @retval The new state of __FLAG__ (TRUE or FALSE).
420 #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
422 /** @brief Clears the specified Smartcard pending flags.
423 * @param __HANDLE__: specifies the SMARTCARD Handle.
424 * @param __FLAG__: specifies the flag to check.
425 * This parameter can be any combination of the following values:
426 * @arg SMARTCARD_FLAG_TC: Transmission Complete flag.
427 * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag.
429 * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (Overrun
430 * error) flags are cleared by software sequence: a read operation to
431 * USART_SR register followed by a read operation to USART_DR register.
432 * @note RXNE flag can be also cleared by a read to the USART_DR register.
433 * @note TC flag can be also cleared by software sequence: a read operation to
434 * USART_SR register followed by a write operation to USART_DR register.
435 * @note TXE flag is cleared only by a write to the USART_DR register.
437 #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
439 /** @brief Clear the SMARTCARD PE pending flag.
440 * @param __HANDLE__: specifies the USART Handle.
441 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
442 * SMARTCARD peripheral.
445 #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) \
447 __IO uint32_t tmpreg = 0x00U; \
448 tmpreg = (__HANDLE__)->Instance->SR; \
449 tmpreg = (__HANDLE__)->Instance->DR; \
453 /** @brief Clear the SMARTCARD FE pending flag.
454 * @param __HANDLE__: specifies the USART Handle.
455 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
456 * SMARTCARD peripheral.
459 #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
461 /** @brief Clear the SMARTCARD NE pending flag.
462 * @param __HANDLE__: specifies the USART Handle.
463 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
464 * SMARTCARD peripheral.
467 #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
469 /** @brief Clear the SMARTCARD ORE pending flag.
470 * @param __HANDLE__: specifies the USART Handle.
471 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
472 * SMARTCARD peripheral.
475 #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
477 /** @brief Clear the SMARTCARD IDLE pending flag.
478 * @param __HANDLE__: specifies the USART Handle.
479 * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
480 * SMARTCARD peripheral.
483 #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
485 /** @brief Enables or disables the specified SmartCard interrupts.
486 * @param __HANDLE__: specifies the SMARTCARD Handle.
487 * @param __INTERRUPT__: specifies the SMARTCARD interrupt source to check.
488 * This parameter can be one of the following values:
489 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
490 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
491 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
492 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
493 * @arg SMARTCARD_IT_PE: Parity Error interrupt
494 * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
496 #define __HAL_SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
497 ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
498 #define __HAL_SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28U) == 1U)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
499 ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
501 /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
502 * @param __HANDLE__: specifies the SmartCard Handle.
503 * @param __IT__: specifies the SMARTCARD interrupt source to check.
504 * This parameter can be one of the following values:
505 * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
506 * @arg SMARTCARD_IT_TC: Transmission complete interrupt
507 * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
508 * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
509 * @arg SMARTCARD_IT_ERR: Error interrupt
510 * @arg SMARTCARD_IT_PE: Parity Error interrupt
511 * @retval The new state of __IT__ (TRUE or FALSE).
513 #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28U) == 1U)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
515 /** @brief Macro to enable the SMARTCARD's one bit sample method
516 * @param __HANDLE__: specifies the SMARTCARD Handle.
519 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3|= USART_CR3_ONEBIT)
521 /** @brief Macro to disable the SMARTCARD's one bit sample method
522 * @param __HANDLE__: specifies the SMARTCARD Handle.
525 #define __HAL_SMARTCARD_ONE_BIT_SAMPLE_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR3 &= (uint16_t)~((uint16_t)USART_CR3_ONEBIT))
527 /** @brief Enable the USART associated to the SMARTCARD Handle
528 * @param __HANDLE__: specifies the SMARTCARD Handle.
529 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
532 #define __HAL_SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
534 /** @brief Disable the USART associated to the SMARTCARD Handle
535 * @param __HANDLE__: specifies the SMARTCARD Handle.
536 * SMARTCARD Handle selects the USARTx peripheral (USART availability and x value depending on device).
539 #define __HAL_SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
541 /** @brief Macros to enable or disable the SmartCard DMA request.
542 * @param __HANDLE__: specifies the SmartCard Handle.
543 * @param __REQUEST__: specifies the SmartCard DMA request.
544 * This parameter can be one of the following values:
545 * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
546 * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
548 #define __HAL_SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
549 #define __HAL_SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
555 /* Exported functions --------------------------------------------------------*/
556 /** @addtogroup SMARTCARD_Exported_Functions
560 /** @addtogroup SMARTCARD_Exported_Functions_Group1
563 /* Initialization/de-initialization functions **********************************/
564 HAL_StatusTypeDef
HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef
*hsc
);
565 HAL_StatusTypeDef
HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef
*hsc
);
566 HAL_StatusTypeDef
HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef
*hsc
);
567 void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef
*hsc
);
568 void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef
*hsc
);
573 /** @addtogroup SMARTCARD_Exported_Functions_Group2
576 /* IO operation functions *******************************************************/
577 HAL_StatusTypeDef
HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef
*hsc
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
578 HAL_StatusTypeDef
HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef
*hsc
, uint8_t *pData
, uint16_t Size
, uint32_t Timeout
);
579 HAL_StatusTypeDef
HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef
*hsc
, uint8_t *pData
, uint16_t Size
);
580 HAL_StatusTypeDef
HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef
*hsc
, uint8_t *pData
, uint16_t Size
);
581 HAL_StatusTypeDef
HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef
*hsc
, uint8_t *pData
, uint16_t Size
);
582 HAL_StatusTypeDef
HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef
*hsc
, uint8_t *pData
, uint16_t Size
);
583 /* Transfer Abort functions */
584 HAL_StatusTypeDef
HAL_SMARTCARD_Abort(SMARTCARD_HandleTypeDef
*hsc
);
585 HAL_StatusTypeDef
HAL_SMARTCARD_AbortTransmit(SMARTCARD_HandleTypeDef
*hsc
);
586 HAL_StatusTypeDef
HAL_SMARTCARD_AbortReceive(SMARTCARD_HandleTypeDef
*hsc
);
587 HAL_StatusTypeDef
HAL_SMARTCARD_Abort_IT(SMARTCARD_HandleTypeDef
*hsc
);
588 HAL_StatusTypeDef
HAL_SMARTCARD_AbortTransmit_IT(SMARTCARD_HandleTypeDef
*hsc
);
589 HAL_StatusTypeDef
HAL_SMARTCARD_AbortReceive_IT(SMARTCARD_HandleTypeDef
*hsc
);
591 void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef
*hsc
);
592 void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef
*hsc
);
593 void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef
*hsc
);
594 void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef
*hsc
);
595 void HAL_SMARTCARD_AbortCpltCallback(SMARTCARD_HandleTypeDef
*hsc
);
596 void HAL_SMARTCARD_AbortTransmitCpltCallback(SMARTCARD_HandleTypeDef
*hsc
);
597 void HAL_SMARTCARD_AbortReceiveCpltCallback(SMARTCARD_HandleTypeDef
*hsc
);
602 /** @addtogroup SMARTCARD_Exported_Functions_Group3
605 /* Peripheral State functions **************************************************/
606 HAL_SMARTCARD_StateTypeDef
HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef
*hsc
);
607 uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef
*hsc
);
616 /* Private types -------------------------------------------------------------*/
617 /* Private variables ---------------------------------------------------------*/
618 /* Private constants ---------------------------------------------------------*/
619 /** @defgroup SMARTCARD_Private_Constants SMARTCARD Private Constants
623 /** @brief SMARTCARD interruptions flag mask
626 #define SMARTCARD_IT_MASK ((uint32_t) USART_CR1_PEIE | USART_CR1_TXEIE | USART_CR1_TCIE | USART_CR1_RXNEIE | \
627 USART_CR1_IDLEIE | USART_CR3_EIE )
629 #define SMARTCARD_DIV(_PCLK_, _BAUD_) (((_PCLK_)*25U)/(4U*(_BAUD_)))
630 #define SMARTCARD_DIVMANT(_PCLK_, _BAUD_) (SMARTCARD_DIV((_PCLK_), (_BAUD_))/100U)
631 #define SMARTCARD_DIVFRAQ(_PCLK_, _BAUD_) (((SMARTCARD_DIV((_PCLK_), (_BAUD_)) - (SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) * 100U)) * 16U + 50U) / 100U)
632 /* SMARTCARD BRR = mantissa + overflow + fraction
633 = (SMARTCARD DIVMANT << 4) + (SMARTCARD DIVFRAQ & 0xF0) + (SMARTCARD DIVFRAQ & 0x0FU) */
634 #define SMARTCARD_BRR(_PCLK_, _BAUD_) (((SMARTCARD_DIVMANT((_PCLK_), (_BAUD_)) << 4U) + \
635 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0xF0U)) + \
636 (SMARTCARD_DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0FU))
638 #define SMARTCARD_CR1_REG_INDEX 1U
639 #define SMARTCARD_CR3_REG_INDEX 3U
644 /* Private macros --------------------------------------------------------*/
645 /** @defgroup SMARTCARD_Private_Macros SMARTCARD Private Macros
648 #define IS_SMARTCARD_WORD_LENGTH(LENGTH) ((LENGTH) == SMARTCARD_WORDLENGTH_9B)
649 #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
650 ((STOPBITS) == SMARTCARD_STOPBITS_1_5))
651 #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_EVEN) || \
652 ((PARITY) == SMARTCARD_PARITY_ODD))
653 #define IS_SMARTCARD_MODE(MODE) ((((MODE) & 0x0000FFF3U) == 0x00U) && ((MODE) != 0x000000U))
654 #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
655 #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
656 #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
657 ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
658 #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLE) || \
659 ((NACK) == SMARTCARD_NACK_DISABLE))
660 #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001U)
665 /* Private functions ---------------------------------------------------------*/
666 /** @defgroup SMARTCARD_Private_Functions SMARTCARD Private Functions
685 #endif /* __STM32F4xx_HAL_SMARTCARD_H */
687 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/