You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

494 lines
23 KiB

  1. /**
  2. ******************************************************************************
  3. * @file stm32f4xx_hal_smartcard.h
  4. * @author MCD Application Team
  5. * @version V1.1.0
  6. * @date 19-June-2014
  7. * @brief Header file of SMARTCARD HAL module.
  8. ******************************************************************************
  9. * @attention
  10. *
  11. * <h2><center>&copy; COPYRIGHT(c) 2014 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. /* Define to prevent recursive inclusion -------------------------------------*/
  38. #ifndef __STM32F4xx_HAL_SMARTCARD_H
  39. #define __STM32F4xx_HAL_SMARTCARD_H
  40. #ifdef __cplusplus
  41. extern "C" {
  42. #endif
  43. /* Includes ------------------------------------------------------------------*/
  44. #include "stm32f4xx_hal_def.h"
  45. /** @addtogroup STM32F4xx_HAL_Driver
  46. * @{
  47. */
  48. /** @addtogroup SMARTCARD
  49. * @{
  50. */
  51. /* Exported types ------------------------------------------------------------*/
  52. /**
  53. * @brief SMARTCARD Init Structure definition
  54. */
  55. typedef struct
  56. {
  57. uint32_t BaudRate; /*!< This member configures the SmartCard communication baud rate.
  58. The baud rate is computed using the following formula:
  59. - IntegerDivider = ((PCLKx) / (8 * (hirda->Init.BaudRate)))
  60. - FractionalDivider = ((IntegerDivider - ((uint32_t) IntegerDivider)) * 8) + 0.5 */
  61. uint32_t WordLength; /*!< Specifies the number of data bits transmitted or received in a frame.
  62. This parameter can be a value of @ref SMARTCARD_Word_Length */
  63. uint32_t StopBits; /*!< Specifies the number of stop bits transmitted.
  64. This parameter can be a value of @ref SMARTCARD_Stop_Bits */
  65. uint32_t Parity; /*!< Specifies the parity mode.
  66. This parameter can be a value of @ref SMARTCARD_Parity
  67. @note When parity is enabled, the computed parity is inserted
  68. at the MSB position of the transmitted data (9th bit when
  69. the word length is set to 9 data bits; 8th bit when the
  70. word length is set to 8 data bits).*/
  71. uint32_t Mode; /*!< Specifies wether the Receive or Transmit mode is enabled or disabled.
  72. This parameter can be a value of @ref SMARTCARD_Mode */
  73. uint32_t CLKPolarity; /*!< Specifies the steady state of the serial clock.
  74. This parameter can be a value of @ref SMARTCARD_Clock_Polarity */
  75. uint32_t CLKPhase; /*!< Specifies the clock transition on which the bit capture is made.
  76. This parameter can be a value of @ref SMARTCARD_Clock_Phase */
  77. uint32_t CLKLastBit; /*!< Specifies whether the clock pulse corresponding to the last transmitted
  78. data bit (MSB) has to be output on the SCLK pin in synchronous mode.
  79. This parameter can be a value of @ref SMARTCARD_Last_Bit */
  80. uint32_t Prescaler; /*!< Specifies the SmartCard Prescaler.
  81. This parameter must be a number between Min_Data = 0 and Max_Data = 255 */
  82. uint32_t GuardTime; /*!< Specifies the SmartCard Guard Time.
  83. This parameter must be a number between Min_Data = 0 and Max_Data = 255 */
  84. uint32_t NACKState; /*!< Specifies the SmartCard NACK Transmission state.
  85. This parameter can be a value of @ref SmartCard_NACK_State */
  86. }SMARTCARD_InitTypeDef;
  87. /**
  88. * @brief HAL State structures definition
  89. */
  90. typedef enum
  91. {
  92. HAL_SMARTCARD_STATE_RESET = 0x00, /*!< Peripheral is not yet Initialized */
  93. HAL_SMARTCARD_STATE_READY = 0x01, /*!< Peripheral Initialized and ready for use */
  94. HAL_SMARTCARD_STATE_BUSY = 0x02, /*!< an internal process is ongoing */
  95. HAL_SMARTCARD_STATE_BUSY_TX = 0x12, /*!< Data Transmission process is ongoing */
  96. HAL_SMARTCARD_STATE_BUSY_RX = 0x22, /*!< Data Reception process is ongoing */
  97. HAL_SMARTCARD_STATE_BUSY_TX_RX = 0x32, /*!< Data Transmission and Reception process is ongoing */
  98. HAL_SMARTCARD_STATE_TIMEOUT = 0x03, /*!< Timeout state */
  99. HAL_SMARTCARD_STATE_ERROR = 0x04 /*!< Error */
  100. }HAL_SMARTCARD_StateTypeDef;
  101. /**
  102. * @brief HAL SMARTCARD Error Code structure definition
  103. */
  104. typedef enum
  105. {
  106. HAL_SMARTCARD_ERROR_NONE = 0x00, /*!< No error */
  107. HAL_SMARTCARD_ERROR_PE = 0x01, /*!< Parity error */
  108. HAL_SMARTCARD_ERROR_NE = 0x02, /*!< Noise error */
  109. HAL_SMARTCARD_ERROR_FE = 0x04, /*!< frame error */
  110. HAL_SMARTCARD_ERROR_ORE = 0x08, /*!< Overrun error */
  111. HAL_SMARTCARD_ERROR_DMA = 0x10 /*!< DMA transfer error */
  112. }HAL_SMARTCARD_ErrorTypeDef;
  113. /**
  114. * @brief SMARTCARD handle Structure definition
  115. */
  116. typedef struct
  117. {
  118. USART_TypeDef *Instance; /* USART registers base address */
  119. SMARTCARD_InitTypeDef Init; /* SmartCard communication parameters */
  120. uint8_t *pTxBuffPtr; /* Pointer to SmartCard Tx transfer Buffer */
  121. uint16_t TxXferSize; /* SmartCard Tx Transfer size */
  122. uint16_t TxXferCount; /* SmartCard Tx Transfer Counter */
  123. uint8_t *pRxBuffPtr; /* Pointer to SmartCard Rx transfer Buffer */
  124. uint16_t RxXferSize; /* SmartCard Rx Transfer size */
  125. uint16_t RxXferCount; /* SmartCard Rx Transfer Counter */
  126. DMA_HandleTypeDef *hdmatx; /* SmartCard Tx DMA Handle parameters */
  127. DMA_HandleTypeDef *hdmarx; /* SmartCard Rx DMA Handle parameters */
  128. HAL_LockTypeDef Lock; /* Locking object */
  129. __IO HAL_SMARTCARD_StateTypeDef State; /* SmartCard communication state */
  130. __IO HAL_SMARTCARD_ErrorTypeDef ErrorCode; /* SMARTCARD Error code */
  131. }SMARTCARD_HandleTypeDef;
  132. /* Exported constants --------------------------------------------------------*/
  133. /** @defgroup SMARTCARD_Exported_Constants
  134. * @{
  135. */
  136. /** @defgroup SMARTCARD_Word_Length
  137. * @{
  138. */
  139. #define SMARTCARD_WORDLENGTH_8B ((uint32_t)0x00000000)
  140. #define SMARTCARD_WORDLENGTH_9B ((uint32_t)USART_CR1_M)
  141. #define IS_SMARTCARD_WORD_LENGTH(LENGTH) (((LENGTH) == SMARTCARD_WORDLENGTH_8B) || \
  142. ((LENGTH) == SMARTCARD_WORDLENGTH_9B))
  143. /**
  144. * @}
  145. */
  146. /** @defgroup SMARTCARD_Stop_Bits
  147. * @{
  148. */
  149. #define SMARTCARD_STOPBITS_1 ((uint32_t)0x00000000)
  150. #define SMARTCARD_STOPBITS_0_5 ((uint32_t)USART_CR2_STOP_0)
  151. #define SMARTCARD_STOPBITS_2 ((uint32_t)USART_CR2_STOP_1)
  152. #define SMARTCARD_STOPBITS_1_5 ((uint32_t)(USART_CR2_STOP_0 | USART_CR2_STOP_1))
  153. #define IS_SMARTCARD_STOPBITS(STOPBITS) (((STOPBITS) == SMARTCARD_STOPBITS_1) || \
  154. ((STOPBITS) == SMARTCARD_STOPBITS_0_5) || \
  155. ((STOPBITS) == SMARTCARD_STOPBITS_1_5) || \
  156. ((STOPBITS) == SMARTCARD_STOPBITS_2))
  157. /**
  158. * @}
  159. */
  160. /** @defgroup SMARTCARD_Parity
  161. * @{
  162. */
  163. #define SMARTCARD_PARITY_NONE ((uint32_t)0x00000000)
  164. #define SMARTCARD_PARITY_EVEN ((uint32_t)USART_CR1_PCE)
  165. #define SMARTCARD_PARITY_ODD ((uint32_t)(USART_CR1_PCE | USART_CR1_PS))
  166. #define IS_SMARTCARD_PARITY(PARITY) (((PARITY) == SMARTCARD_PARITY_NONE) || \
  167. ((PARITY) == SMARTCARD_PARITY_EVEN) || \
  168. ((PARITY) == SMARTCARD_PARITY_ODD))
  169. /**
  170. * @}
  171. */
  172. /** @defgroup SMARTCARD_Mode
  173. * @{
  174. */
  175. #define SMARTCARD_MODE_RX ((uint32_t)USART_CR1_RE)
  176. #define SMARTCARD_MODE_TX ((uint32_t)USART_CR1_TE)
  177. #define SMARTCARD_MODE_TX_RX ((uint32_t)(USART_CR1_TE |USART_CR1_RE))
  178. #define IS_SMARTCARD_MODE(MODE) ((((MODE) & (uint32_t)0x0000FFF3) == 0x00) && ((MODE) != (uint32_t)0x000000))
  179. /**
  180. * @}
  181. */
  182. /** @defgroup SMARTCARD_Clock_Polarity
  183. * @{
  184. */
  185. #define SMARTCARD_POLARITY_LOW ((uint32_t)0x00000000)
  186. #define SMARTCARD_POLARITY_HIGH ((uint32_t)USART_CR2_CPOL)
  187. #define IS_SMARTCARD_POLARITY(CPOL) (((CPOL) == SMARTCARD_POLARITY_LOW) || ((CPOL) == SMARTCARD_POLARITY_HIGH))
  188. /**
  189. * @}
  190. */
  191. /** @defgroup SMARTCARD_Clock_Phase
  192. * @{
  193. */
  194. #define SMARTCARD_PHASE_1EDGE ((uint32_t)0x00000000)
  195. #define SMARTCARD_PHASE_2EDGE ((uint32_t)USART_CR2_CPHA)
  196. #define IS_SMARTCARD_PHASE(CPHA) (((CPHA) == SMARTCARD_PHASE_1EDGE) || ((CPHA) == SMARTCARD_PHASE_2EDGE))
  197. /**
  198. * @}
  199. */
  200. /** @defgroup SMARTCARD_Last_Bit
  201. * @{
  202. */
  203. #define SMARTCARD_LASTBIT_DISABLE ((uint32_t)0x00000000)
  204. #define SMARTCARD_LASTBIT_ENABLE ((uint32_t)USART_CR2_LBCL)
  205. #define IS_SMARTCARD_LASTBIT(LASTBIT) (((LASTBIT) == SMARTCARD_LASTBIT_DISABLE) || \
  206. ((LASTBIT) == SMARTCARD_LASTBIT_ENABLE))
  207. /**
  208. * @}
  209. */
  210. /** @defgroup SmartCard_NACK_State
  211. * @{
  212. */
  213. #define SMARTCARD_NACK_ENABLED ((uint32_t)USART_CR3_NACK)
  214. #define SMARTCARD_NACK_DISABLED ((uint32_t)0x00000000)
  215. #define IS_SMARTCARD_NACK_STATE(NACK) (((NACK) == SMARTCARD_NACK_ENABLED) || \
  216. ((NACK) == SMARTCARD_NACK_DISABLED))
  217. /**
  218. * @}
  219. */
  220. /** @defgroup SmartCard_DMA_Requests
  221. * @{
  222. */
  223. #define SMARTCARD_DMAREQ_TX ((uint32_t)USART_CR3_DMAT)
  224. #define SMARTCARD_DMAREQ_RX ((uint32_t)USART_CR3_DMAR)
  225. /**
  226. * @}
  227. */
  228. /** @defgroup SmartCard_Flags
  229. * Elements values convention: 0xXXXX
  230. * - 0xXXXX : Flag mask in the SR register
  231. * @{
  232. */
  233. #define SMARTCARD_FLAG_TXE ((uint32_t)0x00000080)
  234. #define SMARTCARD_FLAG_TC ((uint32_t)0x00000040)
  235. #define SMARTCARD_FLAG_RXNE ((uint32_t)0x00000020)
  236. #define SMARTCARD_FLAG_IDLE ((uint32_t)0x00000010)
  237. #define SMARTCARD_FLAG_ORE ((uint32_t)0x00000008)
  238. #define SMARTCARD_FLAG_NE ((uint32_t)0x00000004)
  239. #define SMARTCARD_FLAG_FE ((uint32_t)0x00000002)
  240. #define SMARTCARD_FLAG_PE ((uint32_t)0x00000001)
  241. /**
  242. * @}
  243. */
  244. /** @defgroup SmartCard_Interrupt_definition
  245. * Elements values convention: 0xY000XXXX
  246. * - XXXX : Interrupt mask in the XX register
  247. * - Y : Interrupt source register (2bits)
  248. * - 01: CR1 register
  249. * - 10: CR3 register
  250. *
  251. * @{
  252. */
  253. #define SMARTCARD_IT_PE ((uint32_t)0x10000100)
  254. #define SMARTCARD_IT_TXE ((uint32_t)0x10000080)
  255. #define SMARTCARD_IT_TC ((uint32_t)0x10000040)
  256. #define SMARTCARD_IT_RXNE ((uint32_t)0x10000020)
  257. #define SMARTCARD_IT_IDLE ((uint32_t)0x10000010)
  258. #define SMARTCARD_IT_ERR ((uint32_t)0x20000001)
  259. /**
  260. * @}
  261. */
  262. /**
  263. * @}
  264. */
  265. /* Exported macro ------------------------------------------------------------*/
  266. /** @brief Reset SMARTCARD handle state
  267. * @param __HANDLE__: specifies the SMARTCARD Handle.
  268. * @retval None
  269. */
  270. #define __HAL_SMARTCARD_RESET_HANDLE_STATE(__HANDLE__) ((__HANDLE__)->State = HAL_SMARTCARD_STATE_RESET)
  271. /** @brief Flushs the Smartcard DR register
  272. * @param __HANDLE__: specifies the SMARTCARD Handle.
  273. */
  274. #define __HAL_SMARTCARD_FLUSH_DRREGISTER(__HANDLE__) ((__HANDLE__)->Instance->DR)
  275. /** @brief Checks whether the specified Smartcard flag is set or not.
  276. * @param __HANDLE__: specifies the SMARTCARD Handle.
  277. * @param __FLAG__: specifies the flag to check.
  278. * This parameter can be one of the following values:
  279. * @arg SMARTCARD_FLAG_TXE: Transmit data register empty flag
  280. * @arg SMARTCARD_FLAG_TC: Transmission Complete flag
  281. * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag
  282. * @arg SMARTCARD_FLAG_IDLE: Idle Line detection flag
  283. * @arg SMARTCARD_FLAG_ORE: OverRun Error flag
  284. * @arg SMARTCARD_FLAG_NE: Noise Error flag
  285. * @arg SMARTCARD_FLAG_FE: Framing Error flag
  286. * @arg SMARTCARD_FLAG_PE: Parity Error flag
  287. * @retval The new state of __FLAG__ (TRUE or FALSE).
  288. */
  289. #define __HAL_SMARTCARD_GET_FLAG(__HANDLE__, __FLAG__) (((__HANDLE__)->Instance->SR & (__FLAG__)) == (__FLAG__))
  290. /** @brief Clears the specified Smartcard pending flags.
  291. * @param __HANDLE__: specifies the SMARTCARD Handle.
  292. * @param __FLAG__: specifies the flag to check.
  293. * This parameter can be any combination of the following values:
  294. * @arg SMARTCARD_FLAG_TC: Transmission Complete flag.
  295. * @arg SMARTCARD_FLAG_RXNE: Receive data register not empty flag.
  296. *
  297. * @note PE (Parity error), FE (Framing error), NE (Noise error) and ORE (OverRun
  298. * error) flags are cleared by software sequence: a read operation to
  299. * USART_SR register followed by a read operation to USART_DR register.
  300. * @note RXNE flag can be also cleared by a read to the USART_DR register.
  301. * @note TC flag can be also cleared by software sequence: a read operation to
  302. * USART_SR register followed by a write operation to USART_DR register.
  303. * @note TXE flag is cleared only by a write to the USART_DR register.
  304. */
  305. #define __HAL_SMARTCARD_CLEAR_FLAG(__HANDLE__, __FLAG__) ((__HANDLE__)->Instance->SR = ~(__FLAG__))
  306. /** @brief Clear the SMARTCARD PE pending flag.
  307. * @param __HANDLE__: specifies the USART Handle.
  308. * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
  309. * UART peripheral.
  310. * @retval None
  311. */
  312. #define __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__) do{(__HANDLE__)->Instance->SR;\
  313. (__HANDLE__)->Instance->DR;}while(0)
  314. /** @brief Clear the SMARTCARD FE pending flag.
  315. * @param __HANDLE__: specifies the USART Handle.
  316. * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
  317. * UART peripheral.
  318. * @retval None
  319. */
  320. #define __HAL_SMARTCARD_CLEAR_FEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
  321. /** @brief Clear the SMARTCARD NE pending flag.
  322. * @param __HANDLE__: specifies the USART Handle.
  323. * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
  324. * UART peripheral.
  325. * @retval None
  326. */
  327. #define __HAL_SMARTCARD_CLEAR_NEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
  328. /** @brief Clear the SMARTCARD ORE pending flag.
  329. * @param __HANDLE__: specifies the USART Handle.
  330. * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
  331. * UART peripheral.
  332. * @retval None
  333. */
  334. #define __HAL_SMARTCARD_CLEAR_OREFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
  335. /** @brief Clear the SMARTCARD IDLE pending flag.
  336. * @param __HANDLE__: specifies the USART Handle.
  337. * This parameter can be USARTx where x: 1, 2, 3, 4, 5, 6, 7 or 8 to select the USART or
  338. * UART peripheral.
  339. * @retval None
  340. */
  341. #define __HAL_SMARTCARD_CLEAR_IDLEFLAG(__HANDLE__) __HAL_SMARTCARD_CLEAR_PEFLAG(__HANDLE__)
  342. /** @brief Enables or disables the specified SmartCard interrupts.
  343. * @param __HANDLE__: specifies the SMARTCARD Handle.
  344. * @param __INTERRUPT__: specifies the SMARTCARD interrupt source to check.
  345. * This parameter can be one of the following values:
  346. * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
  347. * @arg SMARTCARD_IT_TC: Transmission complete interrupt
  348. * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
  349. * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
  350. * @arg SMARTCARD_IT_PE: Parity Error interrupt
  351. * @arg SMARTCARD_IT_ERR: Error interrupt(Frame error, noise error, overrun error)
  352. */
  353. #define SMARTCARD_IT_MASK ((uint32_t)0x0000FFFF)
  354. #define __SMARTCARD_ENABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
  355. ((__HANDLE__)->Instance->CR3 |= ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
  356. #define __SMARTCARD_DISABLE_IT(__HANDLE__, __INTERRUPT__) ((((__INTERRUPT__) >> 28) == 1)? ((__HANDLE__)->Instance->CR1 &= ~((__INTERRUPT__) & SMARTCARD_IT_MASK)): \
  357. ((__HANDLE__)->Instance->CR3 &= ~ ((__INTERRUPT__) & SMARTCARD_IT_MASK)))
  358. /** @brief Checks whether the specified SmartCard interrupt has occurred or not.
  359. * @param __HANDLE__: specifies the SmartCard Handle.
  360. * @param __IT__: specifies the SMARTCARD interrupt source to check.
  361. * This parameter can be one of the following values:
  362. * @arg SMARTCARD_IT_TXE: Transmit Data Register empty interrupt
  363. * @arg SMARTCARD_IT_TC: Transmission complete interrupt
  364. * @arg SMARTCARD_IT_RXNE: Receive Data register not empty interrupt
  365. * @arg SMARTCARD_IT_IDLE: Idle line detection interrupt
  366. * @arg SMARTCARD_IT_ERR: Error interrupt
  367. * @arg SMARTCARD_IT_PE: Parity Error interrupt
  368. * @retval The new state of __IT__ (TRUE or FALSE).
  369. */
  370. #define __HAL_SMARTCARD_GET_IT_SOURCE(__HANDLE__, __IT__) (((((__IT__) >> 28) == 1)? (__HANDLE__)->Instance->CR1: (__HANDLE__)->Instance->CR3) & (((uint32_t)(__IT__)) & SMARTCARD_IT_MASK))
  371. /** @brief Macros to enable or disable the SmartCard interface.
  372. * @param __HANDLE__: specifies the SmartCard Handle.
  373. */
  374. #define __SMARTCARD_ENABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 |= USART_CR1_UE)
  375. #define __SMARTCARD_DISABLE(__HANDLE__) ((__HANDLE__)->Instance->CR1 &= ~USART_CR1_UE)
  376. /** @brief Macros to enable or disable the SmartCard DMA request.
  377. * @param __HANDLE__: specifies the SmartCard Handle.
  378. * @param __REQUEST__: specifies the SmartCard DMA request.
  379. * This parameter can be one of the following values:
  380. * @arg SMARTCARD_DMAREQ_TX: SmartCard DMA transmit request
  381. * @arg SMARTCARD_DMAREQ_RX: SmartCard DMA receive request
  382. */
  383. #define __SMARTCARD_DMA_REQUEST_ENABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 |= (__REQUEST__))
  384. #define __SMARTCARD_DMA_REQUEST_DISABLE(__HANDLE__, __REQUEST__) ((__HANDLE__)->Instance->CR3 &= ~(__REQUEST__))
  385. #define __DIV(_PCLK_, _BAUD_) (((_PCLK_)*25)/(4*(_BAUD_)))
  386. #define __DIVMANT(_PCLK_, _BAUD_) (__DIV((_PCLK_), (_BAUD_))/100)
  387. #define __DIVFRAQ(_PCLK_, _BAUD_) (((__DIV((_PCLK_), (_BAUD_)) - (__DIVMANT((_PCLK_), (_BAUD_)) * 100)) * 16 + 50) / 100)
  388. #define __SMARTCARD_BRR(_PCLK_, _BAUD_) ((__DIVMANT((_PCLK_), (_BAUD_)) << 4)|(__DIVFRAQ((_PCLK_), (_BAUD_)) & 0x0F))
  389. #define IS_SMARTCARD_BAUDRATE(BAUDRATE) ((BAUDRATE) < 10500001)
  390. /* Exported functions --------------------------------------------------------*/
  391. /* Initialization/de-initialization functions **********************************/
  392. HAL_StatusTypeDef HAL_SMARTCARD_Init(SMARTCARD_HandleTypeDef *hsc);
  393. HAL_StatusTypeDef HAL_SMARTCARD_ReInit(SMARTCARD_HandleTypeDef *hsc);
  394. HAL_StatusTypeDef HAL_SMARTCARD_DeInit(SMARTCARD_HandleTypeDef *hsc);
  395. void HAL_SMARTCARD_MspInit(SMARTCARD_HandleTypeDef *hsc);
  396. void HAL_SMARTCARD_MspDeInit(SMARTCARD_HandleTypeDef *hsc);
  397. /* IO operation functions *******************************************************/
  398. HAL_StatusTypeDef HAL_SMARTCARD_Transmit(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  399. HAL_StatusTypeDef HAL_SMARTCARD_Receive(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size, uint32_t Timeout);
  400. HAL_StatusTypeDef HAL_SMARTCARD_Transmit_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
  401. HAL_StatusTypeDef HAL_SMARTCARD_Receive_IT(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
  402. HAL_StatusTypeDef HAL_SMARTCARD_Transmit_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
  403. HAL_StatusTypeDef HAL_SMARTCARD_Receive_DMA(SMARTCARD_HandleTypeDef *hsc, uint8_t *pData, uint16_t Size);
  404. void HAL_SMARTCARD_IRQHandler(SMARTCARD_HandleTypeDef *hsc);
  405. void HAL_SMARTCARD_TxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
  406. void HAL_SMARTCARD_RxCpltCallback(SMARTCARD_HandleTypeDef *hsc);
  407. void HAL_SMARTCARD_ErrorCallback(SMARTCARD_HandleTypeDef *hsc);
  408. /* Peripheral State functions **************************************************/
  409. HAL_SMARTCARD_StateTypeDef HAL_SMARTCARD_GetState(SMARTCARD_HandleTypeDef *hsc);
  410. uint32_t HAL_SMARTCARD_GetError(SMARTCARD_HandleTypeDef *hsc);
  411. /**
  412. * @}
  413. */
  414. /**
  415. * @}
  416. */
  417. #ifdef __cplusplus
  418. }
  419. #endif
  420. #endif /* __STM32F4xx_HAL_SMARTCARD_H */
  421. /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/